[gimp] app: redo the buffer's tag-at-iter APIs and fix editor state update



commit 1ddef5d37504f85cc48f0a8c0b31ac837edc0b62
Author: Michael Natterer <mitch gimp org>
Date:   Tue Mar 2 11:37:57 2010 +0100

    app: redo the buffer's tag-at-iter APIs and fix editor state update

 app/widgets/gimptextbuffer.c      |  104 ++++++++++++++++++-------------------
 app/widgets/gimptextbuffer.h      |   12 ++--
 app/widgets/gimptextstyleeditor.c |   31 ++---------
 3 files changed, 63 insertions(+), 84 deletions(-)
---
diff --git a/app/widgets/gimptextbuffer.c b/app/widgets/gimptextbuffer.c
index ae40126..be0a14f 100644
--- a/app/widgets/gimptextbuffer.c
+++ b/app/widgets/gimptextbuffer.c
@@ -303,10 +303,10 @@ gimp_text_buffer_get_markup (GimpTextBuffer *buffer)
   return markup;
 }
 
-gint
-gimp_text_buffer_get_baseline (GimpTextBuffer     *buffer,
-                               const GtkTextIter  *iter,
-                               GtkTextTag        **baseline_tag)
+GtkTextTag *
+gimp_text_buffer_get_iter_baseline (GimpTextBuffer    *buffer,
+                                    const GtkTextIter *iter,
+                                    gint              *baseline)
 {
   GList *list;
 
@@ -316,21 +316,19 @@ gimp_text_buffer_get_baseline (GimpTextBuffer     *buffer,
 
       if (gtk_text_iter_has_tag (iter, tag))
         {
-          gint baseline;
+          if (baseline)
+            g_object_get (tag,
+                          "rise", baseline,
+                          NULL);
 
-          *baseline_tag = tag;
-
-          g_object_get (tag,
-                        "rise", &baseline,
-                        NULL);
-
-          return baseline;
+          return tag;
         }
     }
 
-  *baseline_tag = NULL;
+  if (baseline)
+    *baseline = 0;
 
-  return 0;
+  return NULL;
 }
 
 static GtkTextTag *
@@ -376,8 +374,8 @@ gimp_text_buffer_change_baseline (GimpTextBuffer    *buffer,
   GtkTextIter  iter;
   GtkTextIter  span_start;
   GtkTextIter  span_end;
-  gint         span_baseline;
   GtkTextTag  *span_tag;
+  gint         span_baseline;
 
   g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
   g_return_if_fail (start != NULL);
@@ -386,20 +384,22 @@ gimp_text_buffer_change_baseline (GimpTextBuffer    *buffer,
   if (gtk_text_iter_equal (start, end))
     return;
 
-  iter          = *start;
-  span_start    = *start;
-  span_baseline = gimp_text_buffer_get_baseline (buffer, &iter, &span_tag);
+  iter       = *start;
+  span_start = *start;
+  span_tag   = gimp_text_buffer_get_iter_baseline (buffer, &iter,
+                                                   &span_baseline);
 
   gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
 
   do
     {
-      gint        iter_baseline;
       GtkTextTag *iter_tag;
+      gint        iter_baseline;
 
       gtk_text_iter_forward_char (&iter);
 
-      iter_baseline = gimp_text_buffer_get_baseline (buffer, &iter, &iter_tag);
+      iter_tag = gimp_text_buffer_get_iter_baseline (buffer, &iter,
+                                                     &iter_baseline);
 
       span_end = iter;
 
@@ -435,10 +435,10 @@ gimp_text_buffer_change_baseline (GimpTextBuffer    *buffer,
   gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
 }
 
-gint
-gimp_text_buffer_get_spacing (GimpTextBuffer     *buffer,
-                              const GtkTextIter  *iter,
-                              GtkTextTag        **spacing_tag)
+GtkTextTag *
+gimp_text_buffer_get_iter_spacing (GimpTextBuffer    *buffer,
+                                   const GtkTextIter *iter,
+                                   gint              *spacing)
 {
   GList *list;
 
@@ -448,21 +448,19 @@ gimp_text_buffer_get_spacing (GimpTextBuffer     *buffer,
 
       if (gtk_text_iter_has_tag (iter, tag))
         {
-          gint spacing;
-
-          *spacing_tag = tag;
+          if (spacing)
+            g_object_get (tag,
+                          "rise", spacing, /* FIXME */
+                          NULL);
 
-          g_object_get (tag,
-                        "rise", &spacing, /* FIXME */
-                        NULL);
-
-          return spacing;
+          return tag;
         }
     }
 
-  *spacing_tag = NULL;
+  if (spacing)
+    *spacing = 0;
 
-  return 0;
+  return NULL;
 }
 
 static GtkTextTag *
@@ -508,8 +506,8 @@ gimp_text_buffer_change_spacing (GimpTextBuffer    *buffer,
   GtkTextIter  iter;
   GtkTextIter  span_start;
   GtkTextIter  span_end;
-  gint         span_spacing;
   GtkTextTag  *span_tag;
+  gint         span_spacing;
 
   g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
   g_return_if_fail (start != NULL);
@@ -518,20 +516,22 @@ gimp_text_buffer_change_spacing (GimpTextBuffer    *buffer,
   if (gtk_text_iter_equal (start, end))
     return;
 
-  iter         = *start;
-  span_start   = *start;
-  span_spacing = gimp_text_buffer_get_spacing (buffer, &iter, &span_tag);
+  iter       = *start;
+  span_start = *start;
+  span_tag   = gimp_text_buffer_get_iter_spacing (buffer, &iter,
+                                                  &span_spacing);
 
   gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
 
   do
     {
-      gint        iter_spacing;
       GtkTextTag *iter_tag;
+      gint        iter_spacing;
 
       gtk_text_iter_forward_char (&iter);
 
-      iter_spacing = gimp_text_buffer_get_spacing (buffer, &iter, &iter_tag);
+      iter_tag = gimp_text_buffer_get_iter_spacing (buffer, &iter,
+                                                    &iter_spacing);
 
       span_end = iter;
 
@@ -567,10 +567,10 @@ gimp_text_buffer_change_spacing (GimpTextBuffer    *buffer,
   gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
 }
 
-gchar *
-gimp_text_buffer_get_font (GimpTextBuffer     *buffer,
-                           const GtkTextIter  *iter,
-                           GtkTextTag        **font_tag)
+GtkTextTag *
+gimp_text_buffer_get_iter_font (GimpTextBuffer     *buffer,
+                                const GtkTextIter  *iter,
+                                gchar             **font)
 {
   GList *list;
 
@@ -580,19 +580,17 @@ gimp_text_buffer_get_font (GimpTextBuffer     *buffer,
 
       if (gtk_text_iter_has_tag (iter, tag))
         {
-          gchar *font;
+          if (font)
+            g_object_get (tag,
+                          "font", font,
+                          NULL);
 
-          *font_tag = tag;
-
-          g_object_get (tag,
-                        "font", &font,
-                        NULL);
-
-          return font;
+          return tag;
         }
     }
 
-  *font_tag = NULL;
+  if (font)
+    *font = NULL;
 
   return NULL;
 }
diff --git a/app/widgets/gimptextbuffer.h b/app/widgets/gimptextbuffer.h
index cb982c0..c35a170 100644
--- a/app/widgets/gimptextbuffer.h
+++ b/app/widgets/gimptextbuffer.h
@@ -69,25 +69,25 @@ void             gimp_text_buffer_set_markup        (GimpTextBuffer    *buffer,
                                                      const gchar       *markup);
 gchar          * gimp_text_buffer_get_markup        (GimpTextBuffer    *buffer);
 
-gint             gimp_text_buffer_get_baseline      (GimpTextBuffer    *buffer,
+GtkTextTag     * gimp_text_buffer_get_iter_baseline (GimpTextBuffer    *buffer,
                                                      const GtkTextIter *iter,
-                                                     GtkTextTag       **baseline_tag);
+                                                     gint              *baseline);
 void             gimp_text_buffer_change_baseline   (GimpTextBuffer    *buffer,
                                                      const GtkTextIter *start,
                                                      const GtkTextIter *end,
                                                      gint               count);
 
-gint             gimp_text_buffer_get_spacing       (GimpTextBuffer    *buffer,
+GtkTextTag     * gimp_text_buffer_get_iter_spacing  (GimpTextBuffer    *buffer,
                                                      const GtkTextIter *iter,
-                                                     GtkTextTag       **spacing_tag);
+                                                     gint              *spacing);
 void             gimp_text_buffer_change_spacing    (GimpTextBuffer    *buffer,
                                                      const GtkTextIter *start,
                                                      const GtkTextIter *end,
                                                      gint               count);
 
-gchar          * gimp_text_buffer_get_font          (GimpTextBuffer    *buffer,
+GtkTextTag     * gimp_text_buffer_get_iter_font     (GimpTextBuffer    *buffer,
                                                      const GtkTextIter *iter,
-                                                     GtkTextTag       **font_tag);
+                                                     gchar            **font);
 void             gimp_text_buffer_set_font          (GimpTextBuffer    *buffer,
                                                      const GtkTextIter *start,
                                                      const GtkTextIter *end,
diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c
index cccd42c..5cd03bc 100644
--- a/app/widgets/gimptextstyleeditor.c
+++ b/app/widgets/gimptextstyleeditor.c
@@ -566,16 +566,7 @@ gimp_text_style_editor_update (GimpTextStyleEditor *editor)
         }
 
       /*  and get the initial font tag  */
-      for (list = editor->buffer->font_tags; list; list = g_list_next (list))
-        {
-          GtkTextTag *tag = list->data;
-
-          if (gtk_text_iter_has_tag (&start, tag))
-            {
-              font_tag = tag;
-              break;
-            }
-        }
+      font_tag = gimp_text_buffer_get_iter_font (editor->buffer, &start, NULL);
 
       for (iter = start;
            gtk_text_iter_in_range (&iter, &start, &end);
@@ -604,26 +595,16 @@ gimp_text_style_editor_update (GimpTextStyleEditor *editor)
 
           if (! font_differs)
             {
-              for (list = editor->buffer->font_tags;
-                   list;
-                   list = g_list_next (list))
-                {
-                  GtkTextTag *tag = list->data;
-
-                  if (gtk_text_iter_has_tag (&iter, tag))
-                    {
-                      if (tag != font_tag)
-                        font_differs = TRUE;
+              GtkTextTag *tag;
 
-                      break;
-                    }
-                }
+              tag = gimp_text_buffer_get_iter_font (editor->buffer, &iter,
+                                                    NULL);
 
-              if (! list && font_tag)
+              if (tag != font_tag)
                 font_differs = TRUE;
             }
 
-          if (! any_toggle_active || font_differs)
+          if (! any_toggle_active && font_differs)
             break;
        }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]