Enlightenment CVS committal Author : dj2 Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_list.c ewl_list.h ewl_mvc.c ewl_mvc.h Log Message: - api break. covert ewl_list over to the ewl_mvc selection code - make the ewl_mvc selection code remove selected indices if the widget is deleted/hidden. =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_list.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- ewl_list.c 3 Oct 2006 03:58:16 -0000 1.7 +++ ewl_list.c 3 Oct 2006 05:52:02 -0000 1.8 @@ -44,99 +44,17 @@ ewl_widget_appearance_set(EWL_WIDGET(list), EWL_LIST_TYPE); ewl_widget_inherit(EWL_WIDGET(list), EWL_LIST_TYPE); + ewl_mvc_selected_change_cb_set(EWL_MVC(list), ewl_list_cb_selected_change); + ewl_callback_append(EWL_WIDGET(list), EWL_CALLBACK_CONFIGURE, ewl_list_cb_configure, NULL); - ewl_container_hide_notify_set(EWL_CONTAINER(list), ewl_list_cb_child_hide); ewl_container_add_notify_set(EWL_CONTAINER(list), ewl_list_cb_child_add); - ewl_container_remove_notify_set(EWL_CONTAINER(list), ewl_list_cb_child_del); DRETURN_INT(TRUE, DLEVEL_STABLE); } /** - * @param list: The list to work with - * @param w: The widget to set selected - * @return Returns no value - * @brief Sets the selected widget in the list - */ -void -ewl_list_selected_widget_set(Ewl_List *list, Ewl_Widget *w) -{ - int idx; - - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("list", list); - DCHECK_TYPE("list", list, EWL_LIST_TYPE); - - if (!w) - idx = -1; - else - idx = ewl_container_child_index_get(EWL_CONTAINER(list), w); - - ewl_list_selected_index_set(list, idx); - - DLEAVE_FUNCTION(DLEVEL_STABLE); -} - -/** - * @param list: The list to work with - * @return Returns the currently selected widget or NULL if none set - * @brief Retrieves the currently selected widget or NULL if none set - */ -Ewl_Widget * -ewl_list_selected_widget_get(Ewl_List *list) -{ - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("list", list, NULL); - DCHECK_TYPE_RET("list", list, EWL_LIST_TYPE, NULL); - - if (list->selected == -1) - DRETURN_PTR(NULL, DLEVEL_STABLE); - - DRETURN_PTR(ewl_container_child_get(EWL_CONTAINER(list), - list->selected), DLEVEL_STABLE); -} - -/** - * @param list: The list to work with - * @param idx: The index of the widget to set selected - * @return Returns no value - * @brief Sets the selected widget based on index into the list - */ -void -ewl_list_selected_index_set(Ewl_List *list, int idx) -{ - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("list", list); - DCHECK_TYPE("list", list, EWL_LIST_TYPE); - - if (list->selected == idx) - DRETURN(DLEVEL_STABLE); - - list->selected = idx; - - ewl_callback_call(EWL_WIDGET(list), EWL_CALLBACK_VALUE_CHANGED); - - DLEAVE_FUNCTION(DLEVEL_STABLE); -} - -/** - * @param list: The list to work with - * @return Returns the index of the currently selected or -1 if none set - * @brief Retrieves the currenlty selected widgets index or -1 if none set - */ -int -ewl_list_selected_index_get(Ewl_List *list) -{ - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("list", list, -1); - DCHECK_TYPE_RET("list", list, EWL_LIST_TYPE, -1); - - DRETURN_INT(list->selected, DLEVEL_STABLE); -} - -/** * @internal * @param w: The list to be configured * @param ev: UNUSED @@ -183,8 +101,7 @@ ewl_container_child_append(EWL_CONTAINER(list), o); } - /* XXX mark the selected widget here */ - + ewl_list_cb_selected_change(EWL_MVC(list)); ewl_mvc_dirty_set(EWL_MVC(list), FALSE); DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -214,77 +131,48 @@ /** * @internal - * @param c: The container to work with - * @param w: The widget to work with - * @param idx: The index of the deleted widget - * @return Returns no value - * @brief Removes the selected status from the widget - */ -void -ewl_list_cb_child_del(Ewl_Container *c, Ewl_Widget *w __UNUSED__, int idx) -{ - Ewl_List *list; - - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("c", c); - DCHECK_TYPE("c", c, EWL_CONTAINER_TYPE); - - list = EWL_LIST(c); - if (list->selected == idx) - ewl_list_selected_index_set(list, -1); - - DLEAVE_FUNCTION(DLEVEL_STABLE); -} - -/** - * @internal - * @param c: The container to work with - * @param w: The widget that was hidden + * @param w: The widget that was clicked + * @param ev: The event data + * @param data: The list widget * @return Returns no value - * @brief Handles the hiding of a widget in the list + * @brief Sets the clicked widget as selected */ void -ewl_list_cb_child_hide(Ewl_Container *c, Ewl_Widget *w) +ewl_list_cb_item_clicked(Ewl_Widget *w, void *ev __UNUSED__, void *data) { Ewl_List *list; - Ewl_Widget *sel; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("c", c); DCHECK_PARAM_PTR("w", w); - DCHECK_TYPE("c", c, EWL_CONTAINER_TYPE); + DCHECK_PARAM_PTR("data", data); DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); + DCHECK_TYPE("data", data, EWL_LIST_TYPE); - list = EWL_LIST(c); - sel = ewl_list_selected_widget_get(list); - if (sel == w) - ewl_list_selected_index_set(list, -1); + list = data; + ewl_mvc_selected_set(EWL_MVC(list), + ewl_container_child_index_get(EWL_CONTAINER(list), w)); + + ewl_callback_call(EWL_WIDGET(list), EWL_CALLBACK_VALUE_CHANGED); DLEAVE_FUNCTION(DLEVEL_STABLE); } /** * @internal - * @param w: The widget that was clicked - * @param ev: The event data - * @param data: The list widget + * @param mvc: The MVC to work with * @return Returns no value - * @brief Sets the clicked widget as selected + * @brief Called when the selected widgets changes */ void -ewl_list_cb_item_clicked(Ewl_Widget *w, void *ev __UNUSED__, void *data) +ewl_list_cb_selected_change(Ewl_MVC *mvc) { - Ewl_List *list; - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("w", w); - DCHECK_PARAM_PTR("data", data); - DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); - DCHECK_TYPE("data", data, EWL_LIST_TYPE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); - list = data; - ewl_list_selected_widget_set(list, w); + /* XXX selection highlight code here */ DLEAVE_FUNCTION(DLEVEL_STABLE); } + =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_list.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- ewl_list.h 3 Oct 2006 03:58:16 -0000 1.7 +++ ewl_list.h 3 Oct 2006 05:52:02 -0000 1.8 @@ -31,26 +31,18 @@ struct Ewl_List { Ewl_MVC mvc; /**< The mvc parent */ - int selected; /**< The selected widget */ }; Ewl_Widget *ewl_list_new(void); int ewl_list_init(Ewl_List *list); -void ewl_list_selected_widget_set(Ewl_List *list, Ewl_Widget *w); -Ewl_Widget *ewl_list_selected_widget_get(Ewl_List *list); - -void ewl_list_selected_index_set(Ewl_List *list, int idx); -int ewl_list_selected_index_get(Ewl_List *list); - /* * Internal stuff. */ void ewl_list_cb_configure(Ewl_Widget *w, void *ev, void *data); void ewl_list_cb_item_clicked(Ewl_Widget *w, void *ev, void *data); void ewl_list_cb_child_add(Ewl_Container *c, Ewl_Widget *w); -void ewl_list_cb_child_del(Ewl_Container *c, Ewl_Widget *w, int idx); -void ewl_list_cb_child_hide(Ewl_Container *c, Ewl_Widget *w); +void ewl_list_cb_selected_change(Ewl_MVC *mvc); /** * @} =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_mvc.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_mvc.c 3 Oct 2006 05:17:13 -0000 1.2 +++ ewl_mvc.c 3 Oct 2006 05:52:02 -0000 1.3 @@ -402,6 +402,37 @@ } /** + * @param mvc: The MVC to work with + * @param idx: The index to remove + * @return Returns no value + * @brief Removes the given index from the list of selected indices + */ +void +ewl_mvc_selected_rm(Ewl_MVC *mvc, int idx) +{ + int i; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); + + for (i = 0; i < mvc->selected.count; i++) + { + if (mvc->selected.items[i] == idx) + { + mvc->selected.count --; + memmove((mvc->selected.items + i), + (mvc->selected.items + i + 1), + ((mvc->selected.count - i) * sizeof(int))); + mvc->selected.items[mvc->selected.count] = -1; + break; + } + } + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** * @param mvc: The MVC widget to work with * @return Returns the number of items selected in the MVC * @brief Retrives the number of items selected in the widget @@ -417,6 +448,31 @@ } /** + * @param mvc: The MVC to work with + * @param idx: The index to check for + * @return Returns TRUE if the index is selected, FALSE otherwise + * @brief Checks if the given index is selected or not. + */ +unsigned int +ewl_mvc_is_selected(Ewl_MVC *mvc, int idx) +{ + int i; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("mvc", mvc, FALSE); + DCHECK_TYPE_RET("mvc", mvc, EWL_MVC_TYPE, FALSE); + + for (i = 0; i < mvc->selected.count; i++) + { + if (mvc->selected.items[i] == idx) + DRETURN_INT(TRUE, DLEVEL_STABLE); + } + + DRETURN_INT(FALSE, DLEVEL_STABLE); +} + +/** + * @internal * @param mvc: The MVC to set the callback into * @param cb: The callback to set * @return Returns no value @@ -432,6 +488,53 @@ mvc->cb.selected_change = cb; if (mvc->selected.count > 0) cb(mvc); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @internal + * @param c: The container + * @param w: UNUSED + * @param idx: The index removed from + * @return Returns no value + * @brief Checks if the given widget index is in the selected array and + * removes it + */ +void +ewl_mvc_cb_child_del(Ewl_Container *c, Ewl_Widget *w __UNUSED__, int idx) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("c", c); + DCHECK_TYPE("c", c, EWL_CONTAINER_TYPE); + + if (ewl_mvc_is_selected(EWL_MVC(c), idx)) + ewl_mvc_selected_rm(EWL_MVC(c), idx); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @internal + * @param c: The container to work with + * @param w: The widget + * @return Returns no value + * @brief Checks if the widget is in the selected list and removes it + */ +void +ewl_mvc_cb_child_hide(Ewl_Container *c, Ewl_Widget *w) +{ + int idx; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("c", c); + DCHECK_PARAM_PTR("w", w); + DCHECK_TYPE("c", c, EWL_CONTAINER_TYPE); + DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); + + idx = ewl_container_child_index_get(c, w); + if (idx > -1 && ewl_mvc_is_selected(EWL_MVC(c), idx)) + ewl_mvc_selected_rm(EWL_MVC(c), idx); DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_mvc.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_mvc.h 3 Oct 2006 05:17:13 -0000 1.2 +++ ewl_mvc.h 3 Oct 2006 05:52:02 -0000 1.3 @@ -76,8 +76,10 @@ void ewl_mvc_selected_set(Ewl_MVC *mvc, int i); void ewl_mvc_selected_add(Ewl_MVC *mvc, int i); int ewl_mvc_selected_get(Ewl_MVC *mvc); +void ewl_mvc_selected_rm(Ewl_MVC *mvc, int idx); int ewl_mvc_selected_count_get(Ewl_MVC *mvc); +unsigned int ewl_mvc_is_selected(Ewl_MVC *mvc, int idx); /* * internal @@ -85,6 +87,8 @@ void ewl_mvc_view_change_cb_set(Ewl_MVC *mvc, void (*cb)(Ewl_MVC *mvc)); void ewl_mvc_selected_change_cb_set(Ewl_MVC *mvc, void (*cb)(Ewl_MVC *mvc)); +void ewl_mvc_cb_child_del(Ewl_Container *c, Ewl_Widget *w, int idx); +void ewl_mvc_cb_child_hide(Ewl_Container *c, Ewl_Widget *w); #endif ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs