[gtk+/spread-table] Added gtk_spread_table_get_child_line



commit 7db09805f6f7ea64984963b3234eba13b995458d
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sat Oct 9 00:54:30 2010 +0900

    Added gtk_spread_table_get_child_line
    
    Gets the line index in which a child would be positioned
    if the table were to be allocated size in the opposing
    orientation of the table.
    
    For instance, if the table is oriented vertically,
    this function will return the child's column if
    the table were to be allocated size width.

 gtk/gtkspreadtable.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkspreadtable.h |    4 +++
 2 files changed, 63 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkspreadtable.c b/gtk/gtkspreadtable.c
index df7eef7..6813522 100644
--- a/gtk/gtkspreadtable.c
+++ b/gtk/gtkspreadtable.c
@@ -906,7 +906,7 @@ gtk_spread_table_insert_child (GtkSpreadTable *table,
 			       gint            index)
 {
   GtkSpreadTablePrivate *priv;
-  GList               *list;
+  GList                 *list;
 
   g_return_if_fail (GTK_IS_SPREAD_TABLE (table));
   g_return_if_fail (GTK_IS_WIDGET (child));
@@ -922,6 +922,64 @@ gtk_spread_table_insert_child (GtkSpreadTable *table,
 }
 
 
+
+/**
+ * gtk_spread_table_get_child_line:
+ * @table: A #GtkSpreadTable
+ * @child: A Child of the @table.
+ * @size: A size in the opposing orientation of @table
+ *
+ * Gets the line index in which @child would be positioned 
+ * if @table were to be allocated @size in the opposing
+ * orientation of @table.
+ *
+ * For instance, if the @table is oriented vertically,
+ * this function will return @child's column if @table
+ * were to be allocated @size width.
+ *
+ * Returns: the line index @child would be positioned in
+ * for @size (starting from 0).
+ */
+guint
+gtk_spread_table_get_child_line (GtkSpreadTable *table,
+				 GtkWidget      *child,
+				 gint            size)
+
+{
+  GtkSpreadTablePrivate *priv;
+  gint                  *segments = NULL;
+  gint                   i, child_count, child_idx = 0;
+  GList                 *l;
+
+  g_return_val_if_fail (GTK_IS_SPREAD_TABLE (table), 0);
+  g_return_val_if_fail (GTK_IS_WIDGET (child), 0);
+
+  priv = table->priv;
+
+  segment_lines_for_size (table, size, &segments);
+
+  /* Get child index in list */
+  l = g_list_find (priv->children, child);
+  g_return_val_if_fail (l != NULL, 0);
+
+  child_idx = g_list_position (priv->children, l);
+
+  for (i = 0, child_count = 0; i < priv->lines; i++)
+    {
+      child_count += segments[i];
+
+      if (child_idx < child_count)
+	break;
+    }
+
+  g_assert (i < priv->lines);
+
+  g_free (segments);
+
+  return i;
+}
+
+
 /**
  * gtk_spread_table_set_lines:
  * @table: A #GtkSpreadTable
diff --git a/gtk/gtkspreadtable.h b/gtk/gtkspreadtable.h
index 22d180f..ee0de30 100644
--- a/gtk/gtkspreadtable.h
+++ b/gtk/gtkspreadtable.h
@@ -64,6 +64,10 @@ void                  gtk_spread_table_insert_child              (GtkSpreadTable
 								  GtkWidget      *child,
 								  gint            index);
 
+guint                 gtk_spread_table_get_child_line            (GtkSpreadTable *table,
+								  GtkWidget      *child,
+								  gint            size);
+
 void                  gtk_spread_table_set_lines                 (GtkSpreadTable *table,
 								  guint           lines);
 guint                 gtk_spread_table_get_lines                 (GtkSpreadTable *table);



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