Enlightenment CVS committal Author : dj2 Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_list.c ewl_list.h Log Message: - the ewl_list widget will now keep track of the last selected item in the list. - When the selected item changes a EWL_CALLBACK_VALUE_CHANGED callback will be fired. =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_list.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_list.c 16 Jul 2006 23:17:38 -0000 1.2 +++ ewl_list.c 17 Jul 2006 04:39:06 -0000 1.3 @@ -49,6 +49,10 @@ 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); } @@ -190,6 +194,93 @@ } /** + * @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) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("list", list); + DCHECK_TYPE("list", list, EWL_LIST_TYPE); + + if (list->selected == w) + DRETURN(DLEVEL_STABLE); + + /* XXX probably need to do some theme thing here to highlight as + * selected */ + list->selected = w; + + ewl_callback_call(EWL_WIDGET(list), EWL_CALLBACK_VALUE_CHANGED); + + 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); + + DRETURN_PTR(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 (idx < 0) + { + ewl_list_selected_widget_set(list, NULL); + DRETURN(DLEVEL_STABLE); + } + + ewl_list_selected_widget_set(list, + ewl_container_child_get(EWL_CONTAINER(list), idx)); + + 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) +{ + int idx; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("list", list, -1); + DCHECK_TYPE_RET("list", list, EWL_LIST_TYPE, -1); + + if (!list->selected) + DRETURN_INT(-1, DLEVEL_STABLE); + + idx = ewl_container_child_index_get(EWL_CONTAINER(list), list->selected); + + DRETURN_INT(idx, DLEVEL_STABLE); +} + +/** * @internal * @param w: The list to be configured * @param ev: UNUSED @@ -229,6 +320,104 @@ } ewl_list_dirty_set(list, FALSE); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @internal + * @param c: The container to work with + * @param w: The widget that was added + * @return Returns no value + * @brief Adds the needed callbacks to the widget + */ +void +ewl_list_cb_child_add(Ewl_Container *c, Ewl_Widget *w) +{ + 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); + + ewl_callback_append(w, EWL_CALLBACK_CLICKED, + ewl_list_cb_item_clicked, c); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @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, int idx __UNUSED__) +{ + Ewl_List *list; + + 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); + + list = EWL_LIST(c); + if (list->selected == w) + ewl_list_selected_widget_set(list, NULL); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @internal + * @param c: The container to work with + * @param w: The widget that was hidden + * @return Returns no value + * @brief Handles the hiding of a widget in the list + */ +void +ewl_list_cb_child_hide(Ewl_Container *c, Ewl_Widget *w) +{ + Ewl_List *list; + + 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); + + list = EWL_LIST(c); + if (list->selected == w) + ewl_list_selected_widget_set(list, NULL); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @internal + * @param w: The widget that was clicked + * @param ev: The event data + * @param data: The list widget + * @return Returns no value + * @brief Sets the clicked widget as selected + */ +void +ewl_list_cb_item_clicked(Ewl_Widget *w, void *ev __UNUSED__, void *data) +{ + 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); + + list = data; + ewl_list_selected_widget_set(list, w); DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_list.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_list.h 16 Jul 2006 23:17:38 -0000 1.2 +++ ewl_list.h 17 Jul 2006 04:39:06 -0000 1.3 @@ -36,6 +36,7 @@ Ewl_View *view; /**< The view for the list */ void *data; /**< The data for the list */ + Ewl_Widget *selected; /**< The selected widget */ unsigned char dirty:1; /**< Has the model changed? */ }; @@ -54,10 +55,20 @@ void ewl_list_dirty_set(Ewl_List *list, unsigned int dirty); unsigned int ewl_list_dirty_get(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); /** * @} ------------------------------------------------------------------------- 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