diff options
author | Denis Washington <denisw@online.de> | 2012-02-15 22:46:26 +0100 |
---|---|---|
committer | Denis Washington <denisw@online.de> | 2012-02-15 22:46:26 +0100 |
commit | c3fe8359dda108d0f06400e7cd01801d9bc9595f (patch) | |
tree | 8b4612db91752c9c692ce0005e043814dd30d2a2 | |
parent | b45a20d4e4801d2fe12a6147303d6354fb69cc1b (diff) | |
parent | bf89bc624b34cf4b4291dd05f0adff9d34945f01 (diff) | |
download | gtk+-gtkbuilder-gbinding.tar.gz |
Merge branch 'master' into gtkbuilder-gbindinggtkbuilder-gbinding
78 files changed, 5758 insertions, 630 deletions
diff --git a/demos/gtk-demo/colorsel.c b/demos/gtk-demo/colorsel.c index 8c3fe5e9ca..633e13b9c2 100644 --- a/demos/gtk-demo/colorsel.c +++ b/demos/gtk-demo/colorsel.c @@ -36,26 +36,17 @@ change_color_callback (GtkWidget *button, { GtkWidget *dialog; GtkColorSelection *colorsel; - GtkColorSelectionDialog *selection_dialog; + GtkColorChooserDialog *selection_dialog; gint response; - dialog = gtk_color_selection_dialog_new ("Changing color"); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window)); - - selection_dialog = GTK_COLOR_SELECTION_DIALOG (dialog); - colorsel = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (selection_dialog)); - - gtk_color_selection_set_previous_rgba (colorsel, &color); - gtk_color_selection_set_current_rgba (colorsel, &color); - gtk_color_selection_set_has_palette (colorsel, TRUE); + dialog = gtk_color_chooser_dialog_new ("Changing color", GTK_WINDOW (window)); + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog), &color); response = gtk_dialog_run (GTK_DIALOG (dialog)); if (response == GTK_RESPONSE_OK) { - gtk_color_selection_get_current_rgba (colorsel, &color); - + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &color); gtk_widget_override_background_color (da, 0, &color); } diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index b693422f06..29ce17e156 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -42,7 +42,8 @@ show_about (GtkMenuItem *item, GtkWidget *window) GdkPixbuf *pixbuf; const gchar *authors[] = { "Andrea Cimitan", - "Cosimo Cecchi" + "Cosimo Cecchi", + NULL }; pixbuf = gdk_pixbuf_new_from_resource ("/logos/gtk-logo-256.png", NULL); diff --git a/docs/reference/gtk/Makefile.am b/docs/reference/gtk/Makefile.am index 54f3c7a33d..5099c337a3 100644 --- a/docs/reference/gtk/Makefile.am +++ b/docs/reference/gtk/Makefile.am @@ -287,6 +287,7 @@ HTML_IMAGES = \ $(srcdir)/images/check-button.png \ $(srcdir)/images/color-button.png \ $(srcdir)/images/colorsel.png \ + $(srcdir)/images/colorchooser.png \ $(srcdir)/images/combo-box.png \ $(srcdir)/images/combo-box-entry.png \ $(srcdir)/images/entry.png \ @@ -296,6 +297,7 @@ HTML_IMAGES = \ $(srcdir)/images/filechooser.png \ $(srcdir)/images/font-button.png \ $(srcdir)/images/fontsel.png \ + $(srcdir)/images/fontchooser.png \ $(srcdir)/images/frame.png \ $(srcdir)/images/icon-view.png \ $(srcdir)/images/image.png \ diff --git a/docs/reference/gtk/gtk-docs.sgml b/docs/reference/gtk/gtk-docs.sgml index 06b94b6167..c435070341 100644 --- a/docs/reference/gtk/gtk-docs.sgml +++ b/docs/reference/gtk/gtk-docs.sgml @@ -209,18 +209,22 @@ <chapter id="SelectorWidgets"> <title>Selectors (Color/File/Font)</title> + <xi:include href="xml/gtkcolorchooser.xml" /> <xi:include href="xml/gtkcolorbutton.xml" /> - <xi:include href="xml/gtkcolorseldlg.xml" /> + <xi:include href="xml/gtkcolorchooserwidget.xml" /> + <xi:include href="xml/gtkcolorchooserdialog.xml" /> <xi:include href="xml/gtkcolorsel.xml" /> + <xi:include href="xml/gtkcolorseldlg.xml" /> <xi:include href="xml/gtkhsv.xml" /> <xi:include href="xml/gtkfilechooser.xml" /> <xi:include href="xml/gtkfilechooserbutton.xml" /> <xi:include href="xml/gtkfilechooserdialog.xml" /> <xi:include href="xml/gtkfilechooserwidget.xml" /> <xi:include href="xml/gtkfilefilter.xml" /> - <xi:include href="xml/gtkfontbutton.xml" /> <xi:include href="xml/gtkfontchooser.xml" /> - <xi:include href="xml/gtkfontchooserdlg.xml" /> + <xi:include href="xml/gtkfontbutton.xml" /> + <xi:include href="xml/gtkfontchooserwidget.xml" /> + <xi:include href="xml/gtkfontchooserdialog.xml" /> <xi:include href="xml/gtkfontsel.xml" /> <xi:include href="xml/gtkfontseldlg.xml" /> </chapter> diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index 393e274eff..4674beb913 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -1535,7 +1535,7 @@ gtk_font_chooser_widget_get_type </SECTION> <SECTION> -<FILE>gtkfontchooserdlg</FILE> +<FILE>gtkfontchooserdialog</FILE> <TITLE>GtkFontChooserDialog</TITLE> GtkFontChooserDialog gtk_font_chooser_dialog_new @@ -7298,3 +7298,61 @@ GtkOverlayClass gtk_overlay_get_type GtkOverlayPrivate </SECTION> + +<SECTION> +<FILE>gtkcolorchooser</FILE> +<TITLE>GtkColorChooser</TITLE> +GtkColorChooser +gtk_color_chooser_get_rgba +gtk_color_chooser_set_rgba +gtk_color_chooser_get_use_alpha +gtk_color_chooser_set_use_alpha +gtk_color_chooser_add_palette + +<SUBSECTION Standard> +GTK_TYPE_COLOR_CHOOSER +GTK_COLOR_CHOOSER +GTK_IS_COLOR_CHOOSER +GTK_COLOR_CHOOSER_GET_IFACE + +<SUBSECTION Private> +gtk_color_chooser_get_type +</SECTION> + +<SECTION> +<FILE>gtkcolorchooserwidget</FILE> +<TITLE>GtkColorChooserWidget</TITLE> +GtkColorChooserWidget +gtk_color_chooser_widget_new + +<SUBSECTION Standard> +GTK_TYPE_COLOR_CHOOSER_WIDGET +GTK_COLOR_CHOOSER_WIDGET +GTK_COLOR_CHOOSER_WIDGET_CLASS +GTK_IS_COLOR_CHOOSER_WIDGET +GTK_IS_COLOR_CHOOSER_WIDGET_CLASS +GTK_COLOR_CHOOSER_WIDGET_GET_CLASS + +<SUBSECTION Private> +gtk_color_chooser_widget_get_type +GtkColorChooserWidgetPrivate +</SECTION> + +<SECTION> +<FILE>gtkcolorchooserdialog</FILE> +<TITLE>GtkColorChooserDialog</TITLE> +GtkColorChooserDialog +gtk_color_chooser_dialog_new + +<SUBSECTION Standard> +GTK_TYPE_COLOR_CHOOSER_DIALOG +GTK_COLOR_CHOOSER_DIALOG +GTK_COLOR_CHOOSER_DIALOG_CLASS +GTK_IS_COLOR_CHOOSER_DIALOG +GTK_IS_COLOR_CHOOSER_DIALOG_CLASS +GTK_COLOR_CHOOSER_DIALOG_GET_CLASS + +<SUBSECTION Private> +GtkColorChooserDialogPrivate +gtk_color_chooser_dialog_get_type +</SECTION> diff --git a/docs/reference/gtk/gtk3.types b/docs/reference/gtk/gtk3.types index 7fe92ad4cb..c67ac722a0 100644 --- a/docs/reference/gtk/gtk3.types +++ b/docs/reference/gtk/gtk3.types @@ -47,6 +47,9 @@ gtk_check_button_get_type gtk_check_menu_item_get_type gtk_clipboard_get_type gtk_color_button_get_type +gtk_color_chooser_get_type +gtk_color_chooser_dialog_get_type +gtk_color_chooser_widget_get_type gtk_color_selection_dialog_get_type gtk_color_selection_get_type gtk_combo_box_get_type diff --git a/docs/reference/gtk/images/colorchooser.png b/docs/reference/gtk/images/colorchooser.png Binary files differnew file mode 100644 index 0000000000..fcdabf0081 --- /dev/null +++ b/docs/reference/gtk/images/colorchooser.png diff --git a/docs/reference/gtk/images/fontchooser.png b/docs/reference/gtk/images/fontchooser.png Binary files differnew file mode 100644 index 0000000000..38e3e8f81c --- /dev/null +++ b/docs/reference/gtk/images/fontchooser.png diff --git a/docs/reference/gtk/visual_index.xml b/docs/reference/gtk/visual_index.xml index 37cc0ec6cf..7fb63932d4 100644 --- a/docs/reference/gtk/visual_index.xml +++ b/docs/reference/gtk/visual_index.xml @@ -135,4 +135,10 @@ <link linkend="GtkSwitch"> <inlinegraphic fileref="switch.png" format="PNG"></inlinegraphic> </link> + <link linkend="GtkColorChooserDialog"> + <inlinegraphic fileref="colorchooser.png" format="PNG"></inlinegraphic> + </link> + <link linkend="GtkFontChooserDialog"> + <inlinegraphic fileref="fontchooser.png" format="PNG"></inlinegraphic> + </link> </para> diff --git a/docs/tools/widgets.c b/docs/tools/widgets.c index 949a35a3d9..5b326090f4 100644 --- a/docs/tools/widgets.c +++ b/docs/tools/widgets.c @@ -1154,6 +1154,33 @@ create_appchooserdialog (void) return info; } +static WidgetInfo * +create_fontchooserdialog (void) +{ + WidgetInfo *info; + GtkWidget *widget; + + widget = gtk_font_chooser_dialog_new ("Font Chooser Dialog", NULL); + gtk_window_set_default_size (GTK_WINDOW (widget), 200, 300); + info = new_widget_info ("fontchooser", widget, ASIS); + info->include_decorations = TRUE; + + return info; +} + +static WidgetInfo * +create_colorchooserdialog (void) +{ + WidgetInfo *info; + GtkWidget *widget; + + widget = gtk_color_chooser_dialog_new ("Color Chooser Dialog", NULL); + info = new_widget_info ("colorchooser", widget, ASIS); + info->include_decorations = TRUE; + + return info; +} + GList * get_all_widgets (void) { @@ -1204,6 +1231,8 @@ get_all_widgets (void) retval = g_list_prepend (retval, create_appchooserbutton ()); retval = g_list_prepend (retval, create_appchooserdialog ()); retval = g_list_prepend (retval, create_lockbutton ()); + retval = g_list_prepend (retval, create_fontchooserdialog ()); + retval = g_list_prepend (retval, create_colorchooserdialog ()); return retval; } diff --git a/gtk/Makefile.am b/gtk/Makefile.am index dd8db33a6e..da4a4caa83 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -145,6 +145,8 @@ endif # by configure) deprecated_h_sources = \ + deprecated/gtkcolorsel.h \ + deprecated/gtkcolorseldialog.h \ deprecated/gtkfontsel.h \ deprecated/gtkhandlebox.h \ deprecated/gtkhbbox.h \ @@ -153,6 +155,7 @@ deprecated_h_sources = \ deprecated/gtkhscale.h \ deprecated/gtkhscrollbar.h \ deprecated/gtkhseparator.h \ + deprecated/gtkhsv.h \ deprecated/gtkstyle.h \ deprecated/gtkrc.h \ deprecated/gtktable.h \ @@ -215,8 +218,10 @@ gtk_public_h_sources = \ gtkcheckmenuitem.h \ gtkclipboard.h \ gtkcolorbutton.h \ - gtkcolorsel.h \ - gtkcolorseldialog.h \ + gtkcolorchooser.h \ + gtkcolorchooserwidget.h \ + gtkcolorchooserdialog.h \ + gtkcolorutils.h \ gtkcombobox.h \ gtkcomboboxtext.h \ gtkcontainer.h \ @@ -246,7 +251,6 @@ gtk_public_h_sources = \ gtkframe.h \ gtkgradient.h \ gtkgrid.h \ - gtkhsv.h \ gtkiconfactory.h \ gtkicontheme.h \ gtkiconview.h \ @@ -410,6 +414,11 @@ gtk_private_h_sources = \ gtkbuilderprivate.h \ gtkbuttonprivate.h \ gtkcellareaboxcontextprivate.h \ + gtkcolorswatchprivate.h \ + gtkcoloreditorprivate.h \ + gtkcolorplaneprivate.h \ + gtkcolorscaleprivate.h \ + gtkcolorchooserprivate.h \ gtkcontainerprivate.h \ gtkcsscomputedvaluesprivate.h \ gtkcsscustompropertyprivate.h \ @@ -506,6 +515,8 @@ gtk_private_h_sources = \ # GTK+ C sources to build the library from deprecated_c_sources = \ + deprecated/gtkcolorsel.c \ + deprecated/gtkcolorseldialog.c \ deprecated/gtkfontsel.c \ deprecated/gtkhandlebox.c \ deprecated/gtkhbbox.c \ @@ -514,6 +525,7 @@ deprecated_c_sources = \ deprecated/gtkhscale.c \ deprecated/gtkhscrollbar.c \ deprecated/gtkhseparator.c \ + deprecated/gtkhsv.c \ deprecated/gtkrc.c \ deprecated/gtkstyle.c \ deprecated/gtktable.c \ @@ -590,8 +602,14 @@ gtk_base_c_sources = \ gtkcheckbutton.c \ gtkcheckmenuitem.c \ gtkcolorbutton.c \ - gtkcolorsel.c \ - gtkcolorseldialog.c \ + gtkcolorchooser.c \ + gtkcolorchooserwidget.c \ + gtkcolorchooserdialog.c \ + gtkcoloreditor.c \ + gtkcolorplane.c \ + gtkcolorscale.c \ + gtkcolorswatch.c \ + gtkcolorutils.c \ gtkcombobox.c \ gtkcomboboxtext.c \ gtkcontainer.c \ @@ -641,7 +659,6 @@ gtk_base_c_sources = \ gtkframe.c \ gtkgradient.c \ gtkgrid.c \ - gtkhsv.c \ gtkiconcache.c \ gtkiconcachevalidator.c \ gtkiconfactory.c \ @@ -1549,7 +1566,6 @@ EXTRA_DIST += \ gtkprint-win32.h \ gtkprint-win32.c \ gtksearchenginequartz.h \ - gtk.css.raleigh \ gtk.gresource.xml \ gtk-default.css \ gtk-keys.css.default \ @@ -1562,10 +1578,12 @@ EXTRA_DIST += \ gtktypebuiltins.h.template \ gtkprivatetypebuiltins.c.template \ gtkprivatetypebuiltins.h.template \ - org.gtk.Settings.FileChooser.gschema.xml + org.gtk.Settings.FileChooser.gschema.xml \ + org.gtk.Settings.ColorChooser.gschema.xml gsettings_SCHEMAS = \ - org.gtk.Settings.FileChooser.gschema.xml + org.gtk.Settings.FileChooser.gschema.xml \ + org.gtk.Settings.ColorChooser.gschema.xml @GSETTINGS_RULES@ diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am index b8b69e4e24..c3e92694f0 100644 --- a/gtk/a11y/Makefile.am +++ b/gtk/a11y/Makefile.am @@ -11,6 +11,7 @@ gail_c_sources = \ gtkcellaccessible.c \ gtkcellaccessibleparent.c \ gtkcheckmenuitemaccessible.c \ + gtkcolorswatchaccessible.c \ gtkcomboboxaccessible.c \ gtkcontaineraccessible.c \ gtkcontainercellaccessible.c \ @@ -59,6 +60,7 @@ gail_private_h_sources = \ gtkcellaccessible.h \ gtkcellaccessibleparent.h \ gtkcheckmenuitemaccessible.h \ + gtkcolorswatchaccessible.h \ gtkcomboboxaccessible.h \ gtkcontaineraccessible.h \ gtkcontainercellaccessible.h \ diff --git a/gtk/a11y/gtkcolorswatchaccessible.c b/gtk/a11y/gtkcolorswatchaccessible.c new file mode 100644 index 0000000000..825e25b4ca --- /dev/null +++ b/gtk/a11y/gtkcolorswatchaccessible.c @@ -0,0 +1,104 @@ +/* + * Copyright 2012 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include <gtk/gtk.h> +#include "gtkcolorswatchaccessible.h" + +static void atk_action_interface_init (AtkActionIface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkColorSwatchAccessible, _gtk_color_swatch_accessible, GTK_TYPE_WIDGET_ACCESSIBLE, + G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)) + +static void +_gtk_color_swatch_accessible_class_init (GtkColorSwatchAccessibleClass *klass) +{ +} + +static void +_gtk_color_swatch_accessible_init (GtkColorSwatchAccessible *scale) +{ +} + +static gint +gtk_color_swatch_accessible_get_n_actions (AtkAction *action) +{ + return 3; +} + +static const gchar * +gtk_color_swatch_accessible_get_keybinding (AtkAction *action, + gint i) +{ + return NULL; +} + +static const gchar * +gtk_color_swatch_accessible_get_name (AtkAction *action, + gint i) +{ + switch (i) + { + case 0: return "select"; + case 1: return "activate"; + case 2: return "customize"; + default: return NULL; + } +} + +static gboolean +gtk_color_swatch_accessible_do_action (AtkAction *action, + gint i) +{ + GtkWidget *widget; + + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action)); + if (widget == NULL) + return FALSE; + + switch (i) + { + case 0: + gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE); + break; + + case 1: + g_signal_emit_by_name (widget, "activate"); + break; + + case 2: + g_signal_emit_by_name (widget, "customize"); + break; + + default: + return FALSE; + } + + return TRUE; +} + +static void +atk_action_interface_init (AtkActionIface *iface) +{ + iface->do_action = gtk_color_swatch_accessible_do_action; + iface->get_n_actions = gtk_color_swatch_accessible_get_n_actions; + iface->get_keybinding = gtk_color_swatch_accessible_get_keybinding; + iface->get_name = gtk_color_swatch_accessible_get_name; +} diff --git a/gtk/a11y/gtkcolorswatchaccessible.h b/gtk/a11y/gtkcolorswatchaccessible.h new file mode 100644 index 0000000000..c1cb2f4568 --- /dev/null +++ b/gtk/a11y/gtkcolorswatchaccessible.h @@ -0,0 +1,51 @@ +/* + * Copyright 2012, Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_COLOR_SWATCH_ACCESSIBLE_H__ +#define __GTK_COLOR_SWATCH_ACCESSIBLE_H__ + +#include "gtkwidgetaccessible.h" + +G_BEGIN_DECLS + +#define GTK_TYPE_COLOR_SWATCH_ACCESSIBLE (_gtk_color_swatch_accessible_get_type ()) +#define GTK_COLOR_SWATCH_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_SWATCH_ACCESSIBLE, GtkColorSwatchAccessible)) +#define GTK_COLOR_SWATCH_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_SWATCH_ACCESSIBLE, GtkColorSwatchAccessibleClass)) +#define GTK_IS_COLOR_SWATCH_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_SWATCH_ACCESSIBLE)) +#define GTK_IS_COLOR_SWATCH_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_SWATCH_ACCESSIBLE)) +#define GTK_COLOR_SWATCH_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_SWATCH_ACCESSIBLE, GtkColorSwatchAccessibleClass)) + +typedef struct _GtkColorSwatchAccessible GtkColorSwatchAccessible; +typedef struct _GtkColorSwatchAccessibleClass GtkColorSwatchAccessibleClass; + +struct _GtkColorSwatchAccessible +{ + GtkWidgetAccessible parent; +}; + +struct _GtkColorSwatchAccessibleClass +{ + GtkWidgetAccessibleClass parent_class; +}; + +GType _gtk_color_swatch_accessible_get_type (void); + +G_END_DECLS + +#endif /* __GTK_COLOR_SWATCH_ACCESSIBLE_H__ */ diff --git a/gtk/gtkcolorsel.c b/gtk/deprecated/gtkcolorsel.c index 2f36d3e0bb..66b1018984 100644 --- a/gtk/gtkcolorsel.c +++ b/gtk/deprecated/gtkcolorsel.c @@ -27,6 +27,8 @@ #include "config.h" +#define GDK_DISABLE_DEPRECATION_WARNINGS + #include "gtkcolorsel.h" #include <math.h> @@ -37,6 +39,7 @@ #include "gtkhsv.h" #include "gtkwindow.h" #include "gtkselection.h" +#include "gtkcolorutils.h" #include "gtkdnd.h" #include "gtkdrawingarea.h" #include "gtkframe.h" @@ -62,7 +65,7 @@ /** * SECTION:gtkcolorsel - * @Short_description: A widget used to select a color + * @Short_description: Deprecated widget used to select a color * @Title: GtkColorSelection * * The #GtkColorSelection is a widget that is used to select @@ -3068,7 +3071,7 @@ gtk_color_selection_palette_to_string (const GdkColor *colors, * tries to modify the palette in a color selection. * * This function should save the new palette contents, and update - * the #GtkSettings::gtk-color-palette GtkSettings property so all + * the #GtkSettings:gtk-color-palette GtkSettings property so all * GtkColorSelection widgets will be modified. * * Return value: the previous change palette hook (that was replaced) diff --git a/gtk/gtkcolorsel.h b/gtk/deprecated/gtkcolorsel.h index d8b787712e..9acf9c3ee1 100644 --- a/gtk/gtkcolorsel.h +++ b/gtk/deprecated/gtkcolorsel.h @@ -89,51 +89,67 @@ struct _GtkColorSelectionClass /* ColorSelection */ GType gtk_color_selection_get_type (void) G_GNUC_CONST; +GDK_DEPRECATED_FOR(gtk_color_chooser_widget_new) GtkWidget *gtk_color_selection_new (void); +GDK_DEPRECATED_FOR(gtk_color_chooser_get_use_alpha) gboolean gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel); +GDK_DEPRECATED_FOR(gtk_color_chooser_set_use_alpha) void gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel, gboolean has_opacity); +GDK_DEPRECATED gboolean gtk_color_selection_get_has_palette (GtkColorSelection *colorsel); +GDK_DEPRECATED void gtk_color_selection_set_has_palette (GtkColorSelection *colorsel, gboolean has_palette); +GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba) void gtk_color_selection_set_current_alpha (GtkColorSelection *colorsel, guint16 alpha); +GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba) guint16 gtk_color_selection_get_current_alpha (GtkColorSelection *colorsel); +GDK_DEPRECATED void gtk_color_selection_set_previous_alpha (GtkColorSelection *colorsel, guint16 alpha); +GDK_DEPRECATED guint16 gtk_color_selection_get_previous_alpha (GtkColorSelection *colorsel); +GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba) void gtk_color_selection_set_current_rgba (GtkColorSelection *colorsel, const GdkRGBA *rgba); +GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba) void gtk_color_selection_get_current_rgba (GtkColorSelection *colorsel, GdkRGBA *rgba); +GDK_DEPRECATED void gtk_color_selection_set_previous_rgba (GtkColorSelection *colorsel, const GdkRGBA *rgba); +GDK_DEPRECATED void gtk_color_selection_get_previous_rgba (GtkColorSelection *colorsel, GdkRGBA *rgba); +GDK_DEPRECATED gboolean gtk_color_selection_is_adjusting (GtkColorSelection *colorsel); +GDK_DEPRECATED gboolean gtk_color_selection_palette_from_string (const gchar *str, GdkColor **colors, gint *n_colors); +GDK_DEPRECATED gchar* gtk_color_selection_palette_to_string (const GdkColor *colors, gint n_colors); GtkColorSelectionChangePaletteWithScreenFunc gtk_color_selection_set_change_palette_with_screen_hook (GtkColorSelectionChangePaletteWithScreenFunc func); -GDK_DEPRECATED_FOR(gtk_color_selection_set_current_rgba) +GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba) void gtk_color_selection_set_current_color (GtkColorSelection *colorsel, const GdkColor *color); -GDK_DEPRECATED_FOR(gtk_color_selection_get_current_rgba) +GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba) void gtk_color_selection_get_current_color (GtkColorSelection *colorsel, GdkColor *color); -GDK_DEPRECATED_FOR(gtk_color_selection_set_previous_rgba) +GDK_DEPRECATED void gtk_color_selection_set_previous_color (GtkColorSelection *colorsel, const GdkColor *color); -GDK_DEPRECATED_FOR(gtk_color_selection_get_previous_rgba) +GDK_DEPRECATED void gtk_color_selection_get_previous_color (GtkColorSelection *colorsel, GdkColor *color); diff --git a/gtk/gtkcolorseldialog.c b/gtk/deprecated/gtkcolorseldialog.c index a8a77e7177..772a8cb7ec 100644 --- a/gtk/gtkcolorseldialog.c +++ b/gtk/deprecated/gtkcolorseldialog.c @@ -24,6 +24,10 @@ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "config.h" + +#define GDK_DISABLE_DEPRECATION_WARNINGS + + #include <string.h> #include <glib.h> #include "gtkcolorseldialog.h" @@ -36,7 +40,7 @@ /** * SECTION:gtkcolorseldlg - * @Short_description: A standard dialog box for selecting a color + * @Short_description: Deprecated dialog box for selecting a color * @Title: GtkColorSelectionDialog * * The #GtkColorSelectionDialog provides a standard dialog which diff --git a/gtk/gtkcolorseldialog.h b/gtk/deprecated/gtkcolorseldialog.h index aeaa507ced..a989fc2db3 100644 --- a/gtk/gtkcolorseldialog.h +++ b/gtk/deprecated/gtkcolorseldialog.h @@ -32,7 +32,7 @@ #define __GTK_COLOR_SELECTION_DIALOG_H__ #include <gtk/gtkdialog.h> -#include <gtk/gtkcolorsel.h> +#include <gtk/deprecated/gtkcolorsel.h> G_BEGIN_DECLS @@ -71,7 +71,9 @@ struct _GtkColorSelectionDialogClass /* ColorSelectionDialog */ GType gtk_color_selection_dialog_get_type (void) G_GNUC_CONST; +GDK_DEPRECATED_FOR(gtk_color_chooser_dialog_new) GtkWidget* gtk_color_selection_dialog_new (const gchar *title); +GDK_DEPRECATED_FOR(GtkColorChooser) GtkWidget* gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel); diff --git a/gtk/deprecated/gtkfontsel.c b/gtk/deprecated/gtkfontsel.c index e2f715610a..9b64107cd1 100644 --- a/gtk/deprecated/gtkfontsel.c +++ b/gtk/deprecated/gtkfontsel.c @@ -1635,7 +1635,7 @@ gtk_font_selection_set_preview_text (GtkFontSelection *fontsel, /** * SECTION:gtkfontseldlg - * @Short_description: A dialog box for selecting fonts + * @Short_description: Deprecated dialog box for selecting fonts * @Title: GtkFontSelectionDialog * @See_also: #GtkFontSelection, #GtkDialog, #GtkFontChooserDialog * diff --git a/gtk/deprecated/gtkhbox.c b/gtk/deprecated/gtkhbox.c index 0ebd000ef1..3ea3253a30 100644 --- a/gtk/deprecated/gtkhbox.c +++ b/gtk/deprecated/gtkhbox.c @@ -49,7 +49,7 @@ * very quick and easy change. If you have derived your own classes from * GtkHBox, you can simply change the inheritance to derive directly * from #GtkBox. No further changes are needed, since the default - * value of the #GtkOrientable::orientation property is + * value of the #GtkOrientable:orientation property is * %GTK_ORIENTATION_HORIZONTAL. * If you want your code to be future-proof, the recommendation is to * switch to #GtkGrid, since #GtkBox is going to be deprecated in favor diff --git a/gtk/gtkhsv.c b/gtk/deprecated/gtkhsv.c index e3756675dd..3fac2e136a 100644 --- a/gtk/gtkhsv.c +++ b/gtk/deprecated/gtkhsv.c @@ -31,6 +31,8 @@ #include "config.h" +#define GDK_DISABLE_DEPRECATION_WARNINGS + #include <math.h> #include <string.h> @@ -52,6 +54,9 @@ * intuitive way. Moving the selection around the outer ring changes the hue, * and moving the selection point inside the inner triangle changes value and * saturation. + * + * #GtkHSV has been deprecated together with #GtkColorSelection, where + * it was used. */ @@ -1454,84 +1459,6 @@ gtk_hsv_is_adjusting (GtkHSV *hsv) return priv->mode != DRAG_NONE; } -/** - * gtk_hsv_to_rgb: - * @h: Hue - * @s: Saturation - * @v: Value - * @r: (out): Return value for the red component - * @g: (out): Return value for the green component - * @b: (out): Return value for the blue component - * - * Converts a color from HSV space to RGB. - * Input values must be in the [0.0, 1.0] range; - * output values will be in the same range. - * - * Since: 2.14 - */ -void -gtk_hsv_to_rgb (gdouble h, - gdouble s, - gdouble v, - gdouble *r, - gdouble *g, - gdouble *b) -{ - g_return_if_fail (h >= 0.0 && h <= 1.0); - g_return_if_fail (s >= 0.0 && s <= 1.0); - g_return_if_fail (v >= 0.0 && v <= 1.0); - - hsv_to_rgb (&h, &s, &v); - - if (r) - *r = h; - - if (g) - *g = s; - - if (b) - *b = v; -} - -/** - * gtk_rgb_to_hsv: - * @r: Red - * @g: Green - * @b: Blue - * @h: (out): Return value for the hue component - * @s: (out): Return value for the saturation component - * @v: (out): Return value for the value component - * - * Converts a color from RGB space to HSV. - * Input values must be in the [0.0, 1.0] range; - * output values will be in the same range. - * - * Since: 2.14 - */ -void -gtk_rgb_to_hsv (gdouble r, - gdouble g, - gdouble b, - gdouble *h, - gdouble *s, - gdouble *v) -{ - g_return_if_fail (r >= 0.0 && r <= 1.0); - g_return_if_fail (g >= 0.0 && g <= 1.0); - g_return_if_fail (b >= 0.0 && b <= 1.0); - - rgb_to_hsv (&r, &g, &b); - - if (h) - *h = r; - - if (s) - *s = g; - - if (v) - *v = b; -} - static void gtk_hsv_move (GtkHSV *hsv, GtkDirectionType dir) diff --git a/gtk/gtkhsv.h b/gtk/deprecated/gtkhsv.h index ae6bdb3c9d..bdf2694e5e 100644 --- a/gtk/gtkhsv.h +++ b/gtk/deprecated/gtkhsv.h @@ -80,37 +80,29 @@ struct _GtkHSVClass GType gtk_hsv_get_type (void) G_GNUC_CONST; +GDK_DEPRECATED GtkWidget* gtk_hsv_new (void); +GDK_DEPRECATED void gtk_hsv_set_color (GtkHSV *hsv, double h, double s, double v); +GDK_DEPRECATED void gtk_hsv_get_color (GtkHSV *hsv, gdouble *h, gdouble *s, gdouble *v); +GDK_DEPRECATED void gtk_hsv_set_metrics (GtkHSV *hsv, gint size, gint ring_width); +GDK_DEPRECATED void gtk_hsv_get_metrics (GtkHSV *hsv, gint *size, gint *ring_width); +GDK_DEPRECATED gboolean gtk_hsv_is_adjusting (GtkHSV *hsv); -/* Convert colors between the RGB and HSV color spaces */ -void gtk_hsv_to_rgb (gdouble h, - gdouble s, - gdouble v, - gdouble *r, - gdouble *g, - gdouble *b); -void gtk_rgb_to_hsv (gdouble r, - gdouble g, - gdouble b, - gdouble *h, - gdouble *s, - gdouble *v); - G_END_DECLS #endif /* __GTK_HSV_H__ */ diff --git a/gtk/deprecated/gtkvbox.c b/gtk/deprecated/gtkvbox.c index a74b53fceb..9105a8c281 100644 --- a/gtk/deprecated/gtkvbox.c +++ b/gtk/deprecated/gtkvbox.c @@ -49,7 +49,7 @@ * GtkVBox has been deprecated. You can use #GtkBox instead, which is a * very quick and easy change. If you have derived your own classes from * GtkVBox, you can simply change the inheritance to derive directly - * from #GtkBox, and set the #GtkOrientable::orientation property to + * from #GtkBox, and set the #GtkOrientable:orientation property to * %GTK_ORIENTATION_VERTICAL in your instance init function, with a * call like: * |[ @@ -78,8 +78,10 @@ #include <gtk/gtkcheckmenuitem.h> #include <gtk/gtkclipboard.h> #include <gtk/gtkcolorbutton.h> -#include <gtk/gtkcolorsel.h> -#include <gtk/gtkcolorseldialog.h> +#include <gtk/gtkcolorchooser.h> +#include <gtk/gtkcolorchooserdialog.h> +#include <gtk/gtkcolorchooserwidget.h> +#include <gtk/gtkcolorutils.h> #include <gtk/gtkcombobox.h> #include <gtk/gtkcomboboxtext.h> #include <gtk/gtkcontainer.h> @@ -109,7 +111,6 @@ #include <gtk/gtkframe.h> #include <gtk/gtkgradient.h> #include <gtk/gtkgrid.h> -#include <gtk/gtkhsv.h> #include <gtk/gtkiconfactory.h> #include <gtk/gtkicontheme.h> #include <gtk/gtkiconview.h> @@ -223,11 +224,14 @@ #include <gtk/gtkwidgetpath.h> #include <gtk/gtkwindow.h> +#include <gtk/deprecated/gtkcolorsel.h> +#include <gtk/deprecated/gtkcolorseldialog.h> #include <gtk/deprecated/gtkfontsel.h> #include <gtk/deprecated/gtkhandlebox.h> #include <gtk/deprecated/gtkhbbox.h> #include <gtk/deprecated/gtkhbox.h> #include <gtk/deprecated/gtkhpaned.h> +#include <gtk/deprecated/gtkhsv.h> #include <gtk/deprecated/gtkhscale.h> #include <gtk/deprecated/gtkhscrollbar.h> #include <gtk/deprecated/gtkhseparator.h> diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 4acba3d662..9a49a41ec5 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -605,6 +605,15 @@ gtk_color_button_set_color gtk_color_button_set_rgba gtk_color_button_set_title gtk_color_button_set_use_alpha +gtk_color_chooser_dialog_get_type +gtk_color_chooser_dialog_new +gtk_color_chooser_get_color +gtk_color_chooser_get_show_alpha +gtk_color_chooser_get_type +gtk_color_chooser_set_color +gtk_color_chooser_set_show_alpha +gtk_color_chooser_widget_get_type +gtk_color_chooser_widget_new gtk_color_selection_dialog_get_color_selection gtk_color_selection_dialog_get_type gtk_color_selection_dialog_new diff --git a/gtk/gtkactivatable.c b/gtk/gtkactivatable.c index c22690ccb4..9f659e061f 100644 --- a/gtk/gtkactivatable.c +++ b/gtk/gtkactivatable.c @@ -340,9 +340,9 @@ gtk_activatable_update (GtkActivatable *activatable, * @action: (allow-none): the related #GtkAction or %NULL * * This is called to update the activatable completely, this is called - * internally when the #GtkActivatable::related-action property is set + * internally when the #GtkActivatable:related-action property is set * or unset and by the implementing class when - * #GtkActivatable::use-action-appearance changes. + * #GtkActivatable:use-action-appearance changes. * * Since: 2.16 **/ diff --git a/gtk/gtkactivatable.h b/gtk/gtkactivatable.h index 920b4a4eae..d713806a7a 100644 --- a/gtk/gtkactivatable.h +++ b/gtk/gtkactivatable.h @@ -45,8 +45,8 @@ typedef struct _GtkActivatableIface GtkActivatableIface; * You must check the #GtkActivatable:use-action-appearance property only apply action * properties that are meant to effect the appearance accordingly. * @sync_action_properties: Called to update the activatable completely, this is called internally when - * #GtkActivatable::related-action property is set or unset and by the implementor when - * #GtkActivatable::use-action-appearance changes.<note><para>This method can be called + * #GtkActivatable:related-action property is set or unset and by the implementor when + * #GtkActivatable:use-action-appearance changes.<note><para>This method can be called * with a %NULL action at times</para></note> * * Since: 2.16 diff --git a/gtk/gtkappchooserbutton.c b/gtk/gtkappchooserbutton.c index bd1d335d3d..b49cf99f69 100644 --- a/gtk/gtkappchooserbutton.c +++ b/gtk/gtkappchooserbutton.c @@ -31,14 +31,14 @@ * * Initially, a #GtkAppChooserButton selects the first application * in its list, which will either be the most-recently used application - * or, if #GtkAppChooserButton::show-default-item is %TRUE, the + * or, if #GtkAppChooserButton:show-default-item is %TRUE, the * default application. * * The list of applications shown in a #GtkAppChooserButton includes * the recommended applications for the given content type. When - * #GtkAppChooserButton::show-default-item is set, the default application + * #GtkAppChooserButton:show-default-item is set, the default application * is also included. To let the user chooser other applications, - * you can set the #GtkAppChooserButton::show-dialog-item property, + * you can set the #GtkAppChooserButton:show-dialog-item property, * which allows to open a full #GtkAppChooserDialog. * * It is possible to add custom items to the list, using diff --git a/gtk/gtkbbox.c b/gtk/gtkbbox.c index bdecd58b65..69bab4131b 100644 --- a/gtk/gtkbbox.c +++ b/gtk/gtkbbox.c @@ -42,10 +42,10 @@ * same size. GtkButtonBox gives all children the same size, but it does allow * 'outliers' to keep their own larger size. To force all children to be * strictly the same size without exceptions, you can set the - * #GtkButtonBox::homogeneous property to %TRUE. + * #GtkButtonBox:homogeneous property to %TRUE. * * To excempt individual children from homogeneous sizing regardless of their - * 'outlier' status, you can set the #GtkButtonBox::non-homogeneous child + * 'outlier' status, you can set the #GtkButtonBox:non-homogeneous child * property. */ diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c index bee1bec58a..d9aeabc642 100644 --- a/gtk/gtkcolorbutton.c +++ b/gtk/gtkcolorbutton.c @@ -28,18 +28,18 @@ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ +#define GDK_DISABLE_DEPRECATION_WARNINGS #include "config.h" #include "gtkcolorbutton.h" #include "gtkbutton.h" #include "gtkmain.h" -#include "gtkalignment.h" -#include "gtkcolorsel.h" -#include "gtkcolorseldialog.h" +#include "gtkcolorchooser.h" +#include "gtkcolorchooserprivate.h" +#include "gtkcolorchooserdialog.h" #include "gtkdnd.h" #include "gtkdrawingarea.h" -#include "gtkframe.h" #include "gtkmarshalers.h" #include "gtkprivate.h" #include "gtkintl.h" @@ -62,6 +62,7 @@ #define CHECK_DARK (1.0 / 3.0) #define CHECK_LIGHT (2.0 / 3.0) +#define COLOR_SAMPLE_MARGIN 1 struct _GtkColorButtonPrivate { @@ -119,7 +120,7 @@ static void gtk_color_button_drag_data_get (GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint time, - GtkColorButton *color_button); + GtkColorButton *button); /* target side drag signals */ static void gtk_color_button_drag_data_received (GtkWidget *widget, @@ -129,14 +130,18 @@ static void gtk_color_button_drag_data_received (GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint32 time, - GtkColorButton *color_button); + GtkColorButton *button); static guint color_button_signals[LAST_SIGNAL] = { 0 }; static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } }; -G_DEFINE_TYPE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON) +static void gtk_color_button_iface_init (GtkColorChooserInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON, + G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER, + gtk_color_button_iface_init)) static void gtk_color_button_class_init (GtkColorButtonClass *klass) @@ -159,9 +164,9 @@ gtk_color_button_class_init (GtkColorButtonClass *klass) /** * GtkColorButton:use-alpha: * - * If this property is set to %TRUE, the color swatch on the button is rendered against a - * checkerboard background to show its opacity and the opacity slider is displayed in the - * color selection dialog. + * If this property is set to %TRUE, the color swatch on the button is + * rendered against a checkerboard background to show its opacity and + * the opacity slider is displayed in the color selection dialog. * * Since: 2.4 */ @@ -262,33 +267,9 @@ gtk_color_button_class_init (GtkColorButtonClass *klass) } static gboolean -gtk_color_button_has_alpha (GtkColorButton *color_button) +gtk_color_button_has_alpha (GtkColorButton *button) { - return color_button->priv->use_alpha && - color_button->priv->rgba.alpha < 1; -} - -static cairo_pattern_t * -gtk_color_button_get_checkered (void) -{ - /* need to respect pixman's stride being a multiple of 4 */ - static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00, - 0x00, 0xFF, 0x00, 0x00 }; - static cairo_surface_t *checkered = NULL; - cairo_pattern_t *pattern; - - if (checkered == NULL) - { - checkered = cairo_image_surface_create_for_data (data, - CAIRO_FORMAT_A8, - 2, 2, 4); - } - - pattern = cairo_pattern_create_for_surface (checkered); - cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); - cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); - - return pattern; + return button->priv->use_alpha && button->priv->rgba.alpha < 1; } /* Handle exposure events for the color picker's drawing area */ @@ -297,10 +278,10 @@ gtk_color_button_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data) { - GtkColorButton *color_button = GTK_COLOR_BUTTON (data); + GtkColorButton *button = GTK_COLOR_BUTTON (data); cairo_pattern_t *checkered; - if (gtk_color_button_has_alpha (color_button)) + if (gtk_color_button_has_alpha (button)) { cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK); cairo_paint (cr); @@ -308,23 +289,23 @@ gtk_color_button_draw_cb (GtkWidget *widget, cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT); cairo_scale (cr, CHECK_SIZE, CHECK_SIZE); - checkered = gtk_color_button_get_checkered (); + checkered = _gtk_color_chooser_get_checkered_pattern (); cairo_mask (cr, checkered); cairo_pattern_destroy (checkered); - gdk_cairo_set_source_rgba (cr, &color_button->priv->rgba); + gdk_cairo_set_source_rgba (cr, &button->priv->rgba); } else { cairo_set_source_rgb (cr, - color_button->priv->rgba.red, - color_button->priv->rgba.green, - color_button->priv->rgba.blue); + button->priv->rgba.red, + button->priv->rgba.green, + button->priv->rgba.blue); } cairo_paint (cr); - if (!gtk_widget_is_sensitive (GTK_WIDGET (color_button))) + if (!gtk_widget_is_sensitive (GTK_WIDGET (button))) { GtkStyleContext *context; GdkRGBA color; @@ -333,7 +314,7 @@ gtk_color_button_draw_cb (GtkWidget *widget, gtk_style_context_get_background_color (context, GTK_STATE_FLAG_INSENSITIVE, &color); gdk_cairo_set_source_rgba (cr, &color); - checkered = gtk_color_button_get_checkered (); + checkered = _gtk_color_chooser_get_checkered_pattern (); cairo_mask (cr, checkered); cairo_pattern_destroy (checkered); } @@ -356,7 +337,7 @@ gtk_color_button_drag_data_received (GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint32 time, - GtkColorButton *color_button) + GtkColorButton *button) { gint length; guint16 *dropped; @@ -378,20 +359,20 @@ gtk_color_button_drag_data_received (GtkWidget *widget, dropped = (guint16 *) gtk_selection_data_get_data (selection_data); - color_button->priv->rgba.red = dropped[0] / 65535.; - color_button->priv->rgba.green = dropped[1] / 65535.; - color_button->priv->rgba.blue = dropped[2] / 65535.; - color_button->priv->rgba.alpha = dropped[3] / 65535.; + button->priv->rgba.red = dropped[0] / 65535.; + button->priv->rgba.green = dropped[1] / 65535.; + button->priv->rgba.blue = dropped[2] / 65535.; + button->priv->rgba.alpha = dropped[3] / 65535.; - gtk_widget_queue_draw (color_button->priv->draw_area); + gtk_widget_queue_draw (button->priv->draw_area); - g_signal_emit (color_button, color_button_signals[COLOR_SET], 0); + g_signal_emit (button, color_button_signals[COLOR_SET], 0); - g_object_freeze_notify (G_OBJECT (color_button)); - g_object_notify (G_OBJECT (color_button), "color"); - g_object_notify (G_OBJECT (color_button), "alpha"); - g_object_notify (G_OBJECT (color_button), "rgba"); - g_object_thaw_notify (G_OBJECT (color_button)); + g_object_freeze_notify (G_OBJECT (button)); + g_object_notify (G_OBJECT (button), "color"); + g_object_notify (G_OBJECT (button), "alpha"); + g_object_notify (G_OBJECT (button), "rgba"); + g_object_thaw_notify (G_OBJECT (button)); } static void @@ -419,9 +400,9 @@ gtk_color_button_drag_begin (GtkWidget *widget, GdkDragContext *context, gpointer data) { - GtkColorButton *color_button = data; + GtkColorButton *button = data; - set_color_icon (context, &color_button->priv->rgba); + set_color_icon (context, &button->priv->rgba); } static void @@ -430,14 +411,14 @@ gtk_color_button_drag_data_get (GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint time, - GtkColorButton *color_button) + GtkColorButton *button) { guint16 dropped[4]; - dropped[0] = (guint16) (color_button->priv->rgba.red * 65535); - dropped[1] = (guint16) (color_button->priv->rgba.green * 65535); - dropped[2] = (guint16) (color_button->priv->rgba.blue * 65535); - dropped[3] = (guint16) (color_button->priv->rgba.alpha * 65535); + dropped[0] = (guint16) (button->priv->rgba.red * 65535); + dropped[1] = (guint16) (button->priv->rgba.green * 65535); + dropped[2] = (guint16) (button->priv->rgba.blue * 65535); + dropped[3] = (guint16) (button->priv->rgba.alpha * 65535); gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), @@ -445,68 +426,62 @@ gtk_color_button_drag_data_get (GtkWidget *widget, } static void -gtk_color_button_init (GtkColorButton *color_button) +gtk_color_button_init (GtkColorButton *button) { - GtkWidget *alignment; - GtkWidget *frame; PangoLayout *layout; PangoRectangle rect; /* Create the widgets */ - color_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (color_button, - GTK_TYPE_COLOR_BUTTON, - GtkColorButtonPrivate); + button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button, + GTK_TYPE_COLOR_BUTTON, + GtkColorButtonPrivate); gtk_widget_push_composite_child (); - alignment = gtk_alignment_new (0.5, 0.5, 0.5, 1.0); - gtk_container_set_border_width (GTK_CONTAINER (alignment), 1); - gtk_container_add (GTK_CONTAINER (color_button), alignment); - gtk_widget_show (alignment); - - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT); - gtk_container_add (GTK_CONTAINER (alignment), frame); - gtk_widget_show (frame); + button->priv->draw_area = gtk_drawing_area_new (); + g_object_set (button->priv->draw_area, + "margin-top", COLOR_SAMPLE_MARGIN, + "margin-bottom", COLOR_SAMPLE_MARGIN, + "margin-left", 16, + "margin-right", 16, + NULL); - /* Just some widget we can hook to expose-event on */ - color_button->priv->draw_area = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (color_button), "Black"); + layout = gtk_widget_create_pango_layout (GTK_WIDGET (button), "Black"); pango_layout_get_pixel_extents (layout, NULL, &rect); g_object_unref (layout); - gtk_widget_set_size_request (color_button->priv->draw_area, rect.width - 2, rect.height - 2); - g_signal_connect (color_button->priv->draw_area, "draw", - G_CALLBACK (gtk_color_button_draw_cb), color_button); - gtk_container_add (GTK_CONTAINER (frame), color_button->priv->draw_area); - gtk_widget_show (color_button->priv->draw_area); + gtk_widget_set_size_request (button->priv->draw_area, + rect.width, rect.height - 2 * COLOR_SAMPLE_MARGIN); - color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */ + g_signal_connect (button->priv->draw_area, "draw", + G_CALLBACK (gtk_color_button_draw_cb), button); + gtk_container_add (GTK_CONTAINER (button), button->priv->draw_area); + gtk_widget_show (button->priv->draw_area); - /* Start with opaque black, alpha disabled */ + button->priv->title = g_strdup (_("Pick a Color")); /* default title */ - color_button->priv->rgba.red = 0; - color_button->priv->rgba.green = 0; - color_button->priv->rgba.blue = 0; - color_button->priv->rgba.alpha = 1; - color_button->priv->use_alpha = FALSE; + /* Start with opaque black, alpha disabled */ + button->priv->rgba.red = 0; + button->priv->rgba.green = 0; + button->priv->rgba.blue = 0; + button->priv->rgba.alpha = 1; + button->priv->use_alpha = FALSE; - gtk_drag_dest_set (GTK_WIDGET (color_button), + gtk_drag_dest_set (GTK_WIDGET (button), GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, drop_types, 1, GDK_ACTION_COPY); - gtk_drag_source_set (GTK_WIDGET(color_button), + gtk_drag_source_set (GTK_WIDGET (button), GDK_BUTTON1_MASK|GDK_BUTTON3_MASK, drop_types, 1, GDK_ACTION_COPY); - g_signal_connect (color_button, "drag-begin", - G_CALLBACK (gtk_color_button_drag_begin), color_button); - g_signal_connect (color_button, "drag-data-received", - G_CALLBACK (gtk_color_button_drag_data_received), color_button); - g_signal_connect (color_button, "drag-data-get", - G_CALLBACK (gtk_color_button_drag_data_get), color_button); + g_signal_connect (button, "drag-begin", + G_CALLBACK (gtk_color_button_drag_begin), button); + g_signal_connect (button, "drag-data-received", + G_CALLBACK (gtk_color_button_drag_data_received), button); + g_signal_connect (button, "drag-data-get", + G_CALLBACK (gtk_color_button_drag_data_get), button); gtk_widget_pop_composite_child (); } @@ -514,14 +489,14 @@ gtk_color_button_init (GtkColorButton *color_button) static void gtk_color_button_finalize (GObject *object) { - GtkColorButton *color_button = GTK_COLOR_BUTTON (object); + GtkColorButton *button = GTK_COLOR_BUTTON (object); - if (color_button->priv->cs_dialog != NULL) - gtk_widget_destroy (color_button->priv->cs_dialog); - color_button->priv->cs_dialog = NULL; + if (button->priv->cs_dialog != NULL) + gtk_widget_destroy (button->priv->cs_dialog); + button->priv->cs_dialog = NULL; - g_free (color_button->priv->title); - color_button->priv->title = NULL; + g_free (button->priv->title); + button->priv->title = NULL; G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object); } @@ -582,296 +557,278 @@ gtk_color_button_new_with_rgba (const GdkRGBA *rgba) return g_object_new (GTK_TYPE_COLOR_BUTTON, "rgba", rgba, NULL); } -static void -dialog_ok_clicked (GtkWidget *widget, - gpointer data) -{ - GtkColorButton *color_button = GTK_COLOR_BUTTON (data); - GtkColorSelection *color_selection; - GtkColorSelectionDialog *selection_dialog; - - selection_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog); - color_selection = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (selection_dialog)); - - gtk_color_selection_get_current_rgba (color_selection, &color_button->priv->rgba); - - gtk_widget_hide (color_button->priv->cs_dialog); - - gtk_widget_queue_draw (color_button->priv->draw_area); - - g_signal_emit (color_button, color_button_signals[COLOR_SET], 0); - - g_object_freeze_notify (G_OBJECT (color_button)); - g_object_notify (G_OBJECT (color_button), "color"); - g_object_notify (G_OBJECT (color_button), "alpha"); - g_object_notify (G_OBJECT (color_button), "rgba"); - g_object_thaw_notify (G_OBJECT (color_button)); -} - static gboolean dialog_destroy (GtkWidget *widget, gpointer data) { - GtkColorButton *color_button = GTK_COLOR_BUTTON (data); + GtkColorButton *button = GTK_COLOR_BUTTON (data); - color_button->priv->cs_dialog = NULL; + button->priv->cs_dialog = NULL; return FALSE; } static void -dialog_cancel_clicked (GtkWidget *widget, - gpointer data) +dialog_response (GtkDialog *dialog, + gint response, + gpointer data) { - GtkColorButton *color_button = GTK_COLOR_BUTTON (data); + if (response == GTK_RESPONSE_CANCEL) + gtk_widget_hide (GTK_WIDGET (dialog)); + else if (response == GTK_RESPONSE_OK) + { + GtkColorButton *button = GTK_COLOR_BUTTON (data); + + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), + &button->priv->rgba); + + gtk_widget_hide (GTK_WIDGET (dialog)); - gtk_widget_hide (color_button->priv->cs_dialog); + gtk_widget_queue_draw (button->priv->draw_area); + + g_signal_emit (button, color_button_signals[COLOR_SET], 0); + + g_object_freeze_notify (G_OBJECT (button)); + g_object_notify (G_OBJECT (button), "color"); + g_object_notify (G_OBJECT (button), "alpha"); + g_object_notify (G_OBJECT (button), "rgba"); + g_object_thaw_notify (G_OBJECT (button)); + } } static void -gtk_color_button_clicked (GtkButton *button) +gtk_color_button_clicked (GtkButton *b) { - GtkColorButton *color_button = GTK_COLOR_BUTTON (button); - GtkColorSelection *color_selection; - GtkColorSelectionDialog *color_dialog; + GtkColorButton *button = GTK_COLOR_BUTTON (b); + GtkWidget *dialog; /* if dialog already exists, make sure it's shown and raised */ - if (!color_button->priv->cs_dialog) + if (!button->priv->cs_dialog) { /* Create the dialog and connects its buttons */ GtkWidget *parent; - GtkWidget *ok_button, *cancel_button; - - parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button)); - color_button->priv->cs_dialog = gtk_color_selection_dialog_new (color_button->priv->title); + parent = gtk_widget_get_toplevel (GTK_WIDGET (button)); - color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog); + button->priv->cs_dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL); if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent)) { - if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (color_dialog))) - gtk_window_set_transient_for (GTK_WINDOW (color_dialog), GTK_WINDOW (parent)); + if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog))) + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent)); - gtk_window_set_modal (GTK_WINDOW (color_dialog), + gtk_window_set_modal (GTK_WINDOW (dialog), gtk_window_get_modal (GTK_WINDOW (parent))); } - g_object_get (color_dialog, - "ok-button", &ok_button, - "cancel-button", &cancel_button, - NULL); - - g_signal_connect (ok_button, "clicked", - G_CALLBACK (dialog_ok_clicked), color_button); - g_signal_connect (cancel_button, "clicked", - G_CALLBACK (dialog_cancel_clicked), color_button); - g_signal_connect (color_dialog, "destroy", - G_CALLBACK (dialog_destroy), color_button); - - g_object_unref (ok_button); - g_object_unref (cancel_button); + g_signal_connect (dialog, "response", + G_CALLBACK (dialog_response), button); + g_signal_connect (dialog, "destroy", + G_CALLBACK (dialog_destroy), button); } - color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog); - color_selection = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (color_dialog)); - - gtk_color_selection_set_has_opacity_control (color_selection, - color_button->priv->use_alpha); + gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (button->priv->cs_dialog), + button->priv->use_alpha); - gtk_color_selection_set_previous_rgba (color_selection, - &color_button->priv->rgba); - gtk_color_selection_set_current_rgba (color_selection, - &color_button->priv->rgba); - - gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog)); + gtk_window_present (GTK_WINDOW (button->priv->cs_dialog)); } /** * gtk_color_button_set_color: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * @color: A #GdkColor to set the current color with * * Sets the current color to be @color. * * Since: 2.4 * - * Deprecated: Use gtk_color_button_set_rgba() instead. + * Deprecated: Use gtk_color_chooser_set_rgba() instead. */ void -gtk_color_button_set_color (GtkColorButton *color_button, +gtk_color_button_set_color (GtkColorButton *button, const GdkColor *color) { - g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button)); + g_return_if_fail (GTK_IS_COLOR_BUTTON (button)); g_return_if_fail (color != NULL); - color_button->priv->rgba.red = color->red / 65535.; - color_button->priv->rgba.green = color->green / 65535.; - color_button->priv->rgba.blue = color->blue / 65535.; + button->priv->rgba.red = color->red / 65535.; + button->priv->rgba.green = color->green / 65535.; + button->priv->rgba.blue = color->blue / 65535.; - gtk_widget_queue_draw (color_button->priv->draw_area); + gtk_widget_queue_draw (button->priv->draw_area); - g_object_notify (G_OBJECT (color_button), "color"); - g_object_notify (G_OBJECT (color_button), "rgba"); + g_object_notify (G_OBJECT (button), "color"); + g_object_notify (G_OBJECT (button), "rgba"); } /** * gtk_color_button_set_alpha: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * @alpha: an integer between 0 and 65535 * * Sets the current opacity to be @alpha. * * Since: 2.4 + * + * Deprecated: 3.4: Use gtk_color_chooser_set_rgba() instead. */ void -gtk_color_button_set_alpha (GtkColorButton *color_button, +gtk_color_button_set_alpha (GtkColorButton *button, guint16 alpha) { - g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button)); + g_return_if_fail (GTK_IS_COLOR_BUTTON (button)); - color_button->priv->rgba.alpha = alpha / 65535.; + button->priv->rgba.alpha = alpha / 65535.; - gtk_widget_queue_draw (color_button->priv->draw_area); + gtk_widget_queue_draw (button->priv->draw_area); - g_object_notify (G_OBJECT (color_button), "alpha"); - g_object_notify (G_OBJECT (color_button), "rgba"); + g_object_notify (G_OBJECT (button), "alpha"); + g_object_notify (G_OBJECT (button), "rgba"); } /** * gtk_color_button_get_color: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * @color: (out): a #GdkColor to fill in with the current color * * Sets @color to be the current color in the #GtkColorButton widget. * * Since: 2.4 * - * Deprecated: 3.4: Use gtk_color_button_get_rgba() instead. + * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead. */ void -gtk_color_button_get_color (GtkColorButton *color_button, +gtk_color_button_get_color (GtkColorButton *button, GdkColor *color) { - g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button)); + g_return_if_fail (GTK_IS_COLOR_BUTTON (button)); - color->red = (guint16) (color_button->priv->rgba.red * 65535); - color->green = (guint16) (color_button->priv->rgba.green * 65535); - color->blue = (guint16) (color_button->priv->rgba.blue * 65535); + color->red = (guint16) (button->priv->rgba.red * 65535); + color->green = (guint16) (button->priv->rgba.green * 65535); + color->blue = (guint16) (button->priv->rgba.blue * 65535); } /** * gtk_color_button_get_alpha: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * * Returns the current alpha value. * * Return value: an integer between 0 and 65535 * * Since: 2.4 + * + * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead. */ guint16 -gtk_color_button_get_alpha (GtkColorButton *color_button) +gtk_color_button_get_alpha (GtkColorButton *button) { - g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), 0); + g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), 0); - return (guint16) (color_button->priv->rgba.alpha * 65535); + return (guint16) (button->priv->rgba.alpha * 65535); } /** * gtk_color_button_set_rgba: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * @rgba: a #GdkRGBA to set the current color with * * Sets the current color to be @rgba. * * Since: 3.0 + * + * Deprecated: 3.4: Use gtk_color_chooser_set_rgba() instead. */ void -gtk_color_button_set_rgba (GtkColorButton *color_button, +gtk_color_button_set_rgba (GtkColorButton *button, const GdkRGBA *rgba) { - g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button)); + g_return_if_fail (GTK_IS_COLOR_BUTTON (button)); g_return_if_fail (rgba != NULL); - color_button->priv->rgba = *rgba; - - gtk_widget_queue_draw (color_button->priv->draw_area); + button->priv->rgba = *rgba; + gtk_widget_queue_draw (button->priv->draw_area); - g_object_notify (G_OBJECT (color_button), "color"); - g_object_notify (G_OBJECT (color_button), "alpha"); - g_object_notify (G_OBJECT (color_button), "rgba"); + g_object_notify (G_OBJECT (button), "color"); + g_object_notify (G_OBJECT (button), "alpha"); + g_object_notify (G_OBJECT (button), "rgba"); } /** * gtk_color_button_get_rgba: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * @rgba: (out): a #GdkRGBA to fill in with the current color * * Sets @rgba to be the current color in the #GtkColorButton widget. * * Since: 3.0 + * + * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead. */ void -gtk_color_button_get_rgba (GtkColorButton *color_button, +gtk_color_button_get_rgba (GtkColorButton *button, GdkRGBA *rgba) { - g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button)); + g_return_if_fail (GTK_IS_COLOR_BUTTON (button)); g_return_if_fail (rgba != NULL); - *rgba = color_button->priv->rgba; + *rgba = button->priv->rgba; } /** * gtk_color_button_set_use_alpha: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not * * Sets whether or not the color button should use the alpha channel. * * Since: 2.4 + * + * Deprecated: 3.4: Use gtk_color_chooser_set_use_alpha() instead. */ void -gtk_color_button_set_use_alpha (GtkColorButton *color_button, +gtk_color_button_set_use_alpha (GtkColorButton *button, gboolean use_alpha) { - g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button)); + g_return_if_fail (GTK_IS_COLOR_BUTTON (button)); use_alpha = (use_alpha != FALSE); - if (color_button->priv->use_alpha != use_alpha) + if (button->priv->use_alpha != use_alpha) { - color_button->priv->use_alpha = use_alpha; + button->priv->use_alpha = use_alpha; - gtk_widget_queue_draw (color_button->priv->draw_area); + gtk_widget_queue_draw (button->priv->draw_area); - g_object_notify (G_OBJECT (color_button), "use-alpha"); + g_object_notify (G_OBJECT (button), "use-alpha"); } } /** * gtk_color_button_get_use_alpha: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * * Does the color selection dialog use the alpha channel ? * * Returns: %TRUE if the color sample uses alpha channel, %FALSE if not * * Since: 2.4 + * + * Deprecated: 3.4: Use gtk_color_chooser_get_use_alpha() instead. */ gboolean -gtk_color_button_get_use_alpha (GtkColorButton *color_button) +gtk_color_button_get_use_alpha (GtkColorButton *button) { - g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), FALSE); + g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), FALSE); - return color_button->priv->use_alpha; + return button->priv->use_alpha; } /** * gtk_color_button_set_title: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * @title: String containing new window title * * Sets the title for the color selection dialog. @@ -879,27 +836,27 @@ gtk_color_button_get_use_alpha (GtkColorButton *color_button) * Since: 2.4 */ void -gtk_color_button_set_title (GtkColorButton *color_button, +gtk_color_button_set_title (GtkColorButton *button, const gchar *title) { gchar *old_title; - g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button)); + g_return_if_fail (GTK_IS_COLOR_BUTTON (button)); - old_title = color_button->priv->title; - color_button->priv->title = g_strdup (title); + old_title = button->priv->title; + button->priv->title = g_strdup (title); g_free (old_title); - if (color_button->priv->cs_dialog) - gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog), - color_button->priv->title); + if (button->priv->cs_dialog) + gtk_window_set_title (GTK_WINDOW (button->priv->cs_dialog), + button->priv->title); - g_object_notify (G_OBJECT (color_button), "title"); + g_object_notify (G_OBJECT (button), "title"); } /** * gtk_color_button_get_title: - * @color_button: a #GtkColorButton + * @button: a #GtkColorButton * * Gets the title of the color selection dialog. * @@ -908,11 +865,11 @@ gtk_color_button_set_title (GtkColorButton *color_button, * Since: 2.4 */ const gchar * -gtk_color_button_get_title (GtkColorButton *color_button) +gtk_color_button_get_title (GtkColorButton *button) { - g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), NULL); + g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), NULL); - return color_button->priv->title; + return button->priv->title; } static void @@ -921,15 +878,15 @@ gtk_color_button_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - GtkColorButton *color_button = GTK_COLOR_BUTTON (object); + GtkColorButton *button = GTK_COLOR_BUTTON (object); switch (param_id) { case PROP_USE_ALPHA: - gtk_color_button_set_use_alpha (color_button, g_value_get_boolean (value)); + gtk_color_button_set_use_alpha (button, g_value_get_boolean (value)); break; case PROP_TITLE: - gtk_color_button_set_title (color_button, g_value_get_string (value)); + gtk_color_button_set_title (button, g_value_get_string (value)); break; case PROP_COLOR: { @@ -943,14 +900,14 @@ gtk_color_button_set_property (GObject *object, rgba.blue = color->blue / 65535.0; rgba.alpha = 1.0; - gtk_color_button_set_rgba (color_button, &rgba); + gtk_color_button_set_rgba (button, &rgba); } break; case PROP_ALPHA: - gtk_color_button_set_alpha (color_button, g_value_get_uint (value)); + gtk_color_button_set_alpha (button, g_value_get_uint (value)); break; case PROP_RGBA: - gtk_color_button_set_rgba (color_button, g_value_get_boxed (value)); + gtk_color_button_set_rgba (button, g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -964,22 +921,22 @@ gtk_color_button_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - GtkColorButton *color_button = GTK_COLOR_BUTTON (object); + GtkColorButton *button = GTK_COLOR_BUTTON (object); switch (param_id) { case PROP_USE_ALPHA: - g_value_set_boolean (value, gtk_color_button_get_use_alpha (color_button)); + g_value_set_boolean (value, gtk_color_button_get_use_alpha (button)); break; case PROP_TITLE: - g_value_set_string (value, gtk_color_button_get_title (color_button)); + g_value_set_string (value, gtk_color_button_get_title (button)); break; case PROP_COLOR: { GdkColor color; GdkRGBA rgba; - gtk_color_button_get_rgba (color_button, &rgba); + gtk_color_button_get_rgba (button, &rgba); color.red = (guint16) (rgba.red * 65535 + 0.5); color.green = (guint16) (rgba.green * 65535 + 0.5); @@ -989,13 +946,13 @@ gtk_color_button_get_property (GObject *object, } break; case PROP_ALPHA: - g_value_set_uint (value, gtk_color_button_get_alpha (color_button)); + g_value_set_uint (value, gtk_color_button_get_alpha (button)); break; case PROP_RGBA: { GdkRGBA rgba; - gtk_color_button_get_rgba (color_button, &rgba); + gtk_color_button_get_rgba (button, &rgba); g_value_set_boxed (value, &rgba); } break; @@ -1004,3 +961,29 @@ gtk_color_button_get_property (GObject *object, break; } } + +static void +gtk_color_button_add_palette (GtkColorChooser *chooser, + gboolean horizontal, + gint colors_per_line, + gint n_colors, + GdkRGBA *colors) +{ + GtkColorButton *button = GTK_COLOR_BUTTON (chooser); + + if (button->priv->cs_dialog) + gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (button->priv->cs_dialog), + horizontal, colors_per_line, n_colors, colors); +} + +typedef void (* get_rgba) (GtkColorChooser *, GdkRGBA *); +typedef void (* set_rgba) (GtkColorChooser *, const GdkRGBA *); + +static void +gtk_color_button_iface_init (GtkColorChooserInterface *iface) +{ + iface->get_rgba = (get_rgba)gtk_color_button_get_rgba; + iface->set_rgba = (set_rgba)gtk_color_button_set_rgba; + iface->add_palette = gtk_color_button_add_palette; +} + diff --git a/gtk/gtkcolorbutton.h b/gtk/gtkcolorbutton.h index 8f2d2ca588..47ed059a56 100644 --- a/gtk/gtkcolorbutton.h +++ b/gtk/gtkcolorbutton.h @@ -73,32 +73,37 @@ struct _GtkColorButtonClass { }; -GType gtk_color_button_get_type (void) G_GNUC_CONST; -GtkWidget *gtk_color_button_new (void); -GtkWidget *gtk_color_button_new_with_rgba (const GdkRGBA *rgba); -void gtk_color_button_set_alpha (GtkColorButton *color_button, - guint16 alpha); -guint16 gtk_color_button_get_alpha (GtkColorButton *color_button); -void gtk_color_button_set_use_alpha (GtkColorButton *color_button, - gboolean use_alpha); -gboolean gtk_color_button_get_use_alpha (GtkColorButton *color_button); -void gtk_color_button_set_rgba (GtkColorButton *color_button, - const GdkRGBA *rgba); -void gtk_color_button_get_rgba (GtkColorButton *color_button, - GdkRGBA *rgba); -void gtk_color_button_set_title (GtkColorButton *color_button, - const gchar *title); -const gchar *gtk_color_button_get_title (GtkColorButton *color_button); +GType gtk_color_button_get_type (void) G_GNUC_CONST; +GtkWidget * gtk_color_button_new (void); +GtkWidget * gtk_color_button_new_with_rgba (const GdkRGBA *rgba); +void gtk_color_button_set_title (GtkColorButton *button, + const gchar *title); +const gchar *gtk_color_button_get_title (GtkColorButton *button); GDK_DEPRECATED_FOR(gtk_color_button_new_with_rgba) GtkWidget *gtk_color_button_new_with_color (const GdkColor *color); GDK_DEPRECATED_FOR(gtk_color_button_set_rgba) -void gtk_color_button_set_color (GtkColorButton *color_button, +void gtk_color_button_set_color (GtkColorButton *button, const GdkColor *color); GDK_DEPRECATED_FOR(gtk_color_button_get_rgba) -void gtk_color_button_get_color (GtkColorButton *color_button, +void gtk_color_button_get_color (GtkColorButton *button, GdkColor *color); - +GDK_DEPRECATED_FOR(gtk_color_button_set_rgba) +void gtk_color_button_set_alpha (GtkColorButton *button, + guint16 alpha); +GDK_DEPRECATED_FOR(gtk_color_button_get_rgba) +guint16 gtk_color_button_get_alpha (GtkColorButton *button); +GDK_DEPRECATED_FOR(gtk_color_chooser_set_use_alpha) +void gtk_color_button_set_use_alpha (GtkColorButton *button, + gboolean use_alpha); +GDK_DEPRECATED_FOR(gtk_color_chooser_get_use_alpha) +gboolean gtk_color_button_get_use_alpha (GtkColorButton *button); +GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba) +void gtk_color_button_set_rgba (GtkColorButton *button, + const GdkRGBA *rgba); +GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba) +void gtk_color_button_get_rgba (GtkColorButton *button, + GdkRGBA *rgba); G_END_DECLS diff --git a/gtk/gtkcolorchooser.c b/gtk/gtkcolorchooser.c new file mode 100644 index 0000000000..a54127b614 --- /dev/null +++ b/gtk/gtkcolorchooser.c @@ -0,0 +1,258 @@ +/* GTK - The GIMP Toolkit + * + * Copyright (C) 2012, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "gtkcolorchooser.h" +#include "gtkcolorchooserprivate.h" +#include "gtkintl.h" +#include "gtktypebuiltins.h" +#include "gtkprivate.h" + +/** + * SECTION:gtkcolorchooser + * @Short_description: Interface implemented by widgets for choosing colors + * @Title: GtkColorChooser + * @See_also: #GtkColorChooserDialog, #GtkColorChooserWidget, #GtkColorButton + * + * #GtkColorChooser is an interface that is implemented by widgets + * for choosing colors. Depending on the situation, colors may be + * allowed to have alpha (translucency). + * + * In GTK+, the main widgets that implement this interface are + * #GtkColorChooserWidget, #GtkColorChooserDialog and #GtkColorButton. + * + * Since: 3.4 + */ + +enum +{ + COLOR_ACTIVATED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +G_DEFINE_INTERFACE (GtkColorChooser, gtk_color_chooser, G_TYPE_OBJECT); + +static void +gtk_color_chooser_default_init (GtkColorChooserInterface *iface) +{ + /** + * GtkColorChooser:rgba: + * + * The ::rgba property contains the currently selected color, + * as a #GdkRGBA struct. The property can be set to change + * the current selection programmatically. + * + * Since: 3.4 + */ + g_object_interface_install_property (iface, + g_param_spec_boxed ("rgba", + P_("Color"), + P_("Current color, as a GdkRGBA"), + GDK_TYPE_RGBA, + GTK_PARAM_READWRITE)); + + /** + * GtkColorChooser:use-alpha: + * + * When ::use-alpha is %TRUE, colors may have alpha (translucency) + * information. When it is %FALSE, the #GdkRGBA struct obtained + * via the #GtkColorChooser:rgba property will be forced to have + * alpha == 1. + * + * Implementations are expected to show alpha by rendering the color + * over a non-uniform background (like a checkerboard pattern). + * + * Since: 3.4 + */ + g_object_interface_install_property (iface, + g_param_spec_boolean ("use-alpha", + P_("Use alpha"), + P_("Whether alpha should be shown"), + TRUE, + GTK_PARAM_READWRITE)); + + /** + * GtkColorChooser::color-activated: + * @chooser: the object which received the signal + * @color: the color + * + * Emitted when a color is activated from the color chooser. + * This usually happens when the user clicks a color swatch, + * or a color is selected and the user presses one of the keys + * Space, Shift+Space, Return or Enter. + * + * Since: 3.4 + */ + signals[COLOR_ACTIVATED] = + g_signal_new ("color-activated", + GTK_TYPE_COLOR_CHOOSER, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkColorChooserInterface, color_activated), + NULL, NULL, + NULL, + G_TYPE_NONE, + 1, G_TYPE_STRING); +} + +void +_gtk_color_chooser_color_activated (GtkColorChooser *chooser, + const GdkRGBA *color) +{ + g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color); +} + +/** + * gtk_color_chooser_get_rgba: + * @chooser: a #GtkColorChooser + * @color: return location for the color + * + * Gets the currently-selected color. + * + * Since: 3.4 + */ +void +gtk_color_chooser_get_rgba (GtkColorChooser *chooser, + GdkRGBA *color) +{ + g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser)); + + GTK_COLOR_CHOOSER_GET_IFACE (chooser)->get_rgba (chooser, color); +} + +/** + * gtk_color_chooser_set_rgba: + * @chooser: a #GtkColorChooser + * @color: the new color + * + * Sets the color. + */ +void +gtk_color_chooser_set_rgba (GtkColorChooser *chooser, + const GdkRGBA *color) +{ + g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser)); + g_return_if_fail (color != NULL); + + GTK_COLOR_CHOOSER_GET_IFACE (chooser)->set_rgba (chooser, color); +} + +/** + * gtk_color_chooser_get_use_alpha: + * @chooser: a #GtkColorChooser + * + * Returns whether the color chooser shows the alpha channel. + * + * Returns: %TRUE if the color chooser uses the alpha channel, + * %FALSE if not + * + * Since: 3.4 + */ +gboolean +gtk_color_chooser_get_use_alpha (GtkColorChooser *chooser) +{ + gboolean use_alpha; + + g_return_val_if_fail (GTK_IS_COLOR_CHOOSER (chooser), TRUE); + + g_object_get (chooser, "use-alpha", &use_alpha, NULL); + + return use_alpha; +} + +/** + * gtk_color_chooser_set_use_alpha: + * @chooser: a #GtkColorChooser + * @use_alpha: %TRUE if color chooser should use alpha channel, %FALSE if not + * + * Sets whether or not the color chooser should use the alpha channel. + * + * Since: 3.4 + */ +void +gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser, + gboolean use_alpha) +{ + + g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser)); + + g_object_set (chooser, "use-alpha", use_alpha, NULL); +} + +/** + * gtk_color_chooser_add_palette: + * @chooser: a #GtkColorChooser + * @horizontal: %TRUE if the palette should be displayed in rows, + * %FALSE for columns + * @colors_per_line: the number of colors to show in each row/column + * @n_colors: the total number of elements in @colors + * @colors: (array length=n_colors): the colors of the palette + * + * Adds a palette to the color chooser. If @horizontal is %TRUE, + * the colors are grouped in rows, with @colors_per_line colors + * in each row. If @horizontal is %FALSE, the colors are grouped + * in columns instead. + * + * The default color palette of #GtkColorChooserWidget has + * 27 colors, organized in columns of 3 colors. The default gray + * palette has 9 grays in a single row. + * + * The layout of the color chooser widget works best when the + * palettes have 9-10 columns. + * + * Calling this function is called for the first time has the + * side effect of removing the default color and gray palettes + * from the color chooser. + */ +void +gtk_color_chooser_add_palette (GtkColorChooser *chooser, + gboolean horizontal, + gint colors_per_line, + gint n_colors, + GdkRGBA *colors) +{ + g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser)); + + if (GTK_COLOR_CHOOSER_GET_IFACE (chooser)->add_palette) + GTK_COLOR_CHOOSER_GET_IFACE (chooser)->add_palette (chooser, horizontal, colors_per_line, n_colors, colors); +} + +cairo_pattern_t * +_gtk_color_chooser_get_checkered_pattern (void) +{ + /* need to respect pixman's stride being a multiple of 4 */ + static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0x00, 0x00 }; + static cairo_surface_t *checkered = NULL; + cairo_pattern_t *pattern; + + if (checkered == NULL) + checkered = cairo_image_surface_create_for_data (data, + CAIRO_FORMAT_A8, + 2, 2, 4); + + pattern = cairo_pattern_create_for_surface (checkered); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); + + return pattern; +} diff --git a/gtk/gtkcolorchooser.h b/gtk/gtkcolorchooser.h new file mode 100644 index 0000000000..052d52d182 --- /dev/null +++ b/gtk/gtkcolorchooser.h @@ -0,0 +1,82 @@ +/* GTK - The GIMP Toolkit + * + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_COLOR_CHOOSER_H__ +#define __GTK_COLOR_CHOOSER_H__ + +#include <gtk/gtkwidget.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_COLOR_CHOOSER (gtk_color_chooser_get_type ()) +#define GTK_COLOR_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_CHOOSER, GtkColorChooser)) +#define GTK_IS_COLOR_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_CHOOSER)) +#define GTK_COLOR_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_COLOR_CHOOSER, GtkColorChooserInterface)) + +typedef struct _GtkColorChooser GtkColorChooser; +typedef struct _GtkColorChooserInterface GtkColorChooserInterface; + +struct _GtkColorChooserInterface +{ + GTypeInterface base_interface; + + /* Methods */ + void (* get_rgba) (GtkColorChooser *chooser, + GdkRGBA *color); + void (* set_rgba) (GtkColorChooser *chooser, + const GdkRGBA *color); + + void (* add_palette) (GtkColorChooser *chooser, + gboolean horizontal, + gint colors_per_line, + gint n_colors, + GdkRGBA *colors); + + /* Signals */ + void (* color_activated) (GtkColorChooser *chooser, + const GdkRGBA *color); + + /* Padding */ + gpointer padding[12]; +}; + +GType gtk_color_chooser_get_type (void) G_GNUC_CONST; + +void gtk_color_chooser_get_rgba (GtkColorChooser *chooser, + GdkRGBA *color); +void gtk_color_chooser_set_rgba (GtkColorChooser *chooser, + const GdkRGBA *color); +gboolean gtk_color_chooser_get_use_alpha (GtkColorChooser *chooser); +void gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser, + gboolean use_alpha); + +void gtk_color_chooser_add_palette (GtkColorChooser *chooser, + gboolean horizontal, + gint colors_per_line, + gint n_colors, + GdkRGBA *colors); + +G_END_DECLS + +#endif /* __GTK_COLOR_CHOOSER_H__ */ diff --git a/gtk/gtkcolorchooserdialog.c b/gtk/gtkcolorchooserdialog.c new file mode 100644 index 0000000000..2d9070f840 --- /dev/null +++ b/gtk/gtkcolorchooserdialog.c @@ -0,0 +1,303 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "gtkdialog.h" +#include "gtkstock.h" +#include "gtkbox.h" +#include "gtkprivate.h" +#include "gtkintl.h" + +#include "gtkcolorchooserprivate.h" +#include "gtkcolorchooserdialog.h" +#include "gtkcolorchooserwidget.h" + +/** + * SECTION:gtkcolorchooserdialog + * @Short_description: A dialog for choosing colors + * @Title: GtkColorChooserDialog + * @See_also: #GtkColorChooser, #GtkDialog + * + * The #GtkColorChooserDialog widget is a dialog for choosing + * a color. It implements the #GtkColorChooser interface. + * + * Since: 3.4 + */ + +struct _GtkColorChooserDialogPrivate +{ + GtkWidget *chooser; + + GtkWidget *select_button; + GtkWidget *cancel_button; +}; + +enum +{ + PROP_ZERO, + PROP_RGBA, + PROP_USE_ALPHA, + PROP_SHOW_EDITOR +}; + +static void gtk_color_chooser_dialog_iface_init (GtkColorChooserInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkColorChooserDialog, gtk_color_chooser_dialog, GTK_TYPE_DIALOG, + G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER, + gtk_color_chooser_dialog_iface_init)) + +static void +propagate_notify (GObject *o, + GParamSpec *pspec, + GtkColorChooserDialog *cc) +{ + g_object_notify (G_OBJECT (cc), pspec->name); +} + +static void +color_activated_cb (GtkColorChooser *chooser, + GdkRGBA *color, + GtkDialog *dialog) +{ + gtk_dialog_response (dialog, GTK_RESPONSE_OK); +} + +static void +gtk_color_chooser_dialog_init (GtkColorChooserDialog *cc) +{ + GtkColorChooserDialogPrivate *priv; + GtkDialog *dialog = GTK_DIALOG (cc); + GtkWidget *action_area, *content_area; + + cc->priv = G_TYPE_INSTANCE_GET_PRIVATE (cc, + GTK_TYPE_COLOR_CHOOSER_DIALOG, + GtkColorChooserDialogPrivate); + priv = cc->priv; + + content_area = gtk_dialog_get_content_area (dialog); + action_area = gtk_dialog_get_action_area (dialog); + + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */ + gtk_container_set_border_width (GTK_CONTAINER (action_area), 5); + gtk_box_set_spacing (GTK_BOX (action_area), 6); + + gtk_widget_push_composite_child (); + + gtk_window_set_resizable (GTK_WINDOW (cc), FALSE); + + /* Create the content area */ + priv->chooser = gtk_color_chooser_widget_new (); + gtk_container_set_border_width (GTK_CONTAINER (priv->chooser), 5); + gtk_widget_show (priv->chooser); + gtk_box_pack_start (GTK_BOX (content_area), + priv->chooser, TRUE, TRUE, 0); + + g_signal_connect (priv->chooser, "notify::rgba", + G_CALLBACK (propagate_notify), cc); + + g_signal_connect (priv->chooser, "notify::show-editor", + G_CALLBACK (propagate_notify), cc); + + g_signal_connect (priv->chooser, "color-activated", + G_CALLBACK (color_activated_cb), cc); + + /* Create the action area */ + priv->cancel_button = gtk_dialog_add_button (dialog, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL); + priv->select_button = gtk_dialog_add_button (dialog, + _("_Select"), + GTK_RESPONSE_OK); + gtk_widget_grab_default (priv->select_button); + + gtk_dialog_set_alternative_button_order (dialog, + GTK_RESPONSE_OK, + GTK_RESPONSE_CANCEL, + -1); + + gtk_window_set_title (GTK_WINDOW (cc), _("Select a Color")); + + gtk_widget_pop_composite_child (); +} + +static void +gtk_color_chooser_dialog_response (GtkDialog *dialog, + gint response_id) +{ + if (response_id == GTK_RESPONSE_OK) + { + GdkRGBA color; + + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &color); + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog), &color); + } + + g_object_set (GTK_COLOR_CHOOSER_DIALOG (dialog)->priv->chooser, + "show-editor", FALSE, NULL); +} + +static void +gtk_color_chooser_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkColorChooserDialog *cd = GTK_COLOR_CHOOSER_DIALOG (object); + GtkColorChooser *cc = GTK_COLOR_CHOOSER (object); + + switch (prop_id) + { + case PROP_RGBA: + { + GdkRGBA color; + + gtk_color_chooser_get_rgba (cc, &color); + g_value_set_boxed (value, &color); + } + break; + case PROP_USE_ALPHA: + g_value_set_boolean (value, gtk_color_chooser_get_use_alpha (GTK_COLOR_CHOOSER (cd->priv->chooser))); + break; + case PROP_SHOW_EDITOR: + { + gboolean show_editor; + g_object_get (cd->priv->chooser, "show-editor", &show_editor, NULL); + g_value_set_boolean (value, show_editor); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_color_chooser_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkColorChooserDialog *cd = GTK_COLOR_CHOOSER_DIALOG (object); + GtkColorChooser *cc = GTK_COLOR_CHOOSER (object); + + switch (prop_id) + { + case PROP_RGBA: + gtk_color_chooser_set_rgba (cc, g_value_get_boxed (value)); + break; + case PROP_USE_ALPHA: + gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cd->priv->chooser), g_value_get_boolean (value)); + break; + case PROP_SHOW_EDITOR: + g_object_set (cd->priv->chooser, + "show-editor", g_value_get_boolean (value), + NULL); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_color_chooser_dialog_class_init (GtkColorChooserDialogClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class); + + object_class->get_property = gtk_color_chooser_dialog_get_property; + object_class->set_property = gtk_color_chooser_dialog_set_property; + + dialog_class->response = gtk_color_chooser_dialog_response; + + g_object_class_override_property (object_class, PROP_RGBA, "rgba"); + g_object_class_override_property (object_class, PROP_USE_ALPHA, "use-alpha"); + g_object_class_install_property (object_class, PROP_SHOW_EDITOR, + g_param_spec_boolean ("show-editor", P_("Show editor"), P_("Show editor"), + FALSE, GTK_PARAM_READWRITE)); + + + g_type_class_add_private (class, sizeof (GtkColorChooserDialogPrivate)); +} + +static void +gtk_color_chooser_dialog_get_rgba (GtkColorChooser *chooser, + GdkRGBA *color) +{ + GtkColorChooserDialog *cc = GTK_COLOR_CHOOSER_DIALOG (chooser); + + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cc->priv->chooser), color); +} + +static void +gtk_color_chooser_dialog_set_rgba (GtkColorChooser *chooser, + const GdkRGBA *color) +{ + GtkColorChooserDialog *cc = GTK_COLOR_CHOOSER_DIALOG (chooser); + + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->chooser), color); +} + +static void +gtk_color_chooser_dialog_add_palette (GtkColorChooser *chooser, + gboolean horizontal, + gint colors_per_line, + gint n_colors, + GdkRGBA *colors) +{ + GtkColorChooserDialog *cc = GTK_COLOR_CHOOSER_DIALOG (chooser); + + gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (cc->priv->chooser), + horizontal, colors_per_line, n_colors, colors); +} + +static void +gtk_color_chooser_dialog_iface_init (GtkColorChooserInterface *iface) +{ + iface->get_rgba = gtk_color_chooser_dialog_get_rgba; + iface->set_rgba = gtk_color_chooser_dialog_set_rgba; + iface->add_palette = gtk_color_chooser_dialog_add_palette; +} + +/** + * gtk_color_chooser_dialog_new: + * @title: (allow-none): Title of the dialog, or %NULL + * @parent: (allow-none): Transient parent of the dialog, or %NULL + * + * Creates a new #GtkColorChooserDialog. + * + * Return value: a new #GtkColorChooserDialog + * + * Since: 3.4 + */ +GtkWidget * +gtk_color_chooser_dialog_new (const gchar *title, + GtkWindow *parent) +{ + GtkColorChooserDialog *dialog; + + dialog = g_object_new (GTK_TYPE_COLOR_CHOOSER_DIALOG, + "title", title, + "transient-for", parent, + NULL); + + return GTK_WIDGET (dialog); +} diff --git a/gtk/gtkcolorchooserdialog.h b/gtk/gtkcolorchooserdialog.h new file mode 100644 index 0000000000..c67be0e360 --- /dev/null +++ b/gtk/gtkcolorchooserdialog.h @@ -0,0 +1,68 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_COLOR_CHOOSER_DIALOG_H__ +#define __GTK_COLOR_CHOOSER_DIALOG_H__ + +#include <gtk/gtkdialog.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_COLOR_CHOOSER_DIALOG (gtk_color_chooser_dialog_get_type ()) +#define GTK_COLOR_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_CHOOSER_DIALOG, GtkColorChooserDialog)) +#define GTK_COLOR_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_CHOOSER_DIALOG, GtkColorChooserDialogClass)) +#define GTK_IS_COLOR_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_CHOOSER_DIALOG)) +#define GTK_IS_COLOR_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_CHOOSER_DIALOG)) +#define GTK_COLOR_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_CHOOSER_DIALOG, GtkColorChooserDialogClass)) + +typedef struct _GtkColorChooserDialog GtkColorChooserDialog; +typedef struct _GtkColorChooserDialogPrivate GtkColorChooserDialogPrivate; +typedef struct _GtkColorChooserDialogClass GtkColorChooserDialogClass; + +struct _GtkColorChooserDialog +{ + GtkDialog parent_instance; + + /*< private >*/ + GtkColorChooserDialogPrivate *priv; +}; + +struct _GtkColorChooserDialogClass +{ + GtkDialogClass parent_class; + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); +}; + +GType gtk_color_chooser_dialog_get_type (void) G_GNUC_CONST; + +GtkWidget * gtk_color_chooser_dialog_new (const gchar *title, + GtkWindow *parent); + +G_END_DECLS + +#endif /* __GTK_COLOR_CHOOSER_DIALOG_H__ */ diff --git a/gtk/gtkcolorchooserprivate.h b/gtk/gtkcolorchooserprivate.h new file mode 100644 index 0000000000..4109901ca1 --- /dev/null +++ b/gtk/gtkcolorchooserprivate.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_COLOR_CHOOSER_PRIVATE_H__ +#define __GTK_COLOR_CHOOSER_PRIVATE_H__ + +#include "gtkcolorchooser.h" + +G_BEGIN_DECLS + +void _gtk_color_chooser_color_activated (GtkColorChooser *chooser, + const GdkRGBA *color); + +cairo_pattern_t * _gtk_color_chooser_get_checkered_pattern (void); + +G_END_DECLS + +#endif /* ! __GTK_COLOR_CHOOSER_PRIVATE_H__ */ diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c new file mode 100644 index 0000000000..fad55fa577 --- /dev/null +++ b/gtk/gtkcolorchooserwidget.c @@ -0,0 +1,803 @@ +/* GTK - The GIMP Toolkit + * + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "gtkcolorchooserprivate.h" +#include "gtkcolorchooserwidget.h" +#include "gtkcoloreditorprivate.h" +#include "gtkcolorswatchprivate.h" +#include "gtkbox.h" +#include "gtkgrid.h" +#include "gtklabel.h" +#include "gtkorientable.h" +#include "gtkprivate.h" +#include "gtkintl.h" +#include "gtksizegroup.h" + +#include <math.h> + +/** + * SECTION:gtkcolorchooserwidget + * @Short_description: A widget for choosing colors + * @Title: GtkColorChooserWidget + * @See_also: #GtkColorChooserDialog + * + * The #GtkColorChooserWidget widget lets the user select a + * color. By default, the chooser presents a prefined palette + * of colors, plus a small number of settable custom colors. + * It is also possible to select a different color with the + * single-color editor. To enter the single-color editing mode, + * use the context menu of any color of the palette, or use the + * '+' button to add a new custom color. + * + * The chooser automatically remembers the last selection, as well + * as custom colors. + * + * To change the initially selected color, use gtk_color_chooser_set_rgba(). + * To get the selected font use gtk_color_chooser_get_rgba(). + * + * The #GtkColorChooserWidget is used in the #GtkColorChooserDialog + * to provide a dialog for selecting colors. + * + * Since: 3.4 + */ + +struct _GtkColorChooserWidgetPrivate +{ + GtkWidget *palette; + GtkWidget *editor; + GtkSizeGroup *size_group; + + GtkWidget *custom_label; + GtkWidget *custom; + + GtkWidget *button; + GtkColorSwatch *current; + + gboolean use_alpha; + gboolean has_default_palette; + + GSettings *settings; +}; + +enum +{ + PROP_ZERO, + PROP_RGBA, + PROP_USE_ALPHA, + PROP_SHOW_EDITOR +}; + +static void gtk_color_chooser_widget_iface_init (GtkColorChooserInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkColorChooserWidget, gtk_color_chooser_widget, GTK_TYPE_BOX, + G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER, + gtk_color_chooser_widget_iface_init)) + +static void +select_swatch (GtkColorChooserWidget *cc, + GtkColorSwatch *swatch) +{ + GdkRGBA color; + + if (cc->priv->current == swatch) + return; + + if (cc->priv->current != NULL) + gtk_widget_unset_state_flags (GTK_WIDGET (cc->priv->current), GTK_STATE_FLAG_SELECTED); + gtk_widget_set_state_flags (GTK_WIDGET (swatch), GTK_STATE_FLAG_SELECTED, FALSE); + cc->priv->current = swatch; + + gtk_color_swatch_get_rgba (swatch, &color); + g_settings_set (cc->priv->settings, "selected-color", "(bdddd)", + TRUE, color.red, color.green, color.blue, color.alpha); + + g_object_notify (G_OBJECT (cc), "rgba"); +} + +static void +swatch_activate (GtkColorSwatch *swatch, + GtkColorChooserWidget *cc) +{ + GdkRGBA color; + + gtk_color_swatch_get_rgba (swatch, &color); + _gtk_color_chooser_color_activated (GTK_COLOR_CHOOSER (cc), &color); +} + +static void +swatch_customize (GtkColorSwatch *swatch, + GtkColorChooserWidget *cc) +{ + GdkRGBA color; + + gtk_color_swatch_get_rgba (swatch, &color); + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color); + + gtk_widget_hide (cc->priv->palette); + gtk_widget_show (cc->priv->editor); + g_object_notify (G_OBJECT (cc), "show-editor"); +} + +static void +swatch_selected (GtkColorSwatch *swatch, + GtkStateFlags previous, + GtkColorChooserWidget *cc) +{ + GtkStateFlags flags; + + flags = gtk_widget_get_state_flags (GTK_WIDGET (swatch)); + if ((flags & GTK_STATE_FLAG_SELECTED) != (previous & GTK_STATE_FLAG_SELECTED) && + (flags & GTK_STATE_FLAG_SELECTED) != 0) + select_swatch (cc, swatch); +} + +static void +connect_swatch_signals (GtkWidget *p, + gpointer data) +{ + g_signal_connect (p, "activate", G_CALLBACK (swatch_activate), data); + g_signal_connect (p, "customize", G_CALLBACK (swatch_customize), data); + g_signal_connect (p, "state-flags-changed", G_CALLBACK (swatch_selected), data); +} + +static void +button_activate (GtkColorSwatch *swatch, + GtkColorChooserWidget *cc) +{ + /* somewhat random, makes the hairline nicely visible */ + GdkRGBA color = { 0.75, 0.25, 0.25, 1.0 }; + + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color); + + gtk_widget_hide (cc->priv->palette); + gtk_widget_show (cc->priv->editor); + g_object_notify (G_OBJECT (cc), "show-editor"); +} + +static void +connect_button_signals (GtkWidget *p, + gpointer data) +{ + g_signal_connect (p, "activate", G_CALLBACK (button_activate), data); +} + +static void +save_custom_colors (GtkColorChooserWidget *cc) +{ + GVariantBuilder builder; + GVariant *variant; + GdkRGBA color; + GList *children, *l; + GtkWidget *child; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(dddd)")); + + children = gtk_container_get_children (GTK_CONTAINER (cc->priv->custom)); + for (l = g_list_nth (children, 1); l != NULL; l = l->next) + { + child = l->data; + if (gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (child), &color)) + g_variant_builder_add (&builder, "(dddd)", + color.red, color.green, color.blue, color.alpha); + } + + variant = g_variant_builder_end (&builder); + g_settings_set_value (cc->priv->settings, "custom-colors", variant); + + g_list_free (children); +} + +static void +connect_custom_signals (GtkWidget *p, + gpointer data) +{ + connect_swatch_signals (p, data); + g_signal_connect_swapped (p, "notify::rgba", + G_CALLBACK (save_custom_colors), data); +} + +static void +gtk_color_chooser_widget_set_use_alpha (GtkColorChooserWidget *cc, + gboolean use_alpha) +{ + GList *children, *l; + GList *palettes, *p; + GtkWidget *swatch; + GtkWidget *grid; + + cc->priv->use_alpha = use_alpha; + gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cc->priv->editor), use_alpha); + + palettes = gtk_container_get_children (GTK_CONTAINER (cc->priv->palette)); + for (p = palettes; p; p = p->next) + { + grid = p->data; + + if (!GTK_IS_CONTAINER (grid)) + continue; + + children = gtk_container_get_children (GTK_CONTAINER (grid)); + for (l = children; l; l = l->next) + { + swatch = l->data; + gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (swatch), use_alpha); + } + g_list_free (children); + } + g_list_free (palettes); + + gtk_widget_queue_draw (GTK_WIDGET (cc)); +} + +static void +gtk_color_chooser_widget_set_show_editor (GtkColorChooserWidget *cc, + gboolean show_editor) +{ + if (show_editor) + { + GdkRGBA color = { 0.75, 0.25, 0.25, 1.0 }; + + if (cc->priv->current) + gtk_color_swatch_get_rgba (cc->priv->current, &color); + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color); + } + + gtk_widget_set_visible (cc->priv->editor, show_editor); + gtk_widget_set_visible (cc->priv->palette, !show_editor); +} + +/* UI construction {{{1 */ + +static guint +scale_round (gdouble value, gdouble scale) +{ + value = floor (value * scale + 0.5); + value = MAX (value, 0); + value = MIN (value, scale); + return (guint)value; +} + +gchar * +accessible_color_name (GdkRGBA *color) +{ + if (color->alpha < 1.0) + return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"), + scale_round (color->red, 100), + scale_round (color->green, 100), + scale_round (color->blue, 100), + scale_round (color->alpha, 100)); + else + return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%"), + scale_round (color->red, 100), + scale_round (color->green, 100), + scale_round (color->blue, 100)); +} + + +static void +add_palette (GtkColorChooserWidget *cc, + gboolean horizontal, + gint colors_per_line, + gint n_colors, + GdkRGBA *colors, + const gchar **names) +{ + GtkWidget *grid; + GtkWidget *p; + AtkObject *atk_obj; + gint line, pos; + gint i; + gint left, right; + + grid = gtk_grid_new (); + gtk_widget_set_margin_bottom (grid, 12); + gtk_grid_set_row_spacing (GTK_GRID (grid), 2); + gtk_grid_set_column_spacing (GTK_GRID (grid), 4); + gtk_container_add (GTK_CONTAINER (cc->priv->palette), grid); + + left = 0; + right = colors_per_line - 1; + if (gtk_widget_get_direction (GTK_WIDGET (cc)) == GTK_TEXT_DIR_RTL) + { + i = left; + left = right; + right = i; + } + + for (i = 0; i < n_colors; i++) + { + p = gtk_color_swatch_new (); + atk_obj = gtk_widget_get_accessible (p); + if (names) + { + atk_object_set_description (atk_obj, + g_dpgettext2 (GETTEXT_PACKAGE, "Color name", names[i])); + } + else + { + gchar *text, *name; + + name = accessible_color_name (&colors[i]); + text = g_strdup_printf (_("Color: %s"), name); + atk_object_set_description (atk_obj, text); + g_free (text); + g_free (name); + } + gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), &colors[i]); + connect_swatch_signals (p, cc); + + line = i / colors_per_line; + pos = i % colors_per_line; + + if (horizontal) + { + if (pos == left) + gtk_style_context_add_class (gtk_widget_get_style_context (p), GTK_STYLE_CLASS_LEFT); + else if (pos == right) + gtk_style_context_add_class (gtk_widget_get_style_context (p), GTK_STYLE_CLASS_RIGHT); + + gtk_grid_attach (GTK_GRID (grid), p, pos, line, 1, 1); + } + else + { + if (pos == 0) + gtk_style_context_add_class (gtk_widget_get_style_context (p), GTK_STYLE_CLASS_TOP); + else if (pos == colors_per_line - 1) + gtk_style_context_add_class (gtk_widget_get_style_context (p), GTK_STYLE_CLASS_BOTTOM); + + gtk_grid_attach (GTK_GRID (grid), p, line, pos, 1, 1); + } + } + + gtk_widget_show_all (grid); +} + +static void +remove_default_palette (GtkColorChooserWidget *cc) +{ + GList *children, *l; + GtkWidget *widget; + + if (!cc->priv->has_default_palette) + return; + + children = gtk_container_get_children (GTK_CONTAINER (cc->priv->palette)); + for (l = children; l; l = l->next) + { + widget = l->data; + if (widget == cc->priv->custom_label || widget == cc->priv->custom) + continue; + gtk_container_remove (GTK_CONTAINER (cc->priv->palette), widget); + } + g_list_free (children); + + cc->priv->has_default_palette = FALSE; +} + +static void +add_default_palette (GtkColorChooserWidget *cc) +{ + const gchar *default_colors[9][3] = { + { "#ef2929", "#cc0000", "#a40000" }, /* Scarlet Red */ + { "#fcaf3e", "#f57900", "#ce5c00" }, /* Orange */ + { "#fce94f", "#edd400", "#c4a000" }, /* Butter */ + { "#8ae234", "#73d216", "#4e9a06" }, /* Chameleon */ + { "#729fcf", "#3465a4", "#204a87" }, /* Sky Blue */ + { "#ad7fa8", "#75507b", "#5c3566" }, /* Plum */ + { "#e9b96e", "#c17d11", "#8f5902" }, /* Chocolate */ + { "#888a85", "#555753", "#2e3436" }, /* Aluminum 1 */ + { "#eeeeec", "#d3d7cf", "#babdb6" } /* Aluminum 2 */ + }; + const gchar *color_names[] = { + NC_("Color name", "Light Scarlet Red"), + NC_("Color name", "Scarlet Red"), + NC_("Color name", "Dark Scarlet Red"), + NC_("Color name", "Light Orange"), + NC_("Color name", "Orange"), + NC_("Color name", "Dark Orange"), + NC_("Color name", "Light Butter"), + NC_("Color name", "Butter"), + NC_("Color name", "Dark Butter"), + NC_("Color name", "Light Chameleon"), + NC_("Color name", "Chameleon"), + NC_("Color name", "Dark Chameleon"), + NC_("Color name", "Light Sky Blue"), + NC_("Color name", "Sky Blue"), + NC_("Color name", "Dark Sky Blue"), + NC_("Color name", "Light Plum"), + NC_("Color name", "Plum"), + NC_("Color name", "Dark Plum"), + NC_("Color name", "Light Chocolate"), + NC_("Color name", "Chocolate"), + NC_("Color name", "Dark Chocolate"), + NC_("Color name", "Light Aluminum 1"), + NC_("Color name", "Aluminum 1"), + NC_("Color name", "Dark Aluminum 1"), + NC_("Color name", "Light Aluminum 2"), + NC_("Color name", "Aluminum 2"), + NC_("Color name", "Dark Aluminum 2") + }; + const gchar *default_grays[9] = { + "#000000", /* black */ + "#2e3436", /* very dark gray */ + "#555753", /* darker gray */ + "#888a85", /* dark gray */ + "#babdb6", /* medium gray */ + "#d3d7cf", /* light gray */ + "#eeeeec", /* lighter gray */ + "#f3f3f3", /* very light gray */ + "#ffffff" /* white */ + }; + const gchar *gray_names[] = { + NC_("Color name", "Black"), + NC_("Color name", "Very Dark Gray"), + NC_("Color name", "Darker Gray"), + NC_("Color name", "Dark Gray"), + NC_("Color name", "Medium Gray"), + NC_("Color name", "Light Gray"), + NC_("Color name", "Lighter Gray"), + NC_("Color name", "Very Light Gray"), + NC_("Color name", "White") + }; + GdkRGBA colors[9*3]; + gint i, j; + + for (i = 0; i < 9; i++) + for (j = 0; j < 3; j++) + gdk_rgba_parse (&colors[i*3 + j], default_colors[i][j]); + + add_palette (cc, FALSE, 3, 9*3, colors, color_names); + + for (i = 0; i < 9; i++) + gdk_rgba_parse (&colors[i], default_grays[i]); + + add_palette (cc, TRUE, 9, 9, colors, gray_names); + + cc->priv->has_default_palette = TRUE; +} + +static void +gtk_color_chooser_widget_init (GtkColorChooserWidget *cc) +{ + GtkWidget *box; + GtkWidget *p; + GtkWidget *button; + GtkWidget *label; + gint i; + GdkRGBA color; + GVariant *variant; + GVariantIter iter; + gboolean selected; + AtkObject *atk_obj; + gchar *text, *name; + + cc->priv = G_TYPE_INSTANCE_GET_PRIVATE (cc, GTK_TYPE_COLOR_CHOOSER_WIDGET, GtkColorChooserWidgetPrivate); + + cc->priv->use_alpha = TRUE; + + gtk_orientable_set_orientation (GTK_ORIENTABLE (cc), GTK_ORIENTATION_VERTICAL); + cc->priv->palette = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_container_add (GTK_CONTAINER (cc), cc->priv->palette); + + add_default_palette (cc); + + cc->priv->custom = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + g_object_set (box, "margin-top", 12, NULL); + gtk_box_pack_end (GTK_BOX (cc->priv->palette), box, FALSE, TRUE, 0); + + /* translators: label for the custom section in the color chooser */ + cc->priv->custom_label = label = gtk_label_new (_("Custom")); + gtk_widget_set_halign (label, GTK_ALIGN_START); + gtk_box_pack_end (GTK_BOX (cc->priv->palette), label, FALSE, TRUE, 0); + + cc->priv->button = button = gtk_color_swatch_new (); + atk_obj = gtk_widget_get_accessible (button); + atk_object_set_role (atk_obj, ATK_ROLE_PUSH_BUTTON); + atk_object_set_description (atk_obj, _("Create custom color")); + connect_button_signals (button, cc); + gtk_color_swatch_set_icon (GTK_COLOR_SWATCH (button), "list-add-symbolic"); + gtk_container_add (GTK_CONTAINER (box), button); + + cc->priv->settings = g_settings_new_with_path ("org.gtk.Settings.ColorChooser", + "/org/gtk/settings/color-chooser/"); + variant = g_settings_get_value (cc->priv->settings, "custom-colors"); + g_variant_iter_init (&iter, variant); + i = 0; + p = NULL; + while (g_variant_iter_loop (&iter, "(dddd)", &color.red, &color.green, &color.blue, &color.alpha)) + { + i++; + p = gtk_color_swatch_new (); + gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), &color); + gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (p), TRUE); + atk_obj = gtk_widget_get_accessible (p); + name = accessible_color_name (&color); + text = g_strdup_printf (_("Custom color %d: %s"), i, name); + atk_object_set_description (atk_obj, text); + g_free (text); + g_free (name); + connect_custom_signals (p, cc); + gtk_container_add (GTK_CONTAINER (box), p); + + if (i == 8) + break; + } + g_variant_unref (variant); + + cc->priv->editor = gtk_color_editor_new (); + gtk_widget_set_halign (cc->priv->editor, GTK_ALIGN_CENTER); + gtk_widget_set_hexpand (cc->priv->editor, TRUE); + + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_container_add (GTK_CONTAINER (cc), box); + gtk_container_add (GTK_CONTAINER (box), cc->priv->editor); + + g_settings_get (cc->priv->settings, "selected-color", "(bdddd)", + &selected, + &color.red, &color.green, &color.blue, &color.alpha); + if (selected) + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc), &color); + + gtk_widget_show_all (GTK_WIDGET (cc)); + gtk_widget_hide (GTK_WIDGET (cc->priv->editor)); + gtk_widget_hide (GTK_WIDGET (cc)); + + gtk_widget_set_no_show_all (cc->priv->palette, TRUE); + gtk_widget_set_no_show_all (cc->priv->editor, TRUE); + + cc->priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + gtk_size_group_add_widget (cc->priv->size_group, cc->priv->palette); + gtk_size_group_add_widget (cc->priv->size_group, box); +} + +/* GObject implementation {{{1 */ + +static void +gtk_color_chooser_widget_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkColorChooserWidget *cw = GTK_COLOR_CHOOSER_WIDGET (object); + GtkColorChooser *cc = GTK_COLOR_CHOOSER (object); + + switch (prop_id) + { + case PROP_RGBA: + { + GdkRGBA color; + + gtk_color_chooser_get_rgba (cc, &color); + g_value_set_boxed (value, &color); + } + break; + case PROP_USE_ALPHA: + g_value_set_boolean (value, cw->priv->use_alpha); + break; + case PROP_SHOW_EDITOR: + g_value_set_boolean (value, gtk_widget_get_visible (cw->priv->editor)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_color_chooser_widget_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (object); + + switch (prop_id) + { + case PROP_RGBA: + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc), + g_value_get_boxed (value)); + break; + case PROP_USE_ALPHA: + gtk_color_chooser_widget_set_use_alpha (cc, + g_value_get_boolean (value)); + break; + case PROP_SHOW_EDITOR: + gtk_color_chooser_widget_set_show_editor (cc, + g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_color_chooser_widget_finalize (GObject *object) +{ + GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (object); + + g_object_unref (cc->priv->size_group); + g_object_unref (cc->priv->settings); + + G_OBJECT_CLASS (gtk_color_chooser_widget_parent_class)->finalize (object); +} + +static void +gtk_color_chooser_widget_class_init (GtkColorChooserWidgetClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->get_property = gtk_color_chooser_widget_get_property; + object_class->set_property = gtk_color_chooser_widget_set_property; + object_class->finalize = gtk_color_chooser_widget_finalize; + + g_object_class_override_property (object_class, PROP_RGBA, "rgba"); + g_object_class_override_property (object_class, PROP_USE_ALPHA, "use-alpha"); + + /** + * GtkColorChooserWidget:show-editor: + * + * The ::show-editor property is %TRUE when the color chooser + * is showing the single-color editor. It can be set to switch + * the color chooser into single-color editing mode. + * + * Since: 3.4 + */ + g_object_class_install_property (object_class, PROP_SHOW_EDITOR, + g_param_spec_boolean ("show-editor", P_("Show editor"), P_("Show editor"), + FALSE, GTK_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (GtkColorChooserWidgetPrivate)); +} + +/* GtkColorChooser implementation {{{1 */ + +static void +gtk_color_chooser_widget_get_rgba (GtkColorChooser *chooser, + GdkRGBA *color) +{ + GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (chooser); + + if (gtk_widget_get_visible (cc->priv->editor)) + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), color); + else if (cc->priv->current) + gtk_color_swatch_get_rgba (cc->priv->current, color); + else + { + color->red = 1.0; + color->green = 1.0; + color->blue = 1.0; + color->alpha = 1.0; + } + + if (!cc->priv->use_alpha) + color->alpha = 1.0; +} + +static void +add_custom_color (GtkColorChooserWidget *cc, + const GdkRGBA *color) +{ + GtkWidget *last; + GtkWidget *p; + GList *children; + + children = gtk_container_get_children (GTK_CONTAINER (cc->priv->custom)); + if (g_list_length (children) >= 8) + { + last = g_list_last (children)->data; + gtk_widget_destroy (last); + } + + g_list_free (children); + + p = gtk_color_swatch_new (); + gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), color); + gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (p), TRUE); + connect_custom_signals (p, cc); + + gtk_container_add (GTK_CONTAINER (cc->priv->custom), p); + gtk_box_reorder_child (GTK_BOX (cc->priv->custom), p, 1); + gtk_widget_show (p); + + select_swatch (cc, GTK_COLOR_SWATCH (p)); + save_custom_colors (cc); +} + +static void +gtk_color_chooser_widget_set_rgba (GtkColorChooser *chooser, + const GdkRGBA *color) +{ + GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (chooser); + GList *children, *l; + GList *palettes, *p; + GtkColorSwatch *swatch; + GtkWidget *w; + GdkRGBA c; + + palettes = gtk_container_get_children (GTK_CONTAINER (cc->priv->palette)); + for (p = palettes; p; p = p->next) + { + w = p->data; + if (!GTK_IS_GRID (w) && !GTK_IS_BOX (w)) + continue; + + children = gtk_container_get_children (GTK_CONTAINER (w)); + for (l = children; l; l = l->next) + { + swatch = l->data; + gtk_color_swatch_get_rgba (swatch, &c); + if (!cc->priv->use_alpha) + c.alpha = color->alpha; + if (gdk_rgba_equal (color, &c)) + { + select_swatch (cc, swatch); + g_list_free (children); + return; + } + } + g_list_free (children); + } + g_list_free (palettes); + + add_custom_color (cc, color); +} + +static void +gtk_color_chooser_widget_add_palette (GtkColorChooser *chooser, + gboolean horizontal, + gint colors_per_line, + gint n_colors, + GdkRGBA *colors) +{ + GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (chooser); + + remove_default_palette (cc); + add_palette (cc, horizontal, colors_per_line, n_colors, colors, NULL); +} + +static void +gtk_color_chooser_widget_iface_init (GtkColorChooserInterface *iface) +{ + iface->get_rgba = gtk_color_chooser_widget_get_rgba; + iface->set_rgba = gtk_color_chooser_widget_set_rgba; + iface->add_palette = gtk_color_chooser_widget_add_palette; +} + +/* Public API {{{1 */ + +/** + * gtk_color_chooser_widget_new: + * + * Creates a new #GtkColorChooserWidget. + * + * Returns: a new #GtkColorChooserWidget + * + * Since: 3.4 + */ +GtkWidget * +gtk_color_chooser_widget_new (void) +{ + return g_object_new (GTK_TYPE_COLOR_CHOOSER_WIDGET, NULL); +} + +/* vim:set foldmethod=marker: */ diff --git a/gtk/gtkcolorchooserwidget.h b/gtk/gtkcolorchooserwidget.h new file mode 100644 index 0000000000..177a719120 --- /dev/null +++ b/gtk/gtkcolorchooserwidget.h @@ -0,0 +1,71 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_COLOR_CHOOSER_WIDGET_H__ +#define __GTK_COLOR_CHOOSER_WIDGET_H__ + +#include <gtk/gtkbox.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_COLOR_CHOOSER_WIDGET (gtk_color_chooser_widget_get_type ()) +#define GTK_COLOR_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_CHOOSER_WIDGET, GtkColorChooserWidget)) +#define GTK_COLOR_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_CHOOSER_WIDGET, GtkColorChooserWidgetClass)) +#define GTK_IS_COLOR_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_CHOOSER_WIDGET)) +#define GTK_IS_COLOR_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_CHOOSER_WIDGET)) +#define GTK_COLOR_CHOOSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_CHOOSER_WIDGET, GtkColorChooserWidgetClass)) + +typedef struct _GtkColorChooserWidget GtkColorChooserWidget; +typedef struct _GtkColorChooserWidgetPrivate GtkColorChooserWidgetPrivate; +typedef struct _GtkColorChooserWidgetClass GtkColorChooserWidgetClass; + +struct _GtkColorChooserWidget +{ + GtkBox parent_instance; + + /*< private >*/ + GtkColorChooserWidgetPrivate *priv; +}; + +struct _GtkColorChooserWidgetClass +{ + GtkBoxClass parent_class; + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); + void (*_gtk_reserved5) (void); + void (*_gtk_reserved6) (void); + void (*_gtk_reserved7) (void); + void (*_gtk_reserved8) (void); +}; + +GType gtk_color_chooser_widget_get_type (void) G_GNUC_CONST; + +GtkWidget * gtk_color_chooser_widget_new (void); + +G_END_DECLS + +#endif /* __GTK_COLOR_CHOOSER_WIDGET_H__ */ diff --git a/gtk/gtkcoloreditor.c b/gtk/gtkcoloreditor.c new file mode 100644 index 0000000000..5bab7ae977 --- /dev/null +++ b/gtk/gtkcoloreditor.c @@ -0,0 +1,654 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* TODO + * - touch + * - accessible relations for popups + * - saving per-application (?) + * - better popup theming + */ + +#include "config.h" + +#include "gtkcoloreditorprivate.h" + +#include "gtkcolorchooserprivate.h" +#include "gtkcolorplaneprivate.h" +#include "gtkcolorscaleprivate.h" +#include "gtkcolorswatchprivate.h" +#include "gtkcolorutils.h" +#include "gtkgrid.h" +#include "gtkorientable.h" +#include "gtkentry.h" +#include "gtkoverlay.h" +#include "gtkadjustment.h" +#include "gtklabel.h" +#include "gtkspinbutton.h" +#include "gtkintl.h" + +#include <math.h> + +struct _GtkColorEditorPrivate +{ + GtkWidget *overlay; + GtkWidget *grid; + GtkWidget *swatch; + GtkWidget *entry; + GtkWidget *h_slider; + GtkWidget *h_popup; + GtkWidget *h_entry; + GtkWidget *a_slider; + GtkWidget *a_popup; + GtkWidget *a_entry; + GtkWidget *sv_plane; + GtkWidget *sv_popup; + GtkWidget *s_entry; + GtkWidget *v_entry; + GtkWidget *current_popup; + GtkWidget *popdown_focus; + + GtkAdjustment *h_adj; + GtkAdjustment *s_adj; + GtkAdjustment *v_adj; + GtkAdjustment *a_adj; + + guint text_changed : 1; + guint use_alpha : 1; +}; + +enum +{ + PROP_ZERO, + PROP_RGBA, + PROP_USE_ALPHA +}; + +static void gtk_color_editor_iface_init (GtkColorChooserInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkColorEditor, gtk_color_editor, GTK_TYPE_BOX, + G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER, + gtk_color_editor_iface_init)) + +static guint +scale_round (gdouble value, gdouble scale) +{ + value = floor (value * scale + 0.5); + value = MAX (value, 0); + value = MIN (value, scale); + return (guint)value; +} + +static void +entry_set_rgba (GtkColorEditor *editor, + const GdkRGBA *color) +{ + gchar *text; + + text = g_strdup_printf ("#%02X%02X%02X", + scale_round (color->red, 255), + scale_round (color->green, 255), + scale_round (color->blue, 255)); + gtk_entry_set_text (GTK_ENTRY (editor->priv->entry), text); + editor->priv->text_changed = FALSE; + g_free (text); +} + +static void +entry_apply (GtkWidget *entry, + GtkColorEditor *editor) +{ + GdkRGBA color; + gchar *text; + + if (!editor->priv->text_changed) + return; + + text = gtk_editable_get_chars (GTK_EDITABLE (editor->priv->entry), 0, -1); + if (gdk_rgba_parse (&color, text)) + { + color.alpha = gtk_adjustment_get_value (editor->priv->a_adj); + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (editor), &color); + } + + editor->priv->text_changed = FALSE; + + g_free (text); +} + +static gboolean +entry_focus_out (GtkWidget *entry, + GdkEventFocus *event, + GtkColorEditor *editor) +{ + entry_apply (entry, editor); + return FALSE; +} + +static void +entry_text_changed (GtkWidget *entry, + GParamSpec *pspec, + GtkColorEditor *editor) +{ + editor->priv->text_changed = TRUE; +} + +static void +hsv_changed (GtkColorEditor *editor) +{ + GdkRGBA color; + gdouble h, s, v, a; + + h = gtk_adjustment_get_value (editor->priv->h_adj); + s = gtk_adjustment_get_value (editor->priv->s_adj); + v = gtk_adjustment_get_value (editor->priv->v_adj); + a = gtk_adjustment_get_value (editor->priv->a_adj); + + gtk_hsv_to_rgb (h, s, v, &color.red, &color.green, &color.blue); + color.alpha = a; + + gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->priv->swatch), &color); + gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->priv->a_slider), &color); + entry_set_rgba (editor, &color); + + g_object_notify (G_OBJECT (editor), "rgba"); +} + +static void +dismiss_current_popup (GtkColorEditor *editor) +{ + if (editor->priv->current_popup) + { + gtk_widget_hide (editor->priv->current_popup); + editor->priv->current_popup = NULL; + if (editor->priv->popdown_focus) + { + gtk_widget_grab_focus (editor->priv->popdown_focus); + editor->priv->popdown_focus = NULL; + } + } +} + +static void +popup_edit (GtkWidget *widget, + GtkColorEditor *editor) +{ + GtkWidget *popup = NULL; + GtkWidget *toplevel; + GtkWidget *focus; + + if (widget == editor->priv->sv_plane) + { + popup = editor->priv->sv_popup; + focus = editor->priv->s_entry; + } + else if (widget == editor->priv->h_slider) + { + popup = editor->priv->h_popup; + focus = editor->priv->h_entry; + } + else if (widget == editor->priv->a_slider) + { + popup = editor->priv->a_popup; + focus = editor->priv->a_entry; + } + + if (popup) + { + dismiss_current_popup (editor); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editor)); + editor->priv->popdown_focus = gtk_window_get_focus (GTK_WINDOW (toplevel)); + editor->priv->current_popup = popup; + gtk_widget_show (popup); + gtk_widget_grab_focus (focus); + } +} + +static gboolean +popup_key_press (GtkWidget *popup, + GdkEventKey *event, + GtkColorEditor *editor) +{ + if (event->keyval == GDK_KEY_Escape) + { + dismiss_current_popup (editor); + return TRUE; + } + + return FALSE; +} + +static gboolean +get_child_position (GtkOverlay *overlay, + GtkWidget *widget, + GtkAllocation *allocation, + GtkColorEditor *editor) +{ + GtkRequisition req; + GtkAllocation alloc; + gint s, e; + + gtk_widget_get_preferred_size (widget, &req, NULL); + + allocation->width = req.width; + allocation->height = req.height; + + if (widget == editor->priv->sv_popup) + { + if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL) + allocation->x = 0; + else + allocation->x = gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width; + allocation->y = req.height / 3; + } + else if (widget == editor->priv->h_popup) + { + gtk_widget_get_allocation (editor->priv->h_slider, &alloc); + gtk_range_get_slider_range (GTK_RANGE (editor->priv->h_slider), &s, &e); + + if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL) + gtk_widget_translate_coordinates (editor->priv->h_slider, + gtk_widget_get_parent (editor->priv->grid), + - req.width, (s + e - req.height) / 2, + &allocation->x, &allocation->y); + else + gtk_widget_translate_coordinates (editor->priv->h_slider, + gtk_widget_get_parent (editor->priv->grid), + alloc.width, (s + e - req.height) / 2, + &allocation->x, &allocation->y); + } + else if (widget == editor->priv->a_popup) + { + gtk_widget_get_allocation (editor->priv->a_slider, &alloc); + gtk_range_get_slider_range (GTK_RANGE (editor->priv->a_slider), &s, &e); + + gtk_widget_translate_coordinates (editor->priv->a_slider, + gtk_widget_get_parent (editor->priv->grid), + (s + e - req.width) / 2, - req.height, + &allocation->x, &allocation->y); + } + else + return FALSE; + + allocation->x = CLAMP (allocation->x, 0, gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width); + allocation->y = CLAMP (allocation->y, 0, gtk_widget_get_allocated_height (GTK_WIDGET (overlay)) - req.height); + + return TRUE; +} + +static void +value_changed (GtkAdjustment *a, + GtkAdjustment *as) +{ + gdouble scale; + + scale = gtk_adjustment_get_upper (as) / gtk_adjustment_get_upper (a); + g_signal_handlers_block_by_func (as, value_changed, a); + gtk_adjustment_set_value (as, gtk_adjustment_get_value (a) * scale); + g_signal_handlers_unblock_by_func (as, value_changed, a); +} + +static GtkAdjustment * +scaled_adjustment (GtkAdjustment *a, + gdouble scale) +{ + GtkAdjustment *as; + + as = gtk_adjustment_new (gtk_adjustment_get_value (a) * scale, + gtk_adjustment_get_lower (a) * scale, + gtk_adjustment_get_upper (a) * scale, + gtk_adjustment_get_step_increment (a) * scale, + gtk_adjustment_get_page_increment (a) * scale, + gtk_adjustment_get_page_size (a) * scale); + + g_signal_connect (a, "value-changed", G_CALLBACK (value_changed), as); + g_signal_connect (as, "value-changed", G_CALLBACK (value_changed), a); + + return as; +} + +static gboolean +popup_draw (GtkWidget *popup, + cairo_t *cr, + GtkColorEditor *editor) +{ + GtkStyleContext *context; + gint width, height; + + context = gtk_widget_get_style_context (popup); + width = gtk_widget_get_allocated_width (popup); + height = gtk_widget_get_allocated_height (popup); + + gtk_render_background (context, cr, 0, 0, width, height); + gtk_render_frame (context, cr, 0, 0, width, height); + + return FALSE; +} + +static GtkWidget * +create_popup (GtkColorEditor *editor, + GtkWidget *attach, + GtkWidget *contents) +{ + GtkWidget *popup; + + g_object_set (contents, "margin", 12, NULL); + + popup = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_style_context_add_class (gtk_widget_get_style_context (popup), GTK_STYLE_CLASS_TOOLTIP); + gtk_container_add (GTK_CONTAINER (popup), contents); + + gtk_widget_show_all (contents); + gtk_widget_set_no_show_all (popup, TRUE); + + g_signal_connect (popup, "draw", G_CALLBACK (popup_draw), editor); + + gtk_overlay_add_overlay (GTK_OVERLAY (editor->priv->overlay), popup); + g_signal_connect (attach, "popup-menu", G_CALLBACK (popup_edit), editor); + + return popup; +} + +static void +gtk_color_editor_init (GtkColorEditor *editor) +{ + GtkWidget *grid; + GtkWidget *slider; + GtkWidget *entry; + GtkWidget *swatch; + GtkAdjustment *h_adj, *s_adj, *v_adj, *a_adj; + AtkObject *atk_obj; + GdkRGBA transparent = { 0, 0, 0, 0 }; + + editor->priv = G_TYPE_INSTANCE_GET_PRIVATE (editor, + GTK_TYPE_COLOR_EDITOR, + GtkColorEditorPrivate); + editor->priv->use_alpha = TRUE; + + editor->priv->h_adj = h_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); + editor->priv->s_adj = s_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); + editor->priv->v_adj = v_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); + editor->priv->a_adj = a_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); + + g_object_ref_sink (h_adj); + g_object_ref_sink (s_adj); + g_object_ref_sink (v_adj); + g_object_ref_sink (a_adj); + + g_signal_connect_swapped (h_adj, "value-changed", G_CALLBACK (hsv_changed), editor); + g_signal_connect_swapped (s_adj, "value-changed", G_CALLBACK (hsv_changed), editor); + g_signal_connect_swapped (v_adj, "value-changed", G_CALLBACK (hsv_changed), editor); + g_signal_connect_swapped (a_adj, "value-changed", G_CALLBACK (hsv_changed), editor); + + gtk_widget_push_composite_child (); + + /* Construct the main UI */ + editor->priv->swatch = swatch = gtk_color_swatch_new (); + gtk_widget_set_events (swatch, gtk_widget_get_events (swatch) + & ~(GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_KEY_PRESS_MASK + | GDK_KEY_RELEASE_MASK)); + gtk_widget_set_can_focus (swatch, FALSE); + + editor->priv->entry = entry = gtk_entry_new (); + atk_obj = gtk_widget_get_accessible (entry); + atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); + atk_object_set_name (atk_obj, _("Color Name")); + g_signal_connect (entry, "activate", G_CALLBACK (entry_apply), editor); + g_signal_connect (entry, "notify::text", G_CALLBACK (entry_text_changed), editor); + g_signal_connect (entry, "focus-out-event", G_CALLBACK (entry_focus_out), editor); + + editor->priv->h_slider = slider = gtk_color_scale_new (h_adj, GTK_COLOR_SCALE_HUE); + gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_VERTICAL); + if (gtk_widget_get_direction (slider) == GTK_TEXT_DIR_RTL) + gtk_style_context_add_class (gtk_widget_get_style_context (slider), + GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE); + else + gtk_style_context_add_class (gtk_widget_get_style_context (slider), + GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW); + + editor->priv->sv_plane = gtk_color_plane_new (h_adj, s_adj, v_adj); + gtk_widget_set_size_request (editor->priv->sv_plane, 300, 300); + + editor->priv->a_slider = slider = gtk_color_scale_new (a_adj, GTK_COLOR_SCALE_ALPHA); + gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_HORIZONTAL); + gtk_style_context_add_class (gtk_widget_get_style_context (slider), + GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE); + + editor->priv->grid = grid = gtk_grid_new (); + gtk_grid_set_row_spacing (GTK_GRID (grid), 12); + gtk_grid_set_column_spacing (GTK_GRID (grid), 12); + + gtk_grid_attach (GTK_GRID (grid), editor->priv->swatch, 1, 0, 1, 1); + gtk_grid_attach (GTK_GRID (grid), editor->priv->entry, 2, 0, 1, 1); + gtk_grid_attach (GTK_GRID (grid), editor->priv->h_slider, 0, 1, 1, 1); + gtk_grid_attach (GTK_GRID (grid), editor->priv->sv_plane, 1, 1, 2, 1); + gtk_grid_attach (GTK_GRID (grid), editor->priv->a_slider, 1, 2, 2, 1); + + /* This extra margin is necessary so we have room to the sides + * to place the popups as desired + */ + gtk_widget_set_margin_left (grid, 30); + gtk_widget_set_margin_right (grid, 30); + + editor->priv->overlay = gtk_overlay_new (); + gtk_widget_override_background_color (editor->priv->overlay, 0, &transparent); + gtk_container_add (GTK_CONTAINER (editor->priv->overlay), grid); + + /* Construct the sv popup */ + editor->priv->s_entry = entry = gtk_spin_button_new (scaled_adjustment (s_adj, 100), 1, 0); + atk_obj = gtk_widget_get_accessible (entry); + atk_object_set_name (atk_obj, C_("Color channel", "Saturation")); + atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); + g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor); + + editor->priv->v_entry = entry = gtk_spin_button_new (scaled_adjustment (v_adj, 100), 1, 0); + atk_obj = gtk_widget_get_accessible (entry); + atk_object_set_name (atk_obj, C_("Color channel", "Value")); + atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); + g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor); + + grid = gtk_grid_new (); + gtk_grid_set_row_spacing (GTK_GRID (grid), 6); + gtk_grid_set_column_spacing (GTK_GRID (grid), 6); + + gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "S")), 0, 0, 1, 1); + gtk_grid_attach (GTK_GRID (grid), editor->priv->s_entry, 1, 0, 1, 1); + gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "V")), 0, 1, 1, 1); + gtk_grid_attach (GTK_GRID (grid), editor->priv->v_entry, 1, 1, 1, 1); + + editor->priv->sv_popup = create_popup (editor, editor->priv->sv_plane, grid); + + /* Construct the h popup */ + editor->priv->h_entry = entry = gtk_spin_button_new (scaled_adjustment (h_adj, 100), 1, 0); + atk_obj = gtk_widget_get_accessible (entry); + atk_object_set_name (atk_obj, C_("Color channel", "Hue")); + atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); + g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor); + + grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 6); + + gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "H")), 0, 0, 1, 1); + gtk_grid_attach (GTK_GRID (grid), editor->priv->h_entry, 1, 0, 1, 1); + + editor->priv->h_popup = create_popup (editor, editor->priv->h_slider, grid); + + /* Construct the a popup */ + editor->priv->a_entry = entry = gtk_spin_button_new (scaled_adjustment (a_adj, 100), 1, 0); + atk_obj = gtk_widget_get_accessible (entry); + atk_object_set_name (atk_obj, C_("Color channel", "Alpha")); + atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); + g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor); + + grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 6); + + gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "A")), 0, 0, 1, 1); + gtk_grid_attach (GTK_GRID (grid), editor->priv->a_entry, 1, 0, 1, 1); + + editor->priv->a_popup = create_popup (editor, editor->priv->a_slider, grid); + + /* Hook up popup positioning */ + g_signal_connect (editor->priv->overlay, "get-child-position", G_CALLBACK (get_child_position), editor); + g_signal_connect (editor, "notify::visible", G_CALLBACK (dismiss_current_popup), NULL); + + gtk_widget_show_all (editor->priv->overlay); + gtk_container_add (GTK_CONTAINER (editor), editor->priv->overlay); + + gtk_widget_pop_composite_child (); +} + +static void +gtk_color_editor_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkColorEditor *ce = GTK_COLOR_EDITOR (object); + GtkColorChooser *cc = GTK_COLOR_CHOOSER (object); + + switch (prop_id) + { + case PROP_RGBA: + { + GdkRGBA color; + gtk_color_chooser_get_rgba (cc, &color); + g_value_set_boxed (value, &color); + } + break; + case PROP_USE_ALPHA: + g_value_set_boolean (value, gtk_widget_get_visible (ce->priv->a_slider)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_color_editor_set_use_alpha (GtkColorEditor *editor, + gboolean use_alpha) +{ + if (editor->priv->use_alpha != use_alpha) + { + editor->priv->use_alpha = use_alpha; + gtk_widget_set_visible (editor->priv->a_slider, use_alpha); + gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (editor->priv->swatch), use_alpha); + } +} + +static void +gtk_color_editor_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkColorEditor *ce = GTK_COLOR_EDITOR (object); + GtkColorChooser *cc = GTK_COLOR_CHOOSER (object); + + switch (prop_id) + { + case PROP_RGBA: + gtk_color_chooser_set_rgba (cc, g_value_get_boxed (value)); + break; + case PROP_USE_ALPHA: + gtk_color_editor_set_use_alpha (ce, g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_color_editor_finalize (GObject *object) +{ + GtkColorEditor *editor = GTK_COLOR_EDITOR (object); + + g_clear_object (&editor->priv->h_adj); + g_clear_object (&editor->priv->s_adj); + g_clear_object (&editor->priv->v_adj); + g_clear_object (&editor->priv->a_adj); + + G_OBJECT_CLASS (gtk_color_editor_parent_class)->finalize (object); +} + +static void +gtk_color_editor_class_init (GtkColorEditorClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->finalize = gtk_color_editor_finalize; + object_class->get_property = gtk_color_editor_get_property; + object_class->set_property = gtk_color_editor_set_property; + + g_object_class_override_property (object_class, PROP_RGBA, "rgba"); + g_object_class_override_property (object_class, PROP_USE_ALPHA, "use-alpha"); + + g_type_class_add_private (class, sizeof (GtkColorEditorPrivate)); +} + +static void +gtk_color_editor_get_rgba (GtkColorChooser *chooser, + GdkRGBA *color) +{ + GtkColorEditor *editor = GTK_COLOR_EDITOR (chooser); + gdouble h, s, v; + + h = gtk_adjustment_get_value (editor->priv->h_adj); + s = gtk_adjustment_get_value (editor->priv->s_adj); + v = gtk_adjustment_get_value (editor->priv->v_adj); + gtk_hsv_to_rgb (h, s, v, &color->red, &color->green, &color->blue); + color->alpha = gtk_adjustment_get_value (editor->priv->a_adj); +} + +static void +gtk_color_editor_set_rgba (GtkColorChooser *chooser, + const GdkRGBA *color) +{ + GtkColorEditor *editor = GTK_COLOR_EDITOR (chooser); + gdouble h, s, v; + + gtk_rgb_to_hsv (color->red, color->green, color->blue, &h, &s, &v); + + gtk_adjustment_set_value (editor->priv->h_adj, h); + gtk_adjustment_set_value (editor->priv->s_adj, s); + gtk_adjustment_set_value (editor->priv->v_adj, v); + gtk_adjustment_set_value (editor->priv->a_adj, color->alpha); + + gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->priv->swatch), color); + gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->priv->a_slider), color); + entry_set_rgba (editor, color); + + g_object_notify (G_OBJECT (editor), "rgba"); +} + +static void +gtk_color_editor_iface_init (GtkColorChooserInterface *iface) +{ + iface->get_rgba = gtk_color_editor_get_rgba; + iface->set_rgba = gtk_color_editor_set_rgba; +} + +GtkWidget * +gtk_color_editor_new (void) +{ + return (GtkWidget *) g_object_new (GTK_TYPE_COLOR_EDITOR, NULL); +} diff --git a/gtk/gtkcoloreditorprivate.h b/gtk/gtkcoloreditorprivate.h new file mode 100644 index 0000000000..b8ee2197e7 --- /dev/null +++ b/gtk/gtkcoloreditorprivate.h @@ -0,0 +1,70 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_COLOR_EDITOR_H__ +#define __GTK_COLOR_EDITOR_H__ + +#include <gtk/gtkbox.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_COLOR_EDITOR (gtk_color_editor_get_type ()) +#define GTK_COLOR_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_EDITOR, GtkColorEditor)) +#define GTK_COLOR_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_EDITOR, GtkColorEditorClass)) +#define GTK_IS_COLOR_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_EDITOR)) +#define GTK_IS_COLOR_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_EDITOR)) +#define GTK_COLOR_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_EDITOR, GtkColorEditorClass)) + + +typedef struct _GtkColorEditor GtkColorEditor; +typedef struct _GtkColorEditorClass GtkColorEditorClass; +typedef struct _GtkColorEditorPrivate GtkColorEditorPrivate; + +struct _GtkColorEditor +{ + GtkBox parent_instance; + + GtkColorEditorPrivate *priv; +}; + +struct _GtkColorEditorClass +{ + GtkBoxClass parent_class; + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); +}; + + +G_GNUC_INTERNAL +GType gtk_color_editor_get_type (void) G_GNUC_CONST; + +G_GNUC_INTERNAL +GtkWidget * gtk_color_editor_new (void); + +G_END_DECLS + +#endif /* __GTK_COLOR_EDITOR_H__ */ diff --git a/gtk/gtkcolorplane.c b/gtk/gtkcolorplane.c new file mode 100644 index 0000000000..a34b7fad33 --- /dev/null +++ b/gtk/gtkcolorplane.c @@ -0,0 +1,449 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "gtkcolorplaneprivate.h" + +#include "gtkcolorutils.h" +#include "gtkaccessible.h" +#include "gtkintl.h" + +struct _GtkColorPlanePrivate +{ + GtkAdjustment *h_adj; + GtkAdjustment *s_adj; + GtkAdjustment *v_adj; + + cairo_surface_t *surface; + gboolean in_drag; +}; + +G_DEFINE_TYPE (GtkColorPlane, gtk_color_plane, GTK_TYPE_DRAWING_AREA) + +static void +sv_to_xy (GtkColorPlane *plane, + gint *x, + gint *y) +{ + gdouble s, v; + gint width, height; + + width = gtk_widget_get_allocated_width (GTK_WIDGET (plane)); + height = gtk_widget_get_allocated_height (GTK_WIDGET (plane)); + + s = gtk_adjustment_get_value (plane->priv->s_adj); + v = gtk_adjustment_get_value (plane->priv->v_adj); + + *x = CLAMP (width * v, 0, width - 1); + *y = CLAMP (height * (1 - s), 0, height - 1); +} + +static gboolean +plane_draw (GtkWidget *widget, + cairo_t *cr) +{ + GtkColorPlane *plane = GTK_COLOR_PLANE (widget); + gint x, y; + gint width, height; + + cairo_set_source_surface (cr, plane->priv->surface, 0, 0); + cairo_paint (cr); + + sv_to_xy (plane, &x, &y); + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + + cairo_move_to (cr, 0, y + 0.5); + cairo_line_to (cr, width, y + 0.5); + + cairo_move_to (cr, x + 0.5, 0); + cairo_line_to (cr, x + 0.5, height); + + if (gtk_widget_has_visible_focus (widget)) + { + cairo_set_line_width (cr, 3.0); + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.6); + cairo_stroke_preserve (cr); + + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.8); + cairo_stroke (cr); + } + else + { + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgba (cr, 0.8, 0.8, 0.8, 0.8); + cairo_stroke (cr); + } + + return FALSE; +} + +static void +create_surface (GtkColorPlane *plane) +{ + GtkWidget *widget = GTK_WIDGET (plane); + cairo_t *cr; + cairo_surface_t *surface; + gint width, height, stride; + cairo_surface_t *tmp; + guint red, green, blue; + guint32 *data, *p; + gdouble h, s, v; + gdouble r, g, b; + gdouble sf, vf; + gint x, y; + + if (!gtk_widget_get_realized (widget)) + return; + + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + + surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget), + CAIRO_CONTENT_COLOR, + width, height); + + if (plane->priv->surface) + cairo_surface_destroy (plane->priv->surface); + plane->priv->surface = surface; + + if (width == 1 || height == 1) + return; + + stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width); + + data = g_malloc (height * stride); + + h = gtk_adjustment_get_value (plane->priv->h_adj); + sf = 1.0 / (height - 1); + vf = 1.0 / (width - 1); + for (y = 0; y < height; y++) + { + s = CLAMP (1.0 - y * sf, 0.0, 1.0); + p = data + y * (stride / 4); + for (x = 0; x < width; x++) + { + v = x * vf; + gtk_hsv_to_rgb (h, s, v, &r, &g, &b); + red = CLAMP (r * 255, 0, 255); + green = CLAMP (g * 255, 0, 255); + blue = CLAMP (b * 255, 0, 255); + p[x] = (red << 16) | (green << 8) | blue; + } + } + + tmp = cairo_image_surface_create_for_data ((guchar *)data, CAIRO_FORMAT_RGB24, + width, height, stride); + cr = cairo_create (surface); + + cairo_set_source_surface (cr, tmp, 0, 0); + cairo_paint (cr); + + cairo_destroy (cr); + cairo_surface_destroy (tmp); + g_free (data); +} + +static gboolean +plane_configure (GtkWidget *widget, + GdkEventConfigure *event) +{ + create_surface (GTK_COLOR_PLANE (widget)); + return TRUE; +} + +static void +set_cross_grab (GtkWidget *widget, + GdkDevice *device, + guint32 time) +{ + GdkCursor *cursor; + + cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (widget)), + GDK_CROSSHAIR); + gdk_device_grab (device, + gtk_widget_get_window (widget), + GDK_OWNERSHIP_NONE, + FALSE, + GDK_POINTER_MOTION_MASK + | GDK_POINTER_MOTION_HINT_MASK + | GDK_BUTTON_RELEASE_MASK, + cursor, + time); + g_object_unref (cursor); +} + +static gboolean +plane_grab_broken (GtkWidget *widget, + GdkEventGrabBroken *event) +{ + GTK_COLOR_PLANE (widget)->priv->in_drag = FALSE; + return TRUE; +} + +static void +h_changed (GtkColorPlane *plane) +{ + create_surface (plane); + gtk_widget_queue_draw (GTK_WIDGET (plane)); +} + +static void +sv_changed (GtkColorPlane *plane) +{ + gtk_widget_queue_draw (GTK_WIDGET (plane)); +} + +static void +update_color (GtkColorPlane *plane, + gint x, + gint y) +{ + GtkWidget *widget = GTK_WIDGET (plane); + gdouble s, v; + + s = CLAMP (1 - y * (1.0 / gtk_widget_get_allocated_height (widget)), 0, 1); + v = CLAMP (x * (1.0 / gtk_widget_get_allocated_width (widget)), 0, 1); + gtk_adjustment_set_value (plane->priv->s_adj, s); + gtk_adjustment_set_value (plane->priv->v_adj, v); + + gtk_widget_queue_draw (widget); +} + +static gboolean +plane_button_press (GtkWidget *widget, + GdkEventButton *event) +{ + GtkColorPlane *plane = GTK_COLOR_PLANE (widget); + + if (event->button == GDK_BUTTON_SECONDARY) + { + gboolean handled; + + g_signal_emit_by_name (widget, "popup-menu", &handled); + + return TRUE; + } + + if (plane->priv->in_drag || event->button != GDK_BUTTON_PRIMARY) + return FALSE; + + plane->priv->in_drag = TRUE; + set_cross_grab (widget, gdk_event_get_device ((GdkEvent*)event), event->time); + update_color (plane, event->x, event->y); + gtk_widget_grab_focus (widget); + + return TRUE; +} + +static gboolean +plane_button_release (GtkWidget *widget, + GdkEventButton *event) +{ + GtkColorPlane *plane = GTK_COLOR_PLANE (widget); + + if (!plane->priv->in_drag || event->button != GDK_BUTTON_PRIMARY) + return FALSE; + + plane->priv->in_drag = FALSE; + + update_color (plane, event->x, event->y); + gdk_device_ungrab (gdk_event_get_device ((GdkEvent *) event), event->time); + + return TRUE; +} + +static gboolean +plane_motion_notify (GtkWidget *widget, + GdkEventMotion *event) +{ + GtkColorPlane *plane = GTK_COLOR_PLANE (widget); + + if (!plane->priv->in_drag) + return FALSE; + + gdk_event_request_motions (event); + update_color (plane, event->x, event->y); + + return TRUE; +} + +static void +sv_move (GtkColorPlane *plane, + gdouble ds, + gdouble dv) +{ + gdouble s, v; + + s = gtk_adjustment_get_value (plane->priv->s_adj); + v = gtk_adjustment_get_value (plane->priv->v_adj); + + if (s + ds > 1) + { + if (s < 1) + s = 1; + else + goto error; + } + else if (s + ds < 0) + { + if (s > 0) + s = 0; + else + goto error; + } + else + { + s += ds; + } + + if (v + dv > 1) + { + if (v < 1) + v = 1; + else + goto error; + } + else if (v + dv < 0) + { + if (v > 0) + v = 0; + else + goto error; + } + else + { + v += dv; + } + + gtk_adjustment_set_value (plane->priv->s_adj, s); + gtk_adjustment_set_value (plane->priv->v_adj, v); + return; + +error: + gtk_widget_error_bell (GTK_WIDGET (plane)); +} + +static gboolean +plane_key_press (GtkWidget *widget, + GdkEventKey *event) +{ + GtkColorPlane *plane = GTK_COLOR_PLANE (widget); + gdouble step; + + if ((event->state & GDK_MOD1_MASK) != 0) + step = 0.1; + else + step = 0.01; + + if (event->keyval == GDK_KEY_Up || + event->keyval == GDK_KEY_KP_Up) + sv_move (plane, step, 0); + else if (event->keyval == GDK_KEY_Down || + event->keyval == GDK_KEY_KP_Down) + sv_move (plane, -step, 0); + else if (event->keyval == GDK_KEY_Left || + event->keyval == GDK_KEY_KP_Left) + sv_move (plane, 0, -step); + else if (event->keyval == GDK_KEY_Right || + event->keyval == GDK_KEY_KP_Right) + sv_move (plane, 0, step); + else + return GTK_WIDGET_CLASS (gtk_color_plane_parent_class)->key_press_event (widget, event); + + return TRUE; +} + +static void +gtk_color_plane_init (GtkColorPlane *plane) +{ + AtkObject *atk_obj; + + plane->priv = G_TYPE_INSTANCE_GET_PRIVATE (plane, + GTK_TYPE_COLOR_PLANE, + GtkColorPlanePrivate); + + gtk_widget_set_can_focus (GTK_WIDGET (plane), TRUE); + gtk_widget_set_events (GTK_WIDGET (plane), GDK_KEY_PRESS_MASK + | GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_POINTER_MOTION_MASK); + + atk_obj = gtk_widget_get_accessible (GTK_WIDGET (plane)); + if (GTK_IS_ACCESSIBLE (atk_obj)) + { + atk_object_set_name (atk_obj, _("Color Plane")); + atk_object_set_role (atk_obj, ATK_ROLE_COLOR_CHOOSER); + } +} + +static void +plane_finalize (GObject *object) +{ + GtkColorPlane *plane = GTK_COLOR_PLANE (object); + + if (plane->priv->surface) + cairo_surface_destroy (plane->priv->surface); + + g_clear_object (&plane->priv->h_adj); + g_clear_object (&plane->priv->s_adj); + g_clear_object (&plane->priv->v_adj); + + G_OBJECT_CLASS (gtk_color_plane_parent_class)->finalize (object); +} + +static void +gtk_color_plane_class_init (GtkColorPlaneClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + + object_class->finalize = plane_finalize; + + widget_class->draw = plane_draw; + widget_class->configure_event = plane_configure; + widget_class->button_press_event = plane_button_press; + widget_class->button_release_event = plane_button_release; + widget_class->motion_notify_event = plane_motion_notify; + widget_class->grab_broken_event = plane_grab_broken; + widget_class->key_press_event = plane_key_press; + + g_type_class_add_private (class, sizeof (GtkColorPlanePrivate)); +} + +GtkWidget * +gtk_color_plane_new (GtkAdjustment *h_adj, + GtkAdjustment *s_adj, + GtkAdjustment *v_adj) +{ + GtkColorPlane *plane; + + plane = (GtkColorPlane *) g_object_new (GTK_TYPE_COLOR_PLANE, NULL); + + plane->priv->h_adj = g_object_ref_sink (h_adj); + plane->priv->s_adj = g_object_ref_sink (s_adj); + plane->priv->v_adj = g_object_ref_sink (v_adj); + g_signal_connect_swapped (h_adj, "value-changed", G_CALLBACK (h_changed), plane); + g_signal_connect_swapped (s_adj, "value-changed", G_CALLBACK (sv_changed), plane); + g_signal_connect_swapped (v_adj, "value-changed", G_CALLBACK (sv_changed), plane); + + return (GtkWidget *)plane; +} diff --git a/gtk/gtkcolorplaneprivate.h b/gtk/gtkcolorplaneprivate.h new file mode 100644 index 0000000000..9bf22cacfe --- /dev/null +++ b/gtk/gtkcolorplaneprivate.h @@ -0,0 +1,72 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_COLOR_PLANE_H__ +#define __GTK_COLOR_PLANE_H__ + +#include <gtk/gtkdrawingarea.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_COLOR_PLANE (gtk_color_plane_get_type ()) +#define GTK_COLOR_PLANE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_PLANE, GtkColorPlane)) +#define GTK_COLOR_PLANE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_PLANE, GtkColorPlaneClass)) +#define GTK_IS_COLOR_PLANE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_PLANE)) +#define GTK_IS_COLOR_PLANE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_PLANE)) +#define GTK_COLOR_PLANE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_PLANE, GtkColorPlaneClass)) + + +typedef struct _GtkColorPlane GtkColorPlane; +typedef struct _GtkColorPlaneClass GtkColorPlaneClass; +typedef struct _GtkColorPlanePrivate GtkColorPlanePrivate; + +struct _GtkColorPlane +{ + GtkDrawingArea parent_instance; + + GtkColorPlanePrivate *priv; +}; + +struct _GtkColorPlaneClass +{ + GtkDrawingAreaClass parent_class; + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); +}; + + +G_GNUC_INTERNAL +GType gtk_color_plane_get_type (void) G_GNUC_CONST; + +G_GNUC_INTERNAL +GtkWidget * gtk_color_plane_new (GtkAdjustment *h_adj, + GtkAdjustment *s_adj, + GtkAdjustment *v_adj); + +G_END_DECLS + +#endif /* __GTK_COLOR_PLANE_H__ */ diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c new file mode 100644 index 0000000000..d7fde5aa1d --- /dev/null +++ b/gtk/gtkcolorscale.c @@ -0,0 +1,362 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "gtkcolorscaleprivate.h" + +#include "gtkcolorchooserprivate.h" +#include "gtkcolorutils.h" +#include "gtkorientable.h" +#include "gtkstylecontext.h" +#include "gtkaccessible.h" +#include "gtkprivate.h" +#include "gtkintl.h" + +#include <math.h> + +struct _GtkColorScalePrivate +{ + cairo_surface_t *surface; + gint width, height; + GdkRGBA color; + GtkColorScaleType type; +}; + +enum +{ + PROP_ZERO, + PROP_SCALE_TYPE +}; + +G_DEFINE_TYPE (GtkColorScale, gtk_color_scale, GTK_TYPE_SCALE) + +static void +gtk_color_scale_get_trough_size (GtkColorScale *scale, + gint *x_offset_out, + gint *y_offset_out, + gint *width_out, + gint *height_out) +{ + GtkWidget *widget = GTK_WIDGET (scale); + gint width, height, focus_line_width, focus_padding; + gint x_offset, y_offset; + gint slider_width, slider_height; + + gtk_widget_style_get (widget, + "focus-line-width", &focus_line_width, + "focus-padding", &focus_padding, + "slider-width", &slider_width, + "slider-length", &slider_height, + NULL); + + width = gtk_widget_get_allocated_width (widget) - 2 * (focus_line_width + focus_padding); + height = gtk_widget_get_allocated_height (widget) - 2 * (focus_line_width + focus_padding); + + x_offset = focus_line_width + focus_padding; + y_offset = focus_line_width + focus_padding; + + /* if the slider has a vertical shape, draw the trough asymmetric */ + if (slider_width > slider_height) + { + if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_VERTICAL) + { + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) + x_offset += (gint) floor (slider_width / 2.0); + + width = (gint) floor (slider_width / 2.0); + } + else + { + height = (gint) floor (slider_width / 2.0); + } + } + + if (width_out) + *width_out = width; + if (height_out) + *height_out = height; + if (x_offset_out) + *x_offset_out = x_offset; + if (y_offset_out) + *y_offset_out = y_offset; +} + +static void +create_surface (GtkColorScale *scale) +{ + GtkWidget *widget = GTK_WIDGET (scale); + cairo_surface_t *surface; + gint width, height; + + if (!gtk_widget_get_realized (widget)) + return; + + gtk_color_scale_get_trough_size (scale, + NULL, NULL, + &width, &height); + + if (!scale->priv->surface || + width != scale->priv->width || + height != scale->priv->height) + { + surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget), + CAIRO_CONTENT_COLOR, + width, height); + if (scale->priv->surface) + cairo_surface_destroy (scale->priv->surface); + scale->priv->surface = surface; + scale->priv->width = width; + scale->priv->height= height; + } + else + surface = scale->priv->surface; + + if (width == 1 || height == 1) + return; + + if (scale->priv->type == GTK_COLOR_SCALE_HUE) + { + cairo_t *cr; + gint stride; + cairo_surface_t *tmp; + guint red, green, blue; + guint32 *data, *p; + gdouble h; + gdouble r, g, b; + gdouble f; + gint x, y; + + stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width); + + data = g_malloc (height * stride); + + f = 1.0 / (height - 1); + for (y = 0; y < height; y++) + { + h = CLAMP (y * f, 0.0, 1.0); + p = data + y * (stride / 4); + for (x = 0; x < width; x++) + { + gtk_hsv_to_rgb (h, 1, 1, &r, &g, &b); + red = CLAMP (r * 255, 0, 255); + green = CLAMP (g * 255, 0, 255); + blue = CLAMP (b * 255, 0, 255); + p[x] = (red << 16) | (green << 8) | blue; + } + } + + tmp = cairo_image_surface_create_for_data ((guchar *)data, CAIRO_FORMAT_RGB24, + width, height, stride); + cr = cairo_create (surface); + + cairo_set_source_surface (cr, tmp, 0, 0); + cairo_paint (cr); + + cairo_destroy (cr); + cairo_surface_destroy (tmp); + g_free (data); + } + else if (scale->priv->type == GTK_COLOR_SCALE_ALPHA) + { + cairo_t *cr; + cairo_pattern_t *pattern; + cairo_matrix_t matrix; + GdkRGBA *color; + + cr = cairo_create (surface); + + cairo_set_source_rgb (cr, 0.33, 0.33, 0.33); + cairo_paint (cr); + cairo_set_source_rgb (cr, 0.66, 0.66, 0.66); + + pattern = _gtk_color_chooser_get_checkered_pattern (); + cairo_matrix_init_scale (&matrix, 0.125, 0.125); + cairo_pattern_set_matrix (pattern, &matrix); + cairo_mask (cr, pattern); + cairo_pattern_destroy (pattern); + + color = &scale->priv->color; + + pattern = cairo_pattern_create_linear (0, 0, width, 0); + cairo_pattern_add_color_stop_rgba (pattern, 0, color->red, color->green, color->blue, 0); + cairo_pattern_add_color_stop_rgba (pattern, width, color->red, color->green, color->blue, 1); + cairo_set_source (cr, pattern); + cairo_paint (cr); + cairo_pattern_destroy (pattern); + + cairo_destroy (cr); + } +} + +static gboolean +scale_draw (GtkWidget *widget, + cairo_t *cr) +{ + GtkColorScale *scale = GTK_COLOR_SCALE (widget); + gint width, height, x_offset, y_offset; + cairo_pattern_t *pattern; + + create_surface (scale); + gtk_color_scale_get_trough_size (scale, + &x_offset, &y_offset, + &width, &height); + + cairo_save (cr); + cairo_translate (cr, x_offset, y_offset); + cairo_rectangle (cr, 0, 0, width, height); + + pattern = cairo_pattern_create_for_surface (scale->priv->surface); + if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL && + gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + { + cairo_matrix_t matrix; + + cairo_matrix_init_scale (&matrix, -1, 1); + cairo_matrix_translate (&matrix, -width, 0); + cairo_pattern_set_matrix (pattern, &matrix); + } + cairo_set_source (cr, pattern); + cairo_fill (cr); + + cairo_pattern_destroy (pattern); + + cairo_restore (cr); + + GTK_WIDGET_CLASS (gtk_color_scale_parent_class)->draw (widget, cr); + + return FALSE; +} + +static void +gtk_color_scale_init (GtkColorScale *scale) +{ + scale->priv = G_TYPE_INSTANCE_GET_PRIVATE (scale, + GTK_TYPE_COLOR_SCALE, + GtkColorScalePrivate); +} + +static void +scale_finalize (GObject *object) +{ + GtkColorScale *scale = GTK_COLOR_SCALE (object); + + if (scale->priv->surface) + cairo_surface_destroy (scale->priv->surface); + + G_OBJECT_CLASS (gtk_color_scale_parent_class)->finalize (object); +} + +static void +scale_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkColorScale *scale = GTK_COLOR_SCALE (object); + + switch (prop_id) + { + case PROP_SCALE_TYPE: + g_value_set_int (value, scale->priv->type); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +scale_set_type (GtkColorScale *scale, + GtkColorScaleType type) +{ + AtkObject *atk_obj; + + scale->priv->type = type; + + atk_obj = gtk_widget_get_accessible (GTK_WIDGET (scale)); + if (GTK_IS_ACCESSIBLE (atk_obj)) + { + if (type == GTK_COLOR_SCALE_HUE) + atk_object_set_name (atk_obj, C_("Color channel", "Hue")); + else if (type == GTK_COLOR_SCALE_ALPHA) + atk_object_set_name (atk_obj, C_("Color channel", "Alpha")); + atk_object_set_role (gtk_widget_get_accessible (GTK_WIDGET (scale)), ATK_ROLE_COLOR_CHOOSER); + } +} + +static void +scale_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkColorScale *scale = GTK_COLOR_SCALE (object); + + switch (prop_id) + { + case PROP_SCALE_TYPE: + scale_set_type (scale, (GtkColorScaleType)g_value_get_int (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_color_scale_class_init (GtkColorScaleClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + + object_class->finalize = scale_finalize; + object_class->get_property = scale_get_property; + object_class->set_property = scale_set_property; + + widget_class->draw = scale_draw; + + g_object_class_install_property (object_class, PROP_SCALE_TYPE, + g_param_spec_int ("scale-type", P_("Scale type"), P_("Scale type"), + 0, 1, 0, + GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_type_class_add_private (class, sizeof (GtkColorScalePrivate)); +} + +void +gtk_color_scale_set_rgba (GtkColorScale *scale, + const GdkRGBA *color) +{ + scale->priv->color = *color; + scale->priv->width = -1; /* force surface refresh */ + create_surface (scale); + gtk_widget_queue_draw (GTK_WIDGET (scale)); +} + +GtkWidget * +gtk_color_scale_new (GtkAdjustment *adjustment, + GtkColorScaleType type) +{ + return (GtkWidget *) g_object_new (GTK_TYPE_COLOR_SCALE, + "adjustment", adjustment, + "draw-value", FALSE, + "scale-type", type, + NULL); +} diff --git a/gtk/gtkcolorscaleprivate.h b/gtk/gtkcolorscaleprivate.h new file mode 100644 index 0000000000..acb58883cc --- /dev/null +++ b/gtk/gtkcolorscaleprivate.h @@ -0,0 +1,80 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_COLOR_SCALE_H__ +#define __GTK_COLOR_SCALE_H__ + +#include <gtk/gtkscale.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_COLOR_SCALE (gtk_color_scale_get_type ()) +#define GTK_COLOR_SCALE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_SCALE, GtkColorScale)) +#define GTK_COLOR_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_SCALE, GtkColorScaleClass)) +#define GTK_IS_COLOR_SCALE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_SCALE)) +#define GTK_IS_COLOR_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_SCALE)) +#define GTK_COLOR_SCALE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_SCALE, GtkColorScaleClass)) + + +typedef struct _GtkColorScale GtkColorScale; +typedef struct _GtkColorScaleClass GtkColorScaleClass; +typedef struct _GtkColorScalePrivate GtkColorScalePrivate; + +struct _GtkColorScale +{ + GtkScale parent_instance; + + GtkColorScalePrivate *priv; +}; + +struct _GtkColorScaleClass +{ + GtkScaleClass parent_class; + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); +}; + +typedef enum +{ + GTK_COLOR_SCALE_HUE, + GTK_COLOR_SCALE_ALPHA +} GtkColorScaleType; + +G_GNUC_INTERNAL +GType gtk_color_scale_get_type (void) G_GNUC_CONST; + +G_GNUC_INTERNAL +GtkWidget * gtk_color_scale_new (GtkAdjustment *adjustment, + GtkColorScaleType type); + +G_GNUC_INTERNAL +void gtk_color_scale_set_rgba (GtkColorScale *scale, + const GdkRGBA *color); + +G_END_DECLS + +#endif /* __GTK_COLOR_SCALE_H__ */ diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c new file mode 100644 index 0000000000..11f5d392ea --- /dev/null +++ b/gtk/gtkcolorswatch.c @@ -0,0 +1,699 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "gtkcolorswatchprivate.h" + +#include "gtkcolorchooserprivate.h" +#include "gtkroundedboxprivate.h" +#include "gtkthemingbackgroundprivate.h" +#include "gtkdnd.h" +#include "gtkicontheme.h" +#include "gtkmain.h" +#include "gtkmenu.h" +#include "gtkmenuitem.h" +#include "gtkmenushell.h" +#include "gtkprivate.h" +#include "gtkintl.h" +#include "a11y/gtkcolorswatchaccessible.h" + + +struct _GtkColorSwatchPrivate +{ + GdkRGBA color; + gdouble radius[4]; + gchar *icon; + guint has_color : 1; + guint contains_pointer : 1; + guint use_alpha : 1; +}; + +enum +{ + PROP_ZERO, + PROP_RGBA +}; + +enum +{ + ACTIVATE, + CUSTOMIZE, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +G_DEFINE_TYPE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_DRAWING_AREA) + +static void +gtk_color_swatch_init (GtkColorSwatch *swatch) +{ + swatch->priv = G_TYPE_INSTANCE_GET_PRIVATE (swatch, + GTK_TYPE_COLOR_SWATCH, + GtkColorSwatchPrivate); + + gtk_widget_set_can_focus (GTK_WIDGET (swatch), TRUE); + gtk_widget_set_events (GTK_WIDGET (swatch), GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_EXPOSURE_MASK + | GDK_ENTER_NOTIFY_MASK + | GDK_LEAVE_NOTIFY_MASK); + swatch->priv->use_alpha = TRUE; +} + +#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) + +static gboolean +swatch_draw (GtkWidget *widget, + cairo_t *cr) +{ + GtkColorSwatch *swatch = (GtkColorSwatch*)widget; + GtkThemingBackground background; + gdouble width, height; + GtkStyleContext *context; + GtkStateFlags state; + GtkIconTheme *theme; + GtkIconInfo *icon_info = NULL; + + theme = gtk_icon_theme_get_default (); + context = gtk_widget_get_style_context (widget); + state = gtk_widget_get_state_flags (widget); + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + + cairo_save (cr); + + gtk_style_context_save (context); + gtk_style_context_set_state (context, state); + + _gtk_theming_background_init_from_context (&background, context, + 0, 0, width, height, + GTK_JUNCTION_NONE); + + if (swatch->priv->has_color) + { + cairo_pattern_t *pattern; + cairo_matrix_t matrix; + + if (swatch->priv->use_alpha) + { + cairo_save (cr); + + _gtk_rounded_box_path (&background.clip_box, cr); + cairo_clip_preserve (cr); + + cairo_set_source_rgb (cr, 0.33, 0.33, 0.33); + cairo_fill_preserve (cr); + + pattern = _gtk_color_chooser_get_checkered_pattern (); + cairo_matrix_init_scale (&matrix, 0.125, 0.125); + cairo_pattern_set_matrix (pattern, &matrix); + + cairo_set_source_rgb (cr, 0.66, 0.66, 0.66); + cairo_mask (cr, pattern); + cairo_pattern_destroy (pattern); + + cairo_restore (cr); + + background.bg_color = swatch->priv->color; + } + else + { + background.bg_color = swatch->priv->color; + background.bg_color.alpha = 1.0; + } + + _gtk_theming_background_render (&background, cr); + } + + gtk_render_frame (context, cr, + 0, 0, width, height); + + if (gtk_widget_has_visible_focus (widget)) + { + cairo_set_line_width (cr, 2); + if (swatch->priv->has_color && INTENSITY (swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue) < 0.5) + cairo_set_source_rgba (cr, 1., 1., 1., 0.4); + else + cairo_set_source_rgba (cr, 0., 0., 0., 0.4); + _gtk_rounded_box_shrink (&background.clip_box, 3, 3, 3, 3); + _gtk_rounded_box_path (&background.clip_box, cr); + cairo_stroke (cr); + } + + if (swatch->priv->icon) + { + icon_info = gtk_icon_theme_lookup_icon (theme, swatch->priv->icon, 16, + GTK_ICON_LOOKUP_GENERIC_FALLBACK + | GTK_ICON_LOOKUP_USE_BUILTIN); + } + else if ((state & GTK_STATE_FLAG_SELECTED) != 0) + { + GdkRGBA bg, border; + GtkBorder border_width; + GIcon *gicon; + + gtk_style_context_add_class (context, "color-active-badge"); + gtk_style_context_get_background_color (context, state, &bg); + gtk_style_context_get_border_color (context, state, &border); + gtk_style_context_get_border (context, state, &border_width); + + cairo_new_sub_path (cr); + cairo_arc (cr, width / 2, height / 2, 10, 0, 2 * G_PI); + cairo_close_path (cr); + gdk_cairo_set_source_rgba (cr, &bg); + cairo_fill_preserve (cr); + + gdk_cairo_set_source_rgba (cr, &border); + cairo_set_line_width (cr, border_width.left); + cairo_stroke (cr); + + gicon = g_themed_icon_new ("object-select-symbolic"); + /* fallback for themes that don't have object-select-symbolic */ + g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply"); + + icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, 16, + GTK_ICON_LOOKUP_GENERIC_FALLBACK + | GTK_ICON_LOOKUP_USE_BUILTIN); + g_object_unref (gicon); + } + + if (icon_info != NULL) + { + GdkPixbuf *pixbuf; + + pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, + NULL, NULL); + + if (pixbuf != NULL) + { + gtk_render_icon (context, cr, pixbuf, + (width - gdk_pixbuf_get_width (pixbuf)) / 2, + (height - gdk_pixbuf_get_height (pixbuf)) / 2); + g_object_unref (pixbuf); + } + + gtk_icon_info_free (icon_info); + } + + cairo_restore (cr); + gtk_style_context_restore (context); + + return FALSE; +} + +static void +drag_set_color_icon (GdkDragContext *context, + const GdkRGBA *color) +{ + cairo_surface_t *surface; + cairo_t *cr; + + surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 48, 32); + cr = cairo_create (surface); + gdk_cairo_set_source_rgba (cr, color); + cairo_paint (cr); + + cairo_surface_set_device_offset (surface, -4, -4); + gtk_drag_set_icon_surface (context, surface); + + cairo_destroy (cr); + cairo_surface_destroy (surface); +} + +static void +swatch_drag_begin (GtkWidget *widget, + GdkDragContext *context) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget); + GdkRGBA color; + + gtk_color_swatch_get_rgba (swatch, &color); + drag_set_color_icon (context, &color); +} + +static void +swatch_drag_data_get (GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection_data, + guint info, + guint time) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget); + guint16 vals[4]; + GdkRGBA color; + + gtk_color_swatch_get_rgba (swatch, &color); + + vals[0] = color.red * 0xffff; + vals[1] = color.green * 0xffff; + vals[2] = color.blue * 0xffff; + vals[3] = color.alpha * 0xffff; + + gtk_selection_data_set (selection_data, + gdk_atom_intern_static_string ("application/x-color"), + 16, (guchar *)vals, 8); +} + +static void +swatch_drag_data_received (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint info, + guint time) +{ + gint length; + guint16 *vals; + GdkRGBA color; + + length = gtk_selection_data_get_length (selection_data); + + if (length < 0) + return; + + /* We accept drops with the wrong format, since the KDE color + * chooser incorrectly drops application/x-color with format 8. + */ + if (length != 8) + { + g_warning ("Received invalid color data\n"); + return; + } + + vals = (guint16 *) gtk_selection_data_get_data (selection_data); + + color.red = (gdouble)vals[0] / 0xffff; + color.green = (gdouble)vals[1] / 0xffff; + color.blue = (gdouble)vals[2] / 0xffff; + color.alpha = (gdouble)vals[3] / 0xffff; + + gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (widget), &color); +} + +static void +swatch_get_preferred_width (GtkWidget *widget, + gint *min, + gint *nat) +{ + *min = *nat = 48; +} + +static void +swatch_get_preferred_height (GtkWidget *widget, + gint *min, + gint *nat) +{ + *min = *nat = 32; +} + +static gboolean +swatch_key_press (GtkWidget *widget, + GdkEventKey *event) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget); + + if (event->keyval == GDK_KEY_space || + event->keyval == GDK_KEY_Return || + event->keyval == GDK_KEY_ISO_Enter|| + event->keyval == GDK_KEY_KP_Enter || + event->keyval == GDK_KEY_KP_Space) + { + if (swatch->priv->has_color && (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_SELECTED) == 0) + gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE); + else + g_signal_emit (swatch, signals[ACTIVATE], 0); + return TRUE; + } + + if (GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->key_press_event (widget, event)) + return TRUE; + + return FALSE; +} + +static gboolean +swatch_enter_notify (GtkWidget *widget, + GdkEventCrossing *event) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget); + swatch->priv->contains_pointer = TRUE; + return FALSE; +} + +static gboolean +swatch_leave_notify (GtkWidget *widget, + GdkEventCrossing *event) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget); + swatch->priv->contains_pointer = FALSE; + return FALSE; +} + +static void +emit_customize (GtkColorSwatch *swatch) +{ + g_signal_emit (swatch, signals[CUSTOMIZE], 0); +} + +static void +popup_position_func (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data) +{ + GtkWidget *widget; + GtkRequisition req; + gint root_x, root_y; + GdkScreen *screen; + GdkWindow *window; + GdkRectangle monitor; + gint monitor_num; + + widget = GTK_WIDGET (user_data); + g_return_if_fail (gtk_widget_get_realized (widget)); + window = gtk_widget_get_window (widget); + + screen = gtk_widget_get_screen (widget); + monitor_num = gdk_screen_get_monitor_at_window (screen, window); + if (monitor_num < 0) + monitor_num = 0; + gtk_menu_set_monitor (menu, monitor_num); + + gdk_window_get_origin (window, &root_x, &root_y); + gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); + + /* Put corner of menu centered on swatch */ + *x = root_x + gtk_widget_get_allocated_width (widget) / 2; + *y = root_y + gtk_widget_get_allocated_height (widget) / 2; + + /* Ensure sanity */ + gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor); + *x = CLAMP (*x, monitor.x, MAX (monitor.x, monitor.width - req.width)); + *y = CLAMP (*y, monitor.y, MAX (monitor.y, monitor.height - req.height)); +} + +static void +do_popup (GtkWidget *swatch, + GdkEventButton *event) +{ + GtkWidget *menu; + GtkWidget *item; + + menu = gtk_menu_new (); + item = gtk_menu_item_new_with_mnemonic (_("_Customize")); + gtk_menu_attach_to_widget (GTK_MENU (menu), swatch, NULL); + + g_signal_connect_swapped (item, "activate", + G_CALLBACK (emit_customize), swatch); + + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + gtk_widget_show_all (item); + + if (event) + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + NULL, NULL, event->button, event->time); + else + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + popup_position_func, swatch, + 0, gtk_get_current_event_time ()); +} + +static gboolean +swatch_button_press (GtkWidget *widget, + GdkEventButton *event) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget); + + gtk_widget_grab_focus (widget); + + if (gdk_event_triggers_context_menu ((GdkEvent *) event) && + swatch->priv->has_color) + { + do_popup (widget, event); + return TRUE; + } + else if (event->type == GDK_2BUTTON_PRESS && + event->button == GDK_BUTTON_PRIMARY) + { + g_signal_emit (swatch, signals[ACTIVATE], 0); + return TRUE; + } + + return FALSE; +} + +static gboolean +swatch_button_release (GtkWidget *widget, + GdkEventButton *event) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget); + GtkStateFlags flags; + + if (event->button == GDK_BUTTON_PRIMARY && + swatch->priv->contains_pointer) + { + flags = gtk_widget_get_state_flags (widget); + if (!swatch->priv->has_color) + { + g_signal_emit (swatch, signals[ACTIVATE], 0); + return TRUE; + } + else if ((flags & GTK_STATE_FLAG_SELECTED) == 0) + { + gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE); + return TRUE; + } + } + + return FALSE; +} + +static gboolean +swatch_popup_menu (GtkWidget *swatch) +{ + do_popup (swatch, NULL); + return TRUE; +} + +/* GObject implementation {{{1 */ + +static void +swatch_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object); + GdkRGBA color; + + switch (prop_id) + { + case PROP_RGBA: + gtk_color_swatch_get_rgba (swatch, &color); + g_value_set_boxed (value, &color); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +swatch_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object); + + switch (prop_id) + { + case PROP_RGBA: + gtk_color_swatch_set_rgba (swatch, g_value_get_boxed (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +swatch_finalize (GObject *object) +{ + GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object); + + g_free (swatch->priv->icon); + + G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object); +} + +static void +gtk_color_swatch_class_init (GtkColorSwatchClass *class) +{ + GtkWidgetClass *widget_class = (GtkWidgetClass *)class; + GObjectClass *object_class = (GObjectClass *)class; + + object_class->get_property = swatch_get_property; + object_class->set_property = swatch_set_property; + object_class->finalize = swatch_finalize; + + widget_class->get_preferred_width = swatch_get_preferred_width; + widget_class->get_preferred_height = swatch_get_preferred_height; + widget_class->draw = swatch_draw; + widget_class->drag_begin = swatch_drag_begin; + widget_class->drag_data_get = swatch_drag_data_get; + widget_class->drag_data_received = swatch_drag_data_received; + widget_class->key_press_event = swatch_key_press; + widget_class->popup_menu = swatch_popup_menu; + widget_class->button_press_event = swatch_button_press; + widget_class->button_release_event = swatch_button_release; + widget_class->enter_notify_event = swatch_enter_notify; + widget_class->leave_notify_event = swatch_leave_notify; + + signals[ACTIVATE] = + g_signal_new ("activate", + GTK_TYPE_COLOR_SWATCH, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkColorSwatchClass, activate), + NULL, NULL, NULL, G_TYPE_NONE, 0); + + signals[CUSTOMIZE] = + g_signal_new ("customize", + GTK_TYPE_COLOR_SWATCH, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkColorSwatchClass, customize), + NULL, NULL, NULL, G_TYPE_NONE, 0); + + g_object_class_install_property (object_class, PROP_RGBA, + g_param_spec_boxed ("rgba", P_("RGBA Color"), P_("Color as RGBA"), + GDK_TYPE_RGBA, GTK_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (GtkColorSwatchPrivate)); + + gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_COLOR_SWATCH_ACCESSIBLE); +} + +/* Public API {{{1 */ + +GtkWidget * +gtk_color_swatch_new (void) +{ + return (GtkWidget *) g_object_new (GTK_TYPE_COLOR_SWATCH, NULL); +} + +static const GtkTargetEntry dnd_targets[] = { + { "application/x-color", 0 } +}; + +void +gtk_color_swatch_set_rgba (GtkColorSwatch *swatch, + const GdkRGBA *color) +{ + GtkStyleContext *context; + + context = gtk_widget_get_style_context (GTK_WIDGET (swatch)); + + if (!swatch->priv->has_color) + { + gtk_drag_source_set (GTK_WIDGET (swatch), + GDK_BUTTON1_MASK | GDK_BUTTON3_MASK, + dnd_targets, G_N_ELEMENTS (dnd_targets), + GDK_ACTION_COPY | GDK_ACTION_MOVE); + } + else + { + gtk_style_context_remove_class (context, "color-light"); + gtk_style_context_remove_class (context, "color-dark"); + } + + swatch->priv->has_color = TRUE; + swatch->priv->color = *color; + + if (INTENSITY (swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue) > 0.5) + gtk_style_context_add_class (context, "color-light"); + else + gtk_style_context_add_class (context, "color-dark"); + + gtk_widget_queue_draw (GTK_WIDGET (swatch)); + g_object_notify (G_OBJECT (swatch), "rgba"); +} + +gboolean +gtk_color_swatch_get_rgba (GtkColorSwatch *swatch, + GdkRGBA *color) +{ + if (swatch->priv->has_color) + { + color->red = swatch->priv->color.red; + color->green = swatch->priv->color.green; + color->blue = swatch->priv->color.blue; + color->alpha = swatch->priv->color.alpha; + return TRUE; + } + else + { + color->red = 1.0; + color->green = 1.0; + color->blue = 1.0; + color->alpha = 1.0; + return FALSE; + } +} + +void +gtk_color_swatch_set_icon (GtkColorSwatch *swatch, + const gchar *icon) +{ + swatch->priv->icon = g_strdup (icon); + gtk_widget_queue_draw (GTK_WIDGET (swatch)); +} + +void +gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch, + gboolean can_drop) +{ + if (can_drop) + { + gtk_drag_dest_set (GTK_WIDGET (swatch), + GTK_DEST_DEFAULT_HIGHLIGHT | + GTK_DEST_DEFAULT_MOTION | + GTK_DEST_DEFAULT_DROP, + dnd_targets, G_N_ELEMENTS (dnd_targets), + GDK_ACTION_COPY); + } + else + { + gtk_drag_dest_unset (GTK_WIDGET (swatch)); + } +} + +void +gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch, + gboolean use_alpha) +{ + swatch->priv->use_alpha = use_alpha; + gtk_widget_queue_draw (GTK_WIDGET (swatch)); +} + +/* vim:set foldmethod=marker: */ diff --git a/gtk/gtkcolorswatchprivate.h b/gtk/gtkcolorswatchprivate.h new file mode 100644 index 0000000000..bc8a03df47 --- /dev/null +++ b/gtk/gtkcolorswatchprivate.h @@ -0,0 +1,97 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_COLOR_SWATCH_H__ +#define __GTK_COLOR_SWATCH_H__ + +#include <gtk/gtkdrawingarea.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_COLOR_SWATCH (gtk_color_swatch_get_type ()) +#define GTK_COLOR_SWATCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_SWATCH, GtkColorSwatch)) +#define GTK_COLOR_SWATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_SWATCH, GtkColorSwatchClass)) +#define GTK_IS_COLOR_SWATCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_SWATCH)) +#define GTK_IS_COLOR_SWATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_SWATCH)) +#define GTK_COLOR_SWATCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_SWATCH, GtkColorSwatchClass)) + + +typedef struct _GtkColorSwatch GtkColorSwatch; +typedef struct _GtkColorSwatchClass GtkColorSwatchClass; +typedef struct _GtkColorSwatchPrivate GtkColorSwatchPrivate; + +struct _GtkColorSwatch +{ + GtkDrawingArea parent; + + /*< private >*/ + GtkColorSwatchPrivate *priv; +}; + +struct _GtkColorSwatchClass +{ + GtkDrawingAreaClass parent_class; + + void ( * activate) (GtkColorSwatch *swatch); + void ( * customize) (GtkColorSwatch *swatch); + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); +}; + + +G_GNUC_INTERNAL +GType gtk_color_swatch_get_type (void) G_GNUC_CONST; + +G_GNUC_INTERNAL +GtkWidget * gtk_color_swatch_new (void); + +G_GNUC_INTERNAL +void gtk_color_swatch_set_rgba (GtkColorSwatch *swatch, + const GdkRGBA *color); +G_GNUC_INTERNAL +gboolean gtk_color_swatch_get_rgba (GtkColorSwatch *swatch, + GdkRGBA *color); +G_GNUC_INTERNAL +void gtk_color_swatch_set_hsva (GtkColorSwatch *swatch, + gdouble h, + gdouble s, + gdouble v, + gdouble a); +G_GNUC_INTERNAL +void gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch, + gboolean can_drop); +G_GNUC_INTERNAL +void gtk_color_swatch_set_icon (GtkColorSwatch *swatch, + const gchar *icon); +G_GNUC_INTERNAL +void gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch, + gboolean use_alpha); + + +G_END_DECLS + +#endif /* __GTK_COLOR_SWATCH_H__ */ diff --git a/gtk/gtkcolorutils.c b/gtk/gtkcolorutils.c new file mode 100644 index 0000000000..ef6371236c --- /dev/null +++ b/gtk/gtkcolorutils.c @@ -0,0 +1,260 @@ +/* Color utilities + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code) + * Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+) + * Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +#include "config.h" + +#include <math.h> +#include <string.h> + +#include "gtkcolorutils.h" + + +#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) + +/* Converts from HSV to RGB */ +static void +hsv_to_rgb (gdouble *h, + gdouble *s, + gdouble *v) +{ + gdouble hue, saturation, value; + gdouble f, p, q, t; + + if (*s == 0.0) + { + *h = *v; + *s = *v; + *v = *v; /* heh */ + } + else + { + hue = *h * 6.0; + saturation = *s; + value = *v; + + if (hue == 6.0) + hue = 0.0; + + f = hue - (int) hue; + p = value * (1.0 - saturation); + q = value * (1.0 - saturation * f); + t = value * (1.0 - saturation * (1.0 - f)); + + switch ((int) hue) + { + case 0: + *h = value; + *s = t; + *v = p; + break; + + case 1: + *h = q; + *s = value; + *v = p; + break; + + case 2: + *h = p; + *s = value; + *v = t; + break; + + case 3: + *h = p; + *s = q; + *v = value; + break; + + case 4: + *h = t; + *s = p; + *v = value; + break; + + case 5: + *h = value; + *s = p; + *v = q; + break; + + default: + g_assert_not_reached (); + } + } +} + +/* Converts from RGB to HSV */ +static void +rgb_to_hsv (gdouble *r, + gdouble *g, + gdouble *b) +{ + gdouble red, green, blue; + gdouble h, s, v; + gdouble min, max; + gdouble delta; + + red = *r; + green = *g; + blue = *b; + + h = 0.0; + + if (red > green) + { + if (red > blue) + max = red; + else + max = blue; + + if (green < blue) + min = green; + else + min = blue; + } + else + { + if (green > blue) + max = green; + else + max = blue; + + if (red < blue) + min = red; + else + min = blue; + } + + v = max; + + if (max != 0.0) + s = (max - min) / max; + else + s = 0.0; + + if (s == 0.0) + h = 0.0; + else + { + delta = max - min; + + if (red == max) + h = (green - blue) / delta; + else if (green == max) + h = 2 + (blue - red) / delta; + else if (blue == max) + h = 4 + (red - green) / delta; + + h /= 6.0; + + if (h < 0.0) + h += 1.0; + else if (h > 1.0) + h -= 1.0; + } + + *r = h; + *g = s; + *b = v; +} + +/** + * gtk_hsv_to_rgb: + * @h: Hue + * @s: Saturation + * @v: Value + * @r: (out): Return value for the red component + * @g: (out): Return value for the green component + * @b: (out): Return value for the blue component + * + * Converts a color from HSV space to RGB. + * + * Input values must be in the [0.0, 1.0] range; + * output values will be in the same range. + * + * Since: 2.14 + */ +void +gtk_hsv_to_rgb (gdouble h, gdouble s, gdouble v, + gdouble *r, gdouble *g, gdouble *b) +{ + g_return_if_fail (h >= 0.0 && h <= 1.0); + g_return_if_fail (s >= 0.0 && s <= 1.0); + g_return_if_fail (v >= 0.0 && v <= 1.0); + + hsv_to_rgb (&h, &s, &v); + + if (r) + *r = h; + + if (g) + *g = s; + + if (b) + *b = v; +} + +/** + * gtk_rgb_to_hsv: + * @r: Red + * @g: Green + * @b: Blue + * @h: (out): Return value for the hue component + * @s: (out): Return value for the saturation component + * @v: (out): Return value for the value component + * + * Converts a color from RGB space to HSV. + * + * Input values must be in the [0.0, 1.0] range; + * output values will be in the same range. + * + * Since: 2.14 + */ +void +gtk_rgb_to_hsv (gdouble r, gdouble g, gdouble b, + gdouble *h, gdouble *s, gdouble *v) +{ + g_return_if_fail (r >= 0.0 && r <= 1.0); + g_return_if_fail (g >= 0.0 && g <= 1.0); + g_return_if_fail (b >= 0.0 && b <= 1.0); + + rgb_to_hsv (&r, &g, &b); + + if (h) + *h = r; + + if (s) + *s = g; + + if (v) + *v = b; +} diff --git a/gtk/gtkcolorutils.h b/gtk/gtkcolorutils.h new file mode 100644 index 0000000000..2bb13523c6 --- /dev/null +++ b/gtk/gtkcolorutils.h @@ -0,0 +1,50 @@ +/* Color utilties + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code) + * Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+) + * Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_COLOR_UTILS_H__ +#define __GTK_COLOR_UTILS_H__ + +#include <glib.h> + +G_BEGIN_DECLS + +void gtk_hsv_to_rgb (gdouble h, gdouble s, gdouble v, + gdouble *r, gdouble *g, gdouble *b); +void gtk_rgb_to_hsv (gdouble r, gdouble g, gdouble b, + gdouble *h, gdouble *s, gdouble *v); + +G_END_DECLS + +#endif /* __GTK_COLOR_UTILS_H__ */ diff --git a/gtk/gtkcomboboxtext.c b/gtk/gtkcomboboxtext.c index f077c8e6fc..81bbd19b66 100644 --- a/gtk/gtkcomboboxtext.c +++ b/gtk/gtkcomboboxtext.c @@ -467,7 +467,7 @@ gtk_combo_box_text_prepend (GtkComboBoxText *combo_box, * * Inserts @text at @position in the list of strings stored in @combo_box. * If @id is non-%NULL then it is used as the ID of the row. See - * #GtkComboBox::id-column. + * #GtkComboBox:id-column. * * If @position is negative then @text is appended. * diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 552dfd6bbd..d201affe8c 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -1392,7 +1392,7 @@ gtk_entry_class_init (GtkEntryClass *class) * * The invisible character is used when masking entry contents (in * \"password mode\")"). When it is not explicitly set with the - * #GtkEntry::invisible-char property, GTK+ determines the character + * #GtkEntry:invisible-char property, GTK+ determines the character * to use from a list of possible candidates, depending on availability * in the current font. * diff --git a/gtk/gtkfontchooserdialog.c b/gtk/gtkfontchooserdialog.c index cf1cecac05..2f68c05b83 100644 --- a/gtk/gtkfontchooserdialog.c +++ b/gtk/gtkfontchooserdialog.c @@ -46,12 +46,12 @@ struct _GtkFontChooserDialogPrivate }; /** - * SECTION:gtkfontchooserdlg - * @Short_description: A dialog box for selecting fonts + * SECTION:gtkfontchooserdialog + * @Short_description: A dialog for selecting fonts * @Title: GtkFontChooserDialog * @See_also: #GtkFontChooser, #GtkDialog * - * The #GtkFontChooserDialog widget is a dialog box for selecting a font. + * The #GtkFontChooserDialog widget is a dialog for selecting a font. * It implements the #GtkFontChooser interface. * * <refsect2 id="GtkFontChooserDialog-BUILDER-UI"> diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index e8c160a12b..4188fc9613 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -51,7 +51,7 @@ #include "gtkgrid.h" /** - * SECTION:gtkfontchooser + * SECTION:gtkfontchooserwidget * @Short_description: A widget for selecting fonts * @Title: GtkFontChooserWidget * @See_also: #GtkFontChooserDialog diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c index 57c2b1d130..49ac4a1eb9 100644 --- a/gtk/gtkiconview.c +++ b/gtk/gtkiconview.c @@ -4494,7 +4494,7 @@ gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget, * for you. @column should be set to the column in @icon_view's model * containing the tooltip texts, or -1 to disable this feature. * - * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and + * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and * @icon_view will connect a #GtkWidget::query-tooltip signal handler. * * Note that the signal handler sets the text with gtk_tooltip_set_markup(), diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index 8fefc72d11..032e16d639 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -843,7 +843,6 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context, if (priv->tentative_match && g_unichar_validate (priv->tentative_match)) { -g_print ("committing tentative match on release\n"); gtk_im_context_simple_commit_char (context, priv->tentative_match); priv->compose_buffer[0] = 0; diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 5be5b7a3b8..8f9221135e 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -3185,7 +3185,7 @@ gtk_notebook_stop_reorder (GtkNotebook *notebook) { if (priv->during_reorder) { - gint old_page_num, page_num; + gint old_page_num, page_num, i; GList *element; element = get_drop_position (notebook); @@ -3194,9 +3194,16 @@ gtk_notebook_stop_reorder (GtkNotebook *notebook) gtk_notebook_child_reordered (notebook, page); if (priv->has_scrolled || old_page_num != page_num) - g_signal_emit (notebook, - notebook_signals[PAGE_REORDERED], 0, - page->child, page_num); + { + for (element = priv->children, i = 0; element; element = element->next) + { + if (MIN (old_page_num, page_num) <= i && i <= MAX (old_page_num, page_num)) + gtk_widget_child_notify (((GtkNotebookPage *) element->data)->child, "position"); + } + g_signal_emit (notebook, + notebook_signals[PAGE_REORDERED], 0, + page->child, page_num); + } priv->has_scrolled = FALSE; priv->during_reorder = FALSE; @@ -4097,7 +4104,7 @@ gtk_notebook_remove (GtkContainer *container, GtkNotebook *notebook = GTK_NOTEBOOK (container); GtkNotebookPrivate *priv = notebook->priv; GtkNotebookPage *page; - GList *children; + GList *children, *list; gint page_num = 0; children = priv->children; @@ -4117,8 +4124,15 @@ gtk_notebook_remove (GtkContainer *container, g_object_ref (widget); + list = children->next; gtk_notebook_real_remove (notebook, children); + while (list) + { + gtk_widget_child_notify (((GtkNotebookPage *)list->data)->child, "position"); + list = list->next; + } + g_signal_emit (notebook, notebook_signals[PAGE_REMOVED], 0, @@ -4566,6 +4580,7 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook, GtkNotebookPrivate *priv = notebook->priv; GtkNotebookPage *page; gint nchildren; + GList *list; gtk_widget_freeze_child_notify (child); @@ -4648,7 +4663,14 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook, gtk_widget_child_notify (child, "tab-fill"); gtk_widget_child_notify (child, "tab-label"); gtk_widget_child_notify (child, "menu-label"); - gtk_widget_child_notify (child, "position"); + + list = g_list_nth (priv->children, position); + while (list) + { + gtk_widget_child_notify (((GtkNotebookPage *)list->data)->child, "position"); + list = list->next; + } + gtk_widget_thaw_child_notify (child); /* The page-added handler might have reordered the pages, re-get the position */ diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c index b116ecb144..6f9cd3470a 100644 --- a/gtk/gtkoverlay.c +++ b/gtk/gtkoverlay.c @@ -37,8 +37,8 @@ * * GtkOverlay is a container which contains a single main child, on top * of which it can place <firstterm>overlay</firstterm> widgets. The - * position of each overlay widget is determined by its #GtkWidget::halign - * and #GtkWidget::valign properties. E.g. a widget with both alignments + * position of each overlay widget is determined by its #GtkWidget:halign + * and #GtkWidget:valign properties. E.g. a widget with both alignments * set to %GTK_ALIGN_START will be placed at the top left corner of the * main widget, whereas an overlay with halign set to %GTK_ALIGN_CENTER * and valign set to %GTK_ALIGN_END will be placed a the bottom edge of @@ -605,7 +605,7 @@ gtk_overlay_new (void) * added with gtk_container_add(). * * The position at which @widget is placed is determined - * from its #GtkWidget::halign and #GtkWidget::valign properties. + * from its #GtkWidget:halign and #GtkWidget:valign properties. * * Since: 3.2 */ diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c index 87f4d4ebbd..6150a1108e 100644 --- a/gtk/gtkprintoperation.c +++ b/gtk/gtkprintoperation.c @@ -2420,7 +2420,7 @@ gtk_print_operation_set_embed_page_setup (GtkPrintOperation *op, * gtk_print_operation_get_embed_page_setup: * @op: a #GtkPrintOperation * - * Gets the value of #GtkPrintOperation::embed-page-setup property. + * Gets the value of #GtkPrintOperation:embed-page-setup property. * * Returns: whether page setup selection combos are embedded * @@ -3305,7 +3305,7 @@ gtk_print_operation_set_support_selection (GtkPrintOperation *op, * gtk_print_operation_get_support_selection: * @op: a #GtkPrintOperation * - * Gets the value of #GtkPrintOperation::support-selection property. + * Gets the value of #GtkPrintOperation:support-selection property. * * Returns: whether the application supports print of selection * @@ -3354,7 +3354,7 @@ gtk_print_operation_set_has_selection (GtkPrintOperation *op, * gtk_print_operation_get_has_selection: * @op: a #GtkPrintOperation * - * Gets the value of #GtkPrintOperation::has-selection property. + * Gets the value of #GtkPrintOperation:has-selection property. * * Returns: whether there is a selection * diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c index 44b0fdcb39..3c5320f8a9 100644 --- a/gtk/gtkprintunixdialog.c +++ b/gtk/gtkprintunixdialog.c @@ -4272,7 +4272,7 @@ gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog, * gtk_print_unix_dialog_get_manual_capabilities: * @dialog: a #GtkPrintUnixDialog * - * Gets the value of #GtkPrintUnixDialog::manual-capabilities property. + * Gets the value of #GtkPrintUnixDialog:manual-capabilities property. * * Returns: the printing capabilities * @@ -4332,7 +4332,7 @@ gtk_print_unix_dialog_set_support_selection (GtkPrintUnixDialog *dialog, * gtk_print_unix_dialog_get_support_selection: * @dialog: a #GtkPrintUnixDialog * - * Gets the value of #GtkPrintUnixDialog::support-selection property. + * Gets the value of #GtkPrintUnixDialog:support-selection property. * * Returns: whether the application supports print of selection * @@ -4386,7 +4386,7 @@ gtk_print_unix_dialog_set_has_selection (GtkPrintUnixDialog *dialog, * gtk_print_unix_dialog_get_has_selection: * @dialog: a #GtkPrintUnixDialog * - * Gets the value of #GtkPrintUnixDialog::has-selection property. + * Gets the value of #GtkPrintUnixDialog:has-selection property. * * Returns: whether there is a selection * @@ -4454,7 +4454,7 @@ gtk_print_unix_dialog_set_embed_page_setup (GtkPrintUnixDialog *dialog, * gtk_print_unix_dialog_get_embed_page_setup: * @dialog: a #GtkPrintUnixDialog * - * Gets the value of #GtkPrintUnixDialog::embed-page-setup property. + * Gets the value of #GtkPrintUnixDialog:embed-page-setup property. * * Returns: whether there is a selection * diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index bb13aecab5..0d32f0bb02 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -35,6 +35,7 @@ #include "gtkorientableprivate.h" #include "gtkrange.h" #include "gtkscale.h" +#include "gtkcolorscaleprivate.h" #include "gtkscrollbar.h" #include "gtkwindow.h" #include "gtkprivate.h" @@ -2010,6 +2011,7 @@ gtk_range_draw (GtkWidget *widget, gint focus_padding = 0; gboolean touchscreen; gboolean draw_trough = TRUE; + gboolean draw_slider = TRUE; GtkStyleContext *context; context = gtk_widget_get_style_context (widget); @@ -2019,7 +2021,15 @@ gtk_range_draw (GtkWidget *widget, if (GTK_IS_SCALE (widget) && gtk_adjustment_get_upper (priv->adjustment) == gtk_adjustment_get_lower (priv->adjustment)) - draw_trough = FALSE; + { + draw_trough = TRUE; + draw_slider = FALSE; + } + if (GTK_IS_COLOR_SCALE (widget)) + { + draw_trough = FALSE; + draw_slider = TRUE; + } if (gtk_widget_get_can_focus (GTK_WIDGET (range))) gtk_widget_style_get (GTK_WIDGET (range), @@ -2188,13 +2198,6 @@ gtk_range_draw (GtkWidget *widget, gtk_style_context_restore (context); } } - else - { - gtk_render_background (context, cr, - x, y, width, height); - gtk_render_frame (context, cr, - x, y, width, height); - } gtk_style_context_restore (context); @@ -2270,7 +2273,7 @@ gtk_range_draw (GtkWidget *widget, cairo_restore (cr); - if (draw_trough) + if (draw_slider) { GtkStateFlags state = widget_state; @@ -2545,6 +2548,16 @@ gtk_range_button_press (GtkWidget *widget, if (gtk_range_update_mouse_location (range)) gtk_widget_queue_draw (widget); + if (priv->mouse_location == MOUSE_SLIDER && + gdk_event_triggers_context_menu ((GdkEvent *)event)) + { + gboolean handled; + + g_signal_emit_by_name (widget, "popup-menu", &handled); + + return TRUE; + } + if (priv->mouse_location == MOUSE_TROUGH && event->button == GDK_BUTTON_PRIMARY) { diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c index 94451e8158..69f4dd2f9f 100644 --- a/gtk/gtkroundedbox.c +++ b/gtk/gtkroundedbox.c @@ -20,6 +20,7 @@ #include "config.h" #include "gtkroundedboxprivate.h" +#include "gtkthemingengineprivate.h" #include <string.h> @@ -76,23 +77,10 @@ gtk_rounded_box_clamp_border_radius (GtkRoundedBox *box) } void -_gtk_rounded_box_apply_border_radius (GtkRoundedBox *box, - GtkThemingEngine *engine, - GtkStateFlags state, - GtkJunctionSides junction) +_gtk_rounded_box_apply_border_radius (GtkRoundedBox *box, + GtkCssBorderCornerRadius **corner, + GtkJunctionSides junction) { - GtkCssBorderCornerRadius *corner[4]; - guint i; - - gtk_theming_engine_get (engine, state, - /* Can't use border-radius as it's an int for - * backwards compat */ - "border-top-left-radius", &corner[GTK_CSS_TOP_LEFT], - "border-top-right-radius", &corner[GTK_CSS_TOP_RIGHT], - "border-bottom-right-radius", &corner[GTK_CSS_BOTTOM_RIGHT], - "border-bottom-left-radius", &corner[GTK_CSS_BOTTOM_LEFT], - NULL); - if (corner[GTK_CSS_TOP_LEFT] && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0) { box->corner[GTK_CSS_TOP_LEFT].horizontal = _gtk_css_number_get (&corner[GTK_CSS_TOP_LEFT]->horizontal, @@ -123,11 +111,42 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box, } gtk_rounded_box_clamp_border_radius (box); +} + +void +_gtk_rounded_box_apply_border_radius_for_context (GtkRoundedBox *box, + GtkStyleContext *context, + GtkStateFlags state, + GtkJunctionSides junction) +{ + GtkCssBorderCornerRadius *corner[4]; + guint i; + + gtk_style_context_get (context, state, + /* Can't use border-radius as it's an int for + * backwards compat */ + "border-top-left-radius", &corner[GTK_CSS_TOP_LEFT], + "border-top-right-radius", &corner[GTK_CSS_TOP_RIGHT], + "border-bottom-right-radius", &corner[GTK_CSS_BOTTOM_RIGHT], + "border-bottom-left-radius", &corner[GTK_CSS_BOTTOM_LEFT], + NULL); + + _gtk_rounded_box_apply_border_radius (box, corner, junction); for (i = 0; i < 4; i++) g_free (corner[i]); } +void +_gtk_rounded_box_apply_border_radius_for_engine (GtkRoundedBox *box, + GtkThemingEngine *engine, + GtkStateFlags state, + GtkJunctionSides junction) +{ + _gtk_rounded_box_apply_border_radius_for_context (box, _gtk_theming_engine_get_context (engine), + state, junction); +} + static void gtk_css_border_radius_grow (GtkRoundedBoxCorner *corner, double horizontal, diff --git a/gtk/gtkroundedboxprivate.h b/gtk/gtkroundedboxprivate.h index 07987c4dda..42806c069a 100644 --- a/gtk/gtkroundedboxprivate.h +++ b/gtk/gtkroundedboxprivate.h @@ -49,10 +49,18 @@ void _gtk_rounded_box_init_rect (GtkRoundedBox double width, double height); -void _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box, +void _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box, + GtkCssBorderCornerRadius **corner, + GtkJunctionSides junction); +void _gtk_rounded_box_apply_border_radius_for_engine (GtkRoundedBox *box, GtkThemingEngine *engine, GtkStateFlags state, GtkJunctionSides junction); +void _gtk_rounded_box_apply_border_radius_for_context (GtkRoundedBox *box, + GtkStyleContext *context, + GtkStateFlags state, + GtkJunctionSides junction); + void _gtk_rounded_box_shrink (GtkRoundedBox *box, double top, double right, diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index e497d1f249..0610d13af9 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -27,7 +27,7 @@ #include "gtkstylecontextprivate.h" #include "gtkstylepropertiesprivate.h" #include "gtktypebuiltins.h" -#include "gtkthemingengine.h" +#include "gtkthemingengineprivate.h" #include "gtkintl.h" #include "gtkwidget.h" #include "gtkwindow.h" diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c index 4ffdda3723..83a4741174 100644 --- a/gtk/gtkthemingbackground.c +++ b/gtk/gtkthemingbackground.c @@ -40,7 +40,7 @@ static void _gtk_theming_background_apply_window_background (GtkThemingBackground *bg, cairo_t *cr) { - if (gtk_theming_engine_has_class (bg->engine, "background")) + if (gtk_style_context_has_class (bg->context, "background")) { cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); @@ -54,9 +54,9 @@ _gtk_theming_background_apply_origin (GtkThemingBackground *bg) GtkCssArea origin; cairo_rectangle_t image_rect; - gtk_theming_engine_get (bg->engine, bg->flags, - "background-origin", &origin, - NULL); + gtk_style_context_get (bg->context, bg->flags, + "background-origin", &origin, + NULL); /* The default size of the background image depends on the background-origin value as this affects the top left @@ -93,9 +93,9 @@ _gtk_theming_background_apply_clip (GtkThemingBackground *bg) { GtkCssArea clip; - gtk_theming_engine_get (bg->engine, bg->flags, - "background-clip", &clip, - NULL); + gtk_style_context_get (bg->context, bg->flags, + "background-clip", &clip, + NULL); if (clip == GTK_CSS_AREA_PADDING_BOX) { @@ -167,10 +167,10 @@ _gtk_theming_background_paint (GtkThemingBackground *bg, double image_width, image_height; double width, height; - size = g_value_get_boxed (_gtk_theming_engine_peek_property (bg->engine, "background-size")); - gtk_theming_engine_get (bg->engine, bg->flags, - "background-repeat", &hrepeat, - NULL); + size = g_value_get_boxed (_gtk_style_context_peek_property (bg->context, "background-size")); + gtk_style_context_get (bg->context, bg->flags, + "background-repeat", &hrepeat, + NULL); vrepeat = GTK_CSS_BACKGROUND_VERTICAL (hrepeat); hrepeat = GTK_CSS_BACKGROUND_HORIZONTAL (hrepeat); width = bg->image_rect.width; @@ -300,9 +300,9 @@ _gtk_theming_background_apply_shadow (GtkThemingBackground *bg, { GtkShadow *box_shadow; - gtk_theming_engine_get (bg->engine, bg->flags, - "box-shadow", &box_shadow, - NULL); + gtk_style_context_get (bg->context, bg->flags, + "box-shadow", &box_shadow, + NULL); if (box_shadow != NULL) { @@ -312,13 +312,13 @@ _gtk_theming_background_apply_shadow (GtkThemingBackground *bg, } static void -_gtk_theming_background_init_engine (GtkThemingBackground *bg) +_gtk_theming_background_init_context (GtkThemingBackground *bg) { - bg->flags = gtk_theming_engine_get_state (bg->engine); + bg->flags = gtk_style_context_get_state (bg->context); - gtk_theming_engine_get_border (bg->engine, bg->flags, &bg->border); - gtk_theming_engine_get_padding (bg->engine, bg->flags, &bg->padding); - gtk_theming_engine_get_background_color (bg->engine, bg->flags, &bg->bg_color); + gtk_style_context_get_border (bg->context, bg->flags, &bg->border); + gtk_style_context_get_padding (bg->context, bg->flags, &bg->padding); + gtk_style_context_get_background_color (bg->context, bg->flags, &bg->bg_color); /* In the CSS box model, by default the background positioning area is * the padding-box, i.e. all the border-box minus the borders themselves, @@ -329,7 +329,8 @@ _gtk_theming_background_init_engine (GtkThemingBackground *bg) * right now we just shrink to the default. */ _gtk_rounded_box_init_rect (&bg->padding_box, 0, 0, bg->paint_area.width, bg->paint_area.height); - _gtk_rounded_box_apply_border_radius (&bg->padding_box, bg->engine, bg->flags, bg->junction); + + _gtk_rounded_box_apply_border_radius_for_context (&bg->padding_box, bg->context, bg->flags, bg->junction); bg->clip_box = bg->padding_box; _gtk_rounded_box_shrink (&bg->padding_box, @@ -339,7 +340,7 @@ _gtk_theming_background_init_engine (GtkThemingBackground *bg) _gtk_theming_background_apply_clip (bg); _gtk_theming_background_apply_origin (bg); - bg->image = g_value_get_object (_gtk_theming_engine_peek_property (bg->engine, "background-image")); + bg->image = g_value_get_object (_gtk_style_context_peek_property (bg->context, "background-image")); } void @@ -351,9 +352,28 @@ _gtk_theming_background_init (GtkThemingBackground *bg, gdouble height, GtkJunctionSides junction) { + GtkStyleContext *context; + + g_assert (bg != NULL); + + context = _gtk_theming_engine_get_context (engine); + _gtk_theming_background_init_from_context (bg, context, + x, y, width, height, + junction); +} + +void +_gtk_theming_background_init_from_context (GtkThemingBackground *bg, + GtkStyleContext *context, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + GtkJunctionSides junction) +{ g_assert (bg != NULL); - bg->engine = engine; + bg->context = context; bg->paint_area.x = x; bg->paint_area.y = y; @@ -363,7 +383,7 @@ _gtk_theming_background_init (GtkThemingBackground *bg, bg->image = NULL; bg->junction = junction; - _gtk_theming_background_init_engine (bg); + _gtk_theming_background_init_context (bg); } void diff --git a/gtk/gtkthemingbackgroundprivate.h b/gtk/gtkthemingbackgroundprivate.h index 27dbc821ee..63dd2a069d 100644 --- a/gtk/gtkthemingbackgroundprivate.h +++ b/gtk/gtkthemingbackgroundprivate.h @@ -35,7 +35,7 @@ G_BEGIN_DECLS typedef struct _GtkThemingBackground GtkThemingBackground; struct _GtkThemingBackground { - GtkThemingEngine *engine; + GtkStyleContext *context; cairo_rectangle_t paint_area; cairo_rectangle_t image_rect; @@ -60,6 +60,14 @@ void _gtk_theming_background_init (GtkThemingBackground *bg, gdouble height, GtkJunctionSides junction); +void _gtk_theming_background_init_from_context (GtkThemingBackground *bg, + GtkStyleContext *context, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + GtkJunctionSides junction); + void _gtk_theming_background_render (GtkThemingBackground *bg, cairo_t *cr); diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c index 21bcdb80c6..89a5f443d2 100644 --- a/gtk/gtkthemingengine.c +++ b/gtk/gtkthemingengine.c @@ -330,6 +330,14 @@ _gtk_theming_engine_set_context (GtkThemingEngine *engine, priv->context = context; } +GtkStyleContext * +_gtk_theming_engine_get_context (GtkThemingEngine *engine) +{ + g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL); + + return engine->priv->context; +} + const GValue * _gtk_theming_engine_peek_property (GtkThemingEngine *engine, const char *property_name) @@ -1807,7 +1815,7 @@ render_frame_internal (GtkThemingEngine *engine, } _gtk_rounded_box_init_rect (&border_box, x, y, width, height); - _gtk_rounded_box_apply_border_radius (&border_box, engine, state, junction); + _gtk_rounded_box_apply_border_radius_for_engine (&border_box, engine, state, junction); render_border (cr, &border_box, &border, hidden_side, colors, border_style); } diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h index d3f6c83cb7..8613264ec0 100644 --- a/gtk/gtkthemingengine.h +++ b/gtk/gtkthemingengine.h @@ -182,9 +182,6 @@ struct _GtkThemingEngineClass GType gtk_theming_engine_get_type (void) G_GNUC_CONST; -void _gtk_theming_engine_set_context (GtkThemingEngine *engine, - GtkStyleContext *context); - /* function implemented in gtkcsscustomproperty.c */ void gtk_theming_engine_register_property (const gchar *name_space, GtkStylePropertyParser parse_func, diff --git a/gtk/gtkthemingengineprivate.h b/gtk/gtkthemingengineprivate.h index 10db6f7470..9ec3b52930 100644 --- a/gtk/gtkthemingengineprivate.h +++ b/gtk/gtkthemingengineprivate.h @@ -33,5 +33,8 @@ const GValue *_gtk_theming_engine_peek_property (GtkThemingEngine *engine, double _gtk_theming_engine_get_number (GtkThemingEngine *engine, const char *property_name, double one_hundred_percent); +void _gtk_theming_engine_set_context (GtkThemingEngine *engine, + GtkStyleContext *context); +GtkStyleContext *_gtk_theming_engine_get_context (GtkThemingEngine *engine); #endif /* __GTK_THEMING_ENGINE_PRIVATE_H__ */ diff --git a/gtk/gtktoolitem.c b/gtk/gtktoolitem.c index 213fc82093..dd1b60e567 100644 --- a/gtk/gtktoolitem.c +++ b/gtk/gtktoolitem.c @@ -788,7 +788,7 @@ gtk_tool_item_get_orientation (GtkToolItem *tool_item) * show text</listitem> * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show * both an icon and a label, arranged horizontally (however, note the - * #GtkToolButton::has_text_horizontally that makes tool buttons not + * #GtkToolButton:has_text_horizontally property that makes tool buttons not * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ. * </listitem> * </itemizedlist> diff --git a/gtk/org.gtk.Settings.ColorChooser.gschema.xml b/gtk/org.gtk.Settings.ColorChooser.gschema.xml new file mode 100644 index 0000000000..f707e469f0 --- /dev/null +++ b/gtk/org.gtk.Settings.ColorChooser.gschema.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<schemalist> + + <schema id='org.gtk.Settings.ColorChooser'> + <key name='custom-colors' type='a(dddd)'> + <default>[]</default> + </key> + <key name='selected-color' type='(bdddd)'> + <default>(false,1.0,1.0,1.0,1.0)</default> + </key> + </schema> + +</schemalist> diff --git a/po-properties/POTFILES.in b/po-properties/POTFILES.in index 448b420a26..2e717321b4 100644 --- a/po-properties/POTFILES.in +++ b/po-properties/POTFILES.in @@ -76,8 +76,15 @@ gtk/gtkclipboard.c gtk/gtkclipboard-quartz.c gtk/gtkclipboard-wayland.c gtk/gtkcolorbutton.c -gtk/gtkcolorsel.c -gtk/gtkcolorseldialog.c +gtk/gtkcolorchooser.c +gtk/gtkcolorchooserdialog.c +gtk/gtkcolorchooserwidget.c +gtk/gtkcoloreditor.c +gtk/gtkcolorplane.c +gtk/gtkcolorscale.c +gtk/gtkcolorswatch.c +gtk/deprecated/gtkcolorsel.c +gtk/deprecated/gtkcolorseldialog.c gtk/gtkcombobox.c gtk/gtkcontainer.c gtk/gtkcssprovider.c @@ -112,7 +119,7 @@ gtk/gtkfontchooserdialog.c gtk/gtkfontchooserwidget.c gtk/gtkframe.c gtk/gtkgrid.c -gtk/gtkhsv.c +gtk/deprecated/gtkhsv.c gtk/gtkiconfactory.c gtk/gtkicontheme.c gtk/gtkiconview.c diff --git a/po-properties/es.po b/po-properties/es.po index f961d1dd2b..83db51fe54 100644 --- a/po-properties/es.po +++ b/po-properties/es.po @@ -18,8 +18,8 @@ msgstr "" "Project-Id-Version: gtk+-properties.master\n" "Report-Msgid-Bugs-To: http://bugzilla.gnome.org/enter_bug.cgi?product=gtk%" "2b&keywords=I18N+L10N&component=general\n" -"POT-Creation-Date: 2012-02-02 02:18+0000\n" -"PO-Revision-Date: 2012-02-02 11:58+0100\n" +"POT-Creation-Date: 2012-02-14 22:20+0000\n" +"PO-Revision-Date: 2012-02-15 13:00+0100\n" "Last-Translator: Daniel Mustieles <daniel.mustieles@gmail.com>\n" "Language-Team: Español <gnome-es-list@gnome.org>\n" "MIME-Version: 1.0\n" @@ -1867,7 +1867,7 @@ msgid "The vertical text alignment, from 0 (top) to 1 (bottom)." msgstr "La alineación vertical del texto, desde 0 (superior) a 1 (inferior)." #: ../gtk/gtkcellrendererprogress.c:226 ../gtk/gtkprogressbar.c:152 -#: ../gtk/gtkrange.c:431 +#: ../gtk/gtkrange.c:432 msgid "Inverted" msgstr "Invertido" @@ -1875,7 +1875,7 @@ msgstr "Invertido" msgid "Invert the direction in which the progress bar grows" msgstr "Invertir la dirección en la que aumentan las barras de progreso" -#: ../gtk/gtkcellrendererspin.c:114 ../gtk/gtkrange.c:423 +#: ../gtk/gtkcellrendererspin.c:114 ../gtk/gtkrange.c:424 #: ../gtk/gtkscalebutton.c:237 ../gtk/gtkspinbutton.c:316 msgid "Adjustment" msgstr "Ajuste" @@ -2435,114 +2435,149 @@ msgstr "" "Indica si la apariencia del elemento de menú es como un elemento de menú de " "radio" -#: ../gtk/gtkcolorbutton.c:170 +#: ../gtk/gtkcolorbutton.c:175 ../gtk/gtkcolorchooser.c:89 msgid "Use alpha" msgstr "Usar alfa" -#: ../gtk/gtkcolorbutton.c:171 +#: ../gtk/gtkcolorbutton.c:176 msgid "Whether to give the color an alpha value" msgstr "Indica si se debe dar un valor alfa al color" # components/music/nautilus-music-view.c:198 -#: ../gtk/gtkcolorbutton.c:185 ../gtk/gtkfilechooserbutton.c:440 +#: ../gtk/gtkcolorbutton.c:190 ../gtk/gtkfilechooserbutton.c:440 #: ../gtk/gtkfontbutton.c:435 ../gtk/gtkprintjob.c:141 #: ../gtk/gtkstatusicon.c:427 ../gtk/gtktreeviewcolumn.c:332 msgid "Title" msgstr "Título" -#: ../gtk/gtkcolorbutton.c:186 +#: ../gtk/gtkcolorbutton.c:191 msgid "The title of the color selection dialog" msgstr "El título del diálogo de selección del color" -#: ../gtk/gtkcolorbutton.c:202 ../gtk/gtkcolorsel.c:343 +#: ../gtk/gtkcolorbutton.c:207 ../gtk/deprecated/gtkcolorsel.c:346 msgid "Current Color" msgstr "Color actual" -#: ../gtk/gtkcolorbutton.c:203 +#: ../gtk/gtkcolorbutton.c:208 msgid "The selected color" msgstr "El color seleccionado" -#: ../gtk/gtkcolorbutton.c:217 ../gtk/gtkcolorsel.c:350 +#: ../gtk/gtkcolorbutton.c:222 ../gtk/deprecated/gtkcolorsel.c:353 msgid "Current Alpha" msgstr "Alfa actual" -#: ../gtk/gtkcolorbutton.c:218 +#: ../gtk/gtkcolorbutton.c:223 msgid "The selected opacity value (0 fully transparent, 65535 fully opaque)" msgstr "" "El valor de opacidad actual (0 es completamente transparente, 65535 es " "completamente opaco)" -#: ../gtk/gtkcolorbutton.c:232 +#: ../gtk/gtkcolorbutton.c:237 msgid "Current RGBA Color" msgstr "Color RGBA actual" -#: ../gtk/gtkcolorbutton.c:233 +#: ../gtk/gtkcolorbutton.c:238 msgid "The selected RGBA color" msgstr "El color RGBA seleccionado" -#: ../gtk/gtkcolorsel.c:321 +#: ../gtk/gtkcolorchooser.c:69 +#| msgid "Color Hash" +msgid "Color" +msgstr "Color" + +#: ../gtk/gtkcolorchooser.c:70 +#| msgid "Foreground color as a GdkRGBA" +msgid "Current color, as a GdkRGBA" +msgstr "Color actual como GdkRGBA" + +#: ../gtk/gtkcolorchooser.c:90 +#| msgid "Whether tabs should be shown" +msgid "Whether alpha should be shown" +msgstr "Indica si se debe mostrar el alfa" + +#: ../gtk/gtkcolorchooserdialog.c:234 ../gtk/gtkcolorchooserwidget.c:666 +#| msgid "Show text" +msgid "Show editor" +msgstr "Mostrar editor" + +#: ../gtk/gtkcolorscale.c:336 +#| msgid "Value type" +msgid "Scale type" +msgstr "Tipo de escala" + +#: ../gtk/gtkcolorswatch.c:588 +#| msgid "Current RGBA Color" +msgid "RGBA Color" +msgstr "Color RGBA" + +#: ../gtk/gtkcolorswatch.c:588 +#| msgid "Color Hash" +msgid "Color as RGBA" +msgstr "Color como RGBA" + +#: ../gtk/deprecated/gtkcolorsel.c:324 msgid "Has Opacity Control" msgstr "Tiene control de opacidad" -#: ../gtk/gtkcolorsel.c:322 +#: ../gtk/deprecated/gtkcolorsel.c:325 msgid "Whether the color selector should allow setting opacity" msgstr "Indica si el selector de color permite seleccionar la opacidad" -#: ../gtk/gtkcolorsel.c:328 +#: ../gtk/deprecated/gtkcolorsel.c:331 msgid "Has palette" msgstr "Tiene paleta" -#: ../gtk/gtkcolorsel.c:329 +#: ../gtk/deprecated/gtkcolorsel.c:332 msgid "Whether a palette should be used" msgstr "Indica si se debe usar una paleta" -#: ../gtk/gtkcolorsel.c:344 +#: ../gtk/deprecated/gtkcolorsel.c:347 msgid "The current color" msgstr "El color actual" -#: ../gtk/gtkcolorsel.c:351 +#: ../gtk/deprecated/gtkcolorsel.c:354 msgid "The current opacity value (0 fully transparent, 65535 fully opaque)" msgstr "" "El valor de opacidad actual (0 es completamente transparente, 65535 es " "completamente opaco)" -#: ../gtk/gtkcolorsel.c:365 +#: ../gtk/deprecated/gtkcolorsel.c:368 msgid "Current RGBA" msgstr "RGBA actual" -#: ../gtk/gtkcolorsel.c:366 +#: ../gtk/deprecated/gtkcolorsel.c:369 msgid "The current RGBA color" msgstr "El color RGBA actual" -#: ../gtk/gtkcolorseldialog.c:136 +#: ../gtk/deprecated/gtkcolorseldialog.c:140 msgid "Color Selection" msgstr "Selección de color" -#: ../gtk/gtkcolorseldialog.c:137 +#: ../gtk/deprecated/gtkcolorseldialog.c:141 msgid "The color selection embedded in the dialog." msgstr "La selección de color empotrada en el diálogo." -#: ../gtk/gtkcolorseldialog.c:143 +#: ../gtk/deprecated/gtkcolorseldialog.c:147 msgid "OK Button" msgstr "Botón Aceptar" -#: ../gtk/gtkcolorseldialog.c:144 +#: ../gtk/deprecated/gtkcolorseldialog.c:148 msgid "The OK button of the dialog." msgstr "El botón Aceptar del diálogo." -#: ../gtk/gtkcolorseldialog.c:150 +#: ../gtk/deprecated/gtkcolorseldialog.c:154 msgid "Cancel Button" msgstr "Botón Cancelar" -#: ../gtk/gtkcolorseldialog.c:151 +#: ../gtk/deprecated/gtkcolorseldialog.c:155 msgid "The cancel button of the dialog." msgstr "El botón Cancelar del diálogo." -#: ../gtk/gtkcolorseldialog.c:157 +#: ../gtk/deprecated/gtkcolorseldialog.c:161 msgid "Help Button" msgstr "Botón Ayuda" -#: ../gtk/gtkcolorseldialog.c:158 +#: ../gtk/deprecated/gtkcolorseldialog.c:162 msgid "The help button of the dialog." msgstr "El botón Ayuda del diálogo." @@ -2742,22 +2777,18 @@ msgid "The numeric id for quick access" msgstr "El ID numérico para acceso rápido" #: ../gtk/gtkcssstyleproperty.c:245 -#| msgid "Device type" msgid "Specified type" msgstr "Tipo especificado" #: ../gtk/gtkcssstyleproperty.c:246 -#| msgid "The type of accelerators" msgid "The type of values after parsing" msgstr "El tipo de valores después de analizarlos" #: ../gtk/gtkcssstyleproperty.c:252 -#| msgid "Content type" msgid "Computed type" msgstr "Tipo calculado" #: ../gtk/gtkcssstyleproperty.c:253 -#| msgid "The type of accelerators" msgid "The type of values after style lookup" msgstr "El tipo de después de buscar el estilo" @@ -5138,21 +5169,21 @@ msgstr "El elemento del menú de radio a cuyo grupo pertenece este widget." msgid "The radio tool button whose group this button belongs to." msgstr "La herramienta de botón de radio a cuyo grupo pertenece este widget." -#: ../gtk/gtkrange.c:424 +#: ../gtk/gtkrange.c:425 msgid "The GtkAdjustment that contains the current value of this range object" msgstr "El GtkAdjustment que contiene el valor actual de este objeto de rango" -#: ../gtk/gtkrange.c:432 +#: ../gtk/gtkrange.c:433 msgid "Invert direction slider moves to increase range value" msgstr "" "Invierte la dirección en que se mueve el deslizador para incrementar el " "valor del rango" -#: ../gtk/gtkrange.c:439 +#: ../gtk/gtkrange.c:440 msgid "Lower stepper sensitivity" msgstr "Sensibilidad de la flecha inferior" -#: ../gtk/gtkrange.c:440 +#: ../gtk/gtkrange.c:441 msgid "" "The sensitivity policy for the stepper that points to the adjustment's lower " "side" @@ -5160,11 +5191,11 @@ msgstr "" "La directiva de sensibilidad del botón de desplazamiento que apunta al lado " "más bajo del ajuste" -#: ../gtk/gtkrange.c:448 +#: ../gtk/gtkrange.c:449 msgid "Upper stepper sensitivity" msgstr "Sensibilidad de la flecha superior" -#: ../gtk/gtkrange.c:449 +#: ../gtk/gtkrange.c:450 msgid "" "The sensitivity policy for the stepper that points to the adjustment's upper " "side" @@ -5172,99 +5203,99 @@ msgstr "" "La directiva de sensibilidad del botón de flecha que apunta al lado más alto " "del ajuste" -#: ../gtk/gtkrange.c:466 +#: ../gtk/gtkrange.c:467 msgid "Show Fill Level" msgstr "Mostrar nivel de relleno" -#: ../gtk/gtkrange.c:467 +#: ../gtk/gtkrange.c:468 msgid "Whether to display a fill level indicator graphics on trough." msgstr "" "Indica si se debe mostrar el indicador de nivel de llenado en los gráficos " "mientras se llena." -#: ../gtk/gtkrange.c:483 +#: ../gtk/gtkrange.c:484 msgid "Restrict to Fill Level" msgstr "Restringir al nivel de llenado" -#: ../gtk/gtkrange.c:484 +#: ../gtk/gtkrange.c:485 msgid "Whether to restrict the upper boundary to the fill level." msgstr "Indica si se debe restringir el borde superior al nivel de llenado." -#: ../gtk/gtkrange.c:499 +#: ../gtk/gtkrange.c:500 msgid "Fill Level" msgstr "Nivel de llenado" -#: ../gtk/gtkrange.c:500 +#: ../gtk/gtkrange.c:501 msgid "The fill level." msgstr "El nivel de llenado." -#: ../gtk/gtkrange.c:517 +#: ../gtk/gtkrange.c:518 msgid "Round Digits" msgstr "Redondear dígitos" -#: ../gtk/gtkrange.c:518 +#: ../gtk/gtkrange.c:519 msgid "The number of digits to round the value to." msgstr "El número de dígitos al que redondear el valor." -#: ../gtk/gtkrange.c:526 ../gtk/gtkswitch.c:970 +#: ../gtk/gtkrange.c:527 ../gtk/gtkswitch.c:970 msgid "Slider Width" msgstr "Anchura del deslizador" -#: ../gtk/gtkrange.c:527 +#: ../gtk/gtkrange.c:528 msgid "Width of scrollbar or scale thumb" msgstr "Anchura de la barra de desplazamiento o escala de miniatura" -#: ../gtk/gtkrange.c:534 +#: ../gtk/gtkrange.c:535 msgid "Trough Border" msgstr "Borde del carril" -#: ../gtk/gtkrange.c:535 +#: ../gtk/gtkrange.c:536 msgid "Spacing between thumb/steppers and outer trough bevel" msgstr "" "Espaciado entre la marcador/flechas de desplazamiento y el bisel exterior " "del carril" -#: ../gtk/gtkrange.c:542 +#: ../gtk/gtkrange.c:543 msgid "Stepper Size" msgstr "Tamaño del botón de flecha de desplazamiento" -#: ../gtk/gtkrange.c:543 +#: ../gtk/gtkrange.c:544 msgid "Length of step buttons at ends" msgstr "Longitud de los botones de flecha en los extremos" -#: ../gtk/gtkrange.c:556 +#: ../gtk/gtkrange.c:557 msgid "Stepper Spacing" msgstr "Espaciado de los botones de flecha de desplazamiento" -#: ../gtk/gtkrange.c:557 +#: ../gtk/gtkrange.c:558 msgid "Spacing between step buttons and thumb" msgstr "Espaciado entre los botones de flecha de desplazamiento y el marcador" -#: ../gtk/gtkrange.c:564 +#: ../gtk/gtkrange.c:565 msgid "Arrow X Displacement" msgstr "Desplazamiento de la flecha X" -#: ../gtk/gtkrange.c:565 +#: ../gtk/gtkrange.c:566 msgid "" "How far in the x direction to move the arrow when the button is depressed" msgstr "" "Distancia en la dirección «X» para mover la flecha cuando se suelta el botón " -#: ../gtk/gtkrange.c:572 +#: ../gtk/gtkrange.c:573 msgid "Arrow Y Displacement" msgstr "Desplazamiento de la flecha Y" -#: ../gtk/gtkrange.c:573 +#: ../gtk/gtkrange.c:574 msgid "" "How far in the y direction to move the arrow when the button is depressed" msgstr "" "Distancia en la dirección «Y» para mover la flecha cuando se suelta el botón " -#: ../gtk/gtkrange.c:589 +#: ../gtk/gtkrange.c:590 msgid "Trough Under Steppers" msgstr "Carril bajo las flechas de deslizamiento" -#: ../gtk/gtkrange.c:590 +#: ../gtk/gtkrange.c:591 msgid "" "Whether to draw trough for full length of range or exclude the steppers and " "spacing" @@ -5272,11 +5303,11 @@ msgstr "" "Indica si se debe dibujar para la longitud completa del rango o excluir las " "flechas de desplazamiento y el espaciado" -#: ../gtk/gtkrange.c:603 +#: ../gtk/gtkrange.c:604 msgid "Arrow scaling" msgstr "Escalado de flechas" -#: ../gtk/gtkrange.c:604 +#: ../gtk/gtkrange.c:605 msgid "Arrow scaling with regard to scroll button size" msgstr "" "Escalado de flechas en consideración con el tamaño del botón de " diff --git a/po/POTFILES.in b/po/POTFILES.in index aeb3838ef2..1195a2edca 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -76,8 +76,15 @@ gtk/gtkclipboard.c gtk/gtkclipboard-quartz.c gtk/gtkclipboard-wayland.c gtk/gtkcolorbutton.c -gtk/gtkcolorsel.c -gtk/gtkcolorseldialog.c +gtk/gtkcolorchooser.c +gtk/gtkcolorchooserdialog.c +gtk/gtkcolorchooserwidget.c +gtk/gtkcoloreditor.c +gtk/gtkcolorplane.c +gtk/gtkcolorscale.c +gtk/gtkcolorswatch.c +gtk/deprecated/gtkcolorsel.c +gtk/deprecated/gtkcolorseldialog.c gtk/gtkcombobox.c gtk/gtkcontainer.c gtk/gtkcssprovider.c @@ -113,7 +120,7 @@ gtk/gtkfontchooserdialog.c gtk/gtkfontchooserwidget.c gtk/gtkframe.c gtk/gtkgrid.c -gtk/gtkhsv.c +gtk/deprecated/gtkhsv.c gtk/gtkiconfactory.c gtk/gtkicontheme.c gtk/gtkiconview.c @@ -17,8 +17,8 @@ msgstr "" "Project-Id-Version: gtk+.master\n" "Report-Msgid-Bugs-To: http://bugzilla.gnome.org/enter_bug.cgi?product=gtk%" "2b&keywords=I18N+L10N&component=general\n" -"POT-Creation-Date: 2012-02-03 16:10+0000\n" -"PO-Revision-Date: 2012-02-03 18:05+0100\n" +"POT-Creation-Date: 2012-02-15 12:01+0000\n" +"PO-Revision-Date: 2012-02-15 13:11+0100\n" "Last-Translator: Daniel Mustieles <daniel.mustieles@gmail.com>\n" "Language-Team: Español <gnome-es-list@gnome.org>\n" "MIME-Version: 1.0\n" @@ -513,9 +513,6 @@ msgstr "Selección de tipografías" #. #: ../gtk/gtkaboutdialog.c:106 #, c-format -#| msgid "" -#| "This program comes with ABSOLUTELY NO WARRANTY; for details, visit <a " -#| "href=\"%s\">%s</a>" msgid "" "This program comes with ABSOLUTELY NO WARRANTY;\n" "for details, visit <a href=\"%s\">%s</a>" @@ -703,8 +700,8 @@ msgstr "Olvidar asociación" msgid "Show other applications" msgstr "Mostrar otras aplicaciones" -#: ../gtk/gtkappchooserdialog.c:576 ../gtk/gtkcolorseldialog.c:199 -#: ../gtk/gtkfontchooserdialog.c:176 +#: ../gtk/gtkappchooserdialog.c:576 ../gtk/gtkcolorchooserdialog.c:127 +#: ../gtk/deprecated/gtkcolorseldialog.c:203 ../gtk/gtkfontchooserdialog.c:176 msgid "_Select" msgstr "_Seleccionar" @@ -898,11 +895,277 @@ msgctxt "progress bar label" msgid "%d %%" msgstr "%d %%" -#: ../gtk/gtkcolorbutton.c:187 ../gtk/gtkcolorbutton.c:485 +#: ../gtk/gtkcolorbutton.c:192 ../gtk/gtkcolorbutton.c:461 msgid "Pick a Color" msgstr "Escoja un color" -#: ../gtk/gtkcolorsel.c:423 +#: ../gtk/gtkcolorchooserdialog.c:136 +msgid "Select a Color" +msgstr "Seleccionar un color" + +#: ../gtk/gtkcolorchooserwidget.c:283 +#, c-format +msgid "Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%" +msgstr "Rojo %d%%, verde %d%%, azul %d%%, Alfa %d%%" + +#: ../gtk/gtkcolorchooserwidget.c:289 +#, c-format +msgid "Red %d%%, Green %d%%, Blue %d%%" +msgstr "Rojo %d%%, verde %d%%, azul %d%%" + +#: ../gtk/gtkcolorchooserwidget.c:340 +#, c-format +msgid "Color: %s" +msgstr "Color: %s" + +#: ../gtk/gtkcolorchooserwidget.c:411 +msgctxt "Color name" +msgid "Light Scarlet Red" +msgstr "Rojo escarlata claro" + +#: ../gtk/gtkcolorchooserwidget.c:412 +msgctxt "Color name" +msgid "Scarlet Red" +msgstr "Rojo escarlata" + +#: ../gtk/gtkcolorchooserwidget.c:413 +msgctxt "Color name" +msgid "Dark Scarlet Red" +msgstr "Rojo escarlata oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:414 +msgctxt "Color name" +msgid "Light Orange" +msgstr "Naranja claro" + +#: ../gtk/gtkcolorchooserwidget.c:415 +msgctxt "Color name" +msgid "Orange" +msgstr "Naranja" + +#: ../gtk/gtkcolorchooserwidget.c:416 +msgctxt "Color name" +msgid "Dark Orange" +msgstr "Naranja oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:417 +msgctxt "Color name" +msgid "Light Butter" +msgstr "Mantequilla claro" + +#: ../gtk/gtkcolorchooserwidget.c:418 +msgctxt "Color name" +msgid "Butter" +msgstr "Mantequilla" + +#: ../gtk/gtkcolorchooserwidget.c:419 +msgctxt "Color name" +msgid "Dark Butter" +msgstr "Mantequilla oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:420 +msgctxt "Color name" +msgid "Light Chameleon" +msgstr "Camaleón claro" + +#: ../gtk/gtkcolorchooserwidget.c:421 +msgctxt "Color name" +msgid "Chameleon" +msgstr "Camaleón" + +#: ../gtk/gtkcolorchooserwidget.c:422 +msgctxt "Color name" +msgid "Dark Chameleon" +msgstr "Camaleón oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:423 +msgctxt "Color name" +msgid "Light Sky Blue" +msgstr "Azul cielo claro" + +#: ../gtk/gtkcolorchooserwidget.c:424 +msgctxt "Color name" +msgid "Sky Blue" +msgstr "Azul cielo" + +#: ../gtk/gtkcolorchooserwidget.c:425 +msgctxt "Color name" +msgid "Dark Sky Blue" +msgstr "Azul cielo oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:426 +msgctxt "Color name" +msgid "Light Plum" +msgstr "Ciruela claro" + +#: ../gtk/gtkcolorchooserwidget.c:427 +msgctxt "Color name" +msgid "Plum" +msgstr "Ciruela" + +#: ../gtk/gtkcolorchooserwidget.c:428 +msgctxt "Color name" +msgid "Dark Plum" +msgstr "Ciruela oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:429 +msgctxt "Color name" +msgid "Light Chocolate" +msgstr "Chocolate claro" + +#: ../gtk/gtkcolorchooserwidget.c:430 +msgctxt "Color name" +msgid "Chocolate" +msgstr "Chocolate" + +#: ../gtk/gtkcolorchooserwidget.c:431 +msgctxt "Color name" +msgid "Dark Chocolate" +msgstr "Chocolate oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:432 +msgctxt "Color name" +msgid "Light Aluminum 1" +msgstr "Aluminio claro 1" + +#: ../gtk/gtkcolorchooserwidget.c:433 +msgctxt "Color name" +msgid "Aluminum 1" +msgstr "Aluminio 1" + +#: ../gtk/gtkcolorchooserwidget.c:434 +msgctxt "Color name" +msgid "Dark Aluminum 1" +msgstr "Aluminio oscuro 1" + +#: ../gtk/gtkcolorchooserwidget.c:435 +msgctxt "Color name" +msgid "Light Aluminum 2" +msgstr "Aluminio claro 2" + +#: ../gtk/gtkcolorchooserwidget.c:436 +msgctxt "Color name" +msgid "Aluminum 2" +msgstr "Aluminio 2" + +#: ../gtk/gtkcolorchooserwidget.c:437 +msgctxt "Color name" +msgid "Dark Aluminum 2" +msgstr "Aluminio oscuro 2" + +#: ../gtk/gtkcolorchooserwidget.c:451 +msgctxt "Color name" +msgid "Black" +msgstr "Negro" + +#: ../gtk/gtkcolorchooserwidget.c:452 +msgctxt "Color name" +msgid "Very Dark Gray" +msgstr "Gris muy oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:453 +msgctxt "Color name" +msgid "Darker Gray" +msgstr "Gris más oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:454 +msgctxt "Color name" +msgid "Dark Gray" +msgstr "Gris oscuro" + +#: ../gtk/gtkcolorchooserwidget.c:455 +msgctxt "Color name" +msgid "Medium Gray" +msgstr "Gris medio" + +#: ../gtk/gtkcolorchooserwidget.c:456 +msgctxt "Color name" +msgid "Light Gray" +msgstr "Gris claro" + +#: ../gtk/gtkcolorchooserwidget.c:457 +msgctxt "Color name" +msgid "Lighter Gray" +msgstr "Gris muy claro" + +#: ../gtk/gtkcolorchooserwidget.c:458 +msgctxt "Color name" +msgid "Very Light Gray" +msgstr "Gris muy claro" + +#: ../gtk/gtkcolorchooserwidget.c:459 +msgctxt "Color name" +msgid "White" +msgstr "Blanco" + +#. translators: label for the custom section in the color chooser +#: ../gtk/gtkcolorchooserwidget.c:508 +msgid "Custom" +msgstr "Personalizada" + +# C en conflicto con Cancelar +#: ../gtk/gtkcolorchooserwidget.c:515 +msgid "Create custom color" +msgstr "Crear color personalizado" + +#: ../gtk/gtkcolorchooserwidget.c:534 +#, c-format +msgid "Custom color %d: %s" +msgstr "Color personalizado %d: %s" + +#: ../gtk/gtkcoloreditor.c:412 +msgid "Color Name" +msgstr "Nombre del color" + +#: ../gtk/gtkcoloreditor.c:457 +msgctxt "Color channel" +msgid "Saturation" +msgstr "Saturación" + +#: ../gtk/gtkcoloreditor.c:463 +msgctxt "Color channel" +msgid "Value" +msgstr "Valor" + +#: ../gtk/gtkcoloreditor.c:471 +msgctxt "Color channel" +msgid "S" +msgstr "S" + +#: ../gtk/gtkcoloreditor.c:473 +msgctxt "Color channel" +msgid "V" +msgstr "V" + +#: ../gtk/gtkcoloreditor.c:481 ../gtk/gtkcolorscale.c:297 +msgctxt "Color channel" +msgid "Hue" +msgstr "Tono" + +#: ../gtk/gtkcoloreditor.c:488 +msgctxt "Color channel" +msgid "H" +msgstr "H" + +#: ../gtk/gtkcoloreditor.c:496 ../gtk/gtkcolorscale.c:299 +msgctxt "Color channel" +msgid "Alpha" +msgstr "Alfa" + +#: ../gtk/gtkcoloreditor.c:503 +msgctxt "Color channel" +msgid "A" +msgstr "A" + +#: ../gtk/gtkcolorplane.c:393 +msgid "Color Plane" +msgstr "Plano de color" + +#: ../gtk/gtkcolorswatch.c:423 +msgid "_Customize" +msgstr "_Personalizar" + +#: ../gtk/deprecated/gtkcolorsel.c:426 msgid "" "Select the color you want from the outer ring. Select the darkness or " "lightness of that color using the inner triangle." @@ -910,7 +1173,7 @@ msgstr "" "Seleccionar el color que desea desde el anillo exterior. Seleccionar la " "oscuridad o luminosidad de ese color usando el triángulo interior." -#: ../gtk/gtkcolorsel.c:449 +#: ../gtk/deprecated/gtkcolorsel.c:452 msgid "" "Click the eyedropper, then click a color anywhere on your screen to select " "that color." @@ -918,67 +1181,67 @@ msgstr "" "Pulse en el gotero, luego pulse sobre cualquier color que haya en su " "pantalla para seleccionar ese color." -#: ../gtk/gtkcolorsel.c:459 +#: ../gtk/deprecated/gtkcolorsel.c:462 msgid "_Hue:" msgstr "_Matiz:" -#: ../gtk/gtkcolorsel.c:460 +#: ../gtk/deprecated/gtkcolorsel.c:463 msgid "Position on the color wheel." msgstr "Posición en la rueda de colores." -#: ../gtk/gtkcolorsel.c:462 +#: ../gtk/deprecated/gtkcolorsel.c:465 msgid "S_aturation:" msgstr "_Saturación:" -#: ../gtk/gtkcolorsel.c:463 +#: ../gtk/deprecated/gtkcolorsel.c:466 msgid "Intensity of the color." msgstr "Intensidad del color." -#: ../gtk/gtkcolorsel.c:464 +#: ../gtk/deprecated/gtkcolorsel.c:467 msgid "_Value:" msgstr "_Valor:" -#: ../gtk/gtkcolorsel.c:465 +#: ../gtk/deprecated/gtkcolorsel.c:468 msgid "Brightness of the color." msgstr "Brillo del color." -#: ../gtk/gtkcolorsel.c:466 +#: ../gtk/deprecated/gtkcolorsel.c:469 msgid "_Red:" msgstr "_Rojo:" -#: ../gtk/gtkcolorsel.c:467 +#: ../gtk/deprecated/gtkcolorsel.c:470 msgid "Amount of red light in the color." msgstr "Cantidad de luz roja en el color." -#: ../gtk/gtkcolorsel.c:468 +#: ../gtk/deprecated/gtkcolorsel.c:471 msgid "_Green:" msgstr "_Verde:" -#: ../gtk/gtkcolorsel.c:469 +#: ../gtk/deprecated/gtkcolorsel.c:472 msgid "Amount of green light in the color." msgstr "Cantidad de luz verde en el color." -#: ../gtk/gtkcolorsel.c:470 +#: ../gtk/deprecated/gtkcolorsel.c:473 msgid "_Blue:" msgstr "_Azul:" -#: ../gtk/gtkcolorsel.c:471 +#: ../gtk/deprecated/gtkcolorsel.c:474 msgid "Amount of blue light in the color." msgstr "Cantidad de luz azul en el color." -#: ../gtk/gtkcolorsel.c:474 +#: ../gtk/deprecated/gtkcolorsel.c:477 msgid "Op_acity:" msgstr "_Opacidad:" -#: ../gtk/gtkcolorsel.c:482 ../gtk/gtkcolorsel.c:492 +#: ../gtk/deprecated/gtkcolorsel.c:485 ../gtk/deprecated/gtkcolorsel.c:495 msgid "Transparency of the color." msgstr "Transparencia del color." -#: ../gtk/gtkcolorsel.c:499 +#: ../gtk/deprecated/gtkcolorsel.c:502 msgid "Color _name:" msgstr "_Nombre del color:" -#: ../gtk/gtkcolorsel.c:514 +#: ../gtk/deprecated/gtkcolorsel.c:517 msgid "" "You can enter an HTML-style hexadecimal color value, or simply a color name " "such as 'orange' in this entry." @@ -986,15 +1249,15 @@ msgstr "" "Puede introducir en esta entrada un valor de color en estilo HTML " "hexadecimal, o simplemente un nombre de color como «orange»." -#: ../gtk/gtkcolorsel.c:546 +#: ../gtk/deprecated/gtkcolorsel.c:549 msgid "_Palette:" msgstr "_Paleta:" -#: ../gtk/gtkcolorsel.c:576 +#: ../gtk/deprecated/gtkcolorsel.c:579 msgid "Color Wheel" msgstr "Rueda de color" -#: ../gtk/gtkcolorsel.c:1070 +#: ../gtk/deprecated/gtkcolorsel.c:1073 msgid "" "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 " @@ -1005,7 +1268,7 @@ msgstr "" "seleccionar este color como actual arrastrándolo al otro color a lo largo de " "la muestra." -#: ../gtk/gtkcolorsel.c:1076 +#: ../gtk/deprecated/gtkcolorsel.c:1079 msgid "" "The color you've chosen. You can drag this color to a palette entry to save " "it for use in the future." @@ -1013,7 +1276,7 @@ msgstr "" "El color elegido. Puede arrastrar este color a una entrada de la paleta para " "guardarlo para usarlo en el futuro." -#: ../gtk/gtkcolorsel.c:1082 +#: ../gtk/deprecated/gtkcolorsel.c:1085 msgid "" "The previously-selected color, for comparison to the color you're selecting " "now." @@ -1021,15 +1284,15 @@ msgstr "" "El color anteriormente seleccionado, para compararlo con el color que está " "seleccionando ahora" -#: ../gtk/gtkcolorsel.c:1086 +#: ../gtk/deprecated/gtkcolorsel.c:1089 msgid "The color you've chosen." msgstr "El color que ha elegido." -#: ../gtk/gtkcolorsel.c:1489 +#: ../gtk/deprecated/gtkcolorsel.c:1492 msgid "_Save color here" msgstr "_Guardar color aquí" -#: ../gtk/gtkcolorsel.c:1693 +#: ../gtk/deprecated/gtkcolorsel.c:1696 msgid "" "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.\"" @@ -1038,7 +1301,7 @@ msgstr "" "Para cambiar esta entrada, arrastre un color de muestra aquí o pulse con el " "botón derecho sobre éste y seleccione «Guardar color aquí»." -#: ../gtk/gtkcolorseldialog.c:217 +#: ../gtk/deprecated/gtkcolorseldialog.c:221 msgid "Color Selection" msgstr "Selección de color" @@ -1705,7 +1968,7 @@ msgstr "Shell Z" msgid "Cannot end process with PID %d: %s" msgstr "No se puede finalizar el proceso con PID %d: %s" -#: ../gtk/gtknotebook.c:5014 ../gtk/gtknotebook.c:7668 +#: ../gtk/gtknotebook.c:5036 ../gtk/gtknotebook.c:7690 #, c-format msgid "Page %u" msgstr "Página %u" diff --git a/tests/Makefile.am b/tests/Makefile.am index 6c1c1d854e..828761336f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -39,6 +39,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \ testcairo \ testcalendar \ testclipboard \ + testcolorchooser \ testcombo \ testcombochange \ testcellrenderertext \ @@ -158,6 +159,7 @@ testbuttons_DEPENDENCIES = $(TEST_DEPS) testcairo_DEPENDENCIES = $(TEST_DEPS) testcalendar_DEPENDENCIES = $(TEST_DEPS) testclipboard_DEPENDENCIES = $(TEST_DEPS) +testcolorchooser_DEPENDENCIES = $(TEST_DEPS) testcombo_DEPENDENCIES = $(TEST_DEPS) testcombochange_DEPENDENCIES = $(TEST_DEPS) testcellrenderertext_DEPENDENCIES = $(TEST_DEPS) @@ -252,6 +254,7 @@ testbuttons_LDADD = $(LDADDS) testcairo_LDADD = $(LDADDS) testcalendar_LDADD = $(LDADDS) testclipboard_LDADD = $(LDADDS) +testcolorchooser_LDADD = $(LDADDS) testcombo_LDADD = $(LDADDS) testcombochange_LDADD = $(LDADDS) testcellrenderertext_LDADD = $(LDADDS) @@ -519,6 +522,7 @@ testpixbuf_color_SOURCES = testpixbuf-color.c testpixbuf_save_SOURCES = testpixbuf-save.c +testcolorchooser_SOURCES = testcolorchooser.c EXTRA_DIST += \ gradient1.png \ diff --git a/tests/prop-editor.c b/tests/prop-editor.c index b15e41a025..dc284cabe2 100644 --- a/tests/prop-editor.c +++ b/tests/prop-editor.c @@ -666,7 +666,7 @@ rgba_modified (GtkColorButton *cb, gpointer data) ObjectProperty *p = data; GdkRGBA color; - gtk_color_button_get_rgba (cb, &color); + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cb), &color); if (is_child_property (p->spec)) { @@ -692,12 +692,12 @@ rgba_changed (GObject *object, GParamSpec *pspec, gpointer data) get_property_value (object, pspec, &val); color = g_value_get_boxed (&val); - gtk_color_button_get_rgba (cb, &cb_color); + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cb), &cb_color); if (color != NULL && !gdk_rgba_equal (color, &cb_color)) { block_controller (G_OBJECT (cb)); - gtk_color_button_set_rgba (cb, color); + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cb), color); unblock_controller (G_OBJECT (cb)); } @@ -1013,7 +1013,7 @@ property_widget (GObject *object, G_PARAM_SPEC_VALUE_TYPE (spec) == GDK_TYPE_RGBA) { prop_edit = gtk_color_button_new (); - gtk_color_button_set_use_alpha (GTK_COLOR_BUTTON (prop_edit), TRUE); + gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (prop_edit), TRUE); g_object_connect_property (object, spec, G_CALLBACK (rgba_changed), diff --git a/tests/testcolorchooser.c b/tests/testcolorchooser.c new file mode 100644 index 0000000000..fc06772bad --- /dev/null +++ b/tests/testcolorchooser.c @@ -0,0 +1,98 @@ +#include <gtk/gtk.h> + +static void +color_changed (GObject *o, GParamSpec *pspect, gpointer data) +{ + GdkRGBA color; + + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (o), &color); + g_print ("color changed: %g %g %g %g\n", + color.red, color.green, color.blue, color.alpha); +} + +static void +dialog_response (GtkDialog *dialog, gint response) +{ + GdkRGBA color; + + switch (response) + { + case GTK_RESPONSE_OK: + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &color); + g_print ("color accepted: %g %g %g %g\n", + color.red, color.green, color.blue, color.alpha); + break; + default: + g_print ("canceled\n"); + break; + } + + gtk_main_quit (); +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *dialog; + gint i; + + gtk_init (NULL, NULL); + + dialog = gtk_color_chooser_dialog_new ("Select a color", NULL); + + for (i = 1; i < argc; i++) + { + if (g_strcmp0 (argv[i], "--no-alpha") == 0) + { + g_print ("turning alpha off\n"); + gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (dialog), FALSE); + } + else if (g_strcmp0 (argv[i], "--edit") == 0) + { + g_print ("starting in edit mode\n"); + g_object_set (dialog, "show-editor", TRUE, NULL); + } + else if (g_strcmp0 (argv[i], "--palette") == 0) + { + const gchar *c[9] = { "red", "maroon", "yellow", "green", "blue", "magenta", "DarkOliveGreen4", "khaki2", "thistle1" }; + GdkRGBA color; + GdkRGBA colors[9*9]; + gint i,j; + gdouble f[5] = { 0.2, 0.35, 0.5, 0.65, 0.8 }; + + g_print ("setting custom palette\n"); + for (i = 0; i < 9; i++) + { + gdk_rgba_parse (&color, c[i]); + for (j = 0; j < 5; j++) + { + colors[i*9 + j].red = f[j]*color.red; + colors[i*9 + j].green = f[j]*color.green; + colors[i*9 + j].blue = f[j]*color.blue; + colors[i*9 + j].alpha = 1; + } + for (j = 5; j < 9; j++) + { + colors[i*9 + j].red = f[9-j]*color.red + (1-f[9-j]); + colors[i*9 + j].green = f[9-j]*color.green + (1-f[9-j]); + colors[i*9 + j].blue = f[9-j]*color.blue + (1-f[9-j]); + colors[i*9 + j].alpha = 1; + } + } + gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (dialog), + FALSE, + 9, 9*9, + colors); + } + } + + g_signal_connect (dialog, "notify::color", G_CALLBACK (color_changed), NULL); + g_signal_connect (dialog, "response", G_CALLBACK (dialog_response), NULL); + + gtk_widget_show_all (dialog); + + gtk_main (); + + return 0; +} + diff --git a/tests/testgtk.c b/tests/testgtk.c index 655868b561..c0faa8164b 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -3298,35 +3298,17 @@ static void cmw_color (GtkWidget *widget, GtkWidget *parent) { GtkWidget *csd; - GtkWidget *colorsel; GtkWidget *ok_button, *cancel_button; - csd = gtk_color_selection_dialog_new ("This is a modal color selection dialog"); + csd = gtk_color_chooser_dialog_new ("This is a modal color selection dialog", GTK_WINDOW (parent)); - gtk_window_set_screen (GTK_WINDOW (csd), gtk_widget_get_screen (parent)); - - colorsel = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (csd)); - gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (colorsel), - TRUE); - /* Set as modal */ gtk_window_set_modal (GTK_WINDOW(csd),TRUE); - /* And mark it as a transient dialog */ - gtk_window_set_transient_for (GTK_WINDOW (csd), GTK_WINDOW (parent)); - g_signal_connect (csd, "destroy", G_CALLBACK (cmw_destroy_cb), NULL); - - g_object_get (csd, - "ok-button", &ok_button, - "cancel-button", &cancel_button, - NULL); - - g_signal_connect_swapped (ok_button, - "clicked", G_CALLBACK (gtk_widget_destroy), csd); - g_signal_connect_swapped (cancel_button, - "clicked", G_CALLBACK (gtk_widget_destroy), csd); + g_signal_connect (csd, "response", + G_CALLBACK (gtk_widget_destroy), NULL); /* wait until destroy calls gtk_main_quit */ gtk_widget_show (csd); @@ -4842,7 +4824,7 @@ create_color_selection (GtkWidget *widget) gtk_container_add (GTK_CONTAINER (hbox), label); picker = gtk_color_button_new (); - gtk_color_button_set_use_alpha (GTK_COLOR_BUTTON (picker), TRUE); + gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (picker), TRUE); gtk_container_add (GTK_CONTAINER (hbox), picker); button = gtk_button_new_with_mnemonic ("_Props"); diff --git a/tests/testtoplevelembed.c b/tests/testtoplevelembed.c index 4072e8029f..e183d94f3e 100644 --- a/tests/testtoplevelembed.c +++ b/tests/testtoplevelembed.c @@ -77,7 +77,7 @@ main (gint argc, gchar **argv) toplevel_delete_event (widget, NULL, NULL); g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL); - widget = gtk_color_selection_dialog_new ("the colorsel"); + widget = gtk_color_chooser_dialog_new ("the colorsel", NULL); toplevel_delete_event (widget, NULL, NULL); g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL); |