colorchooser: Allow removing the palettes again
https://bugzilla.gnome.org/show_bug.cgi?id=671057
This commit is contained in:
parent
912ad3b698
commit
5a8dba7eac
@ -143,6 +143,8 @@ gtk_color_chooser_get_rgba (GtkColorChooser *chooser,
|
|||||||
* @color: the new color
|
* @color: the new color
|
||||||
*
|
*
|
||||||
* Sets the color.
|
* Sets the color.
|
||||||
|
*
|
||||||
|
* Since: 3.4
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
gtk_color_chooser_set_rgba (GtkColorChooser *chooser,
|
gtk_color_chooser_set_rgba (GtkColorChooser *chooser,
|
||||||
@ -203,7 +205,7 @@ gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser,
|
|||||||
* %FALSE for columns
|
* %FALSE for columns
|
||||||
* @colors_per_line: the number of colors to show in each row/column
|
* @colors_per_line: the number of colors to show in each row/column
|
||||||
* @n_colors: the total number of elements in @colors
|
* @n_colors: the total number of elements in @colors
|
||||||
* @colors: (array length=n_colors): the colors of the palette
|
* @colors: (allow-none) (array length=n_colors): the colors of the palette, or %NULL
|
||||||
*
|
*
|
||||||
* Adds a palette to the color chooser. If @horizontal is %TRUE,
|
* Adds a palette to the color chooser. If @horizontal is %TRUE,
|
||||||
* the colors are grouped in rows, with @colors_per_line colors
|
* the colors are grouped in rows, with @colors_per_line colors
|
||||||
@ -220,6 +222,10 @@ gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser,
|
|||||||
* Calling this function is called for the first time has the
|
* Calling this function is called for the first time has the
|
||||||
* side effect of removing the default color and gray palettes
|
* side effect of removing the default color and gray palettes
|
||||||
* from the color chooser.
|
* from the color chooser.
|
||||||
|
*
|
||||||
|
* If @colors is %NULL, removes all previously added palettes.
|
||||||
|
*
|
||||||
|
* Since: 3.4
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
gtk_color_chooser_add_palette (GtkColorChooser *chooser,
|
gtk_color_chooser_add_palette (GtkColorChooser *chooser,
|
||||||
|
@ -70,6 +70,7 @@ void gtk_color_chooser_set_rgba (GtkColorChooser *chooser,
|
|||||||
const GdkRGBA *color);
|
const GdkRGBA *color);
|
||||||
GDK_AVAILABLE_IN_3_4
|
GDK_AVAILABLE_IN_3_4
|
||||||
gboolean gtk_color_chooser_get_use_alpha (GtkColorChooser *chooser);
|
gboolean gtk_color_chooser_get_use_alpha (GtkColorChooser *chooser);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_3_4
|
GDK_AVAILABLE_IN_3_4
|
||||||
void gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser,
|
void gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser,
|
||||||
gboolean use_alpha);
|
gboolean use_alpha);
|
||||||
|
@ -290,6 +290,22 @@ accessible_color_name (GdkRGBA *color)
|
|||||||
scale_round (color->blue, 100));
|
scale_round (color->blue, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
remove_palette (GtkColorChooserWidget *cc)
|
||||||
|
{
|
||||||
|
GList *children, *l;
|
||||||
|
GtkWidget *widget;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_palette (GtkColorChooserWidget *cc,
|
add_palette (GtkColorChooserWidget *cc,
|
||||||
@ -306,6 +322,12 @@ add_palette (GtkColorChooserWidget *cc,
|
|||||||
gint i;
|
gint i;
|
||||||
gint left, right;
|
gint left, right;
|
||||||
|
|
||||||
|
if (colors == NULL)
|
||||||
|
{
|
||||||
|
remove_palette (cc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
grid = gtk_grid_new ();
|
grid = gtk_grid_new ();
|
||||||
gtk_widget_set_margin_bottom (grid, 12);
|
gtk_widget_set_margin_bottom (grid, 12);
|
||||||
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
|
||||||
@ -372,22 +394,10 @@ add_palette (GtkColorChooserWidget *cc,
|
|||||||
static void
|
static void
|
||||||
remove_default_palette (GtkColorChooserWidget *cc)
|
remove_default_palette (GtkColorChooserWidget *cc)
|
||||||
{
|
{
|
||||||
GList *children, *l;
|
|
||||||
GtkWidget *widget;
|
|
||||||
|
|
||||||
if (!cc->priv->has_default_palette)
|
if (!cc->priv->has_default_palette)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (cc->priv->palette));
|
remove_palette (cc);
|
||||||
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;
|
cc->priv->has_default_palette = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,11 @@ main (int argc, char *argv[])
|
|||||||
9, 9*9,
|
9, 9*9,
|
||||||
colors);
|
colors);
|
||||||
}
|
}
|
||||||
|
else if (g_strcmp0 (argv[i], "--no-palette") == 0)
|
||||||
|
{
|
||||||
|
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (dialog),
|
||||||
|
FALSE, 0, NULL, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect (dialog, "notify::color", G_CALLBACK (color_changed), NULL);
|
g_signal_connect (dialog, "notify::color", G_CALLBACK (color_changed), NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user