X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkcolorchooser.c;h=cbefdd3b4a855fa008357ea2921c18c8b9995dc6;hb=c8403f697edef57f33c66d3d8deb1488db86d949;hp=153180bbb5b49c408190a342ffb0750a0aabcc01;hpb=23a5f7a22c6fda1e28415584e2b266b9ce1fe3ef;p=~andy%2Fgtk diff --git a/gtk/gtkcolorchooser.c b/gtk/gtkcolorchooser.c index 153180bbb..cbefdd3b4 100644 --- a/gtk/gtkcolorchooser.c +++ b/gtk/gtkcolorchooser.c @@ -13,9 +13,7 @@ * 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. + * License along with this library. If not, see . */ #include "config.h" @@ -111,13 +109,20 @@ gtk_color_chooser_default_init (GtkColorChooserInterface *iface) NULL, NULL, NULL, G_TYPE_NONE, - 1, G_TYPE_STRING); + 1, GDK_TYPE_RGBA); +} + +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 + * @color: (out): a #GdkRGBA to fill in with the current color * * Gets the currently-selected color. * @@ -138,6 +143,8 @@ gtk_color_chooser_get_rgba (GtkColorChooser *chooser, * @color: the new color * * Sets the color. + * + * Since: 3.4 */ void gtk_color_chooser_set_rgba (GtkColorChooser *chooser, @@ -149,13 +156,6 @@ gtk_color_chooser_set_rgba (GtkColorChooser *chooser, GTK_COLOR_CHOOSER_GET_IFACE (chooser)->set_rgba (chooser, color); } -void -_gtk_color_chooser_color_activated (GtkColorChooser *chooser, - const GdkRGBA *color) -{ - g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color); -} - /** * gtk_color_chooser_get_use_alpha: * @chooser: a #GtkColorChooser @@ -197,3 +197,66 @@ gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser, g_object_set (chooser, "use-alpha", use_alpha, NULL); } + +/** + * gtk_color_chooser_add_palette: + * @chooser: a #GtkColorChooser + * @orientation: %GTK_ORIENTATION_HORIZONTAL if the palette should + * be displayed in rows, %GTK_ORIENTATION_VERTICAL 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: (allow-none) (array length=n_colors): the colors of the palette, or %NULL + * + * Adds a palette to the color chooser. If @orientation is horizontal, + * 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 for the first time has the + * side effect of removing the default color and gray palettes + * from the color chooser. + * + * If @colors is %NULL, removes all previously added palettes. + * + * Since: 3.4 + */ +void +gtk_color_chooser_add_palette (GtkColorChooser *chooser, + GtkOrientation orientation, + 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, orientation, 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; +}