]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcoloreditor.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcoloreditor.c
index 404b2b37c646e5e3fe3ae6f334cd5da6d0bf97df..8cbbf21541c48e7141fa7c7253da69d7653243ef 100644 (file)
  * 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 <http://www.gnu.org/licenses/>.
  */
 
 /* TODO
  * - touch
- * - accessible color names
  * - accessible relations for popups
- * - api to replace palette
  * - saving per-application (?)
- * - better checkmark
- * - use css for swatches
  * - better popup theming
  */
 
 #include "config.h"
 
-#include "gtkcoloreditor.h"
+#include "gtkcoloreditorprivate.h"
 
 #include "gtkcolorchooserprivate.h"
-#include "gtkcolorplane.h"
-#include "gtkcolorscale.h"
-#include "gtkcolorswatch.h"
+#include "gtkcolorplaneprivate.h"
+#include "gtkcolorscaleprivate.h"
+#include "gtkcolorswatchprivate.h"
 #include "gtkcolorutils.h"
 #include "gtkgrid.h"
 #include "gtkorientable.h"
@@ -44,8 +38,8 @@
 #include "gtkadjustment.h"
 #include "gtklabel.h"
 #include "gtkspinbutton.h"
-#include "gtkalignment.h"
 #include "gtkintl.h"
+#include "gtkstylecontext.h"
 
 #include <math.h>
 
@@ -352,14 +346,13 @@ create_popup (GtkColorEditor *editor,
 {
   GtkWidget *popup;
 
-  popup = gtk_alignment_new (0.5, 0.5, 0, 0);
-  gtk_alignment_set_padding (GTK_ALIGNMENT (popup), 12, 12, 12, 12);
-  gtk_style_context_add_class (gtk_widget_get_style_context (popup), GTK_STYLE_CLASS_TOOLTIP);
+  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 (popup);
-  gtk_widget_hide (popup);
+  gtk_widget_show_all (contents);
   gtk_widget_set_no_show_all (popup, TRUE);
 
   g_signal_connect (popup, "draw", G_CALLBACK (popup_draw), editor);
@@ -375,10 +368,10 @@ gtk_color_editor_init (GtkColorEditor *editor)
 {
   GtkWidget *grid;
   GtkWidget *slider;
-  GtkWidget *alignment;
   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,
@@ -405,9 +398,18 @@ gtk_color_editor_init (GtkColorEditor *editor)
 
   /* Construct the main UI */
   editor->priv->swatch = swatch = gtk_color_swatch_new ();
-  gtk_widget_set_sensitive (swatch, FALSE);
+  gtk_color_swatch_set_selectable (GTK_COLOR_SWATCH (editor->priv->swatch), FALSE);
+  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);
@@ -439,25 +441,31 @@ gtk_color_editor_init (GtkColorEditor *editor)
   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 alignment is necessary so we have room to the sides
+  /* This extra margin is necessary so we have room to the sides
    * to place the popups as desired
    */
-  alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
-  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 30, 30);
-  gtk_container_add (GTK_CONTAINER (alignment), grid);
+  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), alignment);
+  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);
@@ -469,6 +477,9 @@ gtk_color_editor_init (GtkColorEditor *editor)
 
   /* 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 ();
@@ -481,6 +492,9 @@ gtk_color_editor_init (GtkColorEditor *editor)
 
   /* 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 ();