]> Pileus Git - ~andy/gtk/commitdiff
Move gtk_draw_insertion_cursor out of gtkstyle.[hc]
authorMatthias Clasen <mclasen@redhat.com>
Wed, 2 Nov 2011 03:50:19 +0000 (23:50 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 2 Nov 2011 03:51:18 +0000 (23:51 -0400)
This function does not use GtkStyle at all and is not deprecated.

gtk/gtkstyle.c
gtk/gtkstyle.h
gtk/gtkstylecontext.c
gtk/gtkstylecontext.h

index 06ebfe48b2b9e153a6dd6db52d481e921e9e63f1..dcb222ac1dca421a690db9bf1e58f59fa7f73420 100644 (file)
@@ -3979,93 +3979,3 @@ gtk_paint_spinner (GtkStyle           *style,
 
   cairo_restore (cr);
 }
-
-/**
- * gtk_draw_insertion_cursor:
- * @widget:  a #GtkWidget
- * @cr: cairo context to draw to
- * @location: location where to draw the cursor (@location->width is ignored)
- * @is_primary: if the cursor should be the primary cursor color.
- * @direction: whether the cursor is left-to-right or
- *             right-to-left. Should never be #GTK_TEXT_DIR_NONE
- * @draw_arrow: %TRUE to draw a directional arrow on the
- *        cursor. Should be %FALSE unless the cursor is split.
- *
- * Draws a text caret on @cr at @location. This is not a style function
- * but merely a convenience function for drawing the standard cursor shape.
- *
- * Since: 3.0
- */
-void
-gtk_draw_insertion_cursor (GtkWidget          *widget,
-                           cairo_t            *cr,
-                           const GdkRectangle *location,
-                           gboolean            is_primary,
-                           GtkTextDirection    direction,
-                           gboolean            draw_arrow)
-{
-  gint stem_width;
-  gint arrow_width;
-  gint x, y;
-  gfloat cursor_aspect_ratio;
-  gint offset;
-  GtkStyleContext *context;
-  GdkRGBA primary_color;
-  GdkRGBA secondary_color;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (cr != NULL);
-  g_return_if_fail (location != NULL);
-  g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
-
-  context = gtk_widget_get_style_context (widget);
-
-  _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
-  gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
-
-  /* When changing the shape or size of the cursor here,
-   * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
-   */
-
-  gtk_style_context_get_style (context,
-                               "cursor-aspect-ratio", &cursor_aspect_ratio,
-                               NULL);
-
-  stem_width = location->height * cursor_aspect_ratio + 1;
-  arrow_width = stem_width + 1;
-
-  /* put (stem_width % 2) on the proper side of the cursor */
-  if (direction == GTK_TEXT_DIR_LTR)
-    offset = stem_width / 2;
-  else
-    offset = stem_width - stem_width / 2;
-
-  cairo_rectangle (cr,
-                   location->x - offset, location->y,
-                   stem_width, location->height);
-  cairo_fill (cr);
-
-  if (draw_arrow)
-    {
-      if (direction == GTK_TEXT_DIR_RTL)
-        {
-          x = location->x - offset - 1;
-          y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
-
-          cairo_move_to (cr, x, y + 1);
-          cairo_line_to (cr, x - arrow_width, y + arrow_width);
-          cairo_line_to (cr, x, y + 2 * arrow_width);
-          cairo_fill (cr);
-        }
-      else if (direction == GTK_TEXT_DIR_LTR)
-        {
-          x = location->x + stem_width - offset;
-          y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
-
-          cairo_move_to (cr, x, y + 1);
-          cairo_line_to (cr, x + arrow_width, y + arrow_width);
-          cairo_line_to (cr, x, y + 2 * arrow_width);
-          cairo_fill (cr);
-        }
-    }
-}
index ff8a7684ab8bae8475b9cb723a246656dc92ec98..f2b698104228808d582f3ae16c5e2f9d8c7b16e7 100644 (file)
@@ -668,13 +668,6 @@ void          _gtk_style_shade               (const GdkColor     *a,
                                               GdkColor           *b,
                                               gdouble             k);
 
-void   gtk_draw_insertion_cursor    (GtkWidget          *widget,
-                                     cairo_t            *cr,
-                                     const GdkRectangle *location,
-                                     gboolean            is_primary,
-                                     GtkTextDirection    direction,
-                                     gboolean            draw_arrow);
-
 gboolean   gtk_style_has_context    (GtkStyle *style);
 
 
index 97e9f307f2cc0bdf53df7a2b763323438885134c..e67c4cca383eb19af9baa9943f7580414cb0cf0f 100644 (file)
@@ -3043,7 +3043,7 @@ _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context)
 
 void
 _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
-                                            GtkWidget       *widget)
+                                             GtkWidget       *widget)
 {
   GtkStyleContextPrivate *priv;
   GSList *l;
@@ -3081,9 +3081,9 @@ _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
 
           rect = &g_array_index (info->rectangles, cairo_rectangle_int_t, i);
 
-         /* These are widget relative coordinates,
-          * so have them inverted to be window relative
-          */
+          /* These are widget relative coordinates,
+           * so have them inverted to be window relative
+           */
           rect->x -= rel_x;
           rect->y -= rel_y;
 
@@ -4294,7 +4294,7 @@ gtk_render_icon_pixbuf (GtkStyleContext     *context,
 void
 gtk_render_icon (GtkStyleContext *context,
                  cairo_t         *cr,
-                GdkPixbuf       *pixbuf,
+                 GdkPixbuf       *pixbuf,
                  gdouble          x,
                  gdouble          y)
 {
@@ -4317,7 +4317,97 @@ gtk_render_icon (GtkStyleContext *context,
   _gtk_theming_engine_set_context (priv->theming_engine, context);
   engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
 
-  cairo_restore (cr);  
+  cairo_restore (cr);
+}
+
+/**
+ * gtk_draw_insertion_cursor:
+ * @widget:  a #GtkWidget
+ * @cr: cairo context to draw to
+ * @location: location where to draw the cursor (@location->width is ignored)
+ * @is_primary: if the cursor should be the primary cursor color.
+ * @direction: whether the cursor is left-to-right or
+ *             right-to-left. Should never be #GTK_TEXT_DIR_NONE
+ * @draw_arrow: %TRUE to draw a directional arrow on the
+ *        cursor. Should be %FALSE unless the cursor is split.
+ *
+ * Draws a text caret on @cr at @location. This is not a style function
+ * but merely a convenience function for drawing the standard cursor shape.
+ *
+ * Since: 3.0
+ */
+void
+gtk_draw_insertion_cursor (GtkWidget          *widget,
+                           cairo_t            *cr,
+                           const GdkRectangle *location,
+                           gboolean            is_primary,
+                           GtkTextDirection    direction,
+                           gboolean            draw_arrow)
+{
+  gint stem_width;
+  gint arrow_width;
+  gint x, y;
+  gfloat cursor_aspect_ratio;
+  gint offset;
+  GtkStyleContext *context;
+  GdkRGBA primary_color;
+  GdkRGBA secondary_color;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (cr != NULL);
+  g_return_if_fail (location != NULL);
+  g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
+
+  context = gtk_widget_get_style_context (widget);
+
+  _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
+  gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
+
+  /* When changing the shape or size of the cursor here,
+   * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
+   */
+
+  gtk_style_context_get_style (context,
+                               "cursor-aspect-ratio", &cursor_aspect_ratio,
+                               NULL);
+
+  stem_width = location->height * cursor_aspect_ratio + 1;
+  arrow_width = stem_width + 1;
+
+  /* put (stem_width % 2) on the proper side of the cursor */
+  if (direction == GTK_TEXT_DIR_LTR)
+    offset = stem_width / 2;
+  else
+    offset = stem_width - stem_width / 2;
+
+  cairo_rectangle (cr,
+                   location->x - offset, location->y,
+                   stem_width, location->height);
+  cairo_fill (cr);
+
+  if (draw_arrow)
+    {
+      if (direction == GTK_TEXT_DIR_RTL)
+        {
+          x = location->x - offset - 1;
+          y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+
+          cairo_move_to (cr, x, y + 1);
+          cairo_line_to (cr, x - arrow_width, y + arrow_width);
+          cairo_line_to (cr, x, y + 2 * arrow_width);
+          cairo_fill (cr);
+        }
+      else if (direction == GTK_TEXT_DIR_LTR)
+        {
+          x = location->x + stem_width - offset;
+          y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+
+          cairo_move_to (cr, x, y + 1);
+          cairo_line_to (cr, x + arrow_width, y + arrow_width);
+          cairo_line_to (cr, x, y + 2 * arrow_width);
+          cairo_fill (cr);
+        }
+    }
 }
 
 static AtkAttributeSet *
index 33cf5560faf4e73ca7cdb0f167a28aff09513496..b5af48b60ab2e665d93e3ce3e1ea066b81db05e2 100644 (file)
@@ -903,10 +903,17 @@ GdkPixbuf * gtk_render_icon_pixbuf (GtkStyleContext     *context,
                                     GtkIconSize          size);
 void        gtk_render_icon        (GtkStyleContext     *context,
                                     cairo_t             *cr,
-                                   GdkPixbuf           *pixbuf,
+                                    GdkPixbuf           *pixbuf,
                                     gdouble              x,
                                     gdouble              y);
 
+void   gtk_draw_insertion_cursor    (GtkWidget          *widget,
+                                     cairo_t            *cr,
+                                     const GdkRectangle *location,
+                                     gboolean            is_primary,
+                                     GtkTextDirection    direction,
+                                     gboolean            draw_arrow);
+
 /* Accessibility support */
 AtkAttributeSet *_gtk_style_context_get_attributes (AtkAttributeSet *attributes,
                                                     GtkStyleContext *context,