Enlightenment CVS committal Author : pfritz Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_tree2.h ewl_tree2.c ewl_mvc.c ewl_mvc.h ewl_model.h ewl_model.c Log Message: add an unref cb to the model. It is for unreference the data if the mvc doesn't use it anymore, therefor that the user get a chance to free the data =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_tree2.h,v retrieving revision 1.47 retrieving revision 1.48 diff -u -3 -r1.47 -r1.48 --- ewl_tree2.h 23 Aug 2007 05:26:52 -0000 1.47 +++ ewl_tree2.h 30 Oct 2007 19:47:51 -0000 1.48 @@ -115,6 +115,7 @@ unsigned int columns; /**< Number of columns in the tree */ unsigned char fixed:1; /**< Rows are fixed height */ unsigned char headers_visible:1; /**< Are the headers visible? */ + unsigned char row_color_alternate:1; /**< Are the rows alternating? */ }; /* @@ -141,6 +142,10 @@ void ewl_tree2_fixed_rows_set(Ewl_Tree2 *tree, unsigned int fixed); unsigned int ewl_tree2_fixed_rows_get(Ewl_Tree2 *tree); +void ewl_tree2_alternate_row_colors_set(Ewl_Tree2 *tree, + unsigned char alternate); +unsigned int ewl_tree2_alternate_row_colors_get(Ewl_Tree2 *tree); + Ewl_Widget *ewl_tree2_content_widget_get(Ewl_Tree2 *tree); void ewl_tree2_row_expand(Ewl_Tree2 *tree, void *data, @@ -188,6 +193,12 @@ Ewl_Widget *row; /**< The row this node is for */ Ewl_Widget *handle; /**< the expansion handle */ + struct + { + Ewl_Model *model; /**< The model of the expansion */ + void *data; /**< The data of the expansion */ + } expansion; + unsigned int row_num; /**< The row number of this row */ Ewl_Tree_Node_Flags expanded; @@ -206,6 +217,7 @@ unsigned int ewl_tree2_node_expanded_is(Ewl_Tree2_Node *node); void ewl_tree2_cb_node_configure(Ewl_Widget *w, void *ev_data, void *user_data); +void ewl_tree2_cb_node_data_unref(Ewl_Widget *w, void *ev_data, void *user_data); void ewl_tree2_cb_node_realize(Ewl_Widget *w, void *ev, void *data); void ewl_tree2_cb_node_toggle(Ewl_Widget *w, void *ev_data, void *user_data); =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_tree2.c,v retrieving revision 1.84 retrieving revision 1.85 diff -u -3 -r1.84 -r1.85 --- ewl_tree2.c 23 Aug 2007 05:26:52 -0000 1.84 +++ ewl_tree2.c 30 Oct 2007 19:47:51 -0000 1.85 @@ -95,6 +95,7 @@ ewl_tree2_headers_visible_set(tree, TRUE); ewl_tree2_fixed_rows_set(tree, FALSE); + ewl_tree2_alternate_row_colors_set(tree, TRUE); ewl_callback_append(EWL_WIDGET(tree), EWL_CALLBACK_CONFIGURE, ewl_tree2_cb_configure, NULL); @@ -150,6 +151,43 @@ } /** + * @param tree: The tree to toggle the alternating row colour + * @param alternate: The boolean for alternating the row colour (TRUE == yes, FALSE == no) + * @return Returns no value + * @brief Toggle if the rows alternate in colour + */ +void +ewl_tree2_alternate_row_colors_set(Ewl_Tree2 *tree, unsigned char alternate) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("tree", tree); + DCHECK_TYPE("tree", tree, EWL_TREE2_TYPE); + + if (tree->row_color_alternate == !!alternate) + DRETURN(DLEVEL_STABLE); + + tree->row_color_alternate = !!alternate; + ewl_mvc_dirty_set(EWL_MVC(tree), TRUE); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param tree: The tree to work with + * @return Returns if the row colours are currently being alternated + * @brief Retrieve if the row colours are being alternated + */ +unsigned int +ewl_tree2_alternate_row_colors_get(Ewl_Tree2 *tree) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("tree", tree, FALSE); + DCHECK_TYPE_RET("tree", tree, EWL_TREE2_TYPE, FALSE); + + DRETURN_INT(tree->row_color_alternate, DLEVEL_STABLE); +} + +/** * @param tree: The tree to work with * @param count: The number of columns in the tree * @return Returns no value @@ -730,10 +768,16 @@ EWL_TREE2_NODE(node)->row = row; ewl_widget_show(row); - if (colour) - ewl_widget_state_set(row, "odd", EWL_STATE_PERSISTENT); - else - ewl_widget_state_set(row, "even", EWL_STATE_PERSISTENT); + if (tree->row_color_alternate) + { + if (colour) + ewl_widget_state_set(row, "odd", + EWL_STATE_PERSISTENT); + else + ewl_widget_state_set(row, "even", + EWL_STATE_PERSISTENT); + } + colour = (colour + 1) % 2; /* do the current branch */ @@ -969,6 +1013,11 @@ ewl_tree2_cb_node_child_add); ewl_container_remove_notify_set(EWL_CONTAINER(node), ewl_tree2_cb_node_child_del); + + /* we don't want the mvc to unref our data since the data is owned + * by the tree or the parent node */ + ewl_callback_del(EWL_WIDGET(node), EWL_CALLBACK_DESTROY, + ewl_mvc_cb_data_unref); ewl_object_fill_policy_set(EWL_OBJECT(node), EWL_FLAG_FILL_HFILL | EWL_FLAG_FILL_HSHRINK); @@ -1010,6 +1059,8 @@ { ewl_callback_append(node->handle, EWL_CALLBACK_VALUE_CHANGED, ewl_tree2_cb_node_toggle, node); + ewl_callback_append(EWL_WIDGET(node), EWL_CALLBACK_DESTROY, + ewl_tree2_cb_node_data_unref, NULL); ewl_widget_enable(node->handle); ewl_expansion_expandable_set(EWL_EXPANSION(node->handle), TRUE); } @@ -1017,6 +1068,8 @@ { ewl_callback_del(node->handle, EWL_CALLBACK_VALUE_CHANGED, ewl_tree2_cb_node_toggle); + ewl_callback_del(EWL_WIDGET(node), EWL_CALLBACK_DESTROY, + ewl_tree2_cb_node_data_unref); ewl_widget_disable(node->handle); ewl_expansion_expandable_set(EWL_EXPANSION(node->handle), FALSE); } @@ -1074,15 +1127,21 @@ data = ewl_mvc_data_get(EWL_MVC(node)); if (model->expansion.data && !node->built_children) { - Ewl_Model *tmp_model = NULL; Ewl_View *view, *tmp_view = NULL; - void *tmp_data; + Ewl_Model *tmp_model; - tmp_data = model->expansion.data(data, node->row_num); - if (model->expansion.model) - tmp_model = model->expansion.model(data, node->row_num); - - if (!tmp_model) tmp_model = model; + if (!node->expansion.data) + node->expansion.data = + model->expansion.data(data, node->row_num); + + if (!node->expansion.model && model->expansion.model) + node->expansion.model = + model->expansion.model(data, node->row_num); + + /* We only save the model reference here to unref it on destroy. + * We don't need to save the parent model to unref */ + if (!node->expansion.model) tmp_model = model; + else tmp_model = node->expansion.model; view = ewl_mvc_view_get(EWL_MVC(node)); if (view->expansion) @@ -1091,8 +1150,8 @@ if (!tmp_view) tmp_view = view; ewl_tree2_build_tree_rows(EWL_TREE2(node->tree), tmp_model, - tmp_view, tmp_data, 0, - EWL_WIDGET(node), FALSE); + tmp_view, node->expansion.data, + 0, EWL_WIDGET(node), FALSE); node->built_children = TRUE; } @@ -1202,6 +1261,35 @@ y += ewl_object_current_h_get(child); } } + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void +ewl_tree2_cb_node_data_unref(Ewl_Widget *w, void *ev_data __UNUSED__, + void *user_data __UNUSED__) +{ + Ewl_Tree2_Node *node; + Ewl_Model *model; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("w", w); + DCHECK_TYPE("w", w, EWL_TREE2_NODE_TYPE); + + node = EWL_TREE2_NODE(w); + + if (!node->expansion.data) + DRETURN(DLEVEL_STABLE); + + if (node->expansion.model) + model = node->expansion.model; + else + model = ewl_mvc_model_get(EWL_MVC(w)); + + if (model->unref) + model->unref(node->expansion.data); + + node->expansion.data = NULL; DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_mvc.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -3 -r1.34 -r1.35 --- ewl_mvc.c 11 Sep 2007 03:39:07 -0000 1.34 +++ ewl_mvc.c 30 Oct 2007 19:47:51 -0000 1.35 @@ -53,6 +53,8 @@ ewl_callback_append(EWL_WIDGET(mvc), EWL_CALLBACK_DESTROY, ewl_mvc_cb_destroy, NULL); + ewl_callback_append(EWL_WIDGET(mvc), EWL_CALLBACK_DESTROY, + ewl_mvc_cb_data_unref, NULL); ewl_mvc_selection_mode_set(mvc, EWL_SELECTION_MODE_SINGLE); @@ -1310,6 +1312,34 @@ mvc = EWL_MVC(w); IF_FREE_LIST(mvc->selected); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @internal + * @param w: The wiget to destroy + * @param ev: UNUSED + * @param data: UNUSED + * @return Returns no value + * @brief Cleans up the data of the given mvc + */ +void +ewl_mvc_cb_data_unref(Ewl_Widget *w, void *ev __UNUSED__, void *data __UNUSED__) +{ + Ewl_MVC *mvc; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("w", w); + + mvc = EWL_MVC(w); + + /* unref the data, we don't need it anylonger */ + if (mvc->data && mvc->model && mvc->model->unref) + { + mvc->model->unref(mvc->data); + mvc->data = NULL; + } DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_mvc.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -3 -r1.20 -r1.21 --- ewl_mvc.h 23 Aug 2007 05:26:51 -0000 1.20 +++ ewl_mvc.h 30 Oct 2007 19:47:51 -0000 1.21 @@ -197,6 +197,7 @@ void ewl_mvc_selected_change_cb_set(Ewl_MVC *mvc, void (*cb)(Ewl_MVC *mvc)); void ewl_mvc_cb_destroy(Ewl_Widget *w, void *ev, void *data); +void ewl_mvc_cb_data_unref(Ewl_Widget *w, void *ev, void *data); void ewl_mvc_handle_click(Ewl_MVC *mvc, Ewl_Model *model, void *data, unsigned int row, =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_model.h,v retrieving revision 1.26 retrieving revision 1.27 diff -u -3 -r1.26 -r1.27 --- ewl_model.h 23 Aug 2007 05:26:51 -0000 1.26 +++ ewl_model.h 30 Oct 2007 19:47:51 -0000 1.27 @@ -111,6 +111,18 @@ typedef unsigned int (*Ewl_Model_Data_Count)(void *data); /** + * @def EWL_MODEL_DATA_UNREF(f) + * Model callback to unreference the data used by the model. This signalize + * that the data is not used later from the model nor the controller + */ +#define EWL_MODEL_DATA_UNREF(f) ((Ewl_Model_Data_Unref)f) + +/** + * A typedef to shorten the definition of the model_data_unref callbacks. + */ +typedef unsigned int (*Ewl_Model_Data_Unref)(void *data); + +/** * @def EWL_MODEL_COLUMN_SORTABLE(f) * Model callback to check if a columns data is sortable */ @@ -157,6 +169,7 @@ Ewl_Model_Data_Fetch fetch; /**< Retrieve data for a cell */ Ewl_Model_Data_Free data_free; /**< Free data passed to view */ Ewl_Model_Data_Count count; /**< Count of data items */ + Ewl_Model_Data_Unref unref; /**< Unreference the data */ Ewl_Model_Data_Sort sort; /**< Trigger sort on column */ Ewl_Model_Data_Highlight highlight; /**< Highlight the cell */ }; @@ -193,6 +206,10 @@ void ewl_model_data_count_set(Ewl_Model *m, Ewl_Model_Data_Count count); Ewl_Model_Data_Count ewl_model_data_count_get(Ewl_Model *m); + +void ewl_model_data_unref_set(Ewl_Model *m, + Ewl_Model_Data_Unref unref); +Ewl_Model_Data_Unref ewl_model_data_unref_get(Ewl_Model *m); void ewl_model_data_expandable_set(Ewl_Model *m, Ewl_Model_Data_Expandable exp); =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_model.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -3 -r1.23 -r1.24 --- ewl_model.c 23 Aug 2007 05:26:51 -0000 1.23 +++ ewl_model.c 30 Oct 2007 19:47:51 -0000 1.24 @@ -250,6 +250,38 @@ } /** + * @param m: The Ewl_Model to set the unref callback on + * @param count: The unref callback to set on the model + * @return Returns no value. + * @brief Sets the unref callback into the model + */ +void +ewl_model_data_unref_set(Ewl_Model *m, Ewl_Model_Data_Unref unref) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("m", m); + + m->unref = unref; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param m: The Ewl_Model to get the unref callback from + * @return Returns the Ewl_Model_Data_Unref callback set on the model or + * NULL if none set. + * @brief Gets the unref callback from the model + */ +Ewl_Model_Data_Unref +ewl_model_data_unref_get(Ewl_Model *m) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("m", m, NULL); + + DRETURN_PTR(m->unref, DLEVEL_STABLE); +} + +/** * @param m: The model to set the callback on * @param exp: The expandable callback * @return Returns no value ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs