Enlightenment CVS committal

Author  : moom16
Project : e17
Module  : proto

Dir     : e17/proto/etk/src/lib


Modified Files:
        etk_tree.c etk_tree.h 


Log Message:
* [Etk_Tree] Add a function to scroll to a row
* [Etk_Tree] Add more function to walk through the rows of the tree
* [Etk_Tree] Improve the keyboard navigation


===================================================================
RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_tree.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- etk_tree.c  20 Dec 2005 18:25:28 -0000      1.18
+++ etk_tree.c  21 Dec 2005 00:03:16 -0000      1.19
@@ -768,78 +768,67 @@
 }
 
 /**
- * @brief Sets the different values of the cells of the row
- * @param row a row
- * @param ... an Etk_Tree_Col * followed by the value(s) of the cell, then 
again, an Etk_Tree_Col * followed by its value(s)... terminated by NULL
+ * @brief Gets the first row of the tree
+ * @param tree a tree
+ * @return Returns the first row of the tree
  */
-void etk_tree_row_fields_set(Etk_Tree_Row *row, ...)
+Etk_Tree_Row *etk_tree_first_row_get(Etk_Tree *tree)
 {
-   va_list args;
-
-   va_start(args, row);
-   etk_tree_row_fields_set_valist(row, args);
-   va_end(args);
+   if (!tree)
+      return NULL;
+   return etk_tree_row_first_child_get(&tree->root);
 }
 
 /**
- * @brief Sets the different values of the cells of the row
- * @param row a row
- * @param args an Etk_Tree_Col * followed by the value(s) of the cell, then 
again, an Etk_Tree_Col * followed by its value(s)... terminated by NULL
+ * @brief Gets the last row of the tree
+ * @param tree a tree
+ * @param walking_through_hierarchy if TRUE, the last row is not necessary on 
the first level of hierarchy. @n
+ * This setting has no effect if the tree is in the list mode
+ * @param include_collapsed_children if TRUE, the last row can be a child of a 
collapsed row. @n
+ * This setting has no effect if the tree is in the list mode, or if @a 
walking_through_hierarchy is FALSE
+ * @return Returns the last row of the tree
  */
-void etk_tree_row_fields_set_valist(Etk_Tree_Row *row, va_list args)
+Etk_Tree_Row *etk_tree_last_row_get(Etk_Tree *tree, Etk_Bool 
walking_through_hierarchy, Etk_Bool include_collapsed_children)
 {
-   Etk_Tree_Col *col;
-   va_list args2;
-   
-   if (!row)
-      return;
-
-   va_copy(args2, args);
-   while ((col = va_arg(args2, Etk_Tree_Col *)))
-   {
-      if (col->model->cell_data_set)
-         col->model->cell_data_set(col->model, row->cells_data[col->id], 
&args2);
-   }
-   va_end(args2);
-
-   if (!row->tree->frozen)
-      etk_widget_redraw_queue(ETK_WIDGET(row->tree));
+   if (!tree)
+      return NULL;
+   return etk_tree_row_last_child_get(&tree->root, walking_through_hierarchy, 
include_collapsed_children);
 }
 
 /**
- * @brief Gets the different values of the cells of the row
+ * @brief Gets the first child of the row
  * @param row a row
- * @param ... an Etk_Tree_Col * followed by the location where to store the 
value(s) of the cell, then again, an Etk_Tree_Col * followed by its 
location(s)... terminated by NULL
+ * @return Returns the first child of the row
  */
-void etk_tree_row_fields_get(Etk_Tree_Row *row, ...)
+Etk_Tree_Row *etk_tree_row_first_child_get(Etk_Tree_Row *row)
 {
-   va_list args;
-
-   va_start(args, row);
-   etk_tree_row_fields_get_valist(row, args);
-   va_end(args);
+   if (!row)
+      return NULL;
+   return row->first_child;
 }
 
 /**
- * @brief Gets the different values of the cells of the row
+ * @brief Gets the last child of the row
  * @param row a row
- * @param args an Etk_Tree_Col * followed by the location where to store the 
value(s) of the cell, then again, an Etk_Tree_Col * followed by its 
location(s)... terminated by NULL
+ * @param walking_through_hierarchy if TRUE, the last child is not necessary 
directly a child of the row.
+ * @param include_collapsed_children if TRUE, the last child can be a child of 
a collapsed row. @n
+ * This setting has no effect if @a walking_through_hierarchy is FALSE
+ * @return Returns the last child of the row
  */
-void etk_tree_row_fields_get_valist(Etk_Tree_Row *row, va_list args)
+Etk_Tree_Row *etk_tree_row_last_child_get(Etk_Tree_Row *row, Etk_Bool 
walking_through_hierarchy, Etk_Bool include_collapsed_children)
 {
-   Etk_Tree_Col *col;
-   va_list args2;
-
    if (!row)
-      return;
-
-   va_copy(args2, args);
-   while ((col = va_arg(args2, Etk_Tree_Col *)))
+      return NULL;
+   
+   if (!walking_through_hierarchy)
+      return row->last_child;
+   else
    {
-      if (col->model->cell_data_get)
-         col->model->cell_data_get(col->model, row->cells_data[col->id], 
&args2);
+      Etk_Tree_Row *last;
+      
+      for (last = row->last_child; last && (include_collapsed_children || 
last->expanded) && last->last_child; last = last->last_child);
+      return last;
    }
-   va_end(args2);
 }
 
 /**
@@ -847,7 +836,7 @@
  * @param row the current row
  * @param walking_through_hierarchy if TRUE, the previous row can be a row 
located on a different level in the hierarchy. @n
  * This setting has no effect if the tree is in the list mode
- * @param include_collapsed_children if TRUE, the previous row can be a child 
of a collapsed row
+ * @param include_collapsed_children if TRUE, the previous row can be a child 
of a collapsed row. @n
  * This setting has no effect if the tree is in the list mode, or if @a 
walking_through_hierarchy is FALSE
  * @return Returns the previous row of the tree
  */
@@ -877,7 +866,7 @@
  * @param row the current row
  * @param walking_through_hierarchy if TRUE, the next row can be a row located 
on a different level in the hierarchy. @n
  * This setting has no effect if the tree is in the list mode
- * @param include_collapsed_children if TRUE, the next row can be a child of a 
collapsed row
+ * @param include_collapsed_children if TRUE, the next row can be a child of a 
collapsed row. @n
  * This setting has no effect if the tree is in the list mode, or if @a 
walking_through_hierarchy is FALSE
  * @return Returns the next row of the tree
  */
@@ -908,6 +897,81 @@
 }
 
 /**
+ * @brief Sets the different values of the cells of the row
+ * @param row a row
+ * @param ... an Etk_Tree_Col * followed by the value(s) of the cell, then 
again, an Etk_Tree_Col * followed by its value(s)... terminated by NULL
+ */
+void etk_tree_row_fields_set(Etk_Tree_Row *row, ...)
+{
+   va_list args;
+
+   va_start(args, row);
+   etk_tree_row_fields_set_valist(row, args);
+   va_end(args);
+}
+
+/**
+ * @brief Sets the different values of the cells of the row
+ * @param row a row
+ * @param args an Etk_Tree_Col * followed by the value(s) of the cell, then 
again, an Etk_Tree_Col * followed by its value(s)... terminated by NULL
+ */
+void etk_tree_row_fields_set_valist(Etk_Tree_Row *row, va_list args)
+{
+   Etk_Tree_Col *col;
+   va_list args2;
+   
+   if (!row)
+      return;
+
+   va_copy(args2, args);
+   while ((col = va_arg(args2, Etk_Tree_Col *)))
+   {
+      if (col->model->cell_data_set)
+         col->model->cell_data_set(col->model, row->cells_data[col->id], 
&args2);
+   }
+   va_end(args2);
+
+   if (!row->tree->frozen)
+      etk_widget_redraw_queue(ETK_WIDGET(row->tree));
+}
+
+/**
+ * @brief Gets the different values of the cells of the row
+ * @param row a row
+ * @param ... an Etk_Tree_Col * followed by the location where to store the 
value(s) of the cell, then again, an Etk_Tree_Col * followed by its 
location(s)... terminated by NULL
+ */
+void etk_tree_row_fields_get(Etk_Tree_Row *row, ...)
+{
+   va_list args;
+
+   va_start(args, row);
+   etk_tree_row_fields_get_valist(row, args);
+   va_end(args);
+}
+
+/**
+ * @brief Gets the different values of the cells of the row
+ * @param row a row
+ * @param args an Etk_Tree_Col * followed by the location where to store the 
value(s) of the cell, then again, an Etk_Tree_Col * followed by its 
location(s)... terminated by NULL
+ */
+void etk_tree_row_fields_get_valist(Etk_Tree_Row *row, va_list args)
+{
+   Etk_Tree_Col *col;
+   va_list args2;
+
+   if (!row)
+      return;
+
+   va_copy(args2, args);
+   while ((col = va_arg(args2, Etk_Tree_Col *)))
+   {
+      if (col->model->cell_data_get)
+         col->model->cell_data_get(col->model, row->cells_data[col->id], 
&args2);
+   }
+   va_end(args2);
+}
+
+/**
  * @brief Sets a value to the data member of a row. The date could be 
retrieved with @a etk_tree_row_data_get()
  * @param row a row
  * @param data the data to set
@@ -932,6 +996,47 @@
 }
 
 /**
+ * @brief Makes the tree scroll to show the row
+ * @param row the row up to which you want to scroll
+ * @param center_the_row TRUE if you want the row to be centered
+ */
+void etk_tree_row_scroll_to(Etk_Tree_Row *row, Etk_Bool center_the_row)
+{
+   Etk_Tree *tree;
+   Etk_Tree_Row *r;
+   int row_offset;
+   int tree_height;
+   int i;
+   int new_xoffset;
+   
+   if (!row || !(tree = row->tree))
+      return;
+   
+   for (r = tree->root.first_child, i = 0; r; r = etk_tree_next_row_get(r, 
TRUE, FALSE), i++)
+   {
+      if (r == row)
+      {
+         row_offset = i * tree->row_height;
+         tree_height = tree->grid->inner_geometry.h;
+         
+         /* If the row is already entirely visible, we do nothing */
+         if (!center_the_row && (row_offset >= tree->yoffset && (row_offset + 
tree->row_height) <= (tree->yoffset + tree_height)))
+            return;
+         
+         if (center_the_row)
+            new_xoffset = row_offset + (tree->row_height - tree_height) / 2;
+         else if (row_offset < tree->yoffset)
+            new_xoffset = row_offset;
+         else
+            new_xoffset = row_offset - tree_height + tree->row_height;
+         
+         
etk_range_value_set(ETK_RANGE(etk_scrolled_view_vscrollbar_get(ETK_SCROLLED_VIEW(tree->scrolled_view))),
 new_xoffset);
+         return;
+      }
+   }
+}
+
+/**
  * @brief Selects the row
  * @param row the row to select
  */
@@ -1699,26 +1804,29 @@
    /* Select the previous visible row */
    if (strcmp(key_event->key, "Up") == 0)
    {
+      Etk_Tree_Row *row_to_select;
+      
       if (!tree->last_selected)
-      {
-         Etk_Tree_Row *last_row;
-         
-         for (last_row = tree->root.last_child; last_row && last_row->expanded 
&& last_row->last_child; last_row = last_row->last_child);
-         _etk_tree_row_select(tree, last_row, key_event->modifiers);
-      }
+         row_to_select = etk_tree_last_row_get(tree, TRUE, FALSE);
       else
-         _etk_tree_row_select(tree, etk_tree_prev_row_get(tree->last_selected, 
TRUE, FALSE), key_event->modifiers);
+         row_to_select = etk_tree_prev_row_get(tree->last_selected, TRUE, 
FALSE);
       
+      _etk_tree_row_select(tree, row_to_select, key_event->modifiers);
+      etk_tree_row_scroll_to(row_to_select, FALSE);
       etk_widget_event_propagation_stop();
    }
    /* Select the next visible row */
    else if (strcmp(key_event->key, "Down") == 0)
    {
+      Etk_Tree_Row *row_to_select;
+      
       if (!tree->last_selected)
-         _etk_tree_row_select(tree, tree->root.first_child, 
key_event->modifiers);
+         row_to_select = etk_tree_first_row_get(tree);
       else
-         _etk_tree_row_select(tree, etk_tree_next_row_get(tree->last_selected, 
TRUE, FALSE), key_event->modifiers);
+         row_to_select = etk_tree_next_row_get(tree->last_selected, TRUE, 
FALSE);
       
+      _etk_tree_row_select(tree, row_to_select, key_event->modifiers);
+      etk_tree_row_scroll_to(row_to_select, FALSE);
       etk_widget_event_propagation_stop();
    }
    /* Expand the row */
===================================================================
RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_tree.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- etk_tree.h  20 Dec 2005 18:25:28 -0000      1.12
+++ etk_tree.h  21 Dec 2005 00:03:16 -0000      1.13
@@ -154,7 +154,7 @@
 int etk_tree_col_min_width_get(Etk_Tree_Col *col);
 void etk_tree_col_resizable_set(Etk_Tree_Col *col, Etk_Bool resizable);
 Etk_Bool etk_tree_col_resizable_get(Etk_Tree_Col *col);
-void etk_tree_col_expand_set(Etk_Tree_Col *col, Etk_Bool resizable);
+void etk_tree_col_expand_set(Etk_Tree_Col *col, Etk_Bool expand);
 Etk_Bool etk_tree_col_expand_get(Etk_Tree_Col *col);
 void etk_tree_col_visible_set(Etk_Tree_Col *col, Etk_Bool visible);
 Etk_Bool etk_tree_col_visible_get(Etk_Tree_Col *col);
@@ -174,22 +174,29 @@
 
 Etk_Tree_Row *etk_tree_append(Etk_Tree *tree, ...);
 Etk_Tree_Row *etk_tree_append_to_row(Etk_Tree_Row *row, ...);
-void etk_tree_row_fields_set(Etk_Tree_Row *row, ...);
-void etk_tree_row_fields_set_valist(Etk_Tree_Row *row, va_list args);
-void etk_tree_row_fields_get(Etk_Tree_Row *row, ...);
-void etk_tree_row_fields_get_valist(Etk_Tree_Row *row, va_list args);
 void etk_tree_row_del(Etk_Tree_Row *row);
 void etk_tree_clear(Etk_Tree *tree);
 
+Etk_Tree_Row *etk_tree_first_row_get(Etk_Tree *tree);
+Etk_Tree_Row *etk_tree_last_row_get(Etk_Tree *tree, Etk_Bool 
walking_through_hierarchy, Etk_Bool include_collapsed_children);
+Etk_Tree_Row *etk_tree_row_first_child_get(Etk_Tree_Row *row);
+Etk_Tree_Row *etk_tree_row_last_child_get(Etk_Tree_Row *row, Etk_Bool 
walking_through_hierarchy, Etk_Bool include_collapsed_children);
 Etk_Tree_Row *etk_tree_prev_row_get(Etk_Tree_Row *row, Etk_Bool 
walking_through_hierarchy, Etk_Bool include_collapsed_children);
 Etk_Tree_Row *etk_tree_next_row_get(Etk_Tree_Row *row, Etk_Bool 
walking_through_hierarchy, Etk_Bool include_collapsed_children);
+
+void etk_tree_row_fields_set(Etk_Tree_Row *row, ...);
+void etk_tree_row_fields_set_valist(Etk_Tree_Row *row, va_list args);
+void etk_tree_row_fields_get(Etk_Tree_Row *row, ...);
+void etk_tree_row_fields_get_valist(Etk_Tree_Row *row, va_list args);
 void etk_tree_row_data_set(Etk_Tree_Row *row, void *data);
 void *etk_tree_row_data_get(Etk_Tree_Row *row);
 
+void etk_tree_row_scroll_to(Etk_Tree_Row *row, Etk_Bool center_the_row);
 void etk_tree_row_select(Etk_Tree_Row *row);
 void etk_tree_row_unselect(Etk_Tree_Row *row);
 Etk_Tree_Row *etk_tree_selected_row_get(Etk_Tree *tree);
 Evas_List *etk_tree_selected_rows_get(Etk_Tree *tree);
+
 void etk_tree_row_expand(Etk_Tree_Row *row);
 void etk_tree_row_collapse(Etk_Tree_Row *row);
 




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to