]> Pileus Git - ~andy/gtk/commitdiff
GtkLabel: factor out two getters
authorMatthias Clasen <mclasen@redhat.com>
Fri, 24 Jun 2011 03:30:57 +0000 (23:30 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 5 Jul 2011 20:08:07 +0000 (16:08 -0400)
Make the get_property switch look a little nicer.
We export these functions privately for use in the label
accessible implementation later on.

gtk/gtklabel.c
gtk/gtklabel.h

index 7818048db791b6cea7f9acb4ca59fbe455b2b319..45a7508605c15f5c4d8649784ac3545e994bbeea 100644 (file)
@@ -465,6 +465,7 @@ static void gtk_label_select_region_index (GtkLabel *label,
                                            gint      anchor_index,
                                            gint      end_index);
 
+
 static gboolean gtk_label_mnemonic_activate (GtkWidget         *widget,
                                             gboolean           group_cycling);
 static void     gtk_label_setup_mnemonic    (GtkLabel          *label,
@@ -1204,24 +1205,10 @@ gtk_label_get_property (GObject     *object,
       g_value_set_object (value, (GObject*) priv->mnemonic_widget);
       break;
     case PROP_CURSOR_POSITION:
-      if (priv->select_info && priv->select_info->selectable)
-       {
-         gint offset = g_utf8_pointer_to_offset (priv->text,
-                                                 priv->text + priv->select_info->selection_end);
-         g_value_set_int (value, offset);
-       }
-      else
-       g_value_set_int (value, 0);
+      g_value_set_int (value, _gtk_label_get_cursor_position (label));
       break;
     case PROP_SELECTION_BOUND:
-      if (priv->select_info && priv->select_info->selectable)
-       {
-         gint offset = g_utf8_pointer_to_offset (priv->text,
-                                                 priv->text + priv->select_info->selection_anchor);
-         g_value_set_int (value, offset);
-       }
-      else
-       g_value_set_int (value, 0);
+      g_value_set_int (value, _gtk_label_get_selection_bound (label));
       break;
     case PROP_ELLIPSIZE:
       g_value_set_enum (value, priv->ellipsize);
@@ -6658,3 +6645,27 @@ gtk_label_query_tooltip (GtkWidget  *widget,
                                                                    keyboard_tip,
                                                                    tooltip);
 }
+
+gint
+_gtk_label_get_cursor_position (GtkLabel *label)
+{
+  GtkLabelPrivate *priv = label->priv;
+
+  if (priv->select_info && priv->select_info->selectable)
+    return g_utf8_pointer_to_offset (priv->text,
+                                     priv->text + priv->select_info->selection_end);
+
+  return 0;
+}
+
+gint
+_gtk_label_get_selection_bound (GtkLabel *label)
+{
+  GtkLabelPrivate *priv = label->priv;
+
+  if (priv->select_info && priv->select_info->selectable)
+    return g_utf8_pointer_to_offset (priv->text,
+                                     priv->text + priv->select_info->selection_anchor);
+
+  return 0;
+}
index f22c84df79c714eb9e491b9dcef88da48e6b3e94..38d4052d720936b64987ef2e99d099ffe638814a 100644 (file)
@@ -169,6 +169,8 @@ gboolean     gtk_label_get_track_visited_links  (GtkLabel *label);
 
 void _gtk_label_mnemonics_visible_apply_recursively (GtkWidget *widget,
                                                      gboolean   mnemonics_visible);
+gint _gtk_label_get_cursor_position (GtkLabel *label);
+gint _gtk_label_get_selection_bound (GtkLabel *label);
 
 G_END_DECLS