Enlightenment CVS committal Author : dj2 Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_combo.c ewl_combo.h ewl_filepicker.c ewl_mvc.c ewl_mvc.h Log Message: - start consolidating mvc selection code into ewl_mvc. - ewl_combo converted over to start =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_combo.c,v retrieving revision 1.32 retrieving revision 1.33 diff -u -3 -r1.32 -r1.33 --- ewl_combo.c 30 Sep 2006 18:41:01 -0000 1.32 +++ ewl_combo.c 3 Oct 2006 05:17:13 -0000 1.33 @@ -45,6 +45,8 @@ ewl_widget_inherit(EWL_WIDGET(combo), EWL_COMBO_TYPE); ewl_widget_appearance_set(EWL_WIDGET(combo), EWL_COMBO_TYPE); ewl_box_orientation_set(EWL_BOX(combo), EWL_ORIENTATION_HORIZONTAL); + ewl_mvc_selected_change_cb_set(EWL_MVC(combo), + ewl_combo_cb_selected_change); combo->button = ewl_button_new(); ewl_container_child_append(EWL_CONTAINER(combo), combo->button); @@ -73,8 +75,6 @@ ewl_object_alignment_set(EWL_OBJECT(combo->popup->popup), EWL_FLAG_ALIGN_LEFT | EWL_FLAG_ALIGN_TOP); - /* default this to -2 so that when we first show we will set it to -1 */ - combo->selected_idx = -2; ewl_callback_append(EWL_WIDGET(combo), EWL_CALLBACK_CONFIGURE, ewl_combo_cb_configure, NULL); ewl_object_fill_policy_set(EWL_OBJECT(combo), @@ -84,75 +84,6 @@ } /** - * @param combo: The Ewl_Combo to work with - * @param idx: The data index to set selected - * @return Returns no value - * @brief Sets the given item in the data as selected - */ -void -ewl_combo_selected_set(Ewl_Combo *combo, int idx) -{ - Ewl_View *view; - Ewl_Model *model; - void *mvc_data; - - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("combo", combo); - DCHECK_TYPE("combo", combo, EWL_COMBO_TYPE); - - view = ewl_mvc_view_get(EWL_MVC(combo)); - model = ewl_mvc_model_get(EWL_MVC(combo)); - mvc_data = ewl_mvc_data_get(EWL_MVC(combo)); - - /* we don't bail out early as the user could have prepended widgets - * to their data, so the selected_idx will be the same but the - * widget is actually different */ - combo->selected_idx = idx; - - /* remove the previously selected value */ - if (combo->selected) - ewl_widget_destroy(combo->selected); - - /* if we have a selected value then show it in the top, else show - * the header */ - if ((idx > -1) && (!combo->editable)) - { - combo->selected = view->construct(); - view->assign(combo->selected, - model->fetch(mvc_data, idx, 0)); - } - else if (view && view->header_fetch) - combo->selected = view->header_fetch(mvc_data, - combo->selected_idx); - - if (combo->selected) - { - ewl_container_child_prepend(EWL_CONTAINER(combo), combo->selected); - ewl_object_fill_policy_set(EWL_OBJECT(combo->selected), - EWL_FLAG_FILL_VFILL); - ewl_widget_show(combo->selected); - } - - DLEAVE_FUNCTION(DLEVEL_STABLE); -} - -/** - * @param combo: The Ewl_Combo to get the selected value from - * @return Returns the index of the currently selected item or -1 if none - * selected. - * @brief Retrieves the currently selected index from the combo box - */ -int -ewl_combo_selected_get(Ewl_Combo *combo) -{ - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("combo", combo, -1); - DCHECK_TYPE_RET("combo", combo, EWL_COMBO_TYPE, -1); - - DRETURN_INT(combo->selected_idx, DLEVEL_STABLE); -} - -/** * @param combo: The Ewl_Combo to use * @param editable: Set if the combo is editable or not * @return Returns no value @@ -175,7 +106,7 @@ combo->editable = !!editable; /* force the selected display to change */ - ewl_combo_selected_set(combo, combo->selected_idx); + ewl_combo_cb_selected_change(EWL_MVC(combo)); DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -222,8 +153,8 @@ ewl_floater_position_set(EWL_FLOATER(combo->popup->popup), 0, CURRENT_H(w)); - if (combo->selected_idx < -1) - ewl_combo_selected_set(combo, -1); +// if (combo->selected_idx < -1) +// ewl_combo_selected_set(combo, -1); DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -347,10 +278,56 @@ combo = data; i = ewl_container_child_index_get(EWL_CONTAINER(combo->popup), w); - ewl_combo_selected_set(combo, i); + ewl_mvc_selected_set(EWL_MVC(combo), i); ewl_combo_cb_increment_clicked(NULL, NULL, data); ewl_callback_call(EWL_WIDGET(combo), EWL_CALLBACK_VALUE_CHANGED); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void +ewl_combo_cb_selected_change(Ewl_MVC *mvc) +{ + int idx; + Ewl_View *view; + Ewl_Model *model; + Ewl_Combo *combo; + void *mvc_data; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); + + combo = EWL_COMBO(mvc); + view = ewl_mvc_view_get(mvc); + model = ewl_mvc_model_get(mvc); + mvc_data = ewl_mvc_data_get(mvc); + + /* remove the previously selected value */ + if (combo->header) + ewl_widget_destroy(combo->header); + + idx = ewl_mvc_selected_get(mvc); + + /* if we have a selected value then show it in the top, else show + * the header */ + if ((idx > -1) && (!combo->editable)) + { + combo->header = view->construct(); + view->assign(combo->header, + model->fetch(mvc_data, idx, 0)); + } + else if (view && view->header_fetch) + combo->header = view->header_fetch(mvc_data, idx); + + if (combo->header) + { + ewl_container_child_prepend(EWL_CONTAINER(combo), combo->header); + ewl_object_fill_policy_set(EWL_OBJECT(combo->header), + EWL_FLAG_FILL_VFILL); + ewl_widget_show(combo->header); + } DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_combo.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -3 -r1.15 -r1.16 --- ewl_combo.h 24 Sep 2006 20:26:50 -0000 1.15 +++ ewl_combo.h 3 Oct 2006 05:17:13 -0000 1.16 @@ -39,21 +39,15 @@ { Ewl_MVC mvc; /**< Inherit from Ewl_MVC */ - Ewl_Menu_Base *popup; /**< Use a menu to display with. */ - - Ewl_Widget *button; /**< expand/contract button */ - Ewl_Widget *selected; /**< Selected widget */ - int selected_idx; /**< The selected row */ - + Ewl_Menu_Base *popup; /**< Use a menu to display with. */ + Ewl_Widget *button; /**< expand/contract button */ + Ewl_Widget *header; /**< The combo header widget */ unsigned char editable:1; /**< Is the combo editable */ }; Ewl_Widget *ewl_combo_new(void); int ewl_combo_init(Ewl_Combo *combo); -int ewl_combo_selected_get(Ewl_Combo *combo); -void ewl_combo_selected_set(Ewl_Combo *combo, int); - void ewl_combo_editable_set(Ewl_Combo *combo, unsigned int editable); unsigned int ewl_combo_editable_get(Ewl_Combo *combo); @@ -65,6 +59,8 @@ void ewl_combo_cb_decrement_clicked(Ewl_Widget *w, void *ev, void *data); void ewl_combo_cb_increment_clicked(Ewl_Widget *w, void *ev, void *data); void ewl_combo_cb_item_clicked(Ewl_Widget *w, void *ev, void *data); + +void ewl_combo_cb_selected_change(Ewl_MVC *mvc); /** * @} =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filepicker.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- ewl_filepicker.c 24 Sep 2006 20:26:50 -0000 1.11 +++ ewl_filepicker.c 3 Oct 2006 05:17:13 -0000 1.12 @@ -144,7 +144,7 @@ ewl_mvc_model_set(EWL_MVC(fp->type_combo), model); ewl_mvc_view_set(EWL_MVC(fp->type_combo), view); ewl_mvc_data_set(EWL_MVC(fp->type_combo), fp); - ewl_combo_selected_set(EWL_COMBO(fp->type_combo), 0); + ewl_mvc_selected_set(EWL_MVC(fp->type_combo), 0); ewl_combo_editable_set(EWL_COMBO(fp->type_combo), TRUE); ewl_callback_append(fp->type_combo, EWL_CALLBACK_VALUE_CHANGED, ewl_filepicker_cb_type_change, fp); @@ -712,7 +712,7 @@ ecore_list_prepend(fp->path, strdup(path)); ewl_mvc_dirty_set(EWL_MVC(fp->path_combo), TRUE); - ewl_combo_selected_set(EWL_COMBO(fp->path_combo), 0); + ewl_mvc_selected_set(EWL_MVC(fp->path_combo), 0); DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -730,7 +730,7 @@ fp = data; ecore_list_goto_index(fp->path, - ewl_combo_selected_get(EWL_COMBO(w))); + ewl_mvc_selected_get(EWL_MVC(w))); ewl_filepicker_directory_set(fp, ecore_list_current(fp->path)); DLEAVE_FUNCTION(DLEVEL_STABLE); @@ -766,7 +766,7 @@ DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); fp = data; - idx = ewl_combo_selected_get(EWL_COMBO(w)); + idx = ewl_mvc_selected_get(EWL_MVC(w)); if (idx > -1) { ecore_list_goto_index(fp->filters, idx); =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_mvc.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- ewl_mvc.c 24 Sep 2006 20:26:50 -0000 1.1 +++ ewl_mvc.c 3 Oct 2006 05:17:13 -0000 1.2 @@ -192,3 +192,248 @@ DRETURN_INT(mvc->dirty, DLEVEL_STABLE); } +/** + * @param mvc: The MVC widget to use + * @param multi: Is this widget multiselect capable + * @return Returns no value + * @brief Sets the multiselect capabilities of the mvc widget + */ +void +ewl_mvc_multiselect_set(Ewl_MVC *mvc, unsigned int multi) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); + + mvc->multiselect = !!multi; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param mvc: The MVC widget to use + * @return Returns the multiselect setting of the mvc widget + * @brief Retrieves the multiselect setting of the widget + */ +unsigned int +ewl_mvc_multiselect_get(Ewl_MVC *mvc) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("mvc", mvc, FALSE); + DCHECK_TYPE_RET("mvc", mvc, EWL_MVC_TYPE, FALSE); + + DRETURN_INT(mvc->multiselect, DLEVEL_STABLE); +} + +/** + * @param mvc: The MVC to work with + * @param list: The list of indicies to set selected, list is -1 terminated + * @return Returns no value + * @brief Sets the list of indices selected + */ +void +ewl_mvc_selected_list_set(Ewl_MVC *mvc, int *list) +{ + int i, size; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); + + if (!list) + { + mvc->selected.count = 0; + mvc->selected.items = realloc(mvc->selected.items, 2 * (sizeof(int))); + mvc->selected.items[0] = -1; + } + else if (mvc->multiselect) + { + mvc->selected.count = 0; + for (i = 0; list[i] != -1; i++) + mvc->selected.count ++; + + size = (mvc->selected.count + 1) * (sizeof(int)); + mvc->selected.items = realloc(mvc->selected.items, size); + mvc->selected.items[mvc->selected.count] = -1; + + if (mvc->selected.count > 0) + memcpy(mvc->selected.items, list, size); + } + else + { + mvc->selected.count = 1; + mvc->selected.items = realloc(mvc->selected.items, 2 * sizeof(int)); + mvc->selected.items[0] = list[0]; + mvc->selected.items[1] = -1; + } + + if (mvc->cb.selected_change) + mvc->cb.selected_change(mvc); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param mvc: The MVC to get the list from + * @return Returns the list of selected indices, list is -1 terminated. + * @brief Retrieves the list of selected indicies + */ +const int * +ewl_mvc_selected_list_get(Ewl_MVC *mvc) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("mvc", mvc, NULL); + DCHECK_TYPE_RET("mvc", mvc, EWL_MVC_TYPE, NULL); + + DRETURN_PTR(mvc->selected.items, DLEVEL_STABLE); +} + +/** + * @param mvc: The MVC to set the list into + * @param start: The range start + * @param end: The range end + * @return Returns no value + * @brief Sets the given range, inclusive, as selected in the mvc + */ +void +ewl_mvc_selected_range_set(Ewl_MVC *mvc, int start, int end) +{ + int t; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); + + if (start < 0) start = 0; + if (end < 0) end = 0; + + /* make sure the start comes first */ + if (end < start) + { + t = start; + start = end; + end = t; + } + + /* this isn't multiselect so make this one item, the start */ + if (!mvc->multiselect) + end = start; + + t = (end - start) + 1; + mvc->selected.count = t; + mvc->selected.items = realloc(mvc->selected.items, (t + 1) * sizeof(int)); + mvc->selected.items[mvc->selected.count] = -1; + + for (t = 0; t < mvc->selected.count; t++) + mvc->selected.items[t] = start + t; + + if (mvc->cb.selected_change) + mvc->cb.selected_change(mvc); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param mvc: The MVC to work with + * @param i: The index to set selected + * @return Returns no value + * @brief Sets the given index as selected + */ +void +ewl_mvc_selected_set(Ewl_MVC *mvc, int i) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); + + mvc->selected.count = 1; + mvc->selected.items = realloc(mvc->selected.items, 2 * sizeof(int)); + mvc->selected.items[0] = i; + mvc->selected.items[1] = -1; + + if (mvc->cb.selected_change) + mvc->cb.selected_change(mvc); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param mvc: The MVC to work with + * @param i: The index to add to the selected list + * @return Returns no value + * @brief Adds the given index to the selected list + */ +void +ewl_mvc_selected_add(Ewl_MVC *mvc, int i) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); + + mvc->selected.count ++; + mvc->selected.items = realloc(mvc->selected.items, + (mvc->selected.count + 1) * sizeof(int)); + mvc->selected.items[mvc->selected.count - 1] = i; + mvc->selected.items[mvc->selected.count] = -1; + + if (mvc->cb.selected_change) + mvc->cb.selected_change(mvc); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param mvc: The MVC to get the data from + * @return Returns the last selected item + * @brief Retrieves the last selected item + */ +int +ewl_mvc_selected_get(Ewl_MVC *mvc) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("mvc", mvc, -1); + DCHECK_TYPE_RET("mvc", mvc, EWL_MVC_TYPE, -1); + + if (mvc->selected.count == 0) + DRETURN_INT(-1, DLEVEL_STABLE); + + DRETURN_INT(mvc->selected.items[mvc->selected.count - 1], + 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 + */ +int +ewl_mvc_selected_count_get(Ewl_MVC *mvc) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("mvc", mvc, 0); + DCHECK_TYPE_RET("mvc", mvc, EWL_MVC_TYPE, 0); + + DRETURN_INT(mvc->selected.count, DLEVEL_STABLE); +} + +/** + * @param mvc: The MVC to set the callback into + * @param cb: The callback to set + * @return Returns no value + * @brief Sets the given callback into the MVC widget + */ +void +ewl_mvc_selected_change_cb_set(Ewl_MVC *mvc, void (*cb)(Ewl_MVC *mvc)) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("mvc", mvc); + DCHECK_TYPE("mvc", mvc, EWL_MVC_TYPE); + + mvc->cb.selected_change = cb; + if (mvc->selected.count > 0) + cb(mvc); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + + =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_mvc.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- ewl_mvc.h 24 Sep 2006 20:26:50 -0000 1.1 +++ ewl_mvc.h 3 Oct 2006 05:17:13 -0000 1.2 @@ -38,9 +38,17 @@ struct { void (*view_change)(Ewl_MVC *mvc); + void (*selected_change)(Ewl_MVC *mvc); } cb; - unsigned char dirty:1; /**< Is the data dirty */ + struct + { + int *items; /**< Selected items */ + int count; /**< Number of selected */ + } selected; /**< The selected info */ + + unsigned char multiselect:1; /**< is the widget multiselect capable */ + unsigned char dirty:1; /**< Is the data dirty */ }; int ewl_mvc_init(Ewl_MVC *mvc); @@ -48,8 +56,6 @@ void ewl_mvc_view_set(Ewl_MVC *mvc, Ewl_View *view); Ewl_View *ewl_mvc_view_get(Ewl_MVC *mvc); -void ewl_mvc_view_change_cb_set(Ewl_MVC *mvc, void (*cb)(Ewl_MVC *mvc)); - void ewl_mvc_model_set(Ewl_MVC *mvc, Ewl_Model *model); Ewl_Model *ewl_mvc_model_get(Ewl_MVC *mvc); @@ -58,6 +64,27 @@ void ewl_mvc_dirty_set(Ewl_MVC *mvc, unsigned int dirty); unsigned int ewl_mvc_dirty_get(Ewl_MVC *mvc); + +void ewl_mvc_multiselect_set(Ewl_MVC *mvc, unsigned int multi); +unsigned int ewl_mvc_multiselect_get(Ewl_MVC *mvc); + +void ewl_mvc_selected_list_set(Ewl_MVC *mvc, int *list); +const int *ewl_mvc_selected_list_get(Ewl_MVC *mvc); + +void ewl_mvc_selected_range_set(Ewl_MVC *mvc, int start, int end); + +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); + +int ewl_mvc_selected_count_get(Ewl_MVC *mvc); + +/* + * internal + */ +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)); + #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