]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcellrenderer.c
Translation updated by Ivar Smolin.
[~andy/gtk] / gtk / gtkcellrenderer.c
index dd721233a3f3b904ef9e59964e48d3320ba17d6b..596f6715f701ce5bf39b49a427f48907535fd8a8 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
 #include "gtkcellrenderer.h"
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
+#include "gtkprivate.h"
 #include "gtktreeprivate.h"
+#include "gtkalias.h"
 
 static void gtk_cell_renderer_init       (GtkCellRenderer      *cell);
 static void gtk_cell_renderer_class_init (GtkCellRendererClass *class);
@@ -49,6 +52,7 @@ enum {
   PROP_ZERO,
   PROP_MODE,
   PROP_VISIBLE,
+  PROP_SENSITIVE,
   PROP_XALIGN,
   PROP_YALIGN,
   PROP_XPAD,
@@ -65,6 +69,7 @@ enum {
 /* Signal IDs */
 enum {
   EDITING_CANCELED,
+  EDITING_STARTED,
   LAST_SIGNAL
 };
 
@@ -110,6 +115,10 @@ gtk_cell_renderer_init (GtkCellRenderer *cell)
   cell->yalign = 0.5;
   cell->xpad = 0;
   cell->ypad = 0;
+  cell->sensitive = TRUE;
+  cell->is_expander = FALSE;
+  cell->is_expanded = FALSE;
+  cell->editing = FALSE;
 }
 
 static void
@@ -125,16 +134,16 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
 
   /**
    * GtkCellRenderer::editing-canceled:
+   * @renderer: the object which received the signal
    *
    * This signal gets emitted when the user cancels the process of editing a
    * cell.  For example, an editable cell renderer could be written to cancel
-   * editing when the user presses Escape.
+   * editing when the user presses Escape. 
    *
    * See also: gtk_cell_renderer_editing_canceled()
    *
    * Since: 2.4
    */
-
   cell_renderer_signals[EDITING_CANCELED] =
     g_signal_new ("editing-canceled",
                  G_OBJECT_CLASS_TYPE (object_class),
@@ -144,6 +153,53 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                  _gtk_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
 
+  /**
+   * GtkCellRenderer::editing-started:
+   * @renderer: the object which received the signal
+   * @editable: the #GtkCellEditable
+   * @path: the path identifying the edited cell
+   *
+   * This signal gets emitted when a cell starts to be edited.
+   * The indended use of this signal is to do special setup
+   * on @editable, e.g. adding a #GtkEntryCompletion or setting
+   * up additional columns in a #GtkComboBox.
+   *
+   * Note that GTK+ doesn't guarantee that cell renderers will
+   * continue to use the same kind of widget for editing in future
+   * releases, therefore you should check the type of @editable
+   * before doing any specific setup, as in the following example:
+   *
+   * <informalexample><programlisting>
+   * static void
+   * text_editing_started (GtkCellRenderer *cell,
+   *                       GtkCellEditable *editable,
+   *                       const gchar     *path,
+   *                       gpointer         data)
+   * {
+   *   if (GTK_IS_ENTRY (editable)) 
+   *     {
+   *       GtkEntry *entry = GTK_ENTRY (editable);
+   *       <!-- -->
+   *       /<!-- -->* ... create a GtkEntryCompletion *<!-- -->/
+   *       <!-- -->
+   *       gtk_entry_set_completion (entry, completion);
+   *     }
+   * }
+   * </programlisting></informalexample>
+   *
+   * Since: 2.6
+   */
+  cell_renderer_signals[EDITING_STARTED] =
+    g_signal_new ("editing-started",
+                 G_OBJECT_CLASS_TYPE (object_class),
+                 G_SIGNAL_RUN_FIRST,
+                 G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__OBJECT_STRING,
+                 G_TYPE_NONE, 2,
+                 GTK_TYPE_CELL_EDITABLE,
+                 G_TYPE_STRING);
+
   g_object_class_install_property (object_class,
                                   PROP_MODE,
                                   g_param_spec_enum ("mode",
@@ -151,8 +207,7 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                                                      P_("Editable mode of the CellRenderer"),
                                                      GTK_TYPE_CELL_RENDERER_MODE,
                                                      GTK_CELL_RENDERER_MODE_INERT,
-                                                     G_PARAM_READABLE |
-                                                     G_PARAM_WRITABLE));
+                                                     GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_VISIBLE,
@@ -160,8 +215,14 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                                                         P_("visible"),
                                                         P_("Display the cell"),
                                                         TRUE,
-                                                        G_PARAM_READABLE |
-                                                        G_PARAM_WRITABLE));
+                                                        GTK_PARAM_READWRITE));
+  g_object_class_install_property (object_class,
+                                  PROP_SENSITIVE,
+                                  g_param_spec_boolean ("sensitive",
+                                                        P_("Sensitive"),
+                                                        P_("Display the cell sensitive"),
+                                                        TRUE,
+                                                        GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_XALIGN,
@@ -170,9 +231,8 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                                                       P_("The x-align"),
                                                       0.0,
                                                       1.0,
-                                                      0.0,
-                                                      G_PARAM_READABLE |
-                                                      G_PARAM_WRITABLE));
+                                                      0.5,
+                                                      GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_YALIGN,
@@ -182,8 +242,7 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                                                       0.0,
                                                       1.0,
                                                       0.5,
-                                                      G_PARAM_READABLE |
-                                                      G_PARAM_WRITABLE));
+                                                      GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_XPAD,
@@ -191,10 +250,9 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                                                      P_("xpad"),
                                                      P_("The xpad"),
                                                      0,
-                                                     100,
-                                                     2,
-                                                     G_PARAM_READABLE |
-                                                     G_PARAM_WRITABLE));
+                                                     G_MAXUINT,
+                                                     0,
+                                                     GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_YPAD,
@@ -202,10 +260,9 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                                                      P_("ypad"),
                                                      P_("The ypad"),
                                                      0,
-                                                     100,
-                                                     2,
-                                                     G_PARAM_READABLE |
-                                                     G_PARAM_WRITABLE));
+                                                     G_MAXUINT,
+                                                     0,
+                                                     GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_WIDTH,
@@ -213,10 +270,9 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                                                     P_("width"),
                                                     P_("The fixed width"),
                                                     -1,
-                                                    100,
+                                                    G_MAXINT,
                                                     -1,
-                                                    G_PARAM_READABLE |
-                                                    G_PARAM_WRITABLE));
+                                                    GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_HEIGHT,
@@ -224,50 +280,47 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                                                     P_("height"),
                                                     P_("The fixed height"),
                                                     -1,
-                                                    100,
+                                                    G_MAXINT,
                                                     -1,
-                                                    G_PARAM_READABLE |
-                                                    G_PARAM_WRITABLE));
+                                                    GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_IS_EXPANDER,
-                                  g_param_spec_boolean ("is_expander",
+                                  g_param_spec_boolean ("is-expander",
                                                         P_("Is Expander"),
                                                         P_("Row has children"),
                                                         FALSE,
-                                                        G_PARAM_READABLE |
-                                                        G_PARAM_WRITABLE));
+                                                        GTK_PARAM_READWRITE));
 
 
   g_object_class_install_property (object_class,
                                   PROP_IS_EXPANDED,
-                                  g_param_spec_boolean ("is_expanded",
+                                  g_param_spec_boolean ("is-expanded",
                                                         P_("Is Expanded"),
                                                         P_("Row is an expander row, and is expanded"),
                                                         FALSE,
-                                                        G_PARAM_READABLE |
-                                                        G_PARAM_WRITABLE));
+                                                        GTK_PARAM_READWRITE));
 
   g_object_class_install_property (object_class,
                                   PROP_CELL_BACKGROUND,
-                                  g_param_spec_string ("cell_background",
+                                  g_param_spec_string ("cell-background",
                                                        P_("Cell background color name"),
                                                        P_("Cell background color as a string"),
                                                        NULL,
-                                                       G_PARAM_WRITABLE));
+                                                       GTK_PARAM_WRITABLE));
 
   g_object_class_install_property (object_class,
                                   PROP_CELL_BACKGROUND_GDK,
-                                  g_param_spec_boxed ("cell_background_gdk",
+                                  g_param_spec_boxed ("cell-background-gdk",
                                                       P_("Cell background color"),
                                                       P_("Cell background color as a GdkColor"),
                                                       GDK_TYPE_COLOR,
-                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                      GTK_PARAM_READWRITE));
 
 
-#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
+#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, GTK_PARAM_READWRITE))
 
-  ADD_SET_PROP ("cell_background_set", PROP_CELL_BACKGROUND_SET,
+  ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
                 P_("Cell background set"),
                 P_("Whether this tag affects the cell background color"));
 
@@ -291,6 +344,9 @@ gtk_cell_renderer_get_property (GObject     *object,
     case PROP_VISIBLE:
       g_value_set_boolean (value, cell->visible);
       break;
+    case PROP_SENSITIVE:
+      g_value_set_boolean (value, cell->sensitive);
+      break;
     case PROP_XALIGN:
       g_value_set_float (value, cell->xalign);
       break;
@@ -353,6 +409,9 @@ gtk_cell_renderer_set_property (GObject      *object,
     case PROP_VISIBLE:
       cell->visible = g_value_get_boolean (value);
       break;
+    case PROP_SENSITIVE:
+      cell->sensitive = g_value_get_boolean (value);
+      break;
     case PROP_XALIGN:
       cell->xalign = g_value_get_float (value);
       break;
@@ -388,7 +447,7 @@ gtk_cell_renderer_set_property (GObject      *object,
        else
          g_warning ("Don't know color `%s'", g_value_get_string (value));
 
-       g_object_notify (object, "cell_background_gdk");
+       g_object_notify (object, "cell-background-gdk");
       }
       break;
     case PROP_CELL_BACKGROUND_GDK:
@@ -414,7 +473,7 @@ set_cell_bg_color (GtkCellRenderer *cell,
       if (!cell->cell_background_set)
         {
          cell->cell_background_set = TRUE;
-         g_object_notify (G_OBJECT (cell), "cell_background_set");
+         g_object_notify (G_OBJECT (cell), "cell-background-set");
        }
 
       priv->cell_background.red = color->red;
@@ -426,7 +485,7 @@ set_cell_bg_color (GtkCellRenderer *cell,
       if (cell->cell_background_set)
         {
          cell->cell_background_set = FALSE;
-         g_object_notify (G_OBJECT (cell), "cell_background_set");
+         g_object_notify (G_OBJECT (cell), "cell-background-set");
        }
     }
 }
@@ -521,19 +580,13 @@ gtk_cell_renderer_render (GtkCellRenderer     *cell,
 
   if (cell->cell_background_set && !selected)
     {
-      GdkColor color;
-      GdkGC *gc;
-
-      color.red = priv->cell_background.red;
-      color.green = priv->cell_background.green;
-      color.blue = priv->cell_background.blue;
-
-      gc = gdk_gc_new (window);
-      gdk_gc_set_rgb_fg_color (gc, &color);
-      gdk_draw_rectangle (window, gc, TRUE,
-                          background_area->x, background_area->y,
-                          background_area->width, background_area->height);
-      g_object_unref (gc);
+      cairo_t *cr = gdk_cairo_create (window);
+
+      gdk_cairo_rectangle (cr, background_area);
+      gdk_cairo_set_source_color (cr, &priv->cell_background);
+      cairo_fill (cr);
+      
+      cairo_destroy (cr);
     }
 
   GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
@@ -611,6 +664,8 @@ gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
                                 GtkCellRendererState  flags)
 
 {
+  GtkCellEditable *editable;
+
   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
 
   if (cell->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
@@ -619,14 +674,21 @@ gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
   if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
     return NULL;
 
-  
-  return GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
-                                                           event,
-                                                           widget,
-                                                           path,
-                                                           background_area,
-                                                           cell_area,
-                                                           flags);
+  editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
+                                                               event,
+                                                               widget,
+                                                               path,
+                                                               background_area,
+                                                               cell_area,
+                                                               flags);
+
+  g_signal_emit (cell, 
+                cell_renderer_signals[EDITING_STARTED], 0,
+                editable, path);
+
+  cell->editing = TRUE;
+
+  return editable;
 }
 
 /**
@@ -696,11 +758,41 @@ gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
  * changes were not committed.
  *
  * Since: 2.4
+ * Deprecated: Use gtk_cell_renderer_stop_editing() instead
  **/
 void
 gtk_cell_renderer_editing_canceled (GtkCellRenderer *cell)
 {
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
-  g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
+  gtk_cell_renderer_stop_editing (cell, TRUE);
 }
+
+/**
+ * gtk_cell_renderer_stop_editing:
+ * @cell: A #GtkCellRenderer
+ * @canceled: %TRUE if the editing has been canceled
+ * 
+ * Informs the cell renderer that the editing is stopped.
+ * If @canceled is %TRUE, the cell renderer will emit the "editing-canceled" 
+ * signal. This function should be called by cell renderer implementations 
+ * in response to the "editing-done" signal of #GtkCellEditable.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
+                               gboolean         canceled)
+{
+  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+
+  if (cell->editing)
+    {
+      cell->editing = FALSE;
+      if (canceled)
+       g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
+    }
+}
+
+#define __GTK_CELL_RENDERER_C__
+#include "gtkaliasdef.c"