]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkentry.c
Minor documentation improvements
[~andy/gtk] / gtk / gtkentry.c
index 69af6639ae9c88b9199a491cbaf2de51cb6d0dfb..4dacb7d83c78f5724749348c823bafa25d2fb2b3 100644 (file)
@@ -33,7 +33,6 @@
 #include <math.h>
 #include <string.h>
 
-#include "gdk/gdkkeysyms.h"
 #include "gtkalignment.h"
 #include "gtkbindings.h"
 #include "gtkcelleditable.h"
 #include "gtkwindow.h"
 #include "gtktreeview.h"
 #include "gtktreeselection.h"
+#include "gtktypebuiltins.h"
 #include "gtkprivate.h"
 #include "gtkentryprivate.h"
 #include "gtkcelllayout.h"
 #include "gtktooltip.h"
 #include "gtkiconfactory.h"
 #include "gtkicontheme.h"
-
+#include "gtkwidgetprivate.h"
+#include "gtkstylecontextprivate.h"
 
 /**
  * SECTION:gtkentry
@@ -514,7 +515,6 @@ static void         gtk_entry_draw_cursor              (GtkEntry       *entry,
 static PangoLayout *gtk_entry_ensure_layout            (GtkEntry       *entry,
                                                         gboolean        include_preedit);
 static void         gtk_entry_reset_layout             (GtkEntry       *entry);
-static void         gtk_entry_queue_draw               (GtkEntry       *entry);
 static void         gtk_entry_recompute                (GtkEntry       *entry);
 static gint         gtk_entry_find_position            (GtkEntry       *entry,
                                                        gint            x);
@@ -1152,7 +1152,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                                    g_param_spec_boolean ("primary-icon-activatable",
                                                          P_("Primary icon activatable"),
                                                          P_("Whether the primary icon is activatable"),
-                                                         FALSE,
+                                                         TRUE,
                                                          GTK_PARAM_READWRITE));
   
   /**
@@ -1173,7 +1173,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                                    g_param_spec_boolean ("secondary-icon-activatable",
                                                          P_("Secondary icon activatable"),
                                                          P_("Whether the secondary icon is activatable"),
-                                                         FALSE,
+                                                         TRUE,
                                                          GTK_PARAM_READWRITE));
   
   
@@ -1865,7 +1865,6 @@ gtk_entry_set_property (GObject         *object,
 {
   GtkEntry *entry = GTK_ENTRY (object);
   GtkEntryPrivate *priv = entry->priv;
-  GtkWidget *widget;
 
   switch (prop_id)
     {
@@ -1879,7 +1878,8 @@ gtk_entry_set_property (GObject         *object,
 
         if (new_value != priv->editable)
          {
-            widget = GTK_WIDGET (entry);
+            GtkWidget *widget = GTK_WIDGET (entry);
+
            if (!new_value)
              {
                _gtk_entry_reset_im_context (entry);
@@ -1895,7 +1895,7 @@ gtk_entry_set_property (GObject         *object,
            if (new_value && gtk_widget_has_focus (widget))
              gtk_im_context_focus_in (priv->im_context);
 
-           gtk_entry_queue_draw (entry);
+           gtk_widget_queue_draw (widget);
          }
       }
       break;
@@ -3242,55 +3242,6 @@ gtk_entry_size_allocate (GtkWidget     *widget,
     }
 }
 
-/* Kudos to the gnome-panel guys. */
-static void
-colorshift_pixbuf (GdkPixbuf *dest,
-                   GdkPixbuf *src,
-                   gint       shift)
-{
-  gint i, j;
-  gint width, height, has_alpha, src_rowstride, dest_rowstride;
-  guchar *target_pixels;
-  guchar *original_pixels;
-  guchar *pix_src;
-  guchar *pix_dest;
-  int val;
-  guchar r, g, b;
-
-  has_alpha       = gdk_pixbuf_get_has_alpha (src);
-  width           = gdk_pixbuf_get_width (src);
-  height          = gdk_pixbuf_get_height (src);
-  src_rowstride   = gdk_pixbuf_get_rowstride (src);
-  dest_rowstride  = gdk_pixbuf_get_rowstride (dest);
-  original_pixels = gdk_pixbuf_get_pixels (src);
-  target_pixels   = gdk_pixbuf_get_pixels (dest);
-
-  for (i = 0; i < height; i++)
-    {
-      pix_dest = target_pixels   + i * dest_rowstride;
-      pix_src  = original_pixels + i * src_rowstride;
-
-      for (j = 0; j < width; j++)
-        {
-          r = *(pix_src++);
-          g = *(pix_src++);
-          b = *(pix_src++);
-
-          val = r + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
-
-          val = g + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
-
-          val = b + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
-
-          if (has_alpha)
-            *(pix_dest++) = *(pix_src++);
-        }
-    }
-}
-
 static gboolean
 should_prelight (GtkEntry             *entry,
                  GtkEntryIconPosition  icon_pos)
@@ -3299,7 +3250,7 @@ should_prelight (GtkEntry             *entry,
   EntryIconInfo *icon_info = priv->icons[icon_pos];
   gboolean prelight;
 
-  if (!icon_info) 
+  if (!icon_info)
     return FALSE;
 
   if (icon_info->nonactivatable && icon_info->target_list == NULL)
@@ -3325,6 +3276,9 @@ draw_icon (GtkWidget            *widget,
   EntryIconInfo *icon_info = priv->icons[icon_pos];
   GdkPixbuf *pixbuf;
   gint x, y, width, height;
+  GtkStyleContext *context;
+  GtkIconSource *icon_source;
+  GtkStateFlags state;
 
   if (!icon_info)
     return;
@@ -3360,28 +3314,23 @@ draw_icon (GtkWidget            *widget,
   x = (width  - gdk_pixbuf_get_width (pixbuf)) / 2;
   y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
 
-  if (!gtk_widget_is_sensitive (widget) ||
-      icon_info->insensitive)
-    {
-      GdkPixbuf *temp_pixbuf;
+  icon_source = gtk_icon_source_new ();
+  gtk_icon_source_set_pixbuf (icon_source, pixbuf);
+  gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
 
-      temp_pixbuf = gdk_pixbuf_copy (pixbuf);
-      gdk_pixbuf_saturate_and_pixelate (pixbuf,
-                                        temp_pixbuf,
-                                        0.8f,
-                                        TRUE);
-      g_object_unref (pixbuf);
-      pixbuf = temp_pixbuf;
-    }
+  state = 0;
+  if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
+    state |= GTK_STATE_FLAG_INSENSITIVE;
   else if (icon_info->prelight)
-    {
-      GdkPixbuf *temp_pixbuf;
+    state |= GTK_STATE_FLAG_PRELIGHT;
 
-      temp_pixbuf = gdk_pixbuf_copy (pixbuf);
-      colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
-      g_object_unref (pixbuf);
-      pixbuf = temp_pixbuf;
-    }
+  context = gtk_widget_get_style_context (widget);
+  gtk_style_context_save (context);
+  gtk_style_context_set_state (context, state);
+  pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
+  gtk_style_context_restore (context);
+
+  gtk_icon_source_free (icon_source);
 
   gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
   cairo_paint (cr);
@@ -3397,15 +3346,12 @@ gtk_entry_draw_frame (GtkWidget       *widget,
 {
   GtkEntry *entry = GTK_ENTRY (widget);
   GtkEntryPrivate *priv = entry->priv;
-  GdkWindow *window;
   gint x = 0, y = 0, width, height;
   GtkAllocation allocation;
   gint frame_x, frame_y;
 
   cairo_save (cr);
 
-  window = gtk_widget_get_window (widget);
-
   get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
   gtk_widget_get_allocation (widget, &allocation);
 
@@ -3554,8 +3500,8 @@ gtk_entry_draw (GtkWidget *widget,
   context = gtk_widget_get_style_context (widget);
   state = gtk_widget_get_state_flags (widget);
 
-  if (gtk_widget_has_focus (widget))
-    state |= GTK_STATE_FLAG_FOCUSED;
+  gtk_style_context_save (context);
+  gtk_style_context_set_state (context, state);
 
   if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
     {
@@ -3598,6 +3544,8 @@ gtk_entry_draw (GtkWidget *widget,
         }
     }
 
+  gtk_style_context_restore (context);
+
   return FALSE;
 }
 
@@ -3985,7 +3933,6 @@ gtk_entry_motion_notify (GtkWidget      *widget,
   GtkEntry *entry = GTK_ENTRY (widget);
   GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = NULL;
-  GdkDragContext *context;
   gint tmp_pos;
   gint i;
 
@@ -4008,11 +3955,11 @@ gtk_entry_motion_notify (GtkWidget      *widget,
             {
               icon_info->in_drag = TRUE;
               icon_info->pressed = FALSE;
-              context = gtk_drag_begin (widget,
-                                        icon_info->target_list,
-                                        icon_info->actions,
-                                        1,
-                                        (GdkEvent*)event);
+              gtk_drag_begin (widget,
+                              icon_info->target_list,
+                              icon_info->actions,
+                              1,
+                              (GdkEvent*)event);
             }
 
           return TRUE;
@@ -4022,7 +3969,7 @@ gtk_entry_motion_notify (GtkWidget      *widget,
   if (priv->mouse_cursor_obscured)
     {
       GdkCursor *cursor;
-      
+
       cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
       gdk_window_set_cursor (priv->text_area, cursor);
       g_object_unref (cursor);
@@ -4521,6 +4468,8 @@ gtk_entry_style_updated (GtkWidget *widget)
   gint focus_width;
   gboolean interior_focus;
 
+  GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
+
   gtk_widget_style_get (widget,
                        "focus-line-width", &focus_width,
                        "interior-focus", &interior_focus,
@@ -5422,8 +5371,8 @@ recompute_idle_func (gpointer data)
   if (gtk_widget_has_screen (GTK_WIDGET (entry)))
     {
       gtk_entry_adjust_scroll (entry);
-      gtk_entry_queue_draw (entry);
-      
+      gtk_widget_queue_draw (GTK_WIDGET (entry));
+
       update_im_cursor_location (entry);
     }
 
@@ -5857,7 +5806,8 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
     }
   else /* overwrite_mode */
     {
-      GdkColor cursor_color;
+      GtkStyleContext *context;
+      GdkRGBA cursor_color;
       GdkRectangle rect;
       gint x, y;
 
@@ -5870,18 +5820,18 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
       rect.width = PANGO_PIXELS (cursor_rect.width);
       rect.height = PANGO_PIXELS (cursor_rect.height);
 
-      _gtk_widget_get_cursor_color (widget, &cursor_color);
-      gdk_cairo_set_source_color (cr, &cursor_color);
+      context = gtk_widget_get_style_context (widget);
+
+      _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
+      gdk_cairo_set_source_rgba (cr, &cursor_color);
       gdk_cairo_rectangle (cr, &rect);
       cairo_fill (cr);
 
       if (!block_at_line_end)
         {
-          GtkStyleContext *context;
           GtkStateFlags state;
           GdkRGBA color;
 
-          context = gtk_widget_get_style_context (widget);
           state = gtk_widget_get_state_flags (widget);
           gtk_style_context_get_background_color (context, state, &color);
 
@@ -5896,14 +5846,6 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
     }
 }
 
-static void
-gtk_entry_queue_draw (GtkEntry *entry)
-{
-  if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
-    gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
-                                NULL, FALSE);
-}
-
 void
 _gtk_entry_reset_im_context (GtkEntry *entry)
 {
@@ -6169,6 +6111,8 @@ gtk_entry_move_adjustments (GtkEntry *entry)
   GtkAdjustment *adjustment;
   PangoContext *context;
   PangoFontMetrics *metrics;
+  GtkStyleContext *style_context;
+  GtkStateFlags state;
   gint x, layout_x, border_x, border_y;
   gint char_width;
 
@@ -6186,8 +6130,11 @@ gtk_entry_move_adjustments (GtkEntry *entry)
 
   /* Approximate width of a char, so user can see what is ahead/behind */
   context = gtk_widget_get_pango_context (widget);
-  metrics = pango_context_get_metrics (context, 
-                                       gtk_widget_get_style (widget)->font_desc,
+  style_context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+
+  metrics = pango_context_get_metrics (context,
+                                       gtk_style_context_get_font (style_context, state),
                                       pango_context_get_language (context));
   char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
 
@@ -6666,7 +6613,7 @@ gtk_entry_ensure_pixbuf (GtkEntry             *entry,
         {
           icon_theme = gtk_icon_theme_get_for_screen (screen);
           settings = gtk_settings_get_for_screen (screen);
-          
+
           gtk_icon_size_lookup_for_settings (settings,
                                              GTK_ICON_SIZE_MENU,
                                              &width, &height);
@@ -6855,7 +6802,7 @@ gtk_entry_set_buffer (GtkEntry       *entry,
 /**
  * gtk_entry_get_text_area:
  * @entry: a #GtkEntry
- * @text_area: Return location for the text area.
+ * @text_area: (out): Return location for the text area.
  *
  * Gets the area where the entry's text is drawn. This function is
  * useful when drawing something to the entry in a draw callback.
@@ -7526,8 +7473,8 @@ gtk_entry_text_index_to_layout_index (GtkEntry *entry,
 /**
  * gtk_entry_get_layout_offsets:
  * @entry: a #GtkEntry
- * @x: (allow-none): location to store X offset of layout, or %NULL
- * @y: (allow-none): location to store Y offset of layout, or %NULL
+ * @x: (out) (allow-none): location to store X offset of layout, or %NULL
+ * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
  *
  *
  * Obtains the position of the #PangoLayout used to render text
@@ -7954,7 +7901,7 @@ gtk_entry_get_icon_activatable (GtkEntry             *entry,
   priv = entry->priv;
   icon_info = priv->icons[icon_pos];
 
-  return (icon_info != NULL && !icon_info->nonactivatable);
+  return (!icon_info || !icon_info->nonactivatable);
 }
 
 /**
@@ -8334,7 +8281,7 @@ gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
  * gtk_entry_get_icon_area:
  * @entry: A #GtkEntry
  * @icon_pos: Icon position
- * @icon_area: Return location for the icon's area
+ * @icon_area: (out): Return location for the icon's area
  *
  * Gets the area where entry's icon at @icon_pos is drawn.
  * This function is useful when drawing something to the
@@ -9632,6 +9579,8 @@ keypress_completion_out:
     {
       GtkTreeIter iter;
       GtkTreeModel *model = NULL;
+      GtkTreeModel *child_model;
+      GtkTreeIter child_iter;
       GtkTreeSelection *sel;
       gboolean retval = TRUE;
 
@@ -9645,9 +9594,11 @@ keypress_completion_out:
           sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
           if (gtk_tree_selection_get_selected (sel, &model, &iter))
             {
+              gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
+              child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
               g_signal_handler_block (widget, completion->priv->changed_id);
               g_signal_emit_by_name (completion, "match-selected",
-                                     model, &iter, &entry_set);
+                                     child_model, &child_iter, &entry_set);
               g_signal_handler_unblock (widget, completion->priv->changed_id);
 
               if (!entry_set)
@@ -10237,7 +10188,7 @@ keymap_state_changed (GdkKeymap *keymap,
  * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
  * is supposed to behave like a GtkCellEditable when placed in a combo box.
  *
- * I.e take up it's allocation and get GtkEntry->is_cell_renderer = TRUE.
+ * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
  *
  */
 void