| File: | ctk/ctkcolorsel.c |
| Warning: | line 1298, column 11 Null pointer passed to 1st parameter expecting 'nonnull' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* CTK - The GIMP Toolkit | ||||
| 2 | * Copyright (C) 2000 Red Hat, Inc. | ||||
| 3 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald | ||||
| 4 | * | ||||
| 5 | * This library is free software; you can redistribute it and/or | ||||
| 6 | * modify it under the terms of the GNU Lesser General Public | ||||
| 7 | * License as published by the Free Software Foundation; either | ||||
| 8 | * version 2 of the License, or (at your option) any later version. | ||||
| 9 | * | ||||
| 10 | * This library is distributed in the hope that it will be useful, | ||||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
| 13 | * Lesser General Public License for more details. | ||||
| 14 | * | ||||
| 15 | * You should have received a copy of the GNU Lesser General Public | ||||
| 16 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
| 17 | */ | ||||
| 18 | |||||
| 19 | /* | ||||
| 20 | * Modified by the CTK+ Team and others 1997-2001. See the AUTHORS | ||||
| 21 | * file for a list of people on the CTK+ Team. See the ChangeLog | ||||
| 22 | * files for a list of changes. These files are distributed with | ||||
| 23 | * CTK+ at ftp://ftp.ctk.org/pub/ctk/. | ||||
| 24 | */ | ||||
| 25 | |||||
| 26 | #include "config.h" | ||||
| 27 | |||||
| 28 | #include "ctkcolorsel.h" | ||||
| 29 | |||||
| 30 | #include <math.h> | ||||
| 31 | #include <string.h> | ||||
| 32 | |||||
| 33 | #include "cdk/cdk.h" | ||||
| 34 | #include "ctkadjustment.h" | ||||
| 35 | #include "ctkorientable.h" | ||||
| 36 | #include "ctkhsv.h" | ||||
| 37 | #include "ctkwindowgroup.h" | ||||
| 38 | #include "ctkselection.h" | ||||
| 39 | #include "ctkcolorutils.h" | ||||
| 40 | #include "ctkdnd.h" | ||||
| 41 | #include "ctkdragsource.h" | ||||
| 42 | #include "ctkdragdest.h" | ||||
| 43 | #include "ctkdrawingarea.h" | ||||
| 44 | #include "ctkframe.h" | ||||
| 45 | #include "ctkgrid.h" | ||||
| 46 | #include "ctklabel.h" | ||||
| 47 | #include "ctkmarshalers.h" | ||||
| 48 | #include "ctkimage.h" | ||||
| 49 | #include "ctkspinbutton.h" | ||||
| 50 | #include "ctkrange.h" | ||||
| 51 | #include "ctkscale.h" | ||||
| 52 | #include "ctkentry.h" | ||||
| 53 | #include "ctkbutton.h" | ||||
| 54 | #include "ctkmenuitem.h" | ||||
| 55 | #include "ctkmain.h" | ||||
| 56 | #include "ctksettings.h" | ||||
| 57 | #include "ctkstock.h" | ||||
| 58 | #include "ctkaccessible.h" | ||||
| 59 | #include "ctksizerequest.h" | ||||
| 60 | #include "ctkseparator.h" | ||||
| 61 | #include "ctkprivate.h" | ||||
| 62 | #include "ctkintl.h" | ||||
| 63 | |||||
| 64 | |||||
| 65 | /** | ||||
| 66 | * SECTION:ctkcolorsel | ||||
| 67 | * @Short_description: Widget used to select a color | ||||
| 68 | * @Title: CtkColorSelection | ||||
| 69 | * | ||||
| 70 | * The #CtkColorSelection is a widget that is used to select | ||||
| 71 | * a color. It consists of a color wheel and number of sliders | ||||
| 72 | * and entry boxes for color parameters such as hue, saturation, | ||||
| 73 | * value, red, green, blue, and opacity. It is found on the standard | ||||
| 74 | * color selection dialog box #CtkColorSelectionDialog. | ||||
| 75 | */ | ||||
| 76 | |||||
| 77 | |||||
| 78 | /* Keep it in sync with ctksettings.c:default_color_palette */ | ||||
| 79 | #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" "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90" | ||||
| 80 | |||||
| 81 | /* Number of elements in the custom palatte */ | ||||
| 82 | #define CTK_CUSTOM_PALETTE_WIDTH10 10 | ||||
| 83 | #define CTK_CUSTOM_PALETTE_HEIGHT2 2 | ||||
| 84 | |||||
| 85 | #define CUSTOM_PALETTE_ENTRY_WIDTH20 20 | ||||
| 86 | #define CUSTOM_PALETTE_ENTRY_HEIGHT20 20 | ||||
| 87 | |||||
| 88 | /* The cursor for the dropper */ | ||||
| 89 | #define DROPPER_WIDTH17 17 | ||||
| 90 | #define DROPPER_HEIGHT17 17 | ||||
| 91 | #define DROPPER_STRIDE(17 * 4) (DROPPER_WIDTH17 * 4) | ||||
| 92 | #define DROPPER_X_HOT2 2 | ||||
| 93 | #define DROPPER_Y_HOT16 16 | ||||
| 94 | |||||
| 95 | #define SAMPLE_WIDTH64 64 | ||||
| 96 | #define SAMPLE_HEIGHT28 28 | ||||
| 97 | #define CHECK_SIZE16 16 | ||||
| 98 | #define BIG_STEP20 20 | ||||
| 99 | |||||
| 100 | /* Conversion between 0->1 double and and guint16. See | ||||
| 101 | * scale_round() below for more general conversions | ||||
| 102 | */ | ||||
| 103 | #define SCALE(i)(i / 65535.) (i / 65535.) | ||||
| 104 | #define UNSCALE(d)((guint16)(d * 65535 + 0.5)) ((guint16)(d * 65535 + 0.5)) | ||||
| 105 | #define INTENSITY(r, g, b)((r) * 0.30 + (g) * 0.59 + (b) * 0.11) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) | ||||
| 106 | |||||
| 107 | enum { | ||||
| 108 | COLOR_CHANGED, | ||||
| 109 | LAST_SIGNAL | ||||
| 110 | }; | ||||
| 111 | |||||
| 112 | enum { | ||||
| 113 | PROP_0, | ||||
| 114 | PROP_HAS_PALETTE, | ||||
| 115 | PROP_HAS_OPACITY_CONTROL, | ||||
| 116 | PROP_CURRENT_COLOR, | ||||
| 117 | PROP_CURRENT_ALPHA, | ||||
| 118 | PROP_CURRENT_RGBA | ||||
| 119 | }; | ||||
| 120 | |||||
| 121 | enum { | ||||
| 122 | COLORSEL_RED = 0, | ||||
| 123 | COLORSEL_GREEN = 1, | ||||
| 124 | COLORSEL_BLUE = 2, | ||||
| 125 | COLORSEL_OPACITY = 3, | ||||
| 126 | COLORSEL_HUE, | ||||
| 127 | COLORSEL_SATURATION, | ||||
| 128 | COLORSEL_VALUE, | ||||
| 129 | COLORSEL_NUM_CHANNELS | ||||
| 130 | }; | ||||
| 131 | |||||
| 132 | |||||
| 133 | struct _CtkColorSelectionPrivate | ||||
| 134 | { | ||||
| 135 | guint has_opacity : 1; | ||||
| 136 | guint has_palette : 1; | ||||
| 137 | guint changing : 1; | ||||
| 138 | guint default_set : 1; | ||||
| 139 | guint default_alpha_set : 1; | ||||
| 140 | guint has_grab : 1; | ||||
| 141 | |||||
| 142 | gdouble color[COLORSEL_NUM_CHANNELS]; | ||||
| 143 | gdouble old_color[COLORSEL_NUM_CHANNELS]; | ||||
| 144 | |||||
| 145 | CtkWidget *triangle_colorsel; | ||||
| 146 | CtkWidget *hue_spinbutton; | ||||
| 147 | CtkWidget *sat_spinbutton; | ||||
| 148 | CtkWidget *val_spinbutton; | ||||
| 149 | CtkWidget *red_spinbutton; | ||||
| 150 | CtkWidget *green_spinbutton; | ||||
| 151 | CtkWidget *blue_spinbutton; | ||||
| 152 | CtkWidget *opacity_slider; | ||||
| 153 | CtkWidget *opacity_label; | ||||
| 154 | CtkWidget *opacity_entry; | ||||
| 155 | CtkWidget *palette_frame; | ||||
| 156 | CtkWidget *hex_entry; | ||||
| 157 | |||||
| 158 | /* The Palette code */ | ||||
| 159 | CtkWidget *custom_palette [CTK_CUSTOM_PALETTE_WIDTH10][CTK_CUSTOM_PALETTE_HEIGHT2]; | ||||
| 160 | |||||
| 161 | /* The color_sample stuff */ | ||||
| 162 | CtkWidget *sample_area; | ||||
| 163 | CtkWidget *old_sample; | ||||
| 164 | CtkWidget *cur_sample; | ||||
| 165 | CtkWidget *colorsel; | ||||
| 166 | |||||
| 167 | /* Window for grabbing on */ | ||||
| 168 | CtkWidget *dropper_grab_widget; | ||||
| 169 | guint32 grab_time; | ||||
| 170 | CdkDevice *keyboard_device; | ||||
| 171 | CdkDevice *pointer_device; | ||||
| 172 | |||||
| 173 | /* Connection to settings */ | ||||
| 174 | gulong settings_connection; | ||||
| 175 | }; | ||||
| 176 | |||||
| 177 | |||||
| 178 | static void ctk_color_selection_destroy (CtkWidget *widget); | ||||
| 179 | static void ctk_color_selection_finalize (GObject *object); | ||||
| 180 | static void update_color (CtkColorSelection *colorsel); | ||||
| 181 | static void ctk_color_selection_set_property (GObject *object, | ||||
| 182 | guint prop_id, | ||||
| 183 | const GValue *value, | ||||
| 184 | GParamSpec *pspec); | ||||
| 185 | static void ctk_color_selection_get_property (GObject *object, | ||||
| 186 | guint prop_id, | ||||
| 187 | GValue *value, | ||||
| 188 | GParamSpec *pspec); | ||||
| 189 | |||||
| 190 | static void ctk_color_selection_realize (CtkWidget *widget); | ||||
| 191 | static void ctk_color_selection_unrealize (CtkWidget *widget); | ||||
| 192 | static void ctk_color_selection_show_all (CtkWidget *widget); | ||||
| 193 | static gboolean ctk_color_selection_grab_broken (CtkWidget *widget, | ||||
| 194 | CdkEventGrabBroken *event); | ||||
| 195 | |||||
| 196 | static void ctk_color_selection_set_palette_color (CtkColorSelection *colorsel, | ||||
| 197 | gint index, | ||||
| 198 | CdkColor *color); | ||||
| 199 | static void set_focus_line_attributes (CtkWidget *drawing_area, | ||||
| 200 | cairo_t *cr, | ||||
| 201 | gint *focus_width); | ||||
| 202 | static void default_noscreen_change_palette_func (const CdkColor *colors, | ||||
| 203 | gint n_colors); | ||||
| 204 | static void default_change_palette_func (CdkScreen *screen, | ||||
| 205 | const CdkColor *colors, | ||||
| 206 | gint n_colors); | ||||
| 207 | static void make_control_relations (AtkObject *atk_obj, | ||||
| 208 | CtkWidget *widget); | ||||
| 209 | static void make_all_relations (AtkObject *atk_obj, | ||||
| 210 | CtkColorSelectionPrivate *priv); | ||||
| 211 | |||||
| 212 | static void hsv_changed (CtkWidget *hsv, | ||||
| 213 | gpointer data); | ||||
| 214 | static void get_screen_color (CtkWidget *button); | ||||
| 215 | static void adjustment_changed (CtkAdjustment *adjustment, | ||||
| 216 | gpointer data); | ||||
| 217 | static void opacity_entry_changed (CtkWidget *opacity_entry, | ||||
| 218 | gpointer data); | ||||
| 219 | static void hex_changed (CtkWidget *hex_entry, | ||||
| 220 | gpointer data); | ||||
| 221 | static gboolean hex_focus_out (CtkWidget *hex_entry, | ||||
| 222 | CdkEventFocus *event, | ||||
| 223 | gpointer data); | ||||
| 224 | static void color_sample_new (CtkColorSelection *colorsel); | ||||
| 225 | static void make_label_spinbutton (CtkColorSelection *colorsel, | ||||
| 226 | CtkWidget **spinbutton, | ||||
| 227 | gchar *text, | ||||
| 228 | CtkWidget *table, | ||||
| 229 | gint i, | ||||
| 230 | gint j, | ||||
| 231 | gint channel_type, | ||||
| 232 | const gchar *tooltip); | ||||
| 233 | static void make_palette_frame (CtkColorSelection *colorsel, | ||||
| 234 | CtkWidget *table, | ||||
| 235 | gint i, | ||||
| 236 | gint j); | ||||
| 237 | static void set_selected_palette (CtkColorSelection *colorsel, | ||||
| 238 | int x, | ||||
| 239 | int y); | ||||
| 240 | static void set_focus_line_attributes (CtkWidget *drawing_area, | ||||
| 241 | cairo_t *cr, | ||||
| 242 | gint *focus_width); | ||||
| 243 | static gboolean mouse_press (CtkWidget *invisible, | ||||
| 244 | CdkEventButton *event, | ||||
| 245 | gpointer data); | ||||
| 246 | static void palette_change_notify_instance (GObject *object, | ||||
| 247 | GParamSpec *pspec, | ||||
| 248 | gpointer data); | ||||
| 249 | static void update_palette (CtkColorSelection *colorsel); | ||||
| 250 | static void shutdown_eyedropper (CtkWidget *widget); | ||||
| 251 | |||||
| 252 | static guint color_selection_signals[LAST_SIGNAL] = { 0 }; | ||||
| 253 | |||||
| 254 | static CtkColorSelectionChangePaletteFunc noscreen_change_palette_hook = default_noscreen_change_palette_func; | ||||
| 255 | static CtkColorSelectionChangePaletteWithScreenFunc change_palette_hook = default_change_palette_func; | ||||
| 256 | |||||
| 257 | static const guchar dropper_bits[] = { | ||||
| 258 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 259 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377" | ||||
| 260 | "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 261 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\0\0\0\377" | ||||
| 262 | "\0\0\0\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 263 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377" | ||||
| 264 | "\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377" | ||||
| 265 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377" | ||||
| 266 | "\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377\0\0" | ||||
| 267 | "\0\377\0\0\0\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 268 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\0\0\0\377\0\0\0\377\0" | ||||
| 269 | "\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377" | ||||
| 270 | "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 271 | "\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0" | ||||
| 272 | "\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 273 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\0\0\0\377\0\0" | ||||
| 274 | "\0\377\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0" | ||||
| 275 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377" | ||||
| 276 | "\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377\377\377" | ||||
| 277 | "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 278 | "\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" | ||||
| 279 | "\0\0\0\377\377\377\377\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0" | ||||
| 280 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377" | ||||
| 281 | "\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\377\377" | ||||
| 282 | "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 283 | "\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0" | ||||
| 284 | "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 285 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377" | ||||
| 286 | "\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 287 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377" | ||||
| 288 | "\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 289 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 290 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0" | ||||
| 291 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 292 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\0\0" | ||||
| 293 | "\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 294 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0\0\0\377\0\0\0" | ||||
| 295 | "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 296 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0" | ||||
| 297 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
| 298 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}; | ||||
| 299 | |||||
| 300 | G_DEFINE_TYPE_WITH_PRIVATE (CtkColorSelection, ctk_color_selection, CTK_TYPE_BOX)static void ctk_color_selection_init (CtkColorSelection *self ); static void ctk_color_selection_class_init (CtkColorSelectionClass *klass); static GType ctk_color_selection_get_type_once (void ); static gpointer ctk_color_selection_parent_class = ((void* )0); static gint CtkColorSelection_private_offset; static void ctk_color_selection_class_intern_init (gpointer klass) { ctk_color_selection_parent_class = g_type_class_peek_parent (klass); if (CtkColorSelection_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkColorSelection_private_offset ); ctk_color_selection_class_init ((CtkColorSelectionClass*) klass ); } __attribute__ ((__unused__)) static inline gpointer ctk_color_selection_get_instance_private (CtkColorSelection *self) { return (((gpointer) ((guint8*) ( self) + (glong) (CtkColorSelection_private_offset)))); } GType ctk_color_selection_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); (void ) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*) 0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_color_selection_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_color_selection_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((ctk_box_get_type ()), g_intern_static_string ("CtkColorSelection" ), sizeof (CtkColorSelectionClass), (GClassInitFunc)(void (*) (void)) ctk_color_selection_class_intern_init, sizeof (CtkColorSelection ), (GInstanceInitFunc)(void (*)(void)) ctk_color_selection_init , (GTypeFlags) 0); { {{ CtkColorSelection_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkColorSelectionPrivate)); };} } return g_define_type_id; } | ||||
| 301 | |||||
| 302 | static void | ||||
| 303 | ctk_color_selection_class_init (CtkColorSelectionClass *klass) | ||||
| 304 | { | ||||
| 305 | GObjectClass *gobject_class; | ||||
| 306 | CtkWidgetClass *widget_class; | ||||
| 307 | |||||
| 308 | gobject_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); | ||||
| 309 | gobject_class->finalize = ctk_color_selection_finalize; | ||||
| 310 | gobject_class->set_property = ctk_color_selection_set_property; | ||||
| 311 | gobject_class->get_property = ctk_color_selection_get_property; | ||||
| 312 | |||||
| 313 | widget_class = CTK_WIDGET_CLASS (klass)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), ((ctk_widget_get_type ())))))); | ||||
| 314 | widget_class->destroy = ctk_color_selection_destroy; | ||||
| 315 | widget_class->realize = ctk_color_selection_realize; | ||||
| 316 | widget_class->unrealize = ctk_color_selection_unrealize; | ||||
| 317 | widget_class->show_all = ctk_color_selection_show_all; | ||||
| 318 | widget_class->grab_broken_event = ctk_color_selection_grab_broken; | ||||
| 319 | |||||
| 320 | g_object_class_install_property (gobject_class, | ||||
| 321 | PROP_HAS_OPACITY_CONTROL, | ||||
| 322 | g_param_spec_boolean ("has-opacity-control", | ||||
| 323 | P_("Has Opacity Control")g_dgettext("ctk30" "-properties","Has Opacity Control"), | ||||
| 324 | P_("Whether the color selector should allow setting opacity")g_dgettext("ctk30" "-properties","Whether the color selector should allow setting opacity" ), | ||||
| 325 | FALSE(0), | ||||
| 326 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)); | ||||
| 327 | g_object_class_install_property (gobject_class, | ||||
| 328 | PROP_HAS_PALETTE, | ||||
| 329 | g_param_spec_boolean ("has-palette", | ||||
| 330 | P_("Has palette")g_dgettext("ctk30" "-properties","Has palette"), | ||||
| 331 | P_("Whether a palette should be used")g_dgettext("ctk30" "-properties","Whether a palette should be used" ), | ||||
| 332 | FALSE(0), | ||||
| 333 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)); | ||||
| 334 | |||||
| 335 | /** | ||||
| 336 | * CtkColorSelection:current-color: | ||||
| 337 | * | ||||
| 338 | * The current CdkColor color. | ||||
| 339 | */ | ||||
| 340 | g_object_class_install_property (gobject_class, | ||||
| 341 | PROP_CURRENT_COLOR, | ||||
| 342 | g_param_spec_boxed ("current-color", | ||||
| 343 | P_("Current Color")g_dgettext("ctk30" "-properties","Current Color"), | ||||
| 344 | P_("The current color")g_dgettext("ctk30" "-properties","The current color"), | ||||
| 345 | CDK_TYPE_COLOR(cdk_color_get_type ()), | ||||
| 346 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)); | ||||
| 347 | g_object_class_install_property (gobject_class, | ||||
| 348 | PROP_CURRENT_ALPHA, | ||||
| 349 | g_param_spec_uint ("current-alpha", | ||||
| 350 | P_("Current Alpha")g_dgettext("ctk30" "-properties","Current Alpha"), | ||||
| 351 | P_("The current opacity value (0 fully transparent, 65535 fully opaque)")g_dgettext("ctk30" "-properties","The current opacity value (0 fully transparent, 65535 fully opaque)" ), | ||||
| 352 | 0, 65535, 65535, | ||||
| 353 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)); | ||||
| 354 | |||||
| 355 | /** | ||||
| 356 | * CtkColorSelection:current-rgba: | ||||
| 357 | * | ||||
| 358 | * The current RGBA color. | ||||
| 359 | * | ||||
| 360 | * Since: 3.0 | ||||
| 361 | */ | ||||
| 362 | g_object_class_install_property (gobject_class, | ||||
| 363 | PROP_CURRENT_RGBA, | ||||
| 364 | g_param_spec_boxed ("current-rgba", | ||||
| 365 | P_("Current RGBA")g_dgettext("ctk30" "-properties","Current RGBA"), | ||||
| 366 | P_("The current RGBA color")g_dgettext("ctk30" "-properties","The current RGBA color"), | ||||
| 367 | CDK_TYPE_RGBA(cdk_rgba_get_type ()), | ||||
| 368 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)); | ||||
| 369 | |||||
| 370 | /** | ||||
| 371 | * CtkColorSelection::color-changed: | ||||
| 372 | * @colorselection: the object which received the signal. | ||||
| 373 | * | ||||
| 374 | * This signal is emitted when the color changes in the #CtkColorSelection | ||||
| 375 | * according to its update policy. | ||||
| 376 | */ | ||||
| 377 | color_selection_signals[COLOR_CHANGED] = | ||||
| 378 | g_signal_new (I_("color-changed")g_intern_static_string ("color-changed"), | ||||
| 379 | G_OBJECT_CLASS_TYPE (gobject_class)((((GTypeClass*) (gobject_class))->g_type)), | ||||
| 380 | G_SIGNAL_RUN_FIRST, | ||||
| 381 | G_STRUCT_OFFSET (CtkColorSelectionClass, color_changed)((glong) __builtin_offsetof(CtkColorSelectionClass, color_changed )), | ||||
| 382 | NULL((void*)0), NULL((void*)0), | ||||
| 383 | NULL((void*)0), | ||||
| 384 | G_TYPE_NONE((GType) ((1) << (2))), 0); | ||||
| 385 | } | ||||
| 386 | |||||
| 387 | static void | ||||
| 388 | ctk_color_selection_init (CtkColorSelection *colorsel) | ||||
| 389 | { | ||||
| 390 | CtkWidget *top_hbox; | ||||
| 391 | CtkWidget *top_right_vbox; | ||||
| 392 | CtkWidget *table, *label, *hbox, *frame, *vbox, *button; | ||||
| 393 | CtkAdjustment *adjust; | ||||
| 394 | CtkWidget *picker_image; | ||||
| 395 | gint i, j; | ||||
| 396 | CtkColorSelectionPrivate *priv; | ||||
| 397 | AtkObject *atk_obj; | ||||
| 398 | GList *focus_chain = NULL((void*)0); | ||||
| 399 | |||||
| 400 | ctk_orientable_set_orientation (CTK_ORIENTABLE (colorsel)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), ((ctk_orientable_get_type ())))))), | ||||
| 401 | CTK_ORIENTATION_VERTICAL); | ||||
| 402 | |||||
| 403 | ctk_widget_push_composite_child (); | ||||
| 404 | |||||
| 405 | priv = colorsel->private_data = ctk_color_selection_get_instance_private (colorsel); | ||||
| 406 | priv->changing = FALSE(0); | ||||
| 407 | priv->default_set = FALSE(0); | ||||
| 408 | priv->default_alpha_set = FALSE(0); | ||||
| 409 | |||||
| 410 | top_hbox = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 12); | ||||
| 411 | ctk_box_pack_start (CTK_BOX (colorsel)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), ((ctk_box_get_type ())))))), top_hbox, FALSE(0), FALSE(0), 0); | ||||
| 412 | |||||
| 413 | vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 6); | ||||
| 414 | priv->triangle_colorsel = ctk_hsv_new (); | ||||
| 415 | g_signal_connect (priv->triangle_colorsel, "changed",g_signal_connect_data ((priv->triangle_colorsel), ("changed" ), (((GCallback) (hsv_changed))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 416 | G_CALLBACK (hsv_changed), colorsel)g_signal_connect_data ((priv->triangle_colorsel), ("changed" ), (((GCallback) (hsv_changed))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 417 | ctk_hsv_set_metrics (CTK_HSV (priv->triangle_colorsel)((((CtkHSV*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->triangle_colorsel)), ((ctk_hsv_get_type ()))))) ), 174, 15); | ||||
| 418 | ctk_box_pack_start (CTK_BOX (top_hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((top_hbox)), ((ctk_box_get_type ())))))), vbox, FALSE(0), FALSE(0), 0); | ||||
| 419 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), priv->triangle_colorsel, FALSE(0), FALSE(0), 0); | ||||
| 420 | ctk_widget_set_tooltip_text (priv->triangle_colorsel, | ||||
| 421 | _("Select the color you want from the outer ring. "((char *) g_dgettext ("ctk30", "Select the color you want from the outer ring. " "Select the darkness or lightness of that color " "using the inner triangle." )) | ||||
| 422 | "Select the darkness or lightness of that color "((char *) g_dgettext ("ctk30", "Select the color you want from the outer ring. " "Select the darkness or lightness of that color " "using the inner triangle." )) | ||||
| 423 | "using the inner triangle.")((char *) g_dgettext ("ctk30", "Select the color you want from the outer ring. " "Select the darkness or lightness of that color " "using the inner triangle." ))); | ||||
| 424 | |||||
| 425 | hbox = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 6); | ||||
| 426 | ctk_box_pack_end (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), hbox, FALSE(0), FALSE(0), 0); | ||||
| 427 | |||||
| 428 | frame = ctk_frame_new (NULL((void*)0)); | ||||
| 429 | ctk_widget_set_size_request (frame, -1, 30); | ||||
| 430 | ctk_frame_set_shadow_type (CTK_FRAME (frame)((((CtkFrame*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((frame)), ((ctk_frame_get_type ())))))), CTK_SHADOW_IN); | ||||
| 431 | color_sample_new (colorsel); | ||||
| 432 | ctk_container_add (CTK_CONTAINER (frame)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((frame)), ((ctk_container_get_type ())))))), priv->sample_area); | ||||
| 433 | ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((ctk_box_get_type ())))))), frame, TRUE(!(0)), TRUE(!(0)), 0); | ||||
| 434 | |||||
| 435 | button = ctk_button_new (); | ||||
| 436 | |||||
| 437 | ctk_widget_set_events (button, CDK_POINTER_MOTION_MASK | CDK_POINTER_MOTION_HINT_MASK); | ||||
| 438 | g_object_set_data (G_OBJECT (button)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((button)), (((GType) ((20) << (2)))))))), I_("COLORSEL")g_intern_static_string ("COLORSEL"), colorsel); | ||||
| 439 | g_signal_connect (button, "clicked",g_signal_connect_data ((button), ("clicked"), (((GCallback) ( get_screen_color))), (((void*)0)), ((void*)0), (GConnectFlags ) 0) | ||||
| 440 | G_CALLBACK (get_screen_color), NULL)g_signal_connect_data ((button), ("clicked"), (((GCallback) ( get_screen_color))), (((void*)0)), ((void*)0), (GConnectFlags ) 0); | ||||
| 441 | picker_image = ctk_image_new_from_stock (CTK_STOCK_COLOR_PICKER((CtkStock)"ctk-color-picker"), CTK_ICON_SIZE_BUTTON); | ||||
| 442 | ctk_container_add (CTK_CONTAINER (button)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((button)), ((ctk_container_get_type ())))))), picker_image); | ||||
| 443 | ctk_widget_show (CTK_WIDGET (picker_image)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((picker_image)), ((ctk_widget_get_type ()))))))); | ||||
| 444 | ctk_box_pack_end (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((ctk_box_get_type ())))))), button, FALSE(0), FALSE(0), 0); | ||||
| 445 | |||||
| 446 | ctk_widget_set_tooltip_text (button, | ||||
| 447 | _("Click the eyedropper, then click a color "((char *) g_dgettext ("ctk30", "Click the eyedropper, then click a color " "anywhere on your screen to select that color.")) | ||||
| 448 | "anywhere on your screen to select that color.")((char *) g_dgettext ("ctk30", "Click the eyedropper, then click a color " "anywhere on your screen to select that color."))); | ||||
| 449 | |||||
| 450 | top_right_vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 6); | ||||
| 451 | ctk_box_pack_start (CTK_BOX (top_hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((top_hbox)), ((ctk_box_get_type ())))))), top_right_vbox, FALSE(0), FALSE(0), 0); | ||||
| 452 | table = ctk_grid_new (); | ||||
| 453 | ctk_box_pack_start (CTK_BOX (top_right_vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((top_right_vbox)), ((ctk_box_get_type ())))))), table, FALSE(0), FALSE(0), 0); | ||||
| 454 | ctk_grid_set_row_spacing (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), 6); | ||||
| 455 | ctk_grid_set_column_spacing (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), 12); | ||||
| 456 | |||||
| 457 | make_label_spinbutton (colorsel, &priv->hue_spinbutton, _("_Hue:")((char *) g_dgettext ("ctk30", "_Hue:")), table, 0, 0, COLORSEL_HUE, | ||||
| 458 | _("Position on the color wheel.")((char *) g_dgettext ("ctk30", "Position on the color wheel." ))); | ||||
| 459 | ctk_spin_button_set_wrap (CTK_SPIN_BUTTON (priv->hue_spinbutton)((((CtkSpinButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->hue_spinbutton)), ((ctk_spin_button_get_type () )))))), TRUE(!(0))); | ||||
| 460 | make_label_spinbutton (colorsel, &priv->sat_spinbutton, _("S_aturation:")((char *) g_dgettext ("ctk30", "S_aturation:")), table, 0, 1, COLORSEL_SATURATION, | ||||
| 461 | _("Intensity of the color.")((char *) g_dgettext ("ctk30", "Intensity of the color."))); | ||||
| 462 | make_label_spinbutton (colorsel, &priv->val_spinbutton, _("_Value:")((char *) g_dgettext ("ctk30", "_Value:")), table, 0, 2, COLORSEL_VALUE, | ||||
| 463 | _("Brightness of the color.")((char *) g_dgettext ("ctk30", "Brightness of the color."))); | ||||
| 464 | make_label_spinbutton (colorsel, &priv->red_spinbutton, _("_Red:")((char *) g_dgettext ("ctk30", "_Red:")), table, 6, 0, COLORSEL_RED, | ||||
| 465 | _("Amount of red light in the color.")((char *) g_dgettext ("ctk30", "Amount of red light in the color." ))); | ||||
| 466 | make_label_spinbutton (colorsel, &priv->green_spinbutton, _("_Green:")((char *) g_dgettext ("ctk30", "_Green:")), table, 6, 1, COLORSEL_GREEN, | ||||
| 467 | _("Amount of green light in the color.")((char *) g_dgettext ("ctk30", "Amount of green light in the color." ))); | ||||
| 468 | make_label_spinbutton (colorsel, &priv->blue_spinbutton, _("_Blue:")((char *) g_dgettext ("ctk30", "_Blue:")), table, 6, 2, COLORSEL_BLUE, | ||||
| 469 | _("Amount of blue light in the color.")((char *) g_dgettext ("ctk30", "Amount of blue light in the color." ))); | ||||
| 470 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), ctk_separator_new (CTK_ORIENTATION_HORIZONTAL), 0, 3, 8, 1); | ||||
| 471 | |||||
| 472 | priv->opacity_label = ctk_label_new_with_mnemonic (_("Op_acity:")((char *) g_dgettext ("ctk30", "Op_acity:"))); | ||||
| 473 | ctk_widget_set_halign (priv->opacity_label, CTK_ALIGN_START); | ||||
| 474 | ctk_widget_set_valign (priv->opacity_label, CTK_ALIGN_CENTER); | ||||
| 475 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), priv->opacity_label, 0, 4, 1, 1); | ||||
| 476 | adjust = ctk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0); | ||||
| 477 | g_object_set_data (G_OBJECT (adjust)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((adjust)), (((GType) ((20) << (2)))))))), I_("COLORSEL")g_intern_static_string ("COLORSEL"), colorsel); | ||||
| 478 | priv->opacity_slider = ctk_scale_new (CTK_ORIENTATION_HORIZONTAL, adjust); | ||||
| 479 | ctk_widget_set_tooltip_text (priv->opacity_slider, | ||||
| 480 | _("Transparency of the color.")((char *) g_dgettext ("ctk30", "Transparency of the color."))); | ||||
| 481 | ctk_label_set_mnemonic_widget (CTK_LABEL (priv->opacity_label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->opacity_label)), ((ctk_label_get_type ())))))), | ||||
| 482 | priv->opacity_slider); | ||||
| 483 | ctk_scale_set_draw_value (CTK_SCALE (priv->opacity_slider)((((CtkScale*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->opacity_slider)), ((ctk_scale_get_type ())))))), FALSE(0)); | ||||
| 484 | g_signal_connect (adjust, "value-changed",g_signal_connect_data ((adjust), ("value-changed"), (((GCallback ) (adjustment_changed))), (((gpointer) (glong) (COLORSEL_OPACITY ))), ((void*)0), (GConnectFlags) 0) | ||||
| 485 | G_CALLBACK (adjustment_changed),g_signal_connect_data ((adjust), ("value-changed"), (((GCallback ) (adjustment_changed))), (((gpointer) (glong) (COLORSEL_OPACITY ))), ((void*)0), (GConnectFlags) 0) | ||||
| 486 | GINT_TO_POINTER (COLORSEL_OPACITY))g_signal_connect_data ((adjust), ("value-changed"), (((GCallback ) (adjustment_changed))), (((gpointer) (glong) (COLORSEL_OPACITY ))), ((void*)0), (GConnectFlags) 0); | ||||
| 487 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), priv->opacity_slider, 1, 4, 6, 1); | ||||
| 488 | priv->opacity_entry = ctk_entry_new (); | ||||
| 489 | ctk_widget_set_tooltip_text (priv->opacity_entry, | ||||
| 490 | _("Transparency of the color.")((char *) g_dgettext ("ctk30", "Transparency of the color."))); | ||||
| 491 | ctk_widget_set_size_request (priv->opacity_entry, 40, -1); | ||||
| 492 | |||||
| 493 | g_signal_connect (priv->opacity_entry, "activate",g_signal_connect_data ((priv->opacity_entry), ("activate") , (((GCallback) (opacity_entry_changed))), (colorsel), ((void *)0), (GConnectFlags) 0) | ||||
| 494 | G_CALLBACK (opacity_entry_changed), colorsel)g_signal_connect_data ((priv->opacity_entry), ("activate") , (((GCallback) (opacity_entry_changed))), (colorsel), ((void *)0), (GConnectFlags) 0); | ||||
| 495 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), priv->opacity_entry, 7, 4, 1, 1); | ||||
| 496 | |||||
| 497 | label = ctk_label_new_with_mnemonic (_("Color _name:")((char *) g_dgettext ("ctk30", "Color _name:"))); | ||||
| 498 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), label, 0, 5, 1, 1); | ||||
| 499 | ctk_widget_set_halign (label, CTK_ALIGN_START); | ||||
| 500 | ctk_widget_set_valign (label, CTK_ALIGN_CENTER); | ||||
| 501 | priv->hex_entry = ctk_entry_new (); | ||||
| 502 | |||||
| 503 | ctk_label_set_mnemonic_widget (CTK_LABEL (label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((ctk_label_get_type ())))))), priv->hex_entry); | ||||
| 504 | |||||
| 505 | g_signal_connect (priv->hex_entry, "activate",g_signal_connect_data ((priv->hex_entry), ("activate"), (( (GCallback) (hex_changed))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 506 | G_CALLBACK (hex_changed), colorsel)g_signal_connect_data ((priv->hex_entry), ("activate"), (( (GCallback) (hex_changed))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 507 | |||||
| 508 | g_signal_connect (priv->hex_entry, "focus-out-event",g_signal_connect_data ((priv->hex_entry), ("focus-out-event" ), (((GCallback) (hex_focus_out))), (colorsel), ((void*)0), ( GConnectFlags) 0) | ||||
| 509 | G_CALLBACK (hex_focus_out), colorsel)g_signal_connect_data ((priv->hex_entry), ("focus-out-event" ), (((GCallback) (hex_focus_out))), (colorsel), ((void*)0), ( GConnectFlags) 0); | ||||
| 510 | |||||
| 511 | ctk_widget_set_tooltip_text (priv->hex_entry, | ||||
| 512 | _("You can enter an HTML-style hexadecimal color "((char *) g_dgettext ("ctk30", "You can enter an HTML-style hexadecimal color " "value, or simply a color name such as “orange” " "in this entry." )) | ||||
| 513 | "value, or simply a color name such as “orange” "((char *) g_dgettext ("ctk30", "You can enter an HTML-style hexadecimal color " "value, or simply a color name such as “orange” " "in this entry." )) | ||||
| 514 | "in this entry.")((char *) g_dgettext ("ctk30", "You can enter an HTML-style hexadecimal color " "value, or simply a color name such as “orange” " "in this entry." ))); | ||||
| 515 | |||||
| 516 | ctk_entry_set_width_chars (CTK_ENTRY (priv->hex_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->hex_entry)), ((ctk_entry_get_type ())))))), 7); | ||||
| 517 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), priv->hex_entry, 1, 5, 4, 1); | ||||
| 518 | |||||
| 519 | focus_chain = g_list_append (focus_chain, priv->hue_spinbutton); | ||||
| 520 | focus_chain = g_list_append (focus_chain, priv->sat_spinbutton); | ||||
| 521 | focus_chain = g_list_append (focus_chain, priv->val_spinbutton); | ||||
| 522 | focus_chain = g_list_append (focus_chain, priv->red_spinbutton); | ||||
| 523 | focus_chain = g_list_append (focus_chain, priv->green_spinbutton); | ||||
| 524 | focus_chain = g_list_append (focus_chain, priv->blue_spinbutton); | ||||
| 525 | focus_chain = g_list_append (focus_chain, priv->opacity_slider); | ||||
| 526 | focus_chain = g_list_append (focus_chain, priv->opacity_entry); | ||||
| 527 | focus_chain = g_list_append (focus_chain, priv->hex_entry); | ||||
| 528 | ctk_container_set_focus_chain (CTK_CONTAINER (table)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_container_get_type ())))))), focus_chain); | ||||
| 529 | g_list_free (focus_chain); | ||||
| 530 | |||||
| 531 | /* Set up the palette */ | ||||
| 532 | table = ctk_grid_new (); | ||||
| 533 | ctk_grid_set_row_spacing (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), 1); | ||||
| 534 | ctk_grid_set_column_spacing (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), 1); | ||||
| 535 | for (i = 0; i < CTK_CUSTOM_PALETTE_WIDTH10; i++) | ||||
| 536 | { | ||||
| 537 | for (j = 0; j < CTK_CUSTOM_PALETTE_HEIGHT2; j++) | ||||
| 538 | { | ||||
| 539 | make_palette_frame (colorsel, table, i, j); | ||||
| 540 | } | ||||
| 541 | } | ||||
| 542 | set_selected_palette (colorsel, 0, 0); | ||||
| 543 | priv->palette_frame = ctk_box_new (CTK_ORIENTATION_VERTICAL, 6); | ||||
| 544 | label = ctk_label_new_with_mnemonic (_("_Palette:")((char *) g_dgettext ("ctk30", "_Palette:"))); | ||||
| 545 | ctk_widget_set_halign (label, CTK_ALIGN_START); | ||||
| 546 | ctk_widget_set_valign (label, CTK_ALIGN_CENTER); | ||||
| 547 | ctk_box_pack_start (CTK_BOX (priv->palette_frame)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->palette_frame)), ((ctk_box_get_type ())))))), label, FALSE(0), FALSE(0), 0); | ||||
| 548 | |||||
| 549 | ctk_label_set_mnemonic_widget (CTK_LABEL (label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((ctk_label_get_type ())))))), | ||||
| 550 | priv->custom_palette[0][0]); | ||||
| 551 | |||||
| 552 | ctk_box_pack_end (CTK_BOX (top_right_vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((top_right_vbox)), ((ctk_box_get_type ())))))), priv->palette_frame, FALSE(0), FALSE(0), 0); | ||||
| 553 | ctk_box_pack_start (CTK_BOX (priv->palette_frame)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->palette_frame)), ((ctk_box_get_type ())))))), table, FALSE(0), FALSE(0), 0); | ||||
| 554 | |||||
| 555 | ctk_widget_show_all (top_hbox); | ||||
| 556 | |||||
| 557 | /* hide unused stuff */ | ||||
| 558 | |||||
| 559 | if (priv->has_opacity == FALSE(0)) | ||||
| 560 | { | ||||
| 561 | ctk_widget_hide (priv->opacity_label); | ||||
| 562 | ctk_widget_hide (priv->opacity_slider); | ||||
| 563 | ctk_widget_hide (priv->opacity_entry); | ||||
| 564 | } | ||||
| 565 | |||||
| 566 | if (priv->has_palette == FALSE(0)) | ||||
| 567 | { | ||||
| 568 | ctk_widget_hide (priv->palette_frame); | ||||
| 569 | } | ||||
| 570 | |||||
| 571 | atk_obj = ctk_widget_get_accessible (priv->triangle_colorsel); | ||||
| 572 | if (CTK_IS_ACCESSIBLE (atk_obj)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (atk_obj)); GType __t = ((ctk_accessible_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | ||||
| 573 | { | ||||
| 574 | atk_object_set_name (atk_obj, _("Color Wheel")((char *) g_dgettext ("ctk30", "Color Wheel"))); | ||||
| 575 | atk_object_set_role (ctk_widget_get_accessible (CTK_WIDGET (colorsel)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), ((ctk_widget_get_type ()))))))), ATK_ROLE_COLOR_CHOOSER); | ||||
| 576 | make_all_relations (atk_obj, priv); | ||||
| 577 | } | ||||
| 578 | |||||
| 579 | ctk_widget_pop_composite_child (); | ||||
| 580 | } | ||||
| 581 | |||||
| 582 | /* GObject methods */ | ||||
| 583 | static void | ||||
| 584 | ctk_color_selection_finalize (GObject *object) | ||||
| 585 | { | ||||
| 586 | G_OBJECT_CLASS (ctk_color_selection_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_color_selection_parent_class)), (((GType) ((20) << (2))))))))->finalize (object); | ||||
| 587 | } | ||||
| 588 | |||||
| 589 | static void | ||||
| 590 | ctk_color_selection_set_property (GObject *object, | ||||
| 591 | guint prop_id, | ||||
| 592 | const GValue *value, | ||||
| 593 | GParamSpec *pspec) | ||||
| 594 | { | ||||
| 595 | CtkColorSelection *colorsel = CTK_COLOR_SELECTION (object)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((object)), ((ctk_color_selection_get_type ( ))))))); | ||||
| 596 | |||||
| 597 | switch (prop_id) | ||||
| 598 | { | ||||
| 599 | case PROP_HAS_OPACITY_CONTROL: | ||||
| 600 | ctk_color_selection_set_has_opacity_control (colorsel, | ||||
| 601 | g_value_get_boolean (value)); | ||||
| 602 | break; | ||||
| 603 | case PROP_HAS_PALETTE: | ||||
| 604 | ctk_color_selection_set_has_palette (colorsel, | ||||
| 605 | g_value_get_boolean (value)); | ||||
| 606 | break; | ||||
| 607 | case PROP_CURRENT_COLOR: | ||||
| 608 | { | ||||
| 609 | CdkColor *color; | ||||
| 610 | CdkRGBA rgba; | ||||
| 611 | |||||
| 612 | color = g_value_get_boxed (value); | ||||
| 613 | |||||
| 614 | rgba.red = SCALE (color->red)(color->red / 65535.); | ||||
| 615 | rgba.green = SCALE (color->green)(color->green / 65535.);; | ||||
| 616 | rgba.blue = SCALE (color->blue)(color->blue / 65535.); | ||||
| 617 | rgba.alpha = 1.0; | ||||
| 618 | |||||
| 619 | ctk_color_selection_set_current_rgba (colorsel, &rgba); | ||||
| 620 | } | ||||
| 621 | break; | ||||
| 622 | case PROP_CURRENT_ALPHA: | ||||
| 623 | ctk_color_selection_set_current_alpha (colorsel, g_value_get_uint (value)); | ||||
| 624 | break; | ||||
| 625 | case PROP_CURRENT_RGBA: | ||||
| 626 | ctk_color_selection_set_current_rgba (colorsel, g_value_get_boxed (value)); | ||||
| 627 | break; | ||||
| 628 | default: | ||||
| 629 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "ctkcolorsel.c", 629, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); | ||||
| 630 | break; | ||||
| 631 | } | ||||
| 632 | |||||
| 633 | } | ||||
| 634 | |||||
| 635 | static void | ||||
| 636 | ctk_color_selection_get_property (GObject *object, | ||||
| 637 | guint prop_id, | ||||
| 638 | GValue *value, | ||||
| 639 | GParamSpec *pspec) | ||||
| 640 | { | ||||
| 641 | CtkColorSelection *colorsel = CTK_COLOR_SELECTION (object)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((object)), ((ctk_color_selection_get_type ( ))))))); | ||||
| 642 | |||||
| 643 | switch (prop_id) | ||||
| 644 | { | ||||
| 645 | case PROP_HAS_OPACITY_CONTROL: | ||||
| 646 | g_value_set_boolean (value, ctk_color_selection_get_has_opacity_control (colorsel)); | ||||
| 647 | break; | ||||
| 648 | case PROP_HAS_PALETTE: | ||||
| 649 | g_value_set_boolean (value, ctk_color_selection_get_has_palette (colorsel)); | ||||
| 650 | break; | ||||
| 651 | case PROP_CURRENT_COLOR: | ||||
| 652 | { | ||||
| 653 | CdkColor color; | ||||
| 654 | CdkRGBA rgba; | ||||
| 655 | |||||
| 656 | ctk_color_selection_get_current_rgba (colorsel, &rgba); | ||||
| 657 | |||||
| 658 | color.red = UNSCALE (rgba.red)((guint16)(rgba.red * 65535 + 0.5)); | ||||
| 659 | color.green = UNSCALE (rgba.green)((guint16)(rgba.green * 65535 + 0.5)); | ||||
| 660 | color.blue = UNSCALE (rgba.blue)((guint16)(rgba.blue * 65535 + 0.5)); | ||||
| 661 | |||||
| 662 | g_value_set_boxed (value, &color); | ||||
| 663 | } | ||||
| 664 | break; | ||||
| 665 | case PROP_CURRENT_ALPHA: | ||||
| 666 | g_value_set_uint (value, ctk_color_selection_get_current_alpha (colorsel)); | ||||
| 667 | break; | ||||
| 668 | case PROP_CURRENT_RGBA: | ||||
| 669 | { | ||||
| 670 | CdkRGBA rgba; | ||||
| 671 | |||||
| 672 | ctk_color_selection_get_current_rgba (colorsel, &rgba); | ||||
| 673 | g_value_set_boxed (value, &rgba); | ||||
| 674 | } | ||||
| 675 | break; | ||||
| 676 | default: | ||||
| 677 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "ctkcolorsel.c", 677, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); | ||||
| 678 | break; | ||||
| 679 | } | ||||
| 680 | } | ||||
| 681 | |||||
| 682 | /* CtkWidget methods */ | ||||
| 683 | |||||
| 684 | static void | ||||
| 685 | ctk_color_selection_destroy (CtkWidget *widget) | ||||
| 686 | { | ||||
| 687 | CtkColorSelection *cselection = CTK_COLOR_SELECTION (widget)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((widget)), ((ctk_color_selection_get_type ( ))))))); | ||||
| 688 | CtkColorSelectionPrivate *priv = cselection->private_data; | ||||
| 689 | |||||
| 690 | if (priv->dropper_grab_widget) | ||||
| 691 | { | ||||
| 692 | ctk_widget_destroy (priv->dropper_grab_widget); | ||||
| 693 | priv->dropper_grab_widget = NULL((void*)0); | ||||
| 694 | } | ||||
| 695 | |||||
| 696 | CTK_WIDGET_CLASS (ctk_color_selection_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_color_selection_parent_class)), ((ctk_widget_get_type ()))))))->destroy (widget); | ||||
| 697 | } | ||||
| 698 | |||||
| 699 | static void | ||||
| 700 | ctk_color_selection_realize (CtkWidget *widget) | ||||
| 701 | { | ||||
| 702 | CtkColorSelection *colorsel = CTK_COLOR_SELECTION (widget)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((widget)), ((ctk_color_selection_get_type ( ))))))); | ||||
| 703 | CtkColorSelectionPrivate *priv = colorsel->private_data; | ||||
| 704 | CtkSettings *settings = ctk_widget_get_settings (widget); | ||||
| 705 | |||||
| 706 | priv->settings_connection = g_signal_connect (settings,g_signal_connect_data ((settings), ("notify::ctk-color-palette" ), (((GCallback) (palette_change_notify_instance))), (widget) , ((void*)0), (GConnectFlags) 0) | ||||
| 707 | "notify::ctk-color-palette",g_signal_connect_data ((settings), ("notify::ctk-color-palette" ), (((GCallback) (palette_change_notify_instance))), (widget) , ((void*)0), (GConnectFlags) 0) | ||||
| 708 | G_CALLBACK (palette_change_notify_instance),g_signal_connect_data ((settings), ("notify::ctk-color-palette" ), (((GCallback) (palette_change_notify_instance))), (widget) , ((void*)0), (GConnectFlags) 0) | ||||
| 709 | widget)g_signal_connect_data ((settings), ("notify::ctk-color-palette" ), (((GCallback) (palette_change_notify_instance))), (widget) , ((void*)0), (GConnectFlags) 0); | ||||
| 710 | update_palette (colorsel); | ||||
| 711 | |||||
| 712 | CTK_WIDGET_CLASS (ctk_color_selection_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_color_selection_parent_class)), ((ctk_widget_get_type ()))))))->realize (widget); | ||||
| 713 | } | ||||
| 714 | |||||
| 715 | static void | ||||
| 716 | ctk_color_selection_unrealize (CtkWidget *widget) | ||||
| 717 | { | ||||
| 718 | CtkColorSelection *colorsel = CTK_COLOR_SELECTION (widget)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((widget)), ((ctk_color_selection_get_type ( ))))))); | ||||
| 719 | CtkColorSelectionPrivate *priv = colorsel->private_data; | ||||
| 720 | CtkSettings *settings = ctk_widget_get_settings (widget); | ||||
| 721 | |||||
| 722 | g_signal_handler_disconnect (settings, priv->settings_connection); | ||||
| 723 | |||||
| 724 | CTK_WIDGET_CLASS (ctk_color_selection_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_color_selection_parent_class)), ((ctk_widget_get_type ()))))))->unrealize (widget); | ||||
| 725 | } | ||||
| 726 | |||||
| 727 | /* We override show-all since we have internal widgets that | ||||
| 728 | * shouldn’t be shown when you call show_all(), like the | ||||
| 729 | * palette and opacity sliders. | ||||
| 730 | */ | ||||
| 731 | static void | ||||
| 732 | ctk_color_selection_show_all (CtkWidget *widget) | ||||
| 733 | { | ||||
| 734 | ctk_widget_show (widget); | ||||
| 735 | } | ||||
| 736 | |||||
| 737 | static gboolean | ||||
| 738 | ctk_color_selection_grab_broken (CtkWidget *widget, | ||||
| 739 | CdkEventGrabBroken *event G_GNUC_UNUSED__attribute__ ((__unused__))) | ||||
| 740 | { | ||||
| 741 | shutdown_eyedropper (widget); | ||||
| 742 | |||||
| 743 | return TRUE(!(0)); | ||||
| 744 | } | ||||
| 745 | |||||
| 746 | /* | ||||
| 747 | * | ||||
| 748 | * The Sample Color | ||||
| 749 | * | ||||
| 750 | */ | ||||
| 751 | |||||
| 752 | static void color_sample_draw_sample (CtkColorSelection *colorsel, | ||||
| 753 | int which, | ||||
| 754 | cairo_t * cr); | ||||
| 755 | static void color_sample_update_samples (CtkColorSelection *colorsel); | ||||
| 756 | |||||
| 757 | static void | ||||
| 758 | set_color_internal (CtkColorSelection *colorsel, | ||||
| 759 | gdouble *color) | ||||
| 760 | { | ||||
| 761 | CtkColorSelectionPrivate *priv; | ||||
| 762 | gint i; | ||||
| 763 | |||||
| 764 | priv = colorsel->private_data; | ||||
| 765 | priv->changing = TRUE(!(0)); | ||||
| 766 | priv->color[COLORSEL_RED] = color[0]; | ||||
| 767 | priv->color[COLORSEL_GREEN] = color[1]; | ||||
| 768 | priv->color[COLORSEL_BLUE] = color[2]; | ||||
| 769 | priv->color[COLORSEL_OPACITY] = color[3]; | ||||
| 770 | ctk_rgb_to_hsv (priv->color[COLORSEL_RED], | ||||
| 771 | priv->color[COLORSEL_GREEN], | ||||
| 772 | priv->color[COLORSEL_BLUE], | ||||
| 773 | &priv->color[COLORSEL_HUE], | ||||
| 774 | &priv->color[COLORSEL_SATURATION], | ||||
| 775 | &priv->color[COLORSEL_VALUE]); | ||||
| 776 | if (priv->default_set == FALSE(0)) | ||||
| 777 | { | ||||
| 778 | for (i = 0; i < COLORSEL_NUM_CHANNELS; i++) | ||||
| 779 | priv->old_color[i] = priv->color[i]; | ||||
| 780 | } | ||||
| 781 | priv->default_set = TRUE(!(0)); | ||||
| 782 | priv->default_alpha_set = TRUE(!(0)); | ||||
| 783 | update_color (colorsel); | ||||
| 784 | } | ||||
| 785 | |||||
| 786 | static void | ||||
| 787 | set_color_icon (CdkDragContext *context, | ||||
| 788 | gdouble *colors) | ||||
| 789 | { | ||||
| 790 | GdkPixbuf *pixbuf; | ||||
| 791 | guint32 pixel; | ||||
| 792 | |||||
| 793 | pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE(0), | ||||
| 794 | 8, 48, 32); | ||||
| 795 | |||||
| 796 | pixel = (((UNSCALE (colors[COLORSEL_RED])((guint16)(colors[COLORSEL_RED] * 65535 + 0.5)) & 0xff00) << 16) | | ||||
| 797 | ((UNSCALE (colors[COLORSEL_GREEN])((guint16)(colors[COLORSEL_GREEN] * 65535 + 0.5)) & 0xff00) << 8) | | ||||
| 798 | ((UNSCALE (colors[COLORSEL_BLUE])((guint16)(colors[COLORSEL_BLUE] * 65535 + 0.5)) & 0xff00))); | ||||
| 799 | |||||
| 800 | gdk_pixbuf_fill (pixbuf, pixel); | ||||
| 801 | |||||
| 802 | ctk_drag_set_icon_pixbuf (context, pixbuf, -2, -2); | ||||
| 803 | g_object_unref (pixbuf); | ||||
| 804 | } | ||||
| 805 | |||||
| 806 | static void | ||||
| 807 | color_sample_drag_begin (CtkWidget *widget, | ||||
| 808 | CdkDragContext *context, | ||||
| 809 | gpointer data) | ||||
| 810 | { | ||||
| 811 | CtkColorSelection *colorsel = data; | ||||
| 812 | CtkColorSelectionPrivate *priv; | ||||
| 813 | gdouble *colsrc; | ||||
| 814 | |||||
| 815 | priv = colorsel->private_data; | ||||
| 816 | |||||
| 817 | if (widget == priv->old_sample) | ||||
| 818 | colsrc = priv->old_color; | ||||
| 819 | else | ||||
| 820 | colsrc = priv->color; | ||||
| 821 | |||||
| 822 | set_color_icon (context, colsrc); | ||||
| 823 | } | ||||
| 824 | |||||
| 825 | static void | ||||
| 826 | color_sample_drag_end (CtkWidget *widget, | ||||
| 827 | CdkDragContext *context G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 828 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | ||||
| 829 | { | ||||
| 830 | g_object_set_data (G_OBJECT (widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), I_("ctk-color-selection-drag-window")g_intern_static_string ("ctk-color-selection-drag-window"), NULL((void*)0)); | ||||
| 831 | } | ||||
| 832 | |||||
| 833 | static void | ||||
| 834 | color_sample_drop_handle (CtkWidget *widget, | ||||
| 835 | CdkDragContext *context G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 836 | gint x G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 837 | gint y G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 838 | CtkSelectionData *selection_data, | ||||
| 839 | guint info G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 840 | guint time G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 841 | gpointer data) | ||||
| 842 | { | ||||
| 843 | CtkColorSelection *colorsel = data; | ||||
| 844 | CtkColorSelectionPrivate *priv; | ||||
| 845 | gint length; | ||||
| 846 | guint16 *vals; | ||||
| 847 | gdouble color[4]; | ||||
| 848 | priv = colorsel->private_data; | ||||
| 849 | |||||
| 850 | /* This is currently a guint16 array of the format: | ||||
| 851 | * R | ||||
| 852 | * G | ||||
| 853 | * B | ||||
| 854 | * opacity | ||||
| 855 | */ | ||||
| 856 | |||||
| 857 | length = ctk_selection_data_get_length (selection_data); | ||||
| 858 | |||||
| 859 | if (length < 0) | ||||
| 860 | return; | ||||
| 861 | |||||
| 862 | /* We accept drops with the wrong format, since the KDE color | ||||
| 863 | * chooser incorrectly drops application/x-color with format 8. | ||||
| 864 | */ | ||||
| 865 | if (length != 8) | ||||
| 866 | { | ||||
| 867 | g_warning ("Received invalid color data"); | ||||
| 868 | return; | ||||
| 869 | } | ||||
| 870 | |||||
| 871 | vals = (guint16 *) ctk_selection_data_get_data (selection_data); | ||||
| 872 | |||||
| 873 | if (widget == priv->cur_sample) | ||||
| 874 | { | ||||
| 875 | color[0] = (gdouble)vals[0] / 0xffff; | ||||
| 876 | color[1] = (gdouble)vals[1] / 0xffff; | ||||
| 877 | color[2] = (gdouble)vals[2] / 0xffff; | ||||
| 878 | color[3] = (gdouble)vals[3] / 0xffff; | ||||
| 879 | |||||
| 880 | set_color_internal (colorsel, color); | ||||
| 881 | } | ||||
| 882 | } | ||||
| 883 | |||||
| 884 | static void | ||||
| 885 | color_sample_drag_handle (CtkWidget *widget, | ||||
| 886 | CdkDragContext *context G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 887 | CtkSelectionData *selection_data, | ||||
| 888 | guint info G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 889 | guint time G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 890 | gpointer data) | ||||
| 891 | { | ||||
| 892 | CtkColorSelection *colorsel = data; | ||||
| 893 | CtkColorSelectionPrivate *priv; | ||||
| 894 | guint16 vals[4]; | ||||
| 895 | gdouble *colsrc; | ||||
| 896 | |||||
| 897 | priv = colorsel->private_data; | ||||
| 898 | |||||
| 899 | if (widget == priv->old_sample) | ||||
| 900 | colsrc = priv->old_color; | ||||
| 901 | else | ||||
| 902 | colsrc = priv->color; | ||||
| 903 | |||||
| 904 | vals[0] = colsrc[COLORSEL_RED] * 0xffff; | ||||
| 905 | vals[1] = colsrc[COLORSEL_GREEN] * 0xffff; | ||||
| 906 | vals[2] = colsrc[COLORSEL_BLUE] * 0xffff; | ||||
| 907 | vals[3] = priv->has_opacity ? colsrc[COLORSEL_OPACITY] * 0xffff : 0xffff; | ||||
| 908 | |||||
| 909 | ctk_selection_data_set (selection_data, | ||||
| 910 | cdk_atom_intern_static_string ("application/x-color"), | ||||
| 911 | 16, (guchar *)vals, 8); | ||||
| 912 | } | ||||
| 913 | |||||
| 914 | /* which = 0 means draw old sample, which = 1 means draw new */ | ||||
| 915 | static void | ||||
| 916 | color_sample_draw_sample (CtkColorSelection *colorsel, | ||||
| 917 | int which, | ||||
| 918 | cairo_t *cr) | ||||
| 919 | { | ||||
| 920 | CtkWidget *da; | ||||
| 921 | gint x, y, goff; | ||||
| 922 | CtkColorSelectionPrivate *priv; | ||||
| 923 | int width, height; | ||||
| 924 | |||||
| 925 | g_return_if_fail (colorsel != NULL)do { if ((colorsel != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "colorsel != NULL"); return ; } } while (0); | ||||
| 926 | priv = colorsel->private_data; | ||||
| 927 | |||||
| 928 | g_return_if_fail (priv->sample_area != NULL)do { if ((priv->sample_area != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "priv->sample_area != NULL" ); return; } } while (0); | ||||
| 929 | if (!ctk_widget_is_drawable (priv->sample_area)) | ||||
| 930 | return; | ||||
| 931 | |||||
| 932 | if (which == 0) | ||||
| 933 | { | ||||
| 934 | da = priv->old_sample; | ||||
| 935 | goff = 0; | ||||
| 936 | } | ||||
| 937 | else | ||||
| 938 | { | ||||
| 939 | CtkAllocation old_sample_allocation; | ||||
| 940 | |||||
| 941 | da = priv->cur_sample; | ||||
| 942 | ctk_widget_get_allocation (priv->old_sample, &old_sample_allocation); | ||||
| 943 | goff = old_sample_allocation.width % 32; | ||||
| 944 | } | ||||
| 945 | |||||
| 946 | /* Below needs tweaking for non-power-of-two */ | ||||
| 947 | width = ctk_widget_get_allocated_width (da); | ||||
| 948 | height = ctk_widget_get_allocated_height (da); | ||||
| 949 | |||||
| 950 | if (priv->has_opacity) | ||||
| 951 | { | ||||
| 952 | /* Draw checks in background */ | ||||
| 953 | |||||
| 954 | cairo_set_source_rgb (cr, 0.5, 0.5, 0.5); | ||||
| 955 | cairo_rectangle (cr, 0, 0, width, height); | ||||
| 956 | cairo_fill (cr); | ||||
| 957 | |||||
| 958 | cairo_set_source_rgb (cr, 0.75, 0.75, 0.75); | ||||
| 959 | for (x = goff & -CHECK_SIZE16; x < goff + width; x += CHECK_SIZE16) | ||||
| 960 | for (y = 0; y < height; y += CHECK_SIZE16) | ||||
| 961 | if ((x / CHECK_SIZE16 + y / CHECK_SIZE16) % 2 == 0) | ||||
| 962 | cairo_rectangle (cr, x - goff, y, CHECK_SIZE16, CHECK_SIZE16); | ||||
| 963 | cairo_fill (cr); | ||||
| 964 | } | ||||
| 965 | |||||
| 966 | if (which == 0) | ||||
| 967 | { | ||||
| 968 | cairo_set_source_rgba (cr, | ||||
| 969 | priv->old_color[COLORSEL_RED], | ||||
| 970 | priv->old_color[COLORSEL_GREEN], | ||||
| 971 | priv->old_color[COLORSEL_BLUE], | ||||
| 972 | priv->has_opacity ? | ||||
| 973 | priv->old_color[COLORSEL_OPACITY] : 1.0); | ||||
| 974 | } | ||||
| 975 | else | ||||
| 976 | { | ||||
| 977 | cairo_set_source_rgba (cr, | ||||
| 978 | priv->color[COLORSEL_RED], | ||||
| 979 | priv->color[COLORSEL_GREEN], | ||||
| 980 | priv->color[COLORSEL_BLUE], | ||||
| 981 | priv->has_opacity ? | ||||
| 982 | priv->color[COLORSEL_OPACITY] : 1.0); | ||||
| 983 | } | ||||
| 984 | |||||
| 985 | cairo_rectangle (cr, 0, 0, width, height); | ||||
| 986 | cairo_fill (cr); | ||||
| 987 | } | ||||
| 988 | |||||
| 989 | |||||
| 990 | static void | ||||
| 991 | color_sample_update_samples (CtkColorSelection *colorsel) | ||||
| 992 | { | ||||
| 993 | CtkColorSelectionPrivate *priv = colorsel->private_data; | ||||
| 994 | ctk_widget_queue_draw (priv->old_sample); | ||||
| 995 | ctk_widget_queue_draw (priv->cur_sample); | ||||
| 996 | } | ||||
| 997 | |||||
| 998 | static gboolean | ||||
| 999 | color_old_sample_draw (CtkWidget *da G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1000 | cairo_t *cr, | ||||
| 1001 | CtkColorSelection *colorsel) | ||||
| 1002 | { | ||||
| 1003 | color_sample_draw_sample (colorsel, 0, cr); | ||||
| 1004 | return FALSE(0); | ||||
| 1005 | } | ||||
| 1006 | |||||
| 1007 | |||||
| 1008 | static gboolean | ||||
| 1009 | color_cur_sample_draw (CtkWidget *da G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1010 | cairo_t *cr, | ||||
| 1011 | CtkColorSelection *colorsel) | ||||
| 1012 | { | ||||
| 1013 | color_sample_draw_sample (colorsel, 1, cr); | ||||
| 1014 | return FALSE(0); | ||||
| 1015 | } | ||||
| 1016 | |||||
| 1017 | static void | ||||
| 1018 | color_sample_setup_dnd (CtkColorSelection *colorsel, CtkWidget *sample) | ||||
| 1019 | { | ||||
| 1020 | static const CtkTargetEntry targets[] = { | ||||
| 1021 | { .target = "application/x-color", .flags = 0 } | ||||
| 1022 | }; | ||||
| 1023 | CtkColorSelectionPrivate *priv; | ||||
| 1024 | priv = colorsel->private_data; | ||||
| 1025 | |||||
| 1026 | ctk_drag_source_set (sample, | ||||
| 1027 | CDK_BUTTON1_MASK | CDK_BUTTON3_MASK, | ||||
| 1028 | targets, 1, | ||||
| 1029 | CDK_ACTION_COPY | CDK_ACTION_MOVE); | ||||
| 1030 | |||||
| 1031 | g_signal_connect (sample, "drag-begin",g_signal_connect_data ((sample), ("drag-begin"), (((GCallback ) (color_sample_drag_begin))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1032 | G_CALLBACK (color_sample_drag_begin),g_signal_connect_data ((sample), ("drag-begin"), (((GCallback ) (color_sample_drag_begin))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1033 | colorsel)g_signal_connect_data ((sample), ("drag-begin"), (((GCallback ) (color_sample_drag_begin))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1034 | if (sample == priv->cur_sample) | ||||
| 1035 | { | ||||
| 1036 | |||||
| 1037 | ctk_drag_dest_set (sample, | ||||
| 1038 | CTK_DEST_DEFAULT_HIGHLIGHT | | ||||
| 1039 | CTK_DEST_DEFAULT_MOTION | | ||||
| 1040 | CTK_DEST_DEFAULT_DROP, | ||||
| 1041 | targets, 1, | ||||
| 1042 | CDK_ACTION_COPY); | ||||
| 1043 | |||||
| 1044 | g_signal_connect (sample, "drag-end",g_signal_connect_data ((sample), ("drag-end"), (((GCallback) ( color_sample_drag_end))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1045 | G_CALLBACK (color_sample_drag_end),g_signal_connect_data ((sample), ("drag-end"), (((GCallback) ( color_sample_drag_end))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1046 | colorsel)g_signal_connect_data ((sample), ("drag-end"), (((GCallback) ( color_sample_drag_end))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1047 | } | ||||
| 1048 | |||||
| 1049 | g_signal_connect (sample, "drag-data-get",g_signal_connect_data ((sample), ("drag-data-get"), (((GCallback ) (color_sample_drag_handle))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1050 | G_CALLBACK (color_sample_drag_handle),g_signal_connect_data ((sample), ("drag-data-get"), (((GCallback ) (color_sample_drag_handle))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1051 | colorsel)g_signal_connect_data ((sample), ("drag-data-get"), (((GCallback ) (color_sample_drag_handle))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1052 | g_signal_connect (sample, "drag-data-received",g_signal_connect_data ((sample), ("drag-data-received"), (((GCallback ) (color_sample_drop_handle))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1053 | G_CALLBACK (color_sample_drop_handle),g_signal_connect_data ((sample), ("drag-data-received"), (((GCallback ) (color_sample_drop_handle))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1054 | colorsel)g_signal_connect_data ((sample), ("drag-data-received"), (((GCallback ) (color_sample_drop_handle))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1055 | |||||
| 1056 | } | ||||
| 1057 | |||||
| 1058 | static void | ||||
| 1059 | update_tooltips (CtkColorSelection *colorsel) | ||||
| 1060 | { | ||||
| 1061 | CtkColorSelectionPrivate *priv; | ||||
| 1062 | |||||
| 1063 | priv = colorsel->private_data; | ||||
| 1064 | |||||
| 1065 | if (priv->has_palette == TRUE(!(0))) | ||||
| 1066 | { | ||||
| 1067 | ctk_widget_set_tooltip_text (priv->old_sample, | ||||
| 1068 | _("The previously-selected color, for comparison to the color "((char *) g_dgettext ("ctk30", "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.")) | ||||
| 1069 | "you’re selecting now. You can drag this color to a palette "((char *) g_dgettext ("ctk30", "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.")) | ||||
| 1070 | "entry, or select this color as current by dragging it to the "((char *) g_dgettext ("ctk30", "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.")) | ||||
| 1071 | "other color swatch alongside.")((char *) g_dgettext ("ctk30", "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."))); | ||||
| 1072 | |||||
| 1073 | ctk_widget_set_tooltip_text (priv->cur_sample, | ||||
| 1074 | _("The color you’ve chosen. You can drag this color to a palette "((char *) g_dgettext ("ctk30", "The color you’ve chosen. You can drag this color to a palette " "entry to save it for use in the future.")) | ||||
| 1075 | "entry to save it for use in the future.")((char *) g_dgettext ("ctk30", "The color you’ve chosen. You can drag this color to a palette " "entry to save it for use in the future."))); | ||||
| 1076 | } | ||||
| 1077 | else | ||||
| 1078 | { | ||||
| 1079 | ctk_widget_set_tooltip_text (priv->old_sample, | ||||
| 1080 | _("The previously-selected color, for comparison to the color "((char *) g_dgettext ("ctk30", "The previously-selected color, for comparison to the color " "you’re selecting now.")) | ||||
| 1081 | "you’re selecting now.")((char *) g_dgettext ("ctk30", "The previously-selected color, for comparison to the color " "you’re selecting now."))); | ||||
| 1082 | |||||
| 1083 | ctk_widget_set_tooltip_text (priv->cur_sample, | ||||
| 1084 | _("The color you’ve chosen.")((char *) g_dgettext ("ctk30", "The color you’ve chosen."))); | ||||
| 1085 | } | ||||
| 1086 | } | ||||
| 1087 | |||||
| 1088 | static void | ||||
| 1089 | color_sample_new (CtkColorSelection *colorsel) | ||||
| 1090 | { | ||||
| 1091 | CtkColorSelectionPrivate *priv; | ||||
| 1092 | |||||
| 1093 | priv = colorsel->private_data; | ||||
| 1094 | |||||
| 1095 | priv->sample_area = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 0); | ||||
| 1096 | priv->old_sample = ctk_drawing_area_new (); | ||||
| 1097 | priv->cur_sample = ctk_drawing_area_new (); | ||||
| 1098 | |||||
| 1099 | ctk_box_pack_start (CTK_BOX (priv->sample_area)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->sample_area)), ((ctk_box_get_type ())))))), priv->old_sample, | ||||
| 1100 | TRUE(!(0)), TRUE(!(0)), 0); | ||||
| 1101 | ctk_box_pack_start (CTK_BOX (priv->sample_area)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->sample_area)), ((ctk_box_get_type ())))))), priv->cur_sample, | ||||
| 1102 | TRUE(!(0)), TRUE(!(0)), 0); | ||||
| 1103 | |||||
| 1104 | g_signal_connect (priv->old_sample, "draw",g_signal_connect_data ((priv->old_sample), ("draw"), (((GCallback ) (color_old_sample_draw))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1105 | G_CALLBACK (color_old_sample_draw),g_signal_connect_data ((priv->old_sample), ("draw"), (((GCallback ) (color_old_sample_draw))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1106 | colorsel)g_signal_connect_data ((priv->old_sample), ("draw"), (((GCallback ) (color_old_sample_draw))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1107 | g_signal_connect (priv->cur_sample, "draw",g_signal_connect_data ((priv->cur_sample), ("draw"), (((GCallback ) (color_cur_sample_draw))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1108 | G_CALLBACK (color_cur_sample_draw),g_signal_connect_data ((priv->cur_sample), ("draw"), (((GCallback ) (color_cur_sample_draw))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1109 | colorsel)g_signal_connect_data ((priv->cur_sample), ("draw"), (((GCallback ) (color_cur_sample_draw))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1110 | |||||
| 1111 | color_sample_setup_dnd (colorsel, priv->old_sample); | ||||
| 1112 | color_sample_setup_dnd (colorsel, priv->cur_sample); | ||||
| 1113 | |||||
| 1114 | update_tooltips (colorsel); | ||||
| 1115 | |||||
| 1116 | ctk_widget_show_all (priv->sample_area); | ||||
| 1117 | } | ||||
| 1118 | |||||
| 1119 | |||||
| 1120 | /* The palette area code */ | ||||
| 1121 | |||||
| 1122 | static void | ||||
| 1123 | palette_get_color (CtkWidget *drawing_area, gdouble *color) | ||||
| 1124 | { | ||||
| 1125 | gdouble *color_val; | ||||
| 1126 | |||||
| 1127 | g_return_if_fail (color != NULL)do { if ((color != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "color != NULL"); return ; } } while (0); | ||||
| 1128 | |||||
| 1129 | color_val = g_object_get_data (G_OBJECT (drawing_area)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((drawing_area)), (((GType) ((20) << (2)))))))), "color_val"); | ||||
| 1130 | if (color_val == NULL((void*)0)) | ||||
| 1131 | { | ||||
| 1132 | /* Default to white for no good reason */ | ||||
| 1133 | color[0] = 1.0; | ||||
| 1134 | color[1] = 1.0; | ||||
| 1135 | color[2] = 1.0; | ||||
| 1136 | color[3] = 1.0; | ||||
| 1137 | return; | ||||
| 1138 | } | ||||
| 1139 | |||||
| 1140 | color[0] = color_val[0]; | ||||
| 1141 | color[1] = color_val[1]; | ||||
| 1142 | color[2] = color_val[2]; | ||||
| 1143 | color[3] = 1.0; | ||||
| 1144 | } | ||||
| 1145 | |||||
| 1146 | static gboolean | ||||
| 1147 | palette_draw (CtkWidget *drawing_area, | ||||
| 1148 | cairo_t *cr, | ||||
| 1149 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | ||||
| 1150 | { | ||||
| 1151 | CtkStyleContext *context; | ||||
| 1152 | gint focus_width; | ||||
| 1153 | CdkRGBA color; | ||||
| 1154 | |||||
| 1155 | context = ctk_widget_get_style_context (drawing_area); | ||||
| 1156 | ctk_style_context_get_background_color (context, 0, &color); | ||||
| 1157 | cdk_cairo_set_source_rgba (cr, &color); | ||||
| 1158 | cairo_paint (cr); | ||||
| 1159 | |||||
| 1160 | if (ctk_widget_has_visible_focus (drawing_area)) | ||||
| 1161 | { | ||||
| 1162 | set_focus_line_attributes (drawing_area, cr, &focus_width); | ||||
| 1163 | |||||
| 1164 | cairo_rectangle (cr, | ||||
| 1165 | focus_width / 2., focus_width / 2., | ||||
| 1166 | ctk_widget_get_allocated_width (drawing_area) - focus_width, | ||||
| 1167 | ctk_widget_get_allocated_height (drawing_area) - focus_width); | ||||
| 1168 | cairo_stroke (cr); | ||||
| 1169 | } | ||||
| 1170 | |||||
| 1171 | return FALSE(0); | ||||
| 1172 | } | ||||
| 1173 | |||||
| 1174 | static void | ||||
| 1175 | set_focus_line_attributes (CtkWidget *drawing_area, | ||||
| 1176 | cairo_t *cr, | ||||
| 1177 | gint *focus_width) | ||||
| 1178 | { | ||||
| 1179 | gdouble color[4]; | ||||
| 1180 | gint8 *dash_list; | ||||
| 1181 | |||||
| 1182 | ctk_widget_style_get (drawing_area, | ||||
| 1183 | "focus-line-width", focus_width, | ||||
| 1184 | "focus-line-pattern", (gchar *)&dash_list, | ||||
| 1185 | NULL((void*)0)); | ||||
| 1186 | |||||
| 1187 | palette_get_color (drawing_area, color); | ||||
| 1188 | |||||
| 1189 | if (INTENSITY (color[0], color[1], color[2])((color[0]) * 0.30 + (color[1]) * 0.59 + (color[2]) * 0.11) > 0.5) | ||||
| 1190 | cairo_set_source_rgb (cr, 0., 0., 0.); | ||||
| 1191 | else | ||||
| 1192 | cairo_set_source_rgb (cr, 1., 1., 1.); | ||||
| 1193 | |||||
| 1194 | cairo_set_line_width (cr, *focus_width); | ||||
| 1195 | |||||
| 1196 | if (dash_list[0]) | ||||
| 1197 | { | ||||
| 1198 | gint n_dashes = strlen ((gchar *)dash_list); | ||||
| 1199 | gdouble *dashes = g_new (gdouble, n_dashes)((gdouble *) g_malloc_n ((n_dashes), sizeof (gdouble))); | ||||
| 1200 | gdouble total_length = 0; | ||||
| 1201 | gdouble dash_offset; | ||||
| 1202 | gint i; | ||||
| 1203 | |||||
| 1204 | for (i = 0; i < n_dashes; i++) | ||||
| 1205 | { | ||||
| 1206 | dashes[i] = dash_list[i]; | ||||
| 1207 | total_length += dash_list[i]; | ||||
| 1208 | } | ||||
| 1209 | |||||
| 1210 | /* The dash offset here aligns the pattern to integer pixels | ||||
| 1211 | * by starting the dash at the right side of the left border | ||||
| 1212 | * Negative dash offsets in cairo don't work | ||||
| 1213 | * (https://bugs.freedesktop.org/show_bug.cgi?id=2729) | ||||
| 1214 | */ | ||||
| 1215 | dash_offset = - *focus_width / 2.; | ||||
| 1216 | while (dash_offset < 0) | ||||
| 1217 | dash_offset += total_length; | ||||
| 1218 | |||||
| 1219 | cairo_set_dash (cr, dashes, n_dashes, dash_offset); | ||||
| 1220 | g_free (dashes); | ||||
| 1221 | } | ||||
| 1222 | |||||
| 1223 | g_free (dash_list); | ||||
| 1224 | } | ||||
| 1225 | |||||
| 1226 | static void | ||||
| 1227 | palette_drag_begin (CtkWidget *widget, | ||||
| 1228 | CdkDragContext *context, | ||||
| 1229 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | ||||
| 1230 | { | ||||
| 1231 | gdouble colors[4]; | ||||
| 1232 | |||||
| 1233 | palette_get_color (widget, colors); | ||||
| 1234 | set_color_icon (context, colors); | ||||
| 1235 | } | ||||
| 1236 | |||||
| 1237 | static void | ||||
| 1238 | palette_drag_handle (CtkWidget *widget, | ||||
| 1239 | CdkDragContext *context G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1240 | CtkSelectionData *selection_data, | ||||
| 1241 | guint info G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1242 | guint time G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1243 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | ||||
| 1244 | { | ||||
| 1245 | guint16 vals[4]; | ||||
| 1246 | gdouble colsrc[4]; | ||||
| 1247 | |||||
| 1248 | palette_get_color (widget, colsrc); | ||||
| 1249 | |||||
| 1250 | vals[0] = colsrc[COLORSEL_RED] * 0xffff; | ||||
| 1251 | vals[1] = colsrc[COLORSEL_GREEN] * 0xffff; | ||||
| 1252 | vals[2] = colsrc[COLORSEL_BLUE] * 0xffff; | ||||
| 1253 | vals[3] = 0xffff; | ||||
| 1254 | |||||
| 1255 | ctk_selection_data_set (selection_data, | ||||
| 1256 | cdk_atom_intern_static_string ("application/x-color"), | ||||
| 1257 | 16, (guchar *)vals, 8); | ||||
| 1258 | } | ||||
| 1259 | |||||
| 1260 | static void | ||||
| 1261 | palette_drag_end (CtkWidget *widget, | ||||
| 1262 | CdkDragContext *context G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1263 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | ||||
| 1264 | { | ||||
| 1265 | g_object_set_data (G_OBJECT (widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), I_("ctk-color-selection-drag-window")g_intern_static_string ("ctk-color-selection-drag-window"), NULL((void*)0)); | ||||
| 1266 | } | ||||
| 1267 | |||||
| 1268 | static CdkColor * | ||||
| 1269 | get_current_colors (CtkColorSelection *colorsel) | ||||
| 1270 | { | ||||
| 1271 | CtkSettings *settings; | ||||
| 1272 | CdkColor *colors = NULL((void*)0); | ||||
| 1273 | gint n_colors = 0; | ||||
| 1274 | gchar *palette; | ||||
| 1275 | |||||
| 1276 | settings = ctk_widget_get_settings (CTK_WIDGET (colorsel)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), ((ctk_widget_get_type ()))))))); | ||||
| 1277 | g_object_get (settings, "ctk-color-palette", &palette, NULL((void*)0)); | ||||
| 1278 | |||||
| 1279 | if (!ctk_color_selection_palette_from_string (palette, &colors, &n_colors)) | ||||
| 1280 | { | ||||
| 1281 | ctk_color_selection_palette_from_string (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", | ||||
| 1282 | &colors, | ||||
| 1283 | &n_colors); | ||||
| 1284 | } | ||||
| 1285 | else | ||||
| 1286 | { | ||||
| 1287 | /* If there are less colors provided than the number of slots in the | ||||
| 1288 | * color selection, we fill in the rest from the defaults. | ||||
| 1289 | */ | ||||
| 1290 | if (n_colors < (CTK_CUSTOM_PALETTE_WIDTH10 * CTK_CUSTOM_PALETTE_HEIGHT2)) | ||||
| 1291 | { | ||||
| 1292 | CdkColor *tmp_colors = colors; | ||||
| 1293 | gint tmp_n_colors = n_colors; | ||||
| 1294 | |||||
| 1295 | ctk_color_selection_palette_from_string (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", | ||||
| 1296 | &colors, | ||||
| 1297 | &n_colors); | ||||
| 1298 | memcpy (colors, tmp_colors, sizeof (CdkColor) * tmp_n_colors); | ||||
| |||||
| 1299 | |||||
| 1300 | g_free (tmp_colors); | ||||
| 1301 | } | ||||
| 1302 | } | ||||
| 1303 | |||||
| 1304 | /* make sure that we fill every slot */ | ||||
| 1305 | g_assert (n_colors == CTK_CUSTOM_PALETTE_WIDTH * CTK_CUSTOM_PALETTE_HEIGHT)do { if (n_colors == 10 * 2) ; else g_assertion_message_expr ( "Ctk", "ctkcolorsel.c", 1305, ((const char*) (__func__)), "n_colors == CTK_CUSTOM_PALETTE_WIDTH * CTK_CUSTOM_PALETTE_HEIGHT" ); } while (0); | ||||
| 1306 | g_free (palette); | ||||
| 1307 | |||||
| 1308 | return colors; | ||||
| 1309 | } | ||||
| 1310 | |||||
| 1311 | /* Changes the model color */ | ||||
| 1312 | static void | ||||
| 1313 | palette_change_color (CtkWidget *drawing_area, | ||||
| 1314 | CtkColorSelection *colorsel, | ||||
| 1315 | gdouble *color) | ||||
| 1316 | { | ||||
| 1317 | gint x, y; | ||||
| 1318 | CtkColorSelectionPrivate *priv; | ||||
| 1319 | CdkColor cdk_color; | ||||
| 1320 | CdkColor *current_colors; | ||||
| 1321 | CdkScreen *screen; | ||||
| 1322 | |||||
| 1323 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 1324 | g_return_if_fail (CTK_IS_DRAWING_AREA (drawing_area))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((drawing_area)); GType __t = ((ctk_drawing_area_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_DRAWING_AREA (drawing_area)"); return ; } } while (0); | ||||
| 1325 | |||||
| 1326 | priv = colorsel->private_data; | ||||
| 1327 | |||||
| 1328 | cdk_color.red = UNSCALE (color[0])((guint16)(color[0] * 65535 + 0.5)); | ||||
| 1329 | cdk_color.green = UNSCALE (color[1])((guint16)(color[1] * 65535 + 0.5)); | ||||
| 1330 | cdk_color.blue = UNSCALE (color[2])((guint16)(color[2] * 65535 + 0.5)); | ||||
| 1331 | cdk_color.pixel = 0; | ||||
| 1332 | |||||
| 1333 | x = 0; | ||||
| 1334 | y = 0; /* Quiet GCC */ | ||||
| 1335 | while (x < CTK_CUSTOM_PALETTE_WIDTH10) | ||||
| 1336 | { | ||||
| 1337 | y = 0; | ||||
| 1338 | while (y < CTK_CUSTOM_PALETTE_HEIGHT2) | ||||
| 1339 | { | ||||
| 1340 | if (priv->custom_palette[x][y] == drawing_area) | ||||
| 1341 | goto out; | ||||
| 1342 | |||||
| 1343 | ++y; | ||||
| 1344 | } | ||||
| 1345 | |||||
| 1346 | ++x; | ||||
| 1347 | } | ||||
| 1348 | |||||
| 1349 | out: | ||||
| 1350 | |||||
| 1351 | g_assert (x < CTK_CUSTOM_PALETTE_WIDTH || y < CTK_CUSTOM_PALETTE_HEIGHT)do { if (x < 10 || y < 2) ; else g_assertion_message_expr ("Ctk", "ctkcolorsel.c", 1351, ((const char*) (__func__)), "x < CTK_CUSTOM_PALETTE_WIDTH || y < CTK_CUSTOM_PALETTE_HEIGHT" ); } while (0); | ||||
| 1352 | |||||
| 1353 | current_colors = get_current_colors (colorsel); | ||||
| 1354 | current_colors[y * CTK_CUSTOM_PALETTE_WIDTH10 + x] = cdk_color; | ||||
| 1355 | |||||
| 1356 | screen = ctk_widget_get_screen (CTK_WIDGET (colorsel)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), ((ctk_widget_get_type ()))))))); | ||||
| 1357 | if (change_palette_hook != default_change_palette_func) | ||||
| 1358 | (* change_palette_hook) (screen, current_colors, | ||||
| 1359 | CTK_CUSTOM_PALETTE_WIDTH10 * CTK_CUSTOM_PALETTE_HEIGHT2); | ||||
| 1360 | else if (noscreen_change_palette_hook != default_noscreen_change_palette_func) | ||||
| 1361 | { | ||||
| 1362 | if (screen != cdk_screen_get_default ()) | ||||
| 1363 | g_warning ("ctk_color_selection_set_change_palette_hook used by " | ||||
| 1364 | "widget is not on the default screen."); | ||||
| 1365 | (* noscreen_change_palette_hook) (current_colors, | ||||
| 1366 | CTK_CUSTOM_PALETTE_WIDTH10 * CTK_CUSTOM_PALETTE_HEIGHT2); | ||||
| 1367 | } | ||||
| 1368 | else | ||||
| 1369 | (* change_palette_hook) (screen, current_colors, | ||||
| 1370 | CTK_CUSTOM_PALETTE_WIDTH10 * CTK_CUSTOM_PALETTE_HEIGHT2); | ||||
| 1371 | |||||
| 1372 | g_free (current_colors); | ||||
| 1373 | } | ||||
| 1374 | |||||
| 1375 | /* Changes the view color */ | ||||
| 1376 | static void | ||||
| 1377 | palette_set_color (CtkWidget *drawing_area, | ||||
| 1378 | CtkColorSelection *colorsel, | ||||
| 1379 | gdouble *color) | ||||
| 1380 | { | ||||
| 1381 | gdouble *new_color = g_new (double, 4)((double *) g_malloc_n ((4), sizeof (double))); | ||||
| 1382 | CdkRGBA rgba; | ||||
| 1383 | |||||
| 1384 | rgba.red = color[0]; | ||||
| 1385 | rgba.green = color[1]; | ||||
| 1386 | rgba.blue = color[2]; | ||||
| 1387 | rgba.alpha = 1; | ||||
| 1388 | |||||
| 1389 | ctk_widget_override_background_color (drawing_area, CTK_STATE_FLAG_NORMAL, &rgba); | ||||
| 1390 | |||||
| 1391 | if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set"))((gint) (glong) (g_object_get_data (((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((drawing_area)), (((GType) ((20) << (2)))))))), "color_set"))) == 0) | ||||
| 1392 | { | ||||
| 1393 | static const CtkTargetEntry targets[] = { | ||||
| 1394 | { .target = "application/x-color", .flags = 0 } | ||||
| 1395 | }; | ||||
| 1396 | ctk_drag_source_set (drawing_area, | ||||
| 1397 | CDK_BUTTON1_MASK | CDK_BUTTON3_MASK, | ||||
| 1398 | targets, 1, | ||||
| 1399 | CDK_ACTION_COPY | CDK_ACTION_MOVE); | ||||
| 1400 | |||||
| 1401 | g_signal_connect (drawing_area, "drag-begin",g_signal_connect_data ((drawing_area), ("drag-begin"), (((GCallback ) (palette_drag_begin))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1402 | G_CALLBACK (palette_drag_begin),g_signal_connect_data ((drawing_area), ("drag-begin"), (((GCallback ) (palette_drag_begin))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1403 | colorsel)g_signal_connect_data ((drawing_area), ("drag-begin"), (((GCallback ) (palette_drag_begin))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1404 | g_signal_connect (drawing_area, "drag-data-get",g_signal_connect_data ((drawing_area), ("drag-data-get"), ((( GCallback) (palette_drag_handle))), (colorsel), ((void*)0), ( GConnectFlags) 0) | ||||
| 1405 | G_CALLBACK (palette_drag_handle),g_signal_connect_data ((drawing_area), ("drag-data-get"), ((( GCallback) (palette_drag_handle))), (colorsel), ((void*)0), ( GConnectFlags) 0) | ||||
| 1406 | colorsel)g_signal_connect_data ((drawing_area), ("drag-data-get"), ((( GCallback) (palette_drag_handle))), (colorsel), ((void*)0), ( GConnectFlags) 0); | ||||
| 1407 | |||||
| 1408 | g_object_set_data (G_OBJECT (drawing_area)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((drawing_area)), (((GType) ((20) << (2)))))))), I_("color_set")g_intern_static_string ("color_set"), | ||||
| 1409 | GINT_TO_POINTER (1)((gpointer) (glong) (1))); | ||||
| 1410 | } | ||||
| 1411 | |||||
| 1412 | new_color[0] = color[0]; | ||||
| 1413 | new_color[1] = color[1]; | ||||
| 1414 | new_color[2] = color[2]; | ||||
| 1415 | new_color[3] = 1.0; | ||||
| 1416 | |||||
| 1417 | g_object_set_data_full (G_OBJECT (drawing_area)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((drawing_area)), (((GType) ((20) << (2)))))))), | ||||
| 1418 | I_("color_val")g_intern_static_string ("color_val"), new_color, (GDestroyNotify)g_free); | ||||
| 1419 | } | ||||
| 1420 | |||||
| 1421 | static void | ||||
| 1422 | save_color_selected (CtkWidget *menuitem G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1423 | gpointer data) | ||||
| 1424 | { | ||||
| 1425 | CtkColorSelection *colorsel; | ||||
| 1426 | CtkWidget *drawing_area; | ||||
| 1427 | CtkColorSelectionPrivate *priv; | ||||
| 1428 | |||||
| 1429 | drawing_area = CTK_WIDGET (data)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_widget_get_type ())))))); | ||||
| 1430 | |||||
| 1431 | colorsel = CTK_COLOR_SELECTION (g_object_get_data (G_OBJECT (drawing_area),((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((g_object_get_data (((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((drawing_area)), (((GType) ((20) << (2)))))))), "ctk-color-sel"))), ((ctk_color_selection_get_type ())))))) | ||||
| 1432 | "ctk-color-sel"))((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((g_object_get_data (((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((drawing_area)), (((GType) ((20) << (2)))))))), "ctk-color-sel"))), ((ctk_color_selection_get_type ())))))); | ||||
| 1433 | |||||
| 1434 | priv = colorsel->private_data; | ||||
| 1435 | |||||
| 1436 | palette_change_color (drawing_area, colorsel, priv->color); | ||||
| 1437 | } | ||||
| 1438 | |||||
| 1439 | static void | ||||
| 1440 | do_popup (CtkColorSelection *colorsel, | ||||
| 1441 | CtkWidget *drawing_area, | ||||
| 1442 | const CdkEvent *trigger_event) | ||||
| 1443 | { | ||||
| 1444 | CtkWidget *menu; | ||||
| 1445 | CtkWidget *mi; | ||||
| 1446 | |||||
| 1447 | g_object_set_data (G_OBJECT (drawing_area)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((drawing_area)), (((GType) ((20) << (2)))))))), | ||||
| 1448 | I_("ctk-color-sel")g_intern_static_string ("ctk-color-sel"), | ||||
| 1449 | colorsel); | ||||
| 1450 | |||||
| 1451 | menu = ctk_menu_new (); | ||||
| 1452 | g_signal_connect (menu, "hide", G_CALLBACK (ctk_widget_destroy), NULL)g_signal_connect_data ((menu), ("hide"), (((GCallback) (ctk_widget_destroy ))), (((void*)0)), ((void*)0), (GConnectFlags) 0); | ||||
| 1453 | |||||
| 1454 | mi = ctk_menu_item_new_with_mnemonic (_("_Save color here")((char *) g_dgettext ("ctk30", "_Save color here"))); | ||||
| 1455 | |||||
| 1456 | g_signal_connect (mi, "activate",g_signal_connect_data ((mi), ("activate"), (((GCallback) (save_color_selected ))), (drawing_area), ((void*)0), (GConnectFlags) 0) | ||||
| 1457 | G_CALLBACK (save_color_selected),g_signal_connect_data ((mi), ("activate"), (((GCallback) (save_color_selected ))), (drawing_area), ((void*)0), (GConnectFlags) 0) | ||||
| 1458 | drawing_area)g_signal_connect_data ((mi), ("activate"), (((GCallback) (save_color_selected ))), (drawing_area), ((void*)0), (GConnectFlags) 0); | ||||
| 1459 | |||||
| 1460 | ctk_menu_shell_append (CTK_MENU_SHELL (menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), mi); | ||||
| 1461 | |||||
| 1462 | ctk_widget_show_all (mi); | ||||
| 1463 | |||||
| 1464 | if (trigger_event && cdk_event_triggers_context_menu (trigger_event)) | ||||
| 1465 | ctk_menu_popup_at_pointer (CTK_MENU (menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), trigger_event); | ||||
| 1466 | else | ||||
| 1467 | ctk_menu_popup_at_widget (CTK_MENU (menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), | ||||
| 1468 | drawing_area, | ||||
| 1469 | CDK_GRAVITY_CENTER, | ||||
| 1470 | CDK_GRAVITY_NORTH_WEST, | ||||
| 1471 | trigger_event); | ||||
| 1472 | } | ||||
| 1473 | |||||
| 1474 | |||||
| 1475 | static gboolean | ||||
| 1476 | palette_enter (CtkWidget *drawing_area, | ||||
| 1477 | CdkEventCrossing *event G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1478 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | ||||
| 1479 | { | ||||
| 1480 | g_object_set_data (G_OBJECT (drawing_area)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((drawing_area)), (((GType) ((20) << (2)))))))), | ||||
| 1481 | I_("ctk-colorsel-have-pointer")g_intern_static_string ("ctk-colorsel-have-pointer"), | ||||
| 1482 | GUINT_TO_POINTER (TRUE)((gpointer) (gulong) ((!(0))))); | ||||
| 1483 | |||||
| 1484 | return FALSE(0); | ||||
| 1485 | } | ||||
| 1486 | |||||
| 1487 | static gboolean | ||||
| 1488 | palette_leave (CtkWidget *drawing_area, | ||||
| 1489 | CdkEventCrossing *event G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1490 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | ||||
| 1491 | { | ||||
| 1492 | g_object_set_data (G_OBJECT (drawing_area)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((drawing_area)), (((GType) ((20) << (2)))))))), | ||||
| 1493 | I_("ctk-colorsel-have-pointer")g_intern_static_string ("ctk-colorsel-have-pointer"), | ||||
| 1494 | NULL((void*)0)); | ||||
| 1495 | |||||
| 1496 | return FALSE(0); | ||||
| 1497 | } | ||||
| 1498 | |||||
| 1499 | static gboolean | ||||
| 1500 | palette_press (CtkWidget *drawing_area, | ||||
| 1501 | CdkEventButton *event, | ||||
| 1502 | gpointer data) | ||||
| 1503 | { | ||||
| 1504 | CtkColorSelection *colorsel = CTK_COLOR_SELECTION (data)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((data)), ((ctk_color_selection_get_type ()) ))))); | ||||
| 1505 | |||||
| 1506 | ctk_widget_grab_focus (drawing_area); | ||||
| 1507 | |||||
| 1508 | if (cdk_event_triggers_context_menu ((CdkEvent *) event)) | ||||
| 1509 | { | ||||
| 1510 | do_popup (colorsel, drawing_area, (CdkEvent *) event); | ||||
| 1511 | return TRUE(!(0)); | ||||
| 1512 | } | ||||
| 1513 | |||||
| 1514 | return FALSE(0); | ||||
| 1515 | } | ||||
| 1516 | |||||
| 1517 | static gboolean | ||||
| 1518 | palette_release (CtkWidget *drawing_area, | ||||
| 1519 | CdkEventButton *event, | ||||
| 1520 | gpointer data) | ||||
| 1521 | { | ||||
| 1522 | CtkColorSelection *colorsel = CTK_COLOR_SELECTION (data)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((data)), ((ctk_color_selection_get_type ()) ))))); | ||||
| 1523 | |||||
| 1524 | ctk_widget_grab_focus (drawing_area); | ||||
| 1525 | |||||
| 1526 | if (event->button == CDK_BUTTON_PRIMARY(1) && | ||||
| 1527 | g_object_get_data (G_OBJECT (drawing_area)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((drawing_area)), (((GType) ((20) << (2)))))))), | ||||
| 1528 | "ctk-colorsel-have-pointer") != NULL((void*)0)) | ||||
| 1529 | { | ||||
| 1530 | if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set"))((gint) (glong) (g_object_get_data (((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((drawing_area)), (((GType) ((20) << (2)))))))), "color_set"))) != 0) | ||||
| 1531 | { | ||||
| 1532 | gdouble color[4]; | ||||
| 1533 | palette_get_color (drawing_area, color); | ||||
| 1534 | set_color_internal (colorsel, color); | ||||
| 1535 | } | ||||
| 1536 | } | ||||
| 1537 | |||||
| 1538 | return FALSE(0); | ||||
| 1539 | } | ||||
| 1540 | |||||
| 1541 | static void | ||||
| 1542 | palette_drop_handle (CtkWidget *widget, | ||||
| 1543 | CdkDragContext *context G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1544 | gint x G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1545 | gint y G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1546 | CtkSelectionData *selection_data, | ||||
| 1547 | guint info G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1548 | guint time G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1549 | gpointer data) | ||||
| 1550 | { | ||||
| 1551 | CtkColorSelection *colorsel = CTK_COLOR_SELECTION (data)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((data)), ((ctk_color_selection_get_type ()) ))))); | ||||
| 1552 | gint length; | ||||
| 1553 | guint16 *vals; | ||||
| 1554 | gdouble color[4]; | ||||
| 1555 | |||||
| 1556 | length = ctk_selection_data_get_length (selection_data); | ||||
| 1557 | |||||
| 1558 | if (length < 0) | ||||
| 1559 | return; | ||||
| 1560 | |||||
| 1561 | /* We accept drops with the wrong format, since the KDE color | ||||
| 1562 | * chooser incorrectly drops application/x-color with format 8. | ||||
| 1563 | */ | ||||
| 1564 | if (length != 8) | ||||
| 1565 | { | ||||
| 1566 | g_warning ("Received invalid color data"); | ||||
| 1567 | return; | ||||
| 1568 | } | ||||
| 1569 | |||||
| 1570 | vals = (guint16 *) ctk_selection_data_get_data (selection_data); | ||||
| 1571 | |||||
| 1572 | color[0] = (gdouble)vals[0] / 0xffff; | ||||
| 1573 | color[1] = (gdouble)vals[1] / 0xffff; | ||||
| 1574 | color[2] = (gdouble)vals[2] / 0xffff; | ||||
| 1575 | color[3] = (gdouble)vals[3] / 0xffff; | ||||
| 1576 | palette_change_color (widget, colorsel, color); | ||||
| 1577 | set_color_internal (colorsel, color); | ||||
| 1578 | } | ||||
| 1579 | |||||
| 1580 | static gint | ||||
| 1581 | palette_activate (CtkWidget *widget, | ||||
| 1582 | CdkEventKey *event, | ||||
| 1583 | gpointer data) | ||||
| 1584 | { | ||||
| 1585 | /* should have a drawing area subclass with an activate signal */ | ||||
| 1586 | if ((event->keyval == CDK_KEY_space0x020) || | ||||
| 1587 | (event->keyval == CDK_KEY_Return0xff0d) || | ||||
| 1588 | (event->keyval == CDK_KEY_ISO_Enter0xfe34) || | ||||
| 1589 | (event->keyval == CDK_KEY_KP_Enter0xff8d) || | ||||
| 1590 | (event->keyval == CDK_KEY_KP_Space0xff80)) | ||||
| 1591 | { | ||||
| 1592 | if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "color_set"))((gint) (glong) (g_object_get_data (((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((widget)), (((GType) ((20) << (2))) ))))), "color_set"))) != 0) | ||||
| 1593 | { | ||||
| 1594 | gdouble color[4]; | ||||
| 1595 | palette_get_color (widget, color); | ||||
| 1596 | set_color_internal (CTK_COLOR_SELECTION (data)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((data)), ((ctk_color_selection_get_type ()) ))))), color); | ||||
| 1597 | } | ||||
| 1598 | return TRUE(!(0)); | ||||
| 1599 | } | ||||
| 1600 | |||||
| 1601 | return FALSE(0); | ||||
| 1602 | } | ||||
| 1603 | |||||
| 1604 | static gboolean | ||||
| 1605 | palette_popup (CtkWidget *widget, | ||||
| 1606 | gpointer data) | ||||
| 1607 | { | ||||
| 1608 | do_popup (data, widget, NULL((void*)0)); | ||||
| 1609 | return TRUE(!(0)); | ||||
| 1610 | } | ||||
| 1611 | |||||
| 1612 | |||||
| 1613 | static CtkWidget* | ||||
| 1614 | palette_new (CtkColorSelection *colorsel) | ||||
| 1615 | { | ||||
| 1616 | CtkWidget *retval; | ||||
| 1617 | |||||
| 1618 | static const CtkTargetEntry targets[] = { | ||||
| 1619 | { .target = "application/x-color", .flags = 0 } | ||||
| 1620 | }; | ||||
| 1621 | |||||
| 1622 | retval = ctk_drawing_area_new (); | ||||
| 1623 | |||||
| 1624 | ctk_widget_set_can_focus (retval, TRUE(!(0))); | ||||
| 1625 | |||||
| 1626 | g_object_set_data (G_OBJECT (retval)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((retval)), (((GType) ((20) << (2)))))))), I_("color_set")g_intern_static_string ("color_set"), GINT_TO_POINTER (0)((gpointer) (glong) (0))); | ||||
| 1627 | ctk_widget_set_events (retval, CDK_BUTTON_PRESS_MASK | ||||
| 1628 | | CDK_BUTTON_RELEASE_MASK | ||||
| 1629 | | CDK_ENTER_NOTIFY_MASK | ||||
| 1630 | | CDK_LEAVE_NOTIFY_MASK); | ||||
| 1631 | |||||
| 1632 | g_signal_connect (retval, "draw",g_signal_connect_data ((retval), ("draw"), (((GCallback) (palette_draw ))), (colorsel), ((void*)0), (GConnectFlags) 0) | ||||
| 1633 | G_CALLBACK (palette_draw), colorsel)g_signal_connect_data ((retval), ("draw"), (((GCallback) (palette_draw ))), (colorsel), ((void*)0), (GConnectFlags) 0); | ||||
| 1634 | g_signal_connect (retval, "button-press-event",g_signal_connect_data ((retval), ("button-press-event"), (((GCallback ) (palette_press))), (colorsel), ((void*)0), (GConnectFlags) 0 ) | ||||
| 1635 | G_CALLBACK (palette_press), colorsel)g_signal_connect_data ((retval), ("button-press-event"), (((GCallback ) (palette_press))), (colorsel), ((void*)0), (GConnectFlags) 0 ); | ||||
| 1636 | g_signal_connect (retval, "button-release-event",g_signal_connect_data ((retval), ("button-release-event"), (( (GCallback) (palette_release))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1637 | G_CALLBACK (palette_release), colorsel)g_signal_connect_data ((retval), ("button-release-event"), (( (GCallback) (palette_release))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1638 | g_signal_connect (retval, "enter-notify-event",g_signal_connect_data ((retval), ("enter-notify-event"), (((GCallback ) (palette_enter))), (colorsel), ((void*)0), (GConnectFlags) 0 ) | ||||
| 1639 | G_CALLBACK (palette_enter), colorsel)g_signal_connect_data ((retval), ("enter-notify-event"), (((GCallback ) (palette_enter))), (colorsel), ((void*)0), (GConnectFlags) 0 ); | ||||
| 1640 | g_signal_connect (retval, "leave-notify-event",g_signal_connect_data ((retval), ("leave-notify-event"), (((GCallback ) (palette_leave))), (colorsel), ((void*)0), (GConnectFlags) 0 ) | ||||
| 1641 | G_CALLBACK (palette_leave), colorsel)g_signal_connect_data ((retval), ("leave-notify-event"), (((GCallback ) (palette_leave))), (colorsel), ((void*)0), (GConnectFlags) 0 ); | ||||
| 1642 | g_signal_connect (retval, "key-press-event",g_signal_connect_data ((retval), ("key-press-event"), (((GCallback ) (palette_activate))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1643 | G_CALLBACK (palette_activate), colorsel)g_signal_connect_data ((retval), ("key-press-event"), (((GCallback ) (palette_activate))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1644 | g_signal_connect (retval, "popup-menu",g_signal_connect_data ((retval), ("popup-menu"), (((GCallback ) (palette_popup))), (colorsel), ((void*)0), (GConnectFlags) 0 ) | ||||
| 1645 | G_CALLBACK (palette_popup), colorsel)g_signal_connect_data ((retval), ("popup-menu"), (((GCallback ) (palette_popup))), (colorsel), ((void*)0), (GConnectFlags) 0 ); | ||||
| 1646 | |||||
| 1647 | ctk_drag_dest_set (retval, | ||||
| 1648 | CTK_DEST_DEFAULT_HIGHLIGHT | | ||||
| 1649 | CTK_DEST_DEFAULT_MOTION | | ||||
| 1650 | CTK_DEST_DEFAULT_DROP, | ||||
| 1651 | targets, 1, | ||||
| 1652 | CDK_ACTION_COPY); | ||||
| 1653 | |||||
| 1654 | g_signal_connect (retval, "drag-end",g_signal_connect_data ((retval), ("drag-end"), (((GCallback) ( palette_drag_end))), (((void*)0)), ((void*)0), (GConnectFlags ) 0) | ||||
| 1655 | G_CALLBACK (palette_drag_end), NULL)g_signal_connect_data ((retval), ("drag-end"), (((GCallback) ( palette_drag_end))), (((void*)0)), ((void*)0), (GConnectFlags ) 0); | ||||
| 1656 | g_signal_connect (retval, "drag-data-received",g_signal_connect_data ((retval), ("drag-data-received"), (((GCallback ) (palette_drop_handle))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1657 | G_CALLBACK (palette_drop_handle), colorsel)g_signal_connect_data ((retval), ("drag-data-received"), (((GCallback ) (palette_drop_handle))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1658 | |||||
| 1659 | ctk_widget_set_tooltip_text (retval, | ||||
| 1660 | _("Click this palette entry to make it the current color. "((char *) g_dgettext ("ctk30", "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.”")) | ||||
| 1661 | "To change this entry, drag a color swatch here or right-click "((char *) g_dgettext ("ctk30", "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.”")) | ||||
| 1662 | "it and select “Save color here.”")((char *) g_dgettext ("ctk30", "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.”"))); | ||||
| 1663 | return retval; | ||||
| 1664 | } | ||||
| 1665 | |||||
| 1666 | |||||
| 1667 | /* The actual CtkColorSelection widget */ | ||||
| 1668 | |||||
| 1669 | static CdkCursor * | ||||
| 1670 | make_picker_cursor (CdkScreen *screen) | ||||
| 1671 | { | ||||
| 1672 | CdkCursor *cursor; | ||||
| 1673 | |||||
| 1674 | cursor = cdk_cursor_new_from_name (cdk_screen_get_display (screen), | ||||
| 1675 | "color-picker"); | ||||
| 1676 | |||||
| 1677 | if (!cursor) | ||||
| 1678 | { | ||||
| 1679 | GdkPixbuf *pixbuf; | ||||
| 1680 | |||||
| 1681 | pixbuf = gdk_pixbuf_new_from_data (dropper_bits, | ||||
| 1682 | GDK_COLORSPACE_RGB, TRUE(!(0)), 8, | ||||
| 1683 | DROPPER_WIDTH17, DROPPER_HEIGHT17, | ||||
| 1684 | DROPPER_STRIDE(17 * 4), | ||||
| 1685 | NULL((void*)0), NULL((void*)0)); | ||||
| 1686 | |||||
| 1687 | cursor = cdk_cursor_new_from_pixbuf (cdk_screen_get_display (screen), | ||||
| 1688 | pixbuf, | ||||
| 1689 | DROPPER_X_HOT2, DROPPER_Y_HOT16); | ||||
| 1690 | |||||
| 1691 | g_object_unref (pixbuf); | ||||
| 1692 | } | ||||
| 1693 | |||||
| 1694 | return cursor; | ||||
| 1695 | } | ||||
| 1696 | |||||
| 1697 | static void | ||||
| 1698 | grab_color_at_pointer (CdkScreen *screen, | ||||
| 1699 | CdkDevice *device, | ||||
| 1700 | gint x_root, | ||||
| 1701 | gint y_root, | ||||
| 1702 | gpointer data) | ||||
| 1703 | { | ||||
| 1704 | GdkPixbuf *pixbuf; | ||||
| 1705 | guchar *pixels; | ||||
| 1706 | CtkColorSelection *colorsel = data; | ||||
| 1707 | CtkColorSelectionPrivate *priv; | ||||
| 1708 | CdkColor color; | ||||
| 1709 | CdkWindow *root_window = cdk_screen_get_root_window (screen); | ||||
| 1710 | |||||
| 1711 | priv = colorsel->private_data; | ||||
| 1712 | |||||
| 1713 | pixbuf = gdk_pixbuf_get_from_window (root_window, | ||||
| 1714 | x_root, y_root, | ||||
| 1715 | 1, 1); | ||||
| 1716 | if (!pixbuf) | ||||
| 1717 | { | ||||
| 1718 | gint x, y; | ||||
| 1719 | CdkWindow *window = cdk_device_get_window_at_position (device, &x, &y); | ||||
| 1720 | if (!window) | ||||
| 1721 | return; | ||||
| 1722 | pixbuf = gdk_pixbuf_get_from_window (window, | ||||
| 1723 | x, y, | ||||
| 1724 | 1, 1); | ||||
| 1725 | if (!pixbuf) | ||||
| 1726 | return; | ||||
| 1727 | } | ||||
| 1728 | pixels = gdk_pixbuf_get_pixels (pixbuf); | ||||
| 1729 | color.red = pixels[0] * 0x101; | ||||
| 1730 | color.green = pixels[1] * 0x101; | ||||
| 1731 | color.blue = pixels[2] * 0x101; | ||||
| 1732 | g_object_unref (pixbuf); | ||||
| 1733 | |||||
| 1734 | priv->color[COLORSEL_RED] = SCALE (color.red)(color.red / 65535.); | ||||
| 1735 | priv->color[COLORSEL_GREEN] = SCALE (color.green)(color.green / 65535.); | ||||
| 1736 | priv->color[COLORSEL_BLUE] = SCALE (color.blue)(color.blue / 65535.); | ||||
| 1737 | |||||
| 1738 | ctk_rgb_to_hsv (priv->color[COLORSEL_RED], | ||||
| 1739 | priv->color[COLORSEL_GREEN], | ||||
| 1740 | priv->color[COLORSEL_BLUE], | ||||
| 1741 | &priv->color[COLORSEL_HUE], | ||||
| 1742 | &priv->color[COLORSEL_SATURATION], | ||||
| 1743 | &priv->color[COLORSEL_VALUE]); | ||||
| 1744 | |||||
| 1745 | update_color (colorsel); | ||||
| 1746 | } | ||||
| 1747 | |||||
| 1748 | static void | ||||
| 1749 | shutdown_eyedropper (CtkWidget *widget) | ||||
| 1750 | { | ||||
| 1751 | CtkColorSelection *colorsel; | ||||
| 1752 | CtkColorSelectionPrivate *priv; | ||||
| 1753 | |||||
| 1754 | colorsel = CTK_COLOR_SELECTION (widget)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((widget)), ((ctk_color_selection_get_type ( ))))))); | ||||
| 1755 | priv = colorsel->private_data; | ||||
| 1756 | |||||
| 1757 | if (priv->has_grab) | ||||
| 1758 | { | ||||
| 1759 | cdk_device_ungrab (priv->keyboard_device, priv->grab_time); | ||||
| 1760 | cdk_device_ungrab (priv->pointer_device, priv->grab_time); | ||||
| 1761 | ctk_device_grab_remove (priv->dropper_grab_widget, priv->pointer_device); | ||||
| 1762 | |||||
| 1763 | priv->has_grab = FALSE(0); | ||||
| 1764 | priv->keyboard_device = NULL((void*)0); | ||||
| 1765 | priv->pointer_device = NULL((void*)0); | ||||
| 1766 | } | ||||
| 1767 | } | ||||
| 1768 | |||||
| 1769 | static void | ||||
| 1770 | mouse_motion (CtkWidget *invisible G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1771 | CdkEventMotion *event, | ||||
| 1772 | gpointer data) | ||||
| 1773 | { | ||||
| 1774 | grab_color_at_pointer (cdk_event_get_screen ((CdkEvent *) event), | ||||
| 1775 | cdk_event_get_device ((CdkEvent *) event), | ||||
| 1776 | event->x_root, event->y_root, data); | ||||
| 1777 | } | ||||
| 1778 | |||||
| 1779 | static gboolean | ||||
| 1780 | mouse_release (CtkWidget *invisible, | ||||
| 1781 | CdkEventButton *event, | ||||
| 1782 | gpointer data) | ||||
| 1783 | { | ||||
| 1784 | /* CtkColorSelection *colorsel = data; */ | ||||
| 1785 | |||||
| 1786 | if (event->button != CDK_BUTTON_PRIMARY(1)) | ||||
| 1787 | return FALSE(0); | ||||
| 1788 | |||||
| 1789 | grab_color_at_pointer (cdk_event_get_screen ((CdkEvent *) event), | ||||
| 1790 | cdk_event_get_device ((CdkEvent *) event), | ||||
| 1791 | event->x_root, event->y_root, data); | ||||
| 1792 | |||||
| 1793 | shutdown_eyedropper (CTK_WIDGET (data)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_widget_get_type ()))))))); | ||||
| 1794 | |||||
| 1795 | g_signal_handlers_disconnect_by_func (invisible,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_motion), (data)) | ||||
| 1796 | mouse_motion,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_motion), (data)) | ||||
| 1797 | data)g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_motion), (data)); | ||||
| 1798 | g_signal_handlers_disconnect_by_func (invisible,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_release), (data)) | ||||
| 1799 | mouse_release,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_release), (data)) | ||||
| 1800 | data)g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_release), (data)); | ||||
| 1801 | |||||
| 1802 | return TRUE(!(0)); | ||||
| 1803 | } | ||||
| 1804 | |||||
| 1805 | /* Helper Functions */ | ||||
| 1806 | |||||
| 1807 | static gboolean | ||||
| 1808 | key_press (CtkWidget *invisible, | ||||
| 1809 | CdkEventKey *event, | ||||
| 1810 | gpointer data) | ||||
| 1811 | { | ||||
| 1812 | CdkScreen *screen = cdk_event_get_screen ((CdkEvent *) event); | ||||
| 1813 | CdkDevice *device, *pointer_device; | ||||
| 1814 | guint state = event->state & ctk_accelerator_get_default_mod_mask (); | ||||
| 1815 | gint x, y; | ||||
| 1816 | gint dx, dy; | ||||
| 1817 | |||||
| 1818 | device = cdk_event_get_device ((CdkEvent * ) event); | ||||
| 1819 | pointer_device = cdk_device_get_associated_device (device); | ||||
| 1820 | cdk_device_get_position (pointer_device, NULL((void*)0), &x, &y); | ||||
| 1821 | |||||
| 1822 | dx = 0; | ||||
| 1823 | dy = 0; | ||||
| 1824 | |||||
| 1825 | switch (event->keyval) | ||||
| 1826 | { | ||||
| 1827 | case CDK_KEY_space0x020: | ||||
| 1828 | case CDK_KEY_Return0xff0d: | ||||
| 1829 | case CDK_KEY_ISO_Enter0xfe34: | ||||
| 1830 | case CDK_KEY_KP_Enter0xff8d: | ||||
| 1831 | case CDK_KEY_KP_Space0xff80: | ||||
| 1832 | grab_color_at_pointer (screen, pointer_device, x, y, data); | ||||
| 1833 | /* fall through */ | ||||
| 1834 | |||||
| 1835 | case CDK_KEY_Escape0xff1b: | ||||
| 1836 | shutdown_eyedropper (data); | ||||
| 1837 | |||||
| 1838 | g_signal_handlers_disconnect_by_func (invisible,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_press), (data)) | ||||
| 1839 | mouse_press,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_press), (data)) | ||||
| 1840 | data)g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_press), (data)); | ||||
| 1841 | g_signal_handlers_disconnect_by_func (invisible,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (key_press), (data)) | ||||
| 1842 | key_press,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (key_press), (data)) | ||||
| 1843 | data)g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (key_press), (data)); | ||||
| 1844 | |||||
| 1845 | return TRUE(!(0)); | ||||
| 1846 | |||||
| 1847 | case CDK_KEY_Up0xff52: | ||||
| 1848 | case CDK_KEY_KP_Up0xff97: | ||||
| 1849 | dy = state == CDK_MOD1_MASK ? -BIG_STEP20 : -1; | ||||
| 1850 | break; | ||||
| 1851 | |||||
| 1852 | case CDK_KEY_Down0xff54: | ||||
| 1853 | case CDK_KEY_KP_Down0xff99: | ||||
| 1854 | dy = state == CDK_MOD1_MASK ? BIG_STEP20 : 1; | ||||
| 1855 | break; | ||||
| 1856 | |||||
| 1857 | case CDK_KEY_Left0xff51: | ||||
| 1858 | case CDK_KEY_KP_Left0xff96: | ||||
| 1859 | dx = state == CDK_MOD1_MASK ? -BIG_STEP20 : -1; | ||||
| 1860 | break; | ||||
| 1861 | |||||
| 1862 | case CDK_KEY_Right0xff53: | ||||
| 1863 | case CDK_KEY_KP_Right0xff98: | ||||
| 1864 | dx = state == CDK_MOD1_MASK ? BIG_STEP20 : 1; | ||||
| 1865 | break; | ||||
| 1866 | |||||
| 1867 | default: | ||||
| 1868 | return FALSE(0); | ||||
| 1869 | } | ||||
| 1870 | |||||
| 1871 | cdk_device_warp (pointer_device, screen, x + dx, y + dy); | ||||
| 1872 | |||||
| 1873 | return TRUE(!(0)); | ||||
| 1874 | |||||
| 1875 | } | ||||
| 1876 | |||||
| 1877 | static gboolean | ||||
| 1878 | mouse_press (CtkWidget *invisible, | ||||
| 1879 | CdkEventButton *event, | ||||
| 1880 | gpointer data) | ||||
| 1881 | { | ||||
| 1882 | if (event->type == CDK_BUTTON_PRESS && event->button == CDK_BUTTON_PRIMARY(1)) | ||||
| 1883 | { | ||||
| 1884 | g_signal_connect (invisible, "motion-notify-event",g_signal_connect_data ((invisible), ("motion-notify-event"), ( ((GCallback) (mouse_motion))), (data), ((void*)0), (GConnectFlags ) 0) | ||||
| 1885 | G_CALLBACK (mouse_motion), data)g_signal_connect_data ((invisible), ("motion-notify-event"), ( ((GCallback) (mouse_motion))), (data), ((void*)0), (GConnectFlags ) 0); | ||||
| 1886 | g_signal_connect (invisible, "button-release-event",g_signal_connect_data ((invisible), ("button-release-event"), (((GCallback) (mouse_release))), (data), ((void*)0), (GConnectFlags ) 0) | ||||
| 1887 | G_CALLBACK (mouse_release), data)g_signal_connect_data ((invisible), ("button-release-event"), (((GCallback) (mouse_release))), (data), ((void*)0), (GConnectFlags ) 0); | ||||
| 1888 | g_signal_handlers_disconnect_by_func (invisible,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_press), (data)) | ||||
| 1889 | mouse_press,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_press), (data)) | ||||
| 1890 | data)g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (mouse_press), (data)); | ||||
| 1891 | g_signal_handlers_disconnect_by_func (invisible,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (key_press), (data)) | ||||
| 1892 | key_press,g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (key_press), (data)) | ||||
| 1893 | data)g_signal_handlers_disconnect_matched ((invisible), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (key_press), (data)); | ||||
| 1894 | return TRUE(!(0)); | ||||
| 1895 | } | ||||
| 1896 | |||||
| 1897 | return FALSE(0); | ||||
| 1898 | } | ||||
| 1899 | |||||
| 1900 | /* when the button is clicked */ | ||||
| 1901 | static void | ||||
| 1902 | get_screen_color (CtkWidget *button) | ||||
| 1903 | { | ||||
| 1904 | CtkColorSelection *colorsel = g_object_get_data (G_OBJECT (button)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((button)), (((GType) ((20) << (2)))))))), "COLORSEL"); | ||||
| 1905 | CtkColorSelectionPrivate *priv = colorsel->private_data; | ||||
| 1906 | CdkScreen *screen = ctk_widget_get_screen (CTK_WIDGET (button)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((button)), ((ctk_widget_get_type ()))))))); | ||||
| 1907 | CdkDevice *device, *keyb_device, *pointer_device; | ||||
| 1908 | CdkCursor *picker_cursor; | ||||
| 1909 | CdkGrabStatus grab_status; | ||||
| 1910 | CdkWindow *window; | ||||
| 1911 | CtkWidget *grab_widget, *toplevel; | ||||
| 1912 | |||||
| 1913 | guint32 time = ctk_get_current_event_time (); | ||||
| 1914 | |||||
| 1915 | device = ctk_get_current_event_device (); | ||||
| 1916 | |||||
| 1917 | if (cdk_device_get_source (device) == CDK_SOURCE_KEYBOARD) | ||||
| 1918 | { | ||||
| 1919 | keyb_device = device; | ||||
| 1920 | pointer_device = cdk_device_get_associated_device (device); | ||||
| 1921 | } | ||||
| 1922 | else | ||||
| 1923 | { | ||||
| 1924 | pointer_device = device; | ||||
| 1925 | keyb_device = cdk_device_get_associated_device (device); | ||||
| 1926 | } | ||||
| 1927 | |||||
| 1928 | if (priv->dropper_grab_widget == NULL((void*)0)) | ||||
| 1929 | { | ||||
| 1930 | grab_widget = ctk_window_new (CTK_WINDOW_POPUP); | ||||
| 1931 | ctk_window_set_screen (CTK_WINDOW (grab_widget)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grab_widget)), ((ctk_window_get_type ())))))), screen); | ||||
| 1932 | ctk_window_resize (CTK_WINDOW (grab_widget)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grab_widget)), ((ctk_window_get_type ())))))), 1, 1); | ||||
| 1933 | ctk_window_move (CTK_WINDOW (grab_widget)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grab_widget)), ((ctk_window_get_type ())))))), -100, -100); | ||||
| 1934 | ctk_widget_show (grab_widget); | ||||
| 1935 | |||||
| 1936 | ctk_widget_add_events (grab_widget, | ||||
| 1937 | CDK_BUTTON_RELEASE_MASK | CDK_BUTTON_PRESS_MASK | CDK_POINTER_MOTION_MASK); | ||||
| 1938 | |||||
| 1939 | toplevel = ctk_widget_get_toplevel (CTK_WIDGET (colorsel)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), ((ctk_widget_get_type ()))))))); | ||||
| 1940 | |||||
| 1941 | if (CTK_IS_WINDOW (toplevel)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (toplevel)); GType __t = ((ctk_window_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | ||||
| 1942 | { | ||||
| 1943 | if (ctk_window_has_group (CTK_WINDOW (toplevel)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((toplevel)), ((ctk_window_get_type ())))))))) | ||||
| 1944 | ctk_window_group_add_window (ctk_window_get_group (CTK_WINDOW (toplevel)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((toplevel)), ((ctk_window_get_type ()))))))), | ||||
| 1945 | CTK_WINDOW (grab_widget)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grab_widget)), ((ctk_window_get_type ()))))))); | ||||
| 1946 | } | ||||
| 1947 | |||||
| 1948 | priv->dropper_grab_widget = grab_widget; | ||||
| 1949 | } | ||||
| 1950 | |||||
| 1951 | window = ctk_widget_get_window (priv->dropper_grab_widget); | ||||
| 1952 | |||||
| 1953 | if (cdk_device_grab (keyb_device, | ||||
| 1954 | window, | ||||
| 1955 | CDK_OWNERSHIP_APPLICATION, FALSE(0), | ||||
| 1956 | CDK_KEY_PRESS_MASK | CDK_KEY_RELEASE_MASK, | ||||
| 1957 | NULL((void*)0), time) != CDK_GRAB_SUCCESS) | ||||
| 1958 | return; | ||||
| 1959 | |||||
| 1960 | picker_cursor = make_picker_cursor (screen); | ||||
| 1961 | grab_status = cdk_device_grab (pointer_device, | ||||
| 1962 | window, | ||||
| 1963 | CDK_OWNERSHIP_APPLICATION, | ||||
| 1964 | FALSE(0), | ||||
| 1965 | CDK_BUTTON_RELEASE_MASK | CDK_BUTTON_PRESS_MASK | CDK_POINTER_MOTION_MASK, | ||||
| 1966 | picker_cursor, | ||||
| 1967 | time); | ||||
| 1968 | g_object_unref (picker_cursor); | ||||
| 1969 | |||||
| 1970 | if (grab_status != CDK_GRAB_SUCCESS) | ||||
| 1971 | { | ||||
| 1972 | cdk_device_ungrab (keyb_device, time); | ||||
| 1973 | return; | ||||
| 1974 | } | ||||
| 1975 | |||||
| 1976 | ctk_device_grab_add (priv->dropper_grab_widget, | ||||
| 1977 | pointer_device, | ||||
| 1978 | TRUE(!(0))); | ||||
| 1979 | |||||
| 1980 | priv->grab_time = time; | ||||
| 1981 | priv->has_grab = TRUE(!(0)); | ||||
| 1982 | priv->keyboard_device = keyb_device; | ||||
| 1983 | priv->pointer_device = pointer_device; | ||||
| 1984 | |||||
| 1985 | g_signal_connect (priv->dropper_grab_widget, "button-press-event",g_signal_connect_data ((priv->dropper_grab_widget), ("button-press-event" ), (((GCallback) (mouse_press))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1986 | G_CALLBACK (mouse_press), colorsel)g_signal_connect_data ((priv->dropper_grab_widget), ("button-press-event" ), (((GCallback) (mouse_press))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1987 | g_signal_connect (priv->dropper_grab_widget, "key-press-event",g_signal_connect_data ((priv->dropper_grab_widget), ("key-press-event" ), (((GCallback) (key_press))), (colorsel), ((void*)0), (GConnectFlags ) 0) | ||||
| 1988 | G_CALLBACK (key_press), colorsel)g_signal_connect_data ((priv->dropper_grab_widget), ("key-press-event" ), (((GCallback) (key_press))), (colorsel), ((void*)0), (GConnectFlags ) 0); | ||||
| 1989 | } | ||||
| 1990 | |||||
| 1991 | static void | ||||
| 1992 | hex_changed (CtkWidget *hex_entry G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 1993 | gpointer data) | ||||
| 1994 | { | ||||
| 1995 | CtkColorSelection *colorsel; | ||||
| 1996 | CtkColorSelectionPrivate *priv; | ||||
| 1997 | CdkRGBA color; | ||||
| 1998 | gchar *text; | ||||
| 1999 | |||||
| 2000 | colorsel = CTK_COLOR_SELECTION (data)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((data)), ((ctk_color_selection_get_type ()) ))))); | ||||
| 2001 | priv = colorsel->private_data; | ||||
| 2002 | |||||
| 2003 | if (priv->changing) | ||||
| 2004 | return; | ||||
| 2005 | |||||
| 2006 | text = ctk_editable_get_chars (CTK_EDITABLE (priv->hex_entry)((((CtkEditable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->hex_entry)), ((ctk_editable_get_type ())))))), 0, -1); | ||||
| 2007 | if (cdk_rgba_parse (&color, text)) | ||||
| 2008 | { | ||||
| 2009 | priv->color[COLORSEL_RED] = color.red; | ||||
| 2010 | priv->color[COLORSEL_GREEN] = color.green; | ||||
| 2011 | priv->color[COLORSEL_BLUE] = color.blue; | ||||
| 2012 | ctk_rgb_to_hsv (priv->color[COLORSEL_RED], | ||||
| 2013 | priv->color[COLORSEL_GREEN], | ||||
| 2014 | priv->color[COLORSEL_BLUE], | ||||
| 2015 | &priv->color[COLORSEL_HUE], | ||||
| 2016 | &priv->color[COLORSEL_SATURATION], | ||||
| 2017 | &priv->color[COLORSEL_VALUE]); | ||||
| 2018 | update_color (colorsel); | ||||
| 2019 | } | ||||
| 2020 | g_free (text); | ||||
| 2021 | } | ||||
| 2022 | |||||
| 2023 | static gboolean | ||||
| 2024 | hex_focus_out (CtkWidget *hex_entry, | ||||
| 2025 | CdkEventFocus *event G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 2026 | gpointer data) | ||||
| 2027 | { | ||||
| 2028 | hex_changed (hex_entry, data); | ||||
| 2029 | |||||
| 2030 | return FALSE(0); | ||||
| 2031 | } | ||||
| 2032 | |||||
| 2033 | static void | ||||
| 2034 | hsv_changed (CtkWidget *hsv, | ||||
| 2035 | gpointer data) | ||||
| 2036 | { | ||||
| 2037 | CtkColorSelection *colorsel; | ||||
| 2038 | CtkColorSelectionPrivate *priv; | ||||
| 2039 | |||||
| 2040 | colorsel = CTK_COLOR_SELECTION (data)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((data)), ((ctk_color_selection_get_type ()) ))))); | ||||
| 2041 | priv = colorsel->private_data; | ||||
| 2042 | |||||
| 2043 | if (priv->changing) | ||||
| 2044 | return; | ||||
| 2045 | |||||
| 2046 | ctk_hsv_get_color (CTK_HSV (hsv)((((CtkHSV*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hsv)), ((ctk_hsv_get_type ())))))), | ||||
| 2047 | &priv->color[COLORSEL_HUE], | ||||
| 2048 | &priv->color[COLORSEL_SATURATION], | ||||
| 2049 | &priv->color[COLORSEL_VALUE]); | ||||
| 2050 | ctk_hsv_to_rgb (priv->color[COLORSEL_HUE], | ||||
| 2051 | priv->color[COLORSEL_SATURATION], | ||||
| 2052 | priv->color[COLORSEL_VALUE], | ||||
| 2053 | &priv->color[COLORSEL_RED], | ||||
| 2054 | &priv->color[COLORSEL_GREEN], | ||||
| 2055 | &priv->color[COLORSEL_BLUE]); | ||||
| 2056 | update_color (colorsel); | ||||
| 2057 | } | ||||
| 2058 | |||||
| 2059 | static void | ||||
| 2060 | adjustment_changed (CtkAdjustment *adjustment, | ||||
| 2061 | gpointer data) | ||||
| 2062 | { | ||||
| 2063 | CtkColorSelection *colorsel; | ||||
| 2064 | CtkColorSelectionPrivate *priv; | ||||
| 2065 | |||||
| 2066 | colorsel = CTK_COLOR_SELECTION (g_object_get_data (G_OBJECT (adjustment), "COLORSEL"))((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((g_object_get_data (((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((adjustment)), (((GType) ((20) << ( 2)))))))), "COLORSEL"))), ((ctk_color_selection_get_type ())) )))); | ||||
| 2067 | priv = colorsel->private_data; | ||||
| 2068 | |||||
| 2069 | if (priv->changing) | ||||
| 2070 | return; | ||||
| 2071 | |||||
| 2072 | switch (GPOINTER_TO_INT (data)((gint) (glong) (data))) | ||||
| 2073 | { | ||||
| 2074 | case COLORSEL_SATURATION: | ||||
| 2075 | case COLORSEL_VALUE: | ||||
| 2076 | priv->color[GPOINTER_TO_INT (data)((gint) (glong) (data))] = ctk_adjustment_get_value (adjustment) / 100; | ||||
| 2077 | ctk_hsv_to_rgb (priv->color[COLORSEL_HUE], | ||||
| 2078 | priv->color[COLORSEL_SATURATION], | ||||
| 2079 | priv->color[COLORSEL_VALUE], | ||||
| 2080 | &priv->color[COLORSEL_RED], | ||||
| 2081 | &priv->color[COLORSEL_GREEN], | ||||
| 2082 | &priv->color[COLORSEL_BLUE]); | ||||
| 2083 | break; | ||||
| 2084 | case COLORSEL_HUE: | ||||
| 2085 | priv->color[GPOINTER_TO_INT (data)((gint) (glong) (data))] = ctk_adjustment_get_value (adjustment) / 360; | ||||
| 2086 | ctk_hsv_to_rgb (priv->color[COLORSEL_HUE], | ||||
| 2087 | priv->color[COLORSEL_SATURATION], | ||||
| 2088 | priv->color[COLORSEL_VALUE], | ||||
| 2089 | &priv->color[COLORSEL_RED], | ||||
| 2090 | &priv->color[COLORSEL_GREEN], | ||||
| 2091 | &priv->color[COLORSEL_BLUE]); | ||||
| 2092 | break; | ||||
| 2093 | case COLORSEL_RED: | ||||
| 2094 | case COLORSEL_GREEN: | ||||
| 2095 | case COLORSEL_BLUE: | ||||
| 2096 | priv->color[GPOINTER_TO_INT (data)((gint) (glong) (data))] = ctk_adjustment_get_value (adjustment) / 255; | ||||
| 2097 | |||||
| 2098 | ctk_rgb_to_hsv (priv->color[COLORSEL_RED], | ||||
| 2099 | priv->color[COLORSEL_GREEN], | ||||
| 2100 | priv->color[COLORSEL_BLUE], | ||||
| 2101 | &priv->color[COLORSEL_HUE], | ||||
| 2102 | &priv->color[COLORSEL_SATURATION], | ||||
| 2103 | &priv->color[COLORSEL_VALUE]); | ||||
| 2104 | break; | ||||
| 2105 | default: | ||||
| 2106 | priv->color[GPOINTER_TO_INT (data)((gint) (glong) (data))] = ctk_adjustment_get_value (adjustment) / 255; | ||||
| 2107 | break; | ||||
| 2108 | } | ||||
| 2109 | update_color (colorsel); | ||||
| 2110 | } | ||||
| 2111 | |||||
| 2112 | static void | ||||
| 2113 | opacity_entry_changed (CtkWidget *opacity_entry G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 2114 | gpointer data) | ||||
| 2115 | { | ||||
| 2116 | CtkColorSelection *colorsel; | ||||
| 2117 | CtkColorSelectionPrivate *priv; | ||||
| 2118 | CtkAdjustment *adj; | ||||
| 2119 | gchar *text; | ||||
| 2120 | |||||
| 2121 | colorsel = CTK_COLOR_SELECTION (data)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((data)), ((ctk_color_selection_get_type ()) ))))); | ||||
| 2122 | priv = colorsel->private_data; | ||||
| 2123 | |||||
| 2124 | if (priv->changing) | ||||
| 2125 | return; | ||||
| 2126 | |||||
| 2127 | text = ctk_editable_get_chars (CTK_EDITABLE (priv->opacity_entry)((((CtkEditable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->opacity_entry)), ((ctk_editable_get_type ())))) )), 0, -1); | ||||
| 2128 | adj = ctk_range_get_adjustment (CTK_RANGE (priv->opacity_slider)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->opacity_slider)), ((ctk_range_get_type ()))))))); | ||||
| 2129 | ctk_adjustment_set_value (adj, g_strtod (text, NULL((void*)0))); | ||||
| 2130 | |||||
| 2131 | update_color (colorsel); | ||||
| 2132 | |||||
| 2133 | g_free (text); | ||||
| 2134 | } | ||||
| 2135 | |||||
| 2136 | static void | ||||
| 2137 | make_label_spinbutton (CtkColorSelection *colorsel, | ||||
| 2138 | CtkWidget **spinbutton, | ||||
| 2139 | gchar *text, | ||||
| 2140 | CtkWidget *table, | ||||
| 2141 | gint i, | ||||
| 2142 | gint j, | ||||
| 2143 | gint channel_type, | ||||
| 2144 | const gchar *tooltip) | ||||
| 2145 | { | ||||
| 2146 | CtkWidget *label; | ||||
| 2147 | CtkAdjustment *adjust; | ||||
| 2148 | |||||
| 2149 | if (channel_type == COLORSEL_HUE) | ||||
| 2150 | { | ||||
| 2151 | adjust = ctk_adjustment_new (0.0, 0.0, 360.0, 1.0, 1.0, 0.0); | ||||
| 2152 | } | ||||
| 2153 | else if (channel_type == COLORSEL_SATURATION || | ||||
| 2154 | channel_type == COLORSEL_VALUE) | ||||
| 2155 | { | ||||
| 2156 | adjust = ctk_adjustment_new (0.0, 0.0, 100.0, 1.0, 1.0, 0.0); | ||||
| 2157 | } | ||||
| 2158 | else | ||||
| 2159 | { | ||||
| 2160 | adjust = ctk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0); | ||||
| 2161 | } | ||||
| 2162 | g_object_set_data (G_OBJECT (adjust)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((adjust)), (((GType) ((20) << (2)))))))), I_("COLORSEL")g_intern_static_string ("COLORSEL"), colorsel); | ||||
| 2163 | *spinbutton = ctk_spin_button_new (adjust, 10.0, 0); | ||||
| 2164 | |||||
| 2165 | ctk_widget_set_tooltip_text (*spinbutton, tooltip); | ||||
| 2166 | |||||
| 2167 | g_signal_connect (adjust, "value-changed",g_signal_connect_data ((adjust), ("value-changed"), (((GCallback ) (adjustment_changed))), (((gpointer) (glong) (channel_type) )), ((void*)0), (GConnectFlags) 0) | ||||
| 2168 | G_CALLBACK (adjustment_changed),g_signal_connect_data ((adjust), ("value-changed"), (((GCallback ) (adjustment_changed))), (((gpointer) (glong) (channel_type) )), ((void*)0), (GConnectFlags) 0) | ||||
| 2169 | GINT_TO_POINTER (channel_type))g_signal_connect_data ((adjust), ("value-changed"), (((GCallback ) (adjustment_changed))), (((gpointer) (glong) (channel_type) )), ((void*)0), (GConnectFlags) 0); | ||||
| 2170 | label = ctk_label_new_with_mnemonic (text); | ||||
| 2171 | ctk_label_set_mnemonic_widget (CTK_LABEL (label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((ctk_label_get_type ())))))), *spinbutton); | ||||
| 2172 | |||||
| 2173 | ctk_widget_set_halign (label, CTK_ALIGN_START); | ||||
| 2174 | ctk_widget_set_valign (label, CTK_ALIGN_CENTER); | ||||
| 2175 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), label, i, j, 1, 1); | ||||
| 2176 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), *spinbutton, i+1, j, 1, 1); | ||||
| 2177 | } | ||||
| 2178 | |||||
| 2179 | static void | ||||
| 2180 | make_palette_frame (CtkColorSelection *colorsel, | ||||
| 2181 | CtkWidget *table, | ||||
| 2182 | gint i, | ||||
| 2183 | gint j) | ||||
| 2184 | { | ||||
| 2185 | CtkWidget *frame; | ||||
| 2186 | CtkColorSelectionPrivate *priv; | ||||
| 2187 | |||||
| 2188 | priv = colorsel->private_data; | ||||
| 2189 | frame = ctk_frame_new (NULL((void*)0)); | ||||
| 2190 | ctk_frame_set_shadow_type (CTK_FRAME (frame)((((CtkFrame*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((frame)), ((ctk_frame_get_type ())))))), CTK_SHADOW_IN); | ||||
| 2191 | priv->custom_palette[i][j] = palette_new (colorsel); | ||||
| 2192 | ctk_widget_set_size_request (priv->custom_palette[i][j], CUSTOM_PALETTE_ENTRY_WIDTH20, CUSTOM_PALETTE_ENTRY_HEIGHT20); | ||||
| 2193 | ctk_container_add (CTK_CONTAINER (frame)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((frame)), ((ctk_container_get_type ())))))), priv->custom_palette[i][j]); | ||||
| 2194 | ctk_grid_attach (CTK_GRID (table)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((table)), ((ctk_grid_get_type ())))))), frame, i, j, 1, 1); | ||||
| 2195 | } | ||||
| 2196 | |||||
| 2197 | /* Set the palette entry [x][y] to be the currently selected one. */ | ||||
| 2198 | static void | ||||
| 2199 | set_selected_palette (CtkColorSelection *colorsel, int x, int y) | ||||
| 2200 | { | ||||
| 2201 | CtkColorSelectionPrivate *priv = colorsel->private_data; | ||||
| 2202 | |||||
| 2203 | ctk_widget_grab_focus (priv->custom_palette[x][y]); | ||||
| 2204 | } | ||||
| 2205 | |||||
| 2206 | static double | ||||
| 2207 | scale_round (double val, double factor) | ||||
| 2208 | { | ||||
| 2209 | val = floor (val * factor + 0.5); | ||||
| 2210 | val = MAX (val, 0)(((val) > (0)) ? (val) : (0)); | ||||
| 2211 | val = MIN (val, factor)(((val) < (factor)) ? (val) : (factor)); | ||||
| 2212 | return val; | ||||
| 2213 | } | ||||
| 2214 | |||||
| 2215 | static void | ||||
| 2216 | update_color (CtkColorSelection *colorsel) | ||||
| 2217 | { | ||||
| 2218 | CtkColorSelectionPrivate *priv = colorsel->private_data; | ||||
| 2219 | gchar entryval[12]; | ||||
| 2220 | gchar opacity_text[32]; | ||||
| 2221 | gchar *ptr; | ||||
| 2222 | |||||
| 2223 | priv->changing = TRUE(!(0)); | ||||
| 2224 | color_sample_update_samples (colorsel); | ||||
| 2225 | |||||
| 2226 | ctk_hsv_set_color (CTK_HSV (priv->triangle_colorsel)((((CtkHSV*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->triangle_colorsel)), ((ctk_hsv_get_type ()))))) ), | ||||
| 2227 | priv->color[COLORSEL_HUE], | ||||
| 2228 | priv->color[COLORSEL_SATURATION], | ||||
| 2229 | priv->color[COLORSEL_VALUE]); | ||||
| 2230 | ctk_adjustment_set_value (ctk_spin_button_get_adjustment | ||||
| 2231 | (CTK_SPIN_BUTTON (priv->hue_spinbutton)((((CtkSpinButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->hue_spinbutton)), ((ctk_spin_button_get_type () ))))))), | ||||
| 2232 | scale_round (priv->color[COLORSEL_HUE], 360)); | ||||
| 2233 | ctk_adjustment_set_value (ctk_spin_button_get_adjustment | ||||
| 2234 | (CTK_SPIN_BUTTON (priv->sat_spinbutton)((((CtkSpinButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->sat_spinbutton)), ((ctk_spin_button_get_type () ))))))), | ||||
| 2235 | scale_round (priv->color[COLORSEL_SATURATION], 100)); | ||||
| 2236 | ctk_adjustment_set_value (ctk_spin_button_get_adjustment | ||||
| 2237 | (CTK_SPIN_BUTTON (priv->val_spinbutton)((((CtkSpinButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->val_spinbutton)), ((ctk_spin_button_get_type () ))))))), | ||||
| 2238 | scale_round (priv->color[COLORSEL_VALUE], 100)); | ||||
| 2239 | ctk_adjustment_set_value (ctk_spin_button_get_adjustment | ||||
| 2240 | (CTK_SPIN_BUTTON (priv->red_spinbutton)((((CtkSpinButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->red_spinbutton)), ((ctk_spin_button_get_type () ))))))), | ||||
| 2241 | scale_round (priv->color[COLORSEL_RED], 255)); | ||||
| 2242 | ctk_adjustment_set_value (ctk_spin_button_get_adjustment | ||||
| 2243 | (CTK_SPIN_BUTTON (priv->green_spinbutton)((((CtkSpinButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->green_spinbutton)), ((ctk_spin_button_get_type ( )))))))), | ||||
| 2244 | scale_round (priv->color[COLORSEL_GREEN], 255)); | ||||
| 2245 | ctk_adjustment_set_value (ctk_spin_button_get_adjustment | ||||
| 2246 | (CTK_SPIN_BUTTON (priv->blue_spinbutton)((((CtkSpinButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->blue_spinbutton)), ((ctk_spin_button_get_type ( )))))))), | ||||
| 2247 | scale_round (priv->color[COLORSEL_BLUE], 255)); | ||||
| 2248 | ctk_adjustment_set_value (ctk_range_get_adjustment | ||||
| 2249 | (CTK_RANGE (priv->opacity_slider)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->opacity_slider)), ((ctk_range_get_type ()))))))), | ||||
| 2250 | scale_round (priv->color[COLORSEL_OPACITY], 255)); | ||||
| 2251 | |||||
| 2252 | g_snprintf (opacity_text, 32, "%.0f", scale_round (priv->color[COLORSEL_OPACITY], 255)); | ||||
| 2253 | ctk_entry_set_text (CTK_ENTRY (priv->opacity_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->opacity_entry)), ((ctk_entry_get_type ())))))), opacity_text); | ||||
| 2254 | |||||
| 2255 | g_snprintf (entryval, 11, "#%2X%2X%2X", | ||||
| 2256 | (guint) (scale_round (priv->color[COLORSEL_RED], 255)), | ||||
| 2257 | (guint) (scale_round (priv->color[COLORSEL_GREEN], 255)), | ||||
| 2258 | (guint) (scale_round (priv->color[COLORSEL_BLUE], 255))); | ||||
| 2259 | |||||
| 2260 | for (ptr = entryval; *ptr; ptr++) | ||||
| 2261 | if (*ptr == ' ') | ||||
| 2262 | *ptr = '0'; | ||||
| 2263 | ctk_entry_set_text (CTK_ENTRY (priv->hex_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->hex_entry)), ((ctk_entry_get_type ())))))), entryval); | ||||
| 2264 | priv->changing = FALSE(0); | ||||
| 2265 | |||||
| 2266 | g_object_ref (colorsel)((__typeof__ (colorsel)) (g_object_ref) (colorsel)); | ||||
| 2267 | |||||
| 2268 | g_signal_emit (colorsel, color_selection_signals[COLOR_CHANGED], 0); | ||||
| 2269 | |||||
| 2270 | g_object_freeze_notify (G_OBJECT (colorsel)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), (((GType) ((20) << (2))))))))); | ||||
| 2271 | g_object_notify (G_OBJECT (colorsel)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), (((GType) ((20) << (2)))))))), "current-color"); | ||||
| 2272 | g_object_notify (G_OBJECT (colorsel)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), (((GType) ((20) << (2)))))))), "current-alpha"); | ||||
| 2273 | g_object_thaw_notify (G_OBJECT (colorsel)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), (((GType) ((20) << (2))))))))); | ||||
| 2274 | |||||
| 2275 | g_object_unref (colorsel); | ||||
| 2276 | } | ||||
| 2277 | |||||
| 2278 | static void | ||||
| 2279 | update_palette (CtkColorSelection *colorsel) | ||||
| 2280 | { | ||||
| 2281 | CdkColor *current_colors; | ||||
| 2282 | gint i, j; | ||||
| 2283 | |||||
| 2284 | current_colors = get_current_colors (colorsel); | ||||
| 2285 | |||||
| 2286 | for (i = 0; i < CTK_CUSTOM_PALETTE_HEIGHT2; i++) | ||||
| 2287 | { | ||||
| 2288 | for (j = 0; j < CTK_CUSTOM_PALETTE_WIDTH10; j++) | ||||
| 2289 | { | ||||
| 2290 | gint index; | ||||
| 2291 | |||||
| 2292 | index = i * CTK_CUSTOM_PALETTE_WIDTH10 + j; | ||||
| 2293 | |||||
| 2294 | ctk_color_selection_set_palette_color (colorsel, | ||||
| 2295 | index, | ||||
| 2296 | ¤t_colors[index]); | ||||
| 2297 | } | ||||
| 2298 | } | ||||
| 2299 | |||||
| 2300 | g_free (current_colors); | ||||
| 2301 | } | ||||
| 2302 | |||||
| 2303 | static void | ||||
| 2304 | palette_change_notify_instance (GObject *object G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 2305 | GParamSpec *pspec G_GNUC_UNUSED__attribute__ ((__unused__)), | ||||
| 2306 | gpointer data) | ||||
| 2307 | { | ||||
| 2308 | update_palette (CTK_COLOR_SELECTION (data)((((CtkColorSelection*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((data)), ((ctk_color_selection_get_type ()) )))))); | ||||
| |||||
| 2309 | } | ||||
| 2310 | |||||
| 2311 | static void | ||||
| 2312 | default_noscreen_change_palette_func (const CdkColor *colors, | ||||
| 2313 | gint n_colors) | ||||
| 2314 | { | ||||
| 2315 | default_change_palette_func (cdk_screen_get_default (), colors, n_colors); | ||||
| 2316 | } | ||||
| 2317 | |||||
| 2318 | static void | ||||
| 2319 | default_change_palette_func (CdkScreen *screen, | ||||
| 2320 | const CdkColor *colors, | ||||
| 2321 | gint n_colors) | ||||
| 2322 | { | ||||
| 2323 | gchar *str; | ||||
| 2324 | |||||
| 2325 | str = ctk_color_selection_palette_to_string (colors, n_colors); | ||||
| 2326 | |||||
| 2327 | ctk_settings_set_string_property (ctk_settings_get_for_screen (screen), | ||||
| 2328 | "ctk-color-palette", | ||||
| 2329 | str, | ||||
| 2330 | "ctk_color_selection_palette_to_string"); | ||||
| 2331 | |||||
| 2332 | g_free (str); | ||||
| 2333 | } | ||||
| 2334 | |||||
| 2335 | /** | ||||
| 2336 | * ctk_color_selection_new: | ||||
| 2337 | * | ||||
| 2338 | * Creates a new CtkColorSelection. | ||||
| 2339 | * | ||||
| 2340 | * Returns: a new #CtkColorSelection | ||||
| 2341 | */ | ||||
| 2342 | CtkWidget * | ||||
| 2343 | ctk_color_selection_new (void) | ||||
| 2344 | { | ||||
| 2345 | CtkColorSelection *colorsel; | ||||
| 2346 | CtkColorSelectionPrivate *priv; | ||||
| 2347 | gdouble color[4]; | ||||
| 2348 | color[0] = 1.0; | ||||
| 2349 | color[1] = 1.0; | ||||
| 2350 | color[2] = 1.0; | ||||
| 2351 | color[3] = 1.0; | ||||
| 2352 | |||||
| 2353 | colorsel = g_object_new (CTK_TYPE_COLOR_SELECTION(ctk_color_selection_get_type ()), NULL((void*)0)); | ||||
| 2354 | priv = colorsel->private_data; | ||||
| 2355 | set_color_internal (colorsel, color); | ||||
| 2356 | ctk_color_selection_set_has_opacity_control (colorsel, TRUE(!(0))); | ||||
| 2357 | |||||
| 2358 | /* We want to make sure that default_set is FALSE. | ||||
| 2359 | * This way the user can still set it. | ||||
| 2360 | */ | ||||
| 2361 | priv->default_set = FALSE(0); | ||||
| 2362 | priv->default_alpha_set = FALSE(0); | ||||
| 2363 | |||||
| 2364 | return CTK_WIDGET (colorsel)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), ((ctk_widget_get_type ())))))); | ||||
| 2365 | } | ||||
| 2366 | |||||
| 2367 | /** | ||||
| 2368 | * ctk_color_selection_get_has_opacity_control: | ||||
| 2369 | * @colorsel: a #CtkColorSelection | ||||
| 2370 | * | ||||
| 2371 | * Determines whether the colorsel has an opacity control. | ||||
| 2372 | * | ||||
| 2373 | * Returns: %TRUE if the @colorsel has an opacity control, | ||||
| 2374 | * %FALSE if it does't | ||||
| 2375 | */ | ||||
| 2376 | gboolean | ||||
| 2377 | ctk_color_selection_get_has_opacity_control (CtkColorSelection *colorsel) | ||||
| 2378 | { | ||||
| 2379 | CtkColorSelectionPrivate *priv; | ||||
| 2380 | |||||
| 2381 | g_return_val_if_fail (CTK_IS_COLOR_SELECTION (colorsel), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ((0)); } } while (0); | ||||
| 2382 | |||||
| 2383 | priv = colorsel->private_data; | ||||
| 2384 | |||||
| 2385 | return priv->has_opacity; | ||||
| 2386 | } | ||||
| 2387 | |||||
| 2388 | /** | ||||
| 2389 | * ctk_color_selection_set_has_opacity_control: | ||||
| 2390 | * @colorsel: a #CtkColorSelection | ||||
| 2391 | * @has_opacity: %TRUE if @colorsel can set the opacity, %FALSE otherwise | ||||
| 2392 | * | ||||
| 2393 | * Sets the @colorsel to use or not use opacity. | ||||
| 2394 | */ | ||||
| 2395 | void | ||||
| 2396 | ctk_color_selection_set_has_opacity_control (CtkColorSelection *colorsel, | ||||
| 2397 | gboolean has_opacity) | ||||
| 2398 | { | ||||
| 2399 | CtkColorSelectionPrivate *priv; | ||||
| 2400 | |||||
| 2401 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2402 | |||||
| 2403 | priv = colorsel->private_data; | ||||
| 2404 | has_opacity = has_opacity != FALSE(0); | ||||
| 2405 | |||||
| 2406 | if (priv->has_opacity != has_opacity) | ||||
| 2407 | { | ||||
| 2408 | priv->has_opacity = has_opacity; | ||||
| 2409 | if (has_opacity) | ||||
| 2410 | { | ||||
| 2411 | ctk_widget_show (priv->opacity_slider); | ||||
| 2412 | ctk_widget_show (priv->opacity_label); | ||||
| 2413 | ctk_widget_show (priv->opacity_entry); | ||||
| 2414 | } | ||||
| 2415 | else | ||||
| 2416 | { | ||||
| 2417 | ctk_widget_hide (priv->opacity_slider); | ||||
| 2418 | ctk_widget_hide (priv->opacity_label); | ||||
| 2419 | ctk_widget_hide (priv->opacity_entry); | ||||
| 2420 | } | ||||
| 2421 | color_sample_update_samples (colorsel); | ||||
| 2422 | |||||
| 2423 | g_object_notify (G_OBJECT (colorsel)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), (((GType) ((20) << (2)))))))), "has-opacity-control"); | ||||
| 2424 | } | ||||
| 2425 | } | ||||
| 2426 | |||||
| 2427 | /** | ||||
| 2428 | * ctk_color_selection_get_has_palette: | ||||
| 2429 | * @colorsel: a #CtkColorSelection | ||||
| 2430 | * | ||||
| 2431 | * Determines whether the color selector has a color palette. | ||||
| 2432 | * | ||||
| 2433 | * Returns: %TRUE if the selector has a palette, %FALSE if it hasn't | ||||
| 2434 | */ | ||||
| 2435 | gboolean | ||||
| 2436 | ctk_color_selection_get_has_palette (CtkColorSelection *colorsel) | ||||
| 2437 | { | ||||
| 2438 | CtkColorSelectionPrivate *priv; | ||||
| 2439 | |||||
| 2440 | g_return_val_if_fail (CTK_IS_COLOR_SELECTION (colorsel), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ((0)); } } while (0); | ||||
| 2441 | |||||
| 2442 | priv = colorsel->private_data; | ||||
| 2443 | |||||
| 2444 | return priv->has_palette; | ||||
| 2445 | } | ||||
| 2446 | |||||
| 2447 | /** | ||||
| 2448 | * ctk_color_selection_set_has_palette: | ||||
| 2449 | * @colorsel: a #CtkColorSelection | ||||
| 2450 | * @has_palette: %TRUE if palette is to be visible, %FALSE otherwise | ||||
| 2451 | * | ||||
| 2452 | * Shows and hides the palette based upon the value of @has_palette. | ||||
| 2453 | */ | ||||
| 2454 | void | ||||
| 2455 | ctk_color_selection_set_has_palette (CtkColorSelection *colorsel, | ||||
| 2456 | gboolean has_palette) | ||||
| 2457 | { | ||||
| 2458 | CtkColorSelectionPrivate *priv; | ||||
| 2459 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2460 | |||||
| 2461 | priv = colorsel->private_data; | ||||
| 2462 | has_palette = has_palette != FALSE(0); | ||||
| 2463 | |||||
| 2464 | if (priv->has_palette != has_palette) | ||||
| 2465 | { | ||||
| 2466 | priv->has_palette = has_palette; | ||||
| 2467 | if (has_palette) | ||||
| 2468 | ctk_widget_show (priv->palette_frame); | ||||
| 2469 | else | ||||
| 2470 | ctk_widget_hide (priv->palette_frame); | ||||
| 2471 | |||||
| 2472 | update_tooltips (colorsel); | ||||
| 2473 | |||||
| 2474 | g_object_notify (G_OBJECT (colorsel)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((colorsel)), (((GType) ((20) << (2)))))))), "has-palette"); | ||||
| 2475 | } | ||||
| 2476 | } | ||||
| 2477 | |||||
| 2478 | /** | ||||
| 2479 | * ctk_color_selection_set_current_color: | ||||
| 2480 | * @colorsel: a #CtkColorSelection | ||||
| 2481 | * @color: a #CdkColor to set the current color with | ||||
| 2482 | * | ||||
| 2483 | * Sets the current color to be @color. | ||||
| 2484 | * | ||||
| 2485 | * The first time this is called, it will also set | ||||
| 2486 | * the original color to be @color too. | ||||
| 2487 | */ | ||||
| 2488 | void | ||||
| 2489 | ctk_color_selection_set_current_color (CtkColorSelection *colorsel, | ||||
| 2490 | const CdkColor *color) | ||||
| 2491 | { | ||||
| 2492 | CtkColorSelectionPrivate *priv; | ||||
| 2493 | gint i; | ||||
| 2494 | |||||
| 2495 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2496 | g_return_if_fail (color != NULL)do { if ((color != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "color != NULL"); return ; } } while (0); | ||||
| 2497 | |||||
| 2498 | priv = colorsel->private_data; | ||||
| 2499 | priv->changing = TRUE(!(0)); | ||||
| 2500 | priv->color[COLORSEL_RED] = SCALE (color->red)(color->red / 65535.); | ||||
| 2501 | priv->color[COLORSEL_GREEN] = SCALE (color->green)(color->green / 65535.); | ||||
| 2502 | priv->color[COLORSEL_BLUE] = SCALE (color->blue)(color->blue / 65535.); | ||||
| 2503 | ctk_rgb_to_hsv (priv->color[COLORSEL_RED], | ||||
| 2504 | priv->color[COLORSEL_GREEN], | ||||
| 2505 | priv->color[COLORSEL_BLUE], | ||||
| 2506 | &priv->color[COLORSEL_HUE], | ||||
| 2507 | &priv->color[COLORSEL_SATURATION], | ||||
| 2508 | &priv->color[COLORSEL_VALUE]); | ||||
| 2509 | if (priv->default_set == FALSE(0)) | ||||
| 2510 | { | ||||
| 2511 | for (i = 0; i < COLORSEL_NUM_CHANNELS; i++) | ||||
| 2512 | priv->old_color[i] = priv->color[i]; | ||||
| 2513 | } | ||||
| 2514 | priv->default_set = TRUE(!(0)); | ||||
| 2515 | update_color (colorsel); | ||||
| 2516 | } | ||||
| 2517 | |||||
| 2518 | /** | ||||
| 2519 | * ctk_color_selection_set_current_alpha: | ||||
| 2520 | * @colorsel: a #CtkColorSelection | ||||
| 2521 | * @alpha: an integer between 0 and 65535 | ||||
| 2522 | * | ||||
| 2523 | * Sets the current opacity to be @alpha. | ||||
| 2524 | * | ||||
| 2525 | * The first time this is called, it will also set | ||||
| 2526 | * the original opacity to be @alpha too. | ||||
| 2527 | */ | ||||
| 2528 | void | ||||
| 2529 | ctk_color_selection_set_current_alpha (CtkColorSelection *colorsel, | ||||
| 2530 | guint16 alpha) | ||||
| 2531 | { | ||||
| 2532 | CtkColorSelectionPrivate *priv; | ||||
| 2533 | gint i; | ||||
| 2534 | |||||
| 2535 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2536 | |||||
| 2537 | priv = colorsel->private_data; | ||||
| 2538 | priv->changing = TRUE(!(0)); | ||||
| 2539 | priv->color[COLORSEL_OPACITY] = SCALE (alpha)(alpha / 65535.); | ||||
| 2540 | if (priv->default_alpha_set == FALSE(0)) | ||||
| 2541 | { | ||||
| 2542 | for (i = 0; i < COLORSEL_NUM_CHANNELS; i++) | ||||
| 2543 | priv->old_color[i] = priv->color[i]; | ||||
| 2544 | } | ||||
| 2545 | priv->default_alpha_set = TRUE(!(0)); | ||||
| 2546 | update_color (colorsel); | ||||
| 2547 | } | ||||
| 2548 | |||||
| 2549 | /** | ||||
| 2550 | * ctk_color_selection_get_current_color: | ||||
| 2551 | * @colorsel: a #CtkColorSelection | ||||
| 2552 | * @color: (out): a #CdkColor to fill in with the current color | ||||
| 2553 | * | ||||
| 2554 | * Sets @color to be the current color in the CtkColorSelection widget. | ||||
| 2555 | */ | ||||
| 2556 | void | ||||
| 2557 | ctk_color_selection_get_current_color (CtkColorSelection *colorsel, | ||||
| 2558 | CdkColor *color) | ||||
| 2559 | { | ||||
| 2560 | CtkColorSelectionPrivate *priv; | ||||
| 2561 | |||||
| 2562 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2563 | g_return_if_fail (color != NULL)do { if ((color != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "color != NULL"); return ; } } while (0); | ||||
| 2564 | |||||
| 2565 | priv = colorsel->private_data; | ||||
| 2566 | color->red = UNSCALE (priv->color[COLORSEL_RED])((guint16)(priv->color[COLORSEL_RED] * 65535 + 0.5)); | ||||
| 2567 | color->green = UNSCALE (priv->color[COLORSEL_GREEN])((guint16)(priv->color[COLORSEL_GREEN] * 65535 + 0.5)); | ||||
| 2568 | color->blue = UNSCALE (priv->color[COLORSEL_BLUE])((guint16)(priv->color[COLORSEL_BLUE] * 65535 + 0.5)); | ||||
| 2569 | } | ||||
| 2570 | |||||
| 2571 | /** | ||||
| 2572 | * ctk_color_selection_get_current_alpha: | ||||
| 2573 | * @colorsel: a #CtkColorSelection | ||||
| 2574 | * | ||||
| 2575 | * Returns the current alpha value. | ||||
| 2576 | * | ||||
| 2577 | * Returns: an integer between 0 and 65535 | ||||
| 2578 | */ | ||||
| 2579 | guint16 | ||||
| 2580 | ctk_color_selection_get_current_alpha (CtkColorSelection *colorsel) | ||||
| 2581 | { | ||||
| 2582 | CtkColorSelectionPrivate *priv; | ||||
| 2583 | |||||
| 2584 | g_return_val_if_fail (CTK_IS_COLOR_SELECTION (colorsel), 0)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return (0); } } while (0); | ||||
| 2585 | |||||
| 2586 | priv = colorsel->private_data; | ||||
| 2587 | return priv->has_opacity ? UNSCALE (priv->color[COLORSEL_OPACITY])((guint16)(priv->color[COLORSEL_OPACITY] * 65535 + 0.5)) : 65535; | ||||
| 2588 | } | ||||
| 2589 | |||||
| 2590 | /** | ||||
| 2591 | * ctk_color_selection_set_previous_color: | ||||
| 2592 | * @colorsel: a #CtkColorSelection | ||||
| 2593 | * @color: a #CdkColor to set the previous color with | ||||
| 2594 | * | ||||
| 2595 | * Sets the “previous” color to be @color. | ||||
| 2596 | * | ||||
| 2597 | * This function should be called with some hesitations, | ||||
| 2598 | * as it might seem confusing to have that color change. | ||||
| 2599 | * Calling ctk_color_selection_set_current_color() will also | ||||
| 2600 | * set this color the first time it is called. | ||||
| 2601 | */ | ||||
| 2602 | void | ||||
| 2603 | ctk_color_selection_set_previous_color (CtkColorSelection *colorsel, | ||||
| 2604 | const CdkColor *color) | ||||
| 2605 | { | ||||
| 2606 | CtkColorSelectionPrivate *priv; | ||||
| 2607 | |||||
| 2608 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2609 | g_return_if_fail (color != NULL)do { if ((color != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "color != NULL"); return ; } } while (0); | ||||
| 2610 | |||||
| 2611 | priv = colorsel->private_data; | ||||
| 2612 | priv->changing = TRUE(!(0)); | ||||
| 2613 | priv->old_color[COLORSEL_RED] = SCALE (color->red)(color->red / 65535.); | ||||
| 2614 | priv->old_color[COLORSEL_GREEN] = SCALE (color->green)(color->green / 65535.); | ||||
| 2615 | priv->old_color[COLORSEL_BLUE] = SCALE (color->blue)(color->blue / 65535.); | ||||
| 2616 | ctk_rgb_to_hsv (priv->old_color[COLORSEL_RED], | ||||
| 2617 | priv->old_color[COLORSEL_GREEN], | ||||
| 2618 | priv->old_color[COLORSEL_BLUE], | ||||
| 2619 | &priv->old_color[COLORSEL_HUE], | ||||
| 2620 | &priv->old_color[COLORSEL_SATURATION], | ||||
| 2621 | &priv->old_color[COLORSEL_VALUE]); | ||||
| 2622 | color_sample_update_samples (colorsel); | ||||
| 2623 | priv->default_set = TRUE(!(0)); | ||||
| 2624 | priv->changing = FALSE(0); | ||||
| 2625 | } | ||||
| 2626 | |||||
| 2627 | /** | ||||
| 2628 | * ctk_color_selection_set_previous_alpha: | ||||
| 2629 | * @colorsel: a #CtkColorSelection | ||||
| 2630 | * @alpha: an integer between 0 and 65535 | ||||
| 2631 | * | ||||
| 2632 | * Sets the “previous” alpha to be @alpha. | ||||
| 2633 | * | ||||
| 2634 | * This function should be called with some hesitations, | ||||
| 2635 | * as it might seem confusing to have that alpha change. | ||||
| 2636 | */ | ||||
| 2637 | void | ||||
| 2638 | ctk_color_selection_set_previous_alpha (CtkColorSelection *colorsel, | ||||
| 2639 | guint16 alpha) | ||||
| 2640 | { | ||||
| 2641 | CtkColorSelectionPrivate *priv; | ||||
| 2642 | |||||
| 2643 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2644 | |||||
| 2645 | priv = colorsel->private_data; | ||||
| 2646 | priv->changing = TRUE(!(0)); | ||||
| 2647 | priv->old_color[COLORSEL_OPACITY] = SCALE (alpha)(alpha / 65535.); | ||||
| 2648 | color_sample_update_samples (colorsel); | ||||
| 2649 | priv->default_alpha_set = TRUE(!(0)); | ||||
| 2650 | priv->changing = FALSE(0); | ||||
| 2651 | } | ||||
| 2652 | |||||
| 2653 | |||||
| 2654 | /** | ||||
| 2655 | * ctk_color_selection_get_previous_color: | ||||
| 2656 | * @colorsel: a #CtkColorSelection | ||||
| 2657 | * @color: (out): a #CdkColor to fill in with the original color value | ||||
| 2658 | * | ||||
| 2659 | * Fills @color in with the original color value. | ||||
| 2660 | */ | ||||
| 2661 | void | ||||
| 2662 | ctk_color_selection_get_previous_color (CtkColorSelection *colorsel, | ||||
| 2663 | CdkColor *color) | ||||
| 2664 | { | ||||
| 2665 | CtkColorSelectionPrivate *priv; | ||||
| 2666 | |||||
| 2667 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2668 | g_return_if_fail (color != NULL)do { if ((color != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "color != NULL"); return ; } } while (0); | ||||
| 2669 | |||||
| 2670 | priv = colorsel->private_data; | ||||
| 2671 | color->red = UNSCALE (priv->old_color[COLORSEL_RED])((guint16)(priv->old_color[COLORSEL_RED] * 65535 + 0.5)); | ||||
| 2672 | color->green = UNSCALE (priv->old_color[COLORSEL_GREEN])((guint16)(priv->old_color[COLORSEL_GREEN] * 65535 + 0.5)); | ||||
| 2673 | color->blue = UNSCALE (priv->old_color[COLORSEL_BLUE])((guint16)(priv->old_color[COLORSEL_BLUE] * 65535 + 0.5)); | ||||
| 2674 | } | ||||
| 2675 | |||||
| 2676 | /** | ||||
| 2677 | * ctk_color_selection_get_previous_alpha: | ||||
| 2678 | * @colorsel: a #CtkColorSelection | ||||
| 2679 | * | ||||
| 2680 | * Returns the previous alpha value. | ||||
| 2681 | * | ||||
| 2682 | * Returns: an integer between 0 and 65535 | ||||
| 2683 | */ | ||||
| 2684 | guint16 | ||||
| 2685 | ctk_color_selection_get_previous_alpha (CtkColorSelection *colorsel) | ||||
| 2686 | { | ||||
| 2687 | CtkColorSelectionPrivate *priv; | ||||
| 2688 | |||||
| 2689 | g_return_val_if_fail (CTK_IS_COLOR_SELECTION (colorsel), 0)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return (0); } } while (0); | ||||
| 2690 | |||||
| 2691 | priv = colorsel->private_data; | ||||
| 2692 | return priv->has_opacity ? UNSCALE (priv->old_color[COLORSEL_OPACITY])((guint16)(priv->old_color[COLORSEL_OPACITY] * 65535 + 0.5 )) : 65535; | ||||
| 2693 | } | ||||
| 2694 | |||||
| 2695 | /** | ||||
| 2696 | * ctk_color_selection_set_current_rgba: | ||||
| 2697 | * @colorsel: a #CtkColorSelection | ||||
| 2698 | * @rgba: A #CdkRGBA to set the current color with | ||||
| 2699 | * | ||||
| 2700 | * Sets the current color to be @rgba. | ||||
| 2701 | * | ||||
| 2702 | * The first time this is called, it will also set | ||||
| 2703 | * the original color to be @rgba too. | ||||
| 2704 | * | ||||
| 2705 | * Since: 3.0 | ||||
| 2706 | */ | ||||
| 2707 | void | ||||
| 2708 | ctk_color_selection_set_current_rgba (CtkColorSelection *colorsel, | ||||
| 2709 | const CdkRGBA *rgba) | ||||
| 2710 | { | ||||
| 2711 | CtkColorSelectionPrivate *priv; | ||||
| 2712 | gint i; | ||||
| 2713 | |||||
| 2714 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2715 | g_return_if_fail (rgba != NULL)do { if ((rgba != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "rgba != NULL"); return; } } while (0); | ||||
| 2716 | |||||
| 2717 | priv = colorsel->private_data; | ||||
| 2718 | priv->changing = TRUE(!(0)); | ||||
| 2719 | |||||
| 2720 | priv->color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1)(((rgba->red) > (1)) ? (1) : (((rgba->red) < (0)) ? (0) : (rgba->red))); | ||||
| 2721 | priv->color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1)(((rgba->green) > (1)) ? (1) : (((rgba->green) < ( 0)) ? (0) : (rgba->green))); | ||||
| 2722 | priv->color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1)(((rgba->blue) > (1)) ? (1) : (((rgba->blue) < (0 )) ? (0) : (rgba->blue))); | ||||
| 2723 | priv->color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1)(((rgba->alpha) > (1)) ? (1) : (((rgba->alpha) < ( 0)) ? (0) : (rgba->alpha))); | ||||
| 2724 | |||||
| 2725 | ctk_rgb_to_hsv (priv->color[COLORSEL_RED], | ||||
| 2726 | priv->color[COLORSEL_GREEN], | ||||
| 2727 | priv->color[COLORSEL_BLUE], | ||||
| 2728 | &priv->color[COLORSEL_HUE], | ||||
| 2729 | &priv->color[COLORSEL_SATURATION], | ||||
| 2730 | &priv->color[COLORSEL_VALUE]); | ||||
| 2731 | |||||
| 2732 | if (priv->default_set == FALSE(0)) | ||||
| 2733 | { | ||||
| 2734 | for (i = 0; i < COLORSEL_NUM_CHANNELS; i++) | ||||
| 2735 | priv->old_color[i] = priv->color[i]; | ||||
| 2736 | } | ||||
| 2737 | |||||
| 2738 | priv->default_set = TRUE(!(0)); | ||||
| 2739 | update_color (colorsel); | ||||
| 2740 | } | ||||
| 2741 | |||||
| 2742 | /** | ||||
| 2743 | * ctk_color_selection_get_current_rgba: | ||||
| 2744 | * @colorsel: a #CtkColorSelection | ||||
| 2745 | * @rgba: (out): a #CdkRGBA to fill in with the current color | ||||
| 2746 | * | ||||
| 2747 | * Sets @rgba to be the current color in the CtkColorSelection widget. | ||||
| 2748 | * | ||||
| 2749 | * Since: 3.0 | ||||
| 2750 | */ | ||||
| 2751 | void | ||||
| 2752 | ctk_color_selection_get_current_rgba (CtkColorSelection *colorsel, | ||||
| 2753 | CdkRGBA *rgba) | ||||
| 2754 | { | ||||
| 2755 | CtkColorSelectionPrivate *priv; | ||||
| 2756 | |||||
| 2757 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2758 | g_return_if_fail (rgba != NULL)do { if ((rgba != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "rgba != NULL"); return; } } while (0); | ||||
| 2759 | |||||
| 2760 | priv = colorsel->private_data; | ||||
| 2761 | rgba->red = priv->color[COLORSEL_RED]; | ||||
| 2762 | rgba->green = priv->color[COLORSEL_GREEN]; | ||||
| 2763 | rgba->blue = priv->color[COLORSEL_BLUE]; | ||||
| 2764 | rgba->alpha = (priv->has_opacity) ? priv->color[COLORSEL_OPACITY] : 1; | ||||
| 2765 | } | ||||
| 2766 | |||||
| 2767 | /** | ||||
| 2768 | * ctk_color_selection_set_previous_rgba: | ||||
| 2769 | * @colorsel: a #CtkColorSelection | ||||
| 2770 | * @rgba: a #CdkRGBA to set the previous color with | ||||
| 2771 | * | ||||
| 2772 | * Sets the “previous” color to be @rgba. | ||||
| 2773 | * | ||||
| 2774 | * This function should be called with some hesitations, | ||||
| 2775 | * as it might seem confusing to have that color change. | ||||
| 2776 | * Calling ctk_color_selection_set_current_rgba() will also | ||||
| 2777 | * set this color the first time it is called. | ||||
| 2778 | * | ||||
| 2779 | * Since: 3.0 | ||||
| 2780 | */ | ||||
| 2781 | void | ||||
| 2782 | ctk_color_selection_set_previous_rgba (CtkColorSelection *colorsel, | ||||
| 2783 | const CdkRGBA *rgba) | ||||
| 2784 | { | ||||
| 2785 | CtkColorSelectionPrivate *priv; | ||||
| 2786 | |||||
| 2787 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2788 | g_return_if_fail (rgba != NULL)do { if ((rgba != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "rgba != NULL"); return; } } while (0); | ||||
| 2789 | |||||
| 2790 | priv = colorsel->private_data; | ||||
| 2791 | priv->changing = TRUE(!(0)); | ||||
| 2792 | |||||
| 2793 | priv->old_color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1)(((rgba->red) > (1)) ? (1) : (((rgba->red) < (0)) ? (0) : (rgba->red))); | ||||
| 2794 | priv->old_color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1)(((rgba->green) > (1)) ? (1) : (((rgba->green) < ( 0)) ? (0) : (rgba->green))); | ||||
| 2795 | priv->old_color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1)(((rgba->blue) > (1)) ? (1) : (((rgba->blue) < (0 )) ? (0) : (rgba->blue))); | ||||
| 2796 | priv->old_color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1)(((rgba->alpha) > (1)) ? (1) : (((rgba->alpha) < ( 0)) ? (0) : (rgba->alpha))); | ||||
| 2797 | |||||
| 2798 | ctk_rgb_to_hsv (priv->old_color[COLORSEL_RED], | ||||
| 2799 | priv->old_color[COLORSEL_GREEN], | ||||
| 2800 | priv->old_color[COLORSEL_BLUE], | ||||
| 2801 | &priv->old_color[COLORSEL_HUE], | ||||
| 2802 | &priv->old_color[COLORSEL_SATURATION], | ||||
| 2803 | &priv->old_color[COLORSEL_VALUE]); | ||||
| 2804 | |||||
| 2805 | color_sample_update_samples (colorsel); | ||||
| 2806 | priv->default_set = TRUE(!(0)); | ||||
| 2807 | priv->changing = FALSE(0); | ||||
| 2808 | } | ||||
| 2809 | |||||
| 2810 | /** | ||||
| 2811 | * ctk_color_selection_get_previous_rgba: | ||||
| 2812 | * @colorsel: a #CtkColorSelection | ||||
| 2813 | * @rgba: (out): a #CdkRGBA to fill in with the original color value | ||||
| 2814 | * | ||||
| 2815 | * Fills @rgba in with the original color value. | ||||
| 2816 | * | ||||
| 2817 | * Since: 3.0 | ||||
| 2818 | */ | ||||
| 2819 | void | ||||
| 2820 | ctk_color_selection_get_previous_rgba (CtkColorSelection *colorsel, | ||||
| 2821 | CdkRGBA *rgba) | ||||
| 2822 | { | ||||
| 2823 | CtkColorSelectionPrivate *priv; | ||||
| 2824 | |||||
| 2825 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2826 | g_return_if_fail (rgba != NULL)do { if ((rgba != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "rgba != NULL"); return; } } while (0); | ||||
| 2827 | |||||
| 2828 | priv = colorsel->private_data; | ||||
| 2829 | rgba->red = priv->old_color[COLORSEL_RED]; | ||||
| 2830 | rgba->green = priv->old_color[COLORSEL_GREEN]; | ||||
| 2831 | rgba->blue = priv->old_color[COLORSEL_BLUE]; | ||||
| 2832 | rgba->alpha = (priv->has_opacity) ? priv->old_color[COLORSEL_OPACITY] : 1; | ||||
| 2833 | } | ||||
| 2834 | |||||
| 2835 | /** | ||||
| 2836 | * ctk_color_selection_set_palette_color: | ||||
| 2837 | * @colorsel: a #CtkColorSelection | ||||
| 2838 | * @index: the color index of the palette | ||||
| 2839 | * @color: A #CdkColor to set the palette with | ||||
| 2840 | * | ||||
| 2841 | * Sets the palette located at @index to have @color as its color. | ||||
| 2842 | */ | ||||
| 2843 | static void | ||||
| 2844 | ctk_color_selection_set_palette_color (CtkColorSelection *colorsel, | ||||
| 2845 | gint index, | ||||
| 2846 | CdkColor *color) | ||||
| 2847 | { | ||||
| 2848 | CtkColorSelectionPrivate *priv; | ||||
| 2849 | gint x, y; | ||||
| 2850 | gdouble col[3]; | ||||
| 2851 | |||||
| 2852 | g_return_if_fail (CTK_IS_COLOR_SELECTION (colorsel))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ; } } while (0); | ||||
| 2853 | g_return_if_fail (index >= 0 && index < CTK_CUSTOM_PALETTE_WIDTH*CTK_CUSTOM_PALETTE_HEIGHT)do { if ((index >= 0 && index < 10*2)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__) ), "index >= 0 && index < CTK_CUSTOM_PALETTE_WIDTH*CTK_CUSTOM_PALETTE_HEIGHT" ); return; } } while (0); | ||||
| 2854 | |||||
| 2855 | x = index % CTK_CUSTOM_PALETTE_WIDTH10; | ||||
| 2856 | y = index / CTK_CUSTOM_PALETTE_WIDTH10; | ||||
| 2857 | |||||
| 2858 | priv = colorsel->private_data; | ||||
| 2859 | col[0] = SCALE (color->red)(color->red / 65535.); | ||||
| 2860 | col[1] = SCALE (color->green)(color->green / 65535.); | ||||
| 2861 | col[2] = SCALE (color->blue)(color->blue / 65535.); | ||||
| 2862 | |||||
| 2863 | palette_set_color (priv->custom_palette[x][y], colorsel, col); | ||||
| 2864 | } | ||||
| 2865 | |||||
| 2866 | /** | ||||
| 2867 | * ctk_color_selection_is_adjusting: | ||||
| 2868 | * @colorsel: a #CtkColorSelection | ||||
| 2869 | * | ||||
| 2870 | * Gets the current state of the @colorsel. | ||||
| 2871 | * | ||||
| 2872 | * Returns: %TRUE if the user is currently dragging | ||||
| 2873 | * a color around, and %FALSE if the selection has stopped | ||||
| 2874 | */ | ||||
| 2875 | gboolean | ||||
| 2876 | ctk_color_selection_is_adjusting (CtkColorSelection *colorsel) | ||||
| 2877 | { | ||||
| 2878 | CtkColorSelectionPrivate *priv; | ||||
| 2879 | |||||
| 2880 | g_return_val_if_fail (CTK_IS_COLOR_SELECTION (colorsel), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((colorsel)); GType __t = ((ctk_color_selection_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_COLOR_SELECTION (colorsel)"); return ((0)); } } while (0); | ||||
| 2881 | |||||
| 2882 | priv = colorsel->private_data; | ||||
| 2883 | |||||
| 2884 | return (ctk_hsv_is_adjusting (CTK_HSV (priv->triangle_colorsel)((((CtkHSV*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->triangle_colorsel)), ((ctk_hsv_get_type ()))))) ))); | ||||
| 2885 | } | ||||
| 2886 | |||||
| 2887 | |||||
| 2888 | /** | ||||
| 2889 | * ctk_color_selection_palette_from_string: | ||||
| 2890 | * @str: a string encoding a color palette | ||||
| 2891 | * @colors: (out) (array length=n_colors): return location for | ||||
| 2892 | * allocated array of #CdkColor | ||||
| 2893 | * @n_colors: return location for length of array | ||||
| 2894 | * | ||||
| 2895 | * Parses a color palette string; the string is a colon-separated | ||||
| 2896 | * list of color names readable by cdk_color_parse(). | ||||
| 2897 | * | ||||
| 2898 | * Returns: %TRUE if a palette was successfully parsed | ||||
| 2899 | */ | ||||
| 2900 | gboolean | ||||
| 2901 | ctk_color_selection_palette_from_string (const gchar *str, | ||||
| 2902 | CdkColor **colors, | ||||
| 2903 | gint *n_colors) | ||||
| 2904 | { | ||||
| 2905 | CdkColor *retval; | ||||
| 2906 | gint count; | ||||
| 2907 | gchar *p; | ||||
| 2908 | gchar *start; | ||||
| 2909 | gchar *copy; | ||||
| 2910 | |||||
| 2911 | count = 0; | ||||
| 2912 | retval = NULL((void*)0); | ||||
| 2913 | copy = g_strdup (str)g_strdup_inline (str); | ||||
| 2914 | |||||
| 2915 | start = copy; | ||||
| 2916 | p = copy; | ||||
| 2917 | while (TRUE(!(0))) | ||||
| 2918 | { | ||||
| 2919 | if (*p == ':' || *p == '\0') | ||||
| 2920 | { | ||||
| 2921 | gboolean done = TRUE(!(0)); | ||||
| 2922 | |||||
| 2923 | if (start
| ||||
| 2924 | { | ||||
| 2925 | goto failed; /* empty entry */ | ||||
| 2926 | } | ||||
| 2927 | |||||
| 2928 | if (*p) | ||||
| 2929 | { | ||||
| 2930 | *p = '\0'; | ||||
| 2931 | done = FALSE(0); | ||||
| 2932 | } | ||||
| 2933 | |||||
| 2934 | retval = g_renew (CdkColor, retval, count + 1)((CdkColor *) g_realloc_n (retval, (count + 1), sizeof (CdkColor ))); | ||||
| 2935 | if (!cdk_color_parse (start, retval + count)) | ||||
| 2936 | { | ||||
| 2937 | goto failed; | ||||
| 2938 | } | ||||
| 2939 | |||||
| 2940 | ++count; | ||||
| 2941 | |||||
| 2942 | if (done
| ||||
| 2943 | break; | ||||
| 2944 | else | ||||
| 2945 | start = p + 1; | ||||
| 2946 | } | ||||
| 2947 | |||||
| 2948 | ++p; | ||||
| 2949 | } | ||||
| 2950 | |||||
| 2951 | g_free (copy); | ||||
| 2952 | |||||
| 2953 | if (colors
| ||||
| 2954 | *colors = retval; | ||||
| 2955 | else | ||||
| 2956 | g_free (retval); | ||||
| 2957 | |||||
| 2958 | if (n_colors
| ||||
| 2959 | *n_colors = count; | ||||
| 2960 | |||||
| 2961 | return TRUE(!(0)); | ||||
| 2962 | |||||
| 2963 | failed: | ||||
| 2964 | g_free (copy); | ||||
| 2965 | g_free (retval); | ||||
| 2966 | |||||
| 2967 | if (colors
| ||||
| 2968 | *colors = NULL((void*)0); | ||||
| 2969 | if (n_colors
| ||||
| 2970 | *n_colors = 0; | ||||
| 2971 | |||||
| 2972 | return FALSE(0); | ||||
| 2973 | } | ||||
| 2974 | |||||
| 2975 | /** | ||||
| 2976 | * ctk_color_selection_palette_to_string: | ||||
| 2977 | * @colors: (array length=n_colors): an array of colors | ||||
| 2978 | * @n_colors: length of the array | ||||
| 2979 | * | ||||
| 2980 | * Encodes a palette as a string, useful for persistent storage. | ||||
| 2981 | * | ||||
| 2982 | * Returns: allocated string encoding the palette | ||||
| 2983 | */ | ||||
| 2984 | gchar* | ||||
| 2985 | ctk_color_selection_palette_to_string (const CdkColor *colors, | ||||
| 2986 | gint n_colors) | ||||
| 2987 | { | ||||
| 2988 | gint i; | ||||
| 2989 | gchar **strs = NULL((void*)0); | ||||
| 2990 | gchar *retval; | ||||
| 2991 | |||||
| 2992 | if (n_colors == 0) | ||||
| 2993 | return g_strdup ("")g_strdup_inline (""); | ||||
| 2994 | |||||
| 2995 | strs = g_new0 (gchar*, n_colors + 1)((gchar* *) g_malloc0_n ((n_colors + 1), sizeof (gchar*))); | ||||
| 2996 | |||||
| 2997 | i = 0; | ||||
| 2998 | while (i < n_colors) | ||||
| 2999 | { | ||||
| 3000 | gchar *ptr; | ||||
| 3001 | |||||
| 3002 | strs[i] = | ||||
| 3003 | g_strdup_printf ("#%2X%2X%2X", | ||||
| 3004 | colors[i].red / 256, | ||||
| 3005 | colors[i].green / 256, | ||||
| 3006 | colors[i].blue / 256); | ||||
| 3007 | |||||
| 3008 | for (ptr = strs[i]; *ptr; ptr++) | ||||
| 3009 | if (*ptr == ' ') | ||||
| 3010 | *ptr = '0'; | ||||
| 3011 | |||||
| 3012 | ++i; | ||||
| 3013 | } | ||||
| 3014 | |||||
| 3015 | retval = g_strjoinv (":", strs); | ||||
| 3016 | |||||
| 3017 | g_strfreev (strs); | ||||
| 3018 | |||||
| 3019 | return retval; | ||||
| 3020 | } | ||||
| 3021 | |||||
| 3022 | /** | ||||
| 3023 | * ctk_color_selection_set_change_palette_with_screen_hook: (skip) | ||||
| 3024 | * @func: a function to call when the custom palette needs saving | ||||
| 3025 | * | ||||
| 3026 | * Installs a global function to be called whenever the user | ||||
| 3027 | * tries to modify the palette in a color selection. | ||||
| 3028 | * | ||||
| 3029 | * This function should save the new palette contents, and update | ||||
| 3030 | * the #CtkSettings:ctk-color-palette CtkSettings property so all | ||||
| 3031 | * CtkColorSelection widgets will be modified. | ||||
| 3032 | * | ||||
| 3033 | * Returns: the previous change palette hook (that was replaced) | ||||
| 3034 | * | ||||
| 3035 | * Since: 2.2 | ||||
| 3036 | */ | ||||
| 3037 | CtkColorSelectionChangePaletteWithScreenFunc | ||||
| 3038 | ctk_color_selection_set_change_palette_with_screen_hook (CtkColorSelectionChangePaletteWithScreenFunc func) | ||||
| 3039 | { | ||||
| 3040 | CtkColorSelectionChangePaletteWithScreenFunc old; | ||||
| 3041 | |||||
| 3042 | old = change_palette_hook; | ||||
| 3043 | |||||
| 3044 | change_palette_hook = func; | ||||
| 3045 | |||||
| 3046 | return old; | ||||
| 3047 | } | ||||
| 3048 | |||||
| 3049 | static void | ||||
| 3050 | make_control_relations (AtkObject *atk_obj, | ||||
| 3051 | CtkWidget *widget) | ||||
| 3052 | { | ||||
| 3053 | AtkObject *obj; | ||||
| 3054 | |||||
| 3055 | obj = ctk_widget_get_accessible (widget); | ||||
| 3056 | atk_object_add_relationship (atk_obj, ATK_RELATION_CONTROLLED_BY, obj); | ||||
| 3057 | atk_object_add_relationship (obj, ATK_RELATION_CONTROLLER_FOR, atk_obj); | ||||
| 3058 | } | ||||
| 3059 | |||||
| 3060 | static void | ||||
| 3061 | make_all_relations (AtkObject *atk_obj, | ||||
| 3062 | CtkColorSelectionPrivate *priv) | ||||
| 3063 | { | ||||
| 3064 | make_control_relations (atk_obj, priv->hue_spinbutton); | ||||
| 3065 | make_control_relations (atk_obj, priv->sat_spinbutton); | ||||
| 3066 | make_control_relations (atk_obj, priv->val_spinbutton); | ||||
| 3067 | make_control_relations (atk_obj, priv->red_spinbutton); | ||||
| 3068 | make_control_relations (atk_obj, priv->green_spinbutton); | ||||
| 3069 | make_control_relations (atk_obj, priv->blue_spinbutton); | ||||
| 3070 | } |