Enlightenment CVS committal

Author  : dj2
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_enums.h ewl_model.h ewl_tree2.c ewl_tree2.h 


Log Message:
- ewl_tree2 columns are now sortable. Clicking on the header (of a column
  which has a sort cb) will sort it, clicking again sorts in the other
  direction.

- This needs theme work to mark a header as sorted ascending or descending.
  Currently sets the state of the header but no edc code to react to it yet.

===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_enums.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -3 -r1.51 -r1.52
--- ewl_enums.h 15 Aug 2006 15:06:51 -0000      1.51
+++ ewl_enums.h 20 Aug 2006 21:09:05 -0000      1.52
@@ -694,6 +694,23 @@
 typedef enum Ewl_Mouse_Cursor_Type Ewl_Mouse_Cursor_Type;
 
 /**
+ * @enum Ewl_Sort_Direction
+ * The current sort direction
+ */
+enum Ewl_Sort_Direction
+{
+       EWL_SORT_DIRECTION_NONE = 0,
+       EWL_SORT_DIRECTION_ASCENDING,
+       EWL_SORT_DIRECTION_DESCENDING,
+       EWL_SORT_DIRECTION_MAX
+};
+
+/**
+ * The Ewl_Sort_Direction
+ */
+typedef enum Ewl_Sort_Direction Ewl_Sort_Direction;
+
+/**
  * @}
  */ 
 #endif                         /* __EWL_ENUMS_H__ */
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_model.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- ewl_model.h 11 May 2006 04:01:20 -0000      1.10
+++ ewl_model.h 20 Aug 2006 21:09:05 -0000      1.11
@@ -45,7 +45,8 @@
 /**
  * A typedef to shorten the definition of the model_sort callbacks. 
  */
-typedef void (*Ewl_Model_Sort)(void *data, unsigned int column);
+typedef void (*Ewl_Model_Sort)(void *data, unsigned int column, 
+                                               Ewl_Sort_Direction sort);
 
 /**
  * @def EWL_MODEL_DATA_COUNT(f)
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_tree2.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- ewl_tree2.c 20 Aug 2006 19:00:52 -0000      1.25
+++ ewl_tree2.c 20 Aug 2006 21:09:05 -0000      1.26
@@ -147,6 +147,7 @@
 
        ewl_tree2_column_model_set(c, model);
        ewl_tree2_column_view_set(c, view);
+       ewl_tree2_column_tree_set(c, tree);
 
        ecore_list_append(tree->columns, c);
        ewl_tree2_dirty_set(tree, TRUE);
@@ -181,6 +182,7 @@
 
        ewl_tree2_column_model_set(c, model);
        ewl_tree2_column_view_set(c, view);
+       ewl_tree2_column_tree_set(c, tree);
 
        ecore_list_prepend(tree->columns, c);
        ewl_tree2_dirty_set(tree, TRUE);
@@ -217,6 +219,7 @@
 
        ewl_tree2_column_model_set(c, model);
        ewl_tree2_column_view_set(c, view);
+       ewl_tree2_column_tree_set(c, tree);
 
        ecore_list_goto_index(tree->columns, idx);
        ecore_list_insert(tree->columns, c);
@@ -515,6 +518,84 @@
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
+/**
+ * @internal
+ * @param w: The header that was clicked
+ * @param ev: UNUSED
+ * @param data: The column related to this header
+ * @return Returns no value
+ * @brief Sorts the tree by the given column
+ */
+void
+ewl_tree2_cb_column_sort(Ewl_Widget *w, void *ev __UNUSED__, void *data)
+{
+       Ewl_Tree2_Column *c, *col;
+       Ewl_Widget *child;
+       char *theme_str;
+       int index = 0, count = 0;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("data", data);
+
+       c = data;
+
+       /* sanity check */
+       if (!c->model || !c->model->sort)
+       {
+               DWARNING("In ewl_tree2_cb_column_sort without a sort cb.");
+               DRETURN(DLEVEL_STABLE);
+       }
+
+       /* need to loop over the headers and reset the state */
+       theme_str = "default";
+       ewl_container_child_iterate_begin(EWL_CONTAINER(c->parent->header));
+       while ((child = 
ewl_container_child_next(EWL_CONTAINER(c->parent->header))))
+       {
+               /* don't bother signaling the clicked header as we'll do
+                * that later anyway */
+               if (child == w) 
+               {
+                       index = count;
+                       continue;
+               }
+
+               ewl_widget_state_set(child, theme_str, EWL_STATE_TRANSIENT);
+               count ++;
+       }
+
+       /* loop over the columns and reset the sort settings */
+       ecore_list_goto_first(c->parent->columns);
+       while ((col = ecore_list_next(c->parent->columns)))
+       {
+               /* skip the current column */
+               if (col == c) continue;
+
+               col->sort = EWL_SORT_DIRECTION_NONE;
+       }
+
+       /* update our sort direction and call the sort function, skipping
+        * over SORT_NONE */
+       c->sort = ((c->sort + 1) % EWL_SORT_DIRECTION_MAX);
+       if (!c->sort) c->sort ++;
+
+       /* pick the theme setting for the sort direction and set on the
+        * header */
+       if (c->sort == EWL_SORT_DIRECTION_ASCENDING)
+               theme_str = "ascending";
+       else if (c->sort == EWL_SORT_DIRECTION_DESCENDING)
+               theme_str = "descending";
+
+       ewl_widget_state_set(w, theme_str, EWL_STATE_TRANSIENT);
+
+       c->model->sort(c->parent->data, index, c->sort);
+
+       /* force the tree to redraw */
+       ewl_tree2_dirty_set(c->parent, TRUE);
+       ewl_widget_configure(EWL_WIDGET(c->parent));
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
 static void
 ewl_tree2_build_tree(Ewl_Tree2 *tree)
 {
@@ -533,12 +614,14 @@
                int r;
                Ewl_Widget *h;
 
-
                h = col->view->header_fetch(tree->data, column);
                ewl_object_fill_policy_set(EWL_OBJECT(h), 
                                EWL_FLAG_FILL_HSHRINK | EWL_FLAG_FILL_HFILL);
-
                ewl_container_child_append(EWL_CONTAINER(tree->header), h);
+
+               if (col->model->sort)
+                       ewl_callback_append(h, EWL_CALLBACK_CLICKED, 
+                                               ewl_tree2_cb_column_sort, col);
                column ++;
 
                r = col->model->count(tree->data);
@@ -657,6 +740,9 @@
 
        c->model = NULL;
        c->view = NULL;
+       c->parent = NULL;
+       c->sort = EWL_SORT_DIRECTION_NONE;
+
        FREE(c);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -725,5 +811,71 @@
 
        DRETURN_PTR(c->view, DLEVEL_STABLE);
 }
+
+/**
+ * @param c: The Ewl_Tree2_Column to work with
+ * @param tree: The parent to set
+ * @return Returns no value
+ * @brief Sets @a tree as the parent of the column @a c
+ */
+void
+ewl_tree2_column_tree_set(Ewl_Tree2_Column *c, Ewl_Tree2 *tree)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("c", c);
+       DCHECK_PARAM_PTR("tree", tree);
+       DCHECK_TYPE("tree", tree, EWL_TREE2_TYPE);
+
+       c->parent = tree;
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param c: The Ewl_Tree2_Column to work with
+ * @return Returns the parent tree for this column or NULL if none set
+ * @brief Retrieves the parent tree for this column or NULL if none set
+ */
+Ewl_Tree2 *
+ewl_tree2_column_tree_get(Ewl_Tree2_Column *c)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("c", c, NULL);
+
+       DRETURN_PTR(c->parent, DLEVEL_STABLE);
+}
+
+/**
+ * @param c: The Ewl_Tree2_Column to work with
+ * @param sort: The sort direction to set
+ * @return Returns no value
+ * @brief Sets the sort direction of the column to the given value
+ */
+void
+ewl_tree2_column_sort_direction_set(Ewl_Tree2_Column *c, Ewl_Sort_Direction 
sort)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("c", c);
+
+       c->sort = sort;
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param c: The Ewl_Tree2_Column to get the sort information from
+ * @return Returns the current sort direction for the column or
+ * EWL_SORT_DIRECTION_NONE if none set
+ * @brief Retrieves the current sort information for the Ewl_Tree2_Column
+ */
+Ewl_Sort_Direction
+ewl_tree2_column_sort_direction_get(Ewl_Tree2_Column *c)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("c", c, EWL_SORT_DIRECTION_NONE);
+
+       DRETURN_INT(c->sort, DLEVEL_STABLE);
+}
+
 
 
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_tree2.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- ewl_tree2.h 14 Aug 2006 17:50:55 -0000      1.25
+++ ewl_tree2.h 20 Aug 2006 21:09:05 -0000      1.26
@@ -97,26 +97,6 @@
 #define EWL_TREE2_TYPE "tree2"
 
 /**
- * @def EWL_TREE2_COLUMN
- * Typecasts a pointer to an Ewl_Tree2_Column pointer.
- */
-#define EWL_TREE2_COLUMN(c) ((Ewl_Tree2_Column *)c)
-
-/**
- * The Ewl_Tree2_Column type
- */
-typedef struct Ewl_Tree2_Column Ewl_Tree2_Column;
-
-/**
- * Holdes the model and view to use for this column in the tree
- */
-struct Ewl_Tree2_Column
-{
-       Ewl_Model *model;       /**< The model for the column */
-       Ewl_View  *view;        /**< The view for the column */
-};
-
-/**
  * @def EWL_TREE2(t)
  * Typecasts a pointer to an Ewl_Tree pointer.
  */
@@ -150,6 +130,29 @@
        unsigned char dirty:1;    /**< Has the data changed? */
 };
 
+/**
+ * @def EWL_TREE2_COLUMN
+ * Typecasts a pointer to an Ewl_Tree2_Column pointer.
+ */
+#define EWL_TREE2_COLUMN(c) ((Ewl_Tree2_Column *)c)
+
+/**
+ * The Ewl_Tree2_Column type
+ */
+typedef struct Ewl_Tree2_Column Ewl_Tree2_Column;
+
+/**
+ * Holdes the model and view to use for this column in the tree
+ */
+struct Ewl_Tree2_Column
+{
+       Ewl_Model *model;       /**< The model for the column */
+       Ewl_View  *view;        /**< The view for the column */
+       
+       Ewl_Tree2 *parent;      /**< The tree this column is for */
+       Ewl_Sort_Direction sort; /**< direction the column is sorted in */
+};
+
 /*
  * Tree view/controller manipulation
  */
@@ -189,6 +192,7 @@
  */
 void ewl_tree2_cb_destroy(Ewl_Widget *w, void *ev, void *data);
 void ewl_tree2_cb_configure(Ewl_Widget *w, void *ev, void *data);
+void ewl_tree2_cb_column_sort(Ewl_Widget *w, void *ev, void *data);
 
 /*
  * Ewl_Tree2_Column stuff
@@ -201,6 +205,13 @@
 
 void                    ewl_tree2_column_view_set(Ewl_Tree2_Column *c, 
Ewl_View *v);
 Ewl_View               *ewl_tree2_column_view_get(Ewl_Tree2_Column *c);
+
+void                    ewl_tree2_column_tree_set(Ewl_Tree2_Column *c, 
Ewl_Tree2 *tree);
+Ewl_Tree2              *ewl_tree2_column_tree_get(Ewl_Tree2_Column *c);
+
+void                    ewl_tree2_column_sort_direction_set(Ewl_Tree2_Column 
*c, 
+                                                               
Ewl_Sort_Direction sort);
+Ewl_Sort_Direction      ewl_tree2_column_sort_direction_get(Ewl_Tree2_Column 
*c);
 
 /**
  * @}



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to