]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcolorsel.c
filechooserentry: Start autocomplete immediately
[~andy/gtk] / gtk / gtkcolorsel.c
index febb1a98b8b90ea72a1eaa176536f33a788b91b0..32f18ce715f0c1fd642a1c95e52feb57246484ae 100644 (file)
 #include <string.h>
 
 #include "gdk/gdk.h"
+#include "gtkorientable.h"
 #include "gtkhsv.h"
 #include "gtkwindow.h"
 #include "gtkselection.h"
 #include "gtkdnd.h"
 #include "gtkdrawingarea.h"
-#include "gtkhbox.h"
-#include "gtkhbbox.h"
-#include "gtkrc.h"
 #include "gtkframe.h"
-#include "gtktable.h"
+#include "gtkgrid.h"
 #include "gtklabel.h"
 #include "gtkmarshalers.h"
 #include "gtkimage.h"
 #include "gtkspinbutton.h"
 #include "gtkrange.h"
-#include "gtkhscale.h"
+#include "gtkscale.h"
 #include "gtkentry.h"
 #include "gtkbutton.h"
-#include "gtkhseparator.h"
-#include "gtkinvisible.h"
 #include "gtkmenuitem.h"
 #include "gtkmain.h"
 #include "gtksettings.h"
 #include "gtkstock.h"
 #include "gtkaccessible.h"
 #include "gtksizerequest.h"
+#include "gtkseparator.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 
@@ -298,7 +295,7 @@ static const guchar dropper_bits[] = {
   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"};
 
-G_DEFINE_TYPE (GtkColorSelection, gtk_color_selection, GTK_TYPE_VBOX)
+G_DEFINE_TYPE (GtkColorSelection, gtk_color_selection, GTK_TYPE_BOX)
 
 static void
 gtk_color_selection_class_init (GtkColorSelectionClass *klass)
@@ -394,6 +391,9 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
   AtkObject *atk_obj;
   GList *focus_chain = NULL;
 
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (colorsel),
+                                  GTK_ORIENTATION_VERTICAL);
+
   gtk_widget_push_composite_child ();
 
   priv = colorsel->private_data = G_TYPE_INSTANCE_GET_PRIVATE (colorsel, GTK_TYPE_COLOR_SELECTION, GtkColorSelectionPrivate);
@@ -443,15 +443,15 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
 
   top_right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   gtk_box_pack_start (GTK_BOX (top_hbox), top_right_vbox, FALSE, FALSE, 0);
-  table = gtk_table_new (8, 6, FALSE);
+  table = gtk_grid_new ();
   gtk_box_pack_start (GTK_BOX (top_right_vbox), table, FALSE, FALSE, 0);
-  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
-  gtk_table_set_col_spacings (GTK_TABLE (table), 12);
+  gtk_grid_set_row_spacing (GTK_GRID (table), 6);
+  gtk_grid_set_column_spacing (GTK_GRID (table), 12);
 
   make_label_spinbutton (colorsel, &priv->hue_spinbutton, _("_Hue:"), table, 0, 0, COLORSEL_HUE,
                          _("Position on the color wheel."));
   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (priv->hue_spinbutton), TRUE);
-  make_label_spinbutton (colorsel, &priv->sat_spinbutton, _("_Saturation:"), table, 0, 1, COLORSEL_SATURATION,
+  make_label_spinbutton (colorsel, &priv->sat_spinbutton, _("S_aturation:"), table, 0, 1, COLORSEL_SATURATION,
                          _("Intensity of the color."));
   make_label_spinbutton (colorsel, &priv->val_spinbutton, _("_Value:"), table, 0, 2, COLORSEL_VALUE,
                          _("Brightness of the color."));
@@ -461,11 +461,12 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
                          _("Amount of green light in the color."));
   make_label_spinbutton (colorsel, &priv->blue_spinbutton, _("_Blue:"), table, 6, 2, COLORSEL_BLUE,
                          _("Amount of blue light in the color."));
-  gtk_table_attach_defaults (GTK_TABLE (table), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), 0, 8, 3, 4);
+  gtk_grid_attach (GTK_GRID (table), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), 0, 3, 8, 1);
 
   priv->opacity_label = gtk_label_new_with_mnemonic (_("Op_acity:"));
-  gtk_misc_set_alignment (GTK_MISC (priv->opacity_label), 0.0, 0.5);
-  gtk_table_attach_defaults (GTK_TABLE (table), priv->opacity_label, 0, 1, 4, 5);
+  gtk_widget_set_halign (priv->opacity_label, GTK_ALIGN_START);
+  gtk_widget_set_valign (priv->opacity_label, GTK_ALIGN_CENTER);
+  gtk_grid_attach (GTK_GRID (table), priv->opacity_label, 0, 4, 1, 1);
   adjust = gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0);
   g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel);
   priv->opacity_slider = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjust);
@@ -477,7 +478,7 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
   g_signal_connect (adjust, "value-changed",
                     G_CALLBACK (adjustment_changed),
                     GINT_TO_POINTER (COLORSEL_OPACITY));
-  gtk_table_attach_defaults (GTK_TABLE (table), priv->opacity_slider, 1, 7, 4, 5);
+  gtk_grid_attach (GTK_GRID (table), priv->opacity_slider, 1, 4, 6, 1);
   priv->opacity_entry = gtk_entry_new ();
   gtk_widget_set_tooltip_text (priv->opacity_entry,
                         _("Transparency of the color."));
@@ -485,11 +486,12 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
 
   g_signal_connect (priv->opacity_entry, "activate",
                     G_CALLBACK (opacity_entry_changed), colorsel);
-  gtk_table_attach_defaults (GTK_TABLE (table), priv->opacity_entry, 7, 8, 4, 5);
+  gtk_grid_attach (GTK_GRID (table), priv->opacity_entry, 7, 4, 1, 1);
 
   label = gtk_label_new_with_mnemonic (_("Color _name:"));
-  gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 5, 6);
-  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  gtk_grid_attach (GTK_GRID (table), label, 0, 5, 1, 1);
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
   priv->hex_entry = gtk_entry_new ();
 
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->hex_entry);
@@ -506,7 +508,7 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
                           "in this entry."));
 
   gtk_entry_set_width_chars (GTK_ENTRY (priv->hex_entry), 7);
-  gtk_table_attach_defaults (GTK_TABLE (table), priv->hex_entry, 1, 5, 5, 6);
+  gtk_grid_attach (GTK_GRID (table), priv->hex_entry, 1, 5, 4, 1);
 
   focus_chain = g_list_append (focus_chain, priv->hue_spinbutton);
   focus_chain = g_list_append (focus_chain, priv->sat_spinbutton);
@@ -521,9 +523,9 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
   g_list_free (focus_chain);
 
   /* Set up the palette */
-  table = gtk_table_new (GTK_CUSTOM_PALETTE_HEIGHT, GTK_CUSTOM_PALETTE_WIDTH, TRUE);
-  gtk_table_set_row_spacings (GTK_TABLE (table), 1);
-  gtk_table_set_col_spacings (GTK_TABLE (table), 1);
+  table = gtk_grid_new ();
+  gtk_grid_set_row_spacing (GTK_GRID (table), 1);
+  gtk_grid_set_column_spacing (GTK_GRID (table), 1);
   for (i = 0; i < GTK_CUSTOM_PALETTE_WIDTH; i++)
     {
       for (j = 0; j < GTK_CUSTOM_PALETTE_HEIGHT; j++)
@@ -534,7 +536,8 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
   set_selected_palette (colorsel, 0, 0);
   priv->palette_frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   label = gtk_label_new_with_mnemonic (_("_Palette:"));
-  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
   gtk_box_pack_start (GTK_BOX (priv->palette_frame), label, FALSE, FALSE, 0);
 
   gtk_label_set_mnemonic_widget (GTK_LABEL (label),
@@ -1127,7 +1130,7 @@ palette_draw (GtkWidget *drawing_area,
   gdk_cairo_set_source_rgba (cr, &color);
   cairo_paint (cr);
 
-  if (gtk_widget_has_focus (drawing_area))
+  if (gtk_widget_has_visible_focus (drawing_area))
     {
       set_focus_line_attributes (drawing_area, cr, &focus_width);
 
@@ -1349,13 +1352,14 @@ palette_set_color (GtkWidget         *drawing_area,
                    gdouble           *color)
 {
   gdouble *new_color = g_new (double, 4);
-  GdkColor gdk_color;
+  GdkRGBA rgba;
 
-  gdk_color.red = UNSCALE (color[0]);
-  gdk_color.green = UNSCALE (color[1]);
-  gdk_color.blue = UNSCALE (color[2]);
+  rgba.red = color[0];
+  rgba.green = color[1];
+  rgba.blue = color[2];
+  rgba.alpha = 1;
 
-  gtk_widget_modify_bg (drawing_area, GTK_STATE_NORMAL, &gdk_color);
+  gtk_widget_override_background_color (drawing_area, GTK_STATE_FLAG_NORMAL, &rgba);
 
   if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set")) == 0)
     {
@@ -1502,8 +1506,7 @@ palette_press (GtkWidget      *drawing_area,
 
   gtk_widget_grab_focus (drawing_area);
 
-  if (event->button == 3 &&
-      event->type == GDK_BUTTON_PRESS)
+  if (gdk_event_triggers_context_menu ((GdkEvent *) event))
     {
       do_popup (colorsel, drawing_area, event->time);
       return TRUE;
@@ -2171,9 +2174,10 @@ make_label_spinbutton (GtkColorSelection *colorsel,
   label = gtk_label_new_with_mnemonic (text);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), *spinbutton);
 
-  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-  gtk_table_attach_defaults (GTK_TABLE (table), label, i, i+1, j, j+1);
-  gtk_table_attach_defaults (GTK_TABLE (table), *spinbutton, i+1, i+2, j, j+1);
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+  gtk_grid_attach (GTK_GRID (table), label, i, j, 1, 1);
+  gtk_grid_attach (GTK_GRID (table), *spinbutton, i+1, j, 1, 1);
 }
 
 static void
@@ -2191,7 +2195,7 @@ make_palette_frame (GtkColorSelection *colorsel,
   priv->custom_palette[i][j] = palette_new (colorsel);
   gtk_widget_set_size_request (priv->custom_palette[i][j], CUSTOM_PALETTE_ENTRY_WIDTH, CUSTOM_PALETTE_ENTRY_HEIGHT);
   gtk_container_add (GTK_CONTAINER (frame), priv->custom_palette[i][j]);
-  gtk_table_attach_defaults (GTK_TABLE (table), frame, i, i+1, j, j+1);
+  gtk_grid_attach (GTK_GRID (table), frame, i, j, 1, 1);
 }
 
 /* Set the palette entry [x][y] to be the currently selected one. */