/** * Sort the data in the heap * @param heap The heap to be sorted * * Sorts the data in the heap into the order that is used for the heap's * data. */ EAPI void ecore_sheap_sort(Ecore_Sheap *heap) { int i = 0; void **new_data; CHECK_PARAM_POINTER("heap", heap); new_data = (void **)malloc(heap->size * sizeof(void *)); /* * Extract the heap and insert into the new data array in order. */ while (heap->size > 0) new_data[i++] = ecore_sheap_extract(heap); /* * Free the old data array and update the heap with the new data, also * mark as sorted. */ FREE(heap->data); heap->data = new_data; heap->size = i; heap->sorted = TRUE; }
void inspector_update( Ecore_List *selected ) { Ewl_Widget *prow; Ecore_Sheap *slist, *sheap; Ecore_Hash *elems; Ecore_List *keys; Ecore_List *prow_stack, *sheap_stack, *elems_stack; Ewler_Widget *w; char *key; ewl_container_reset(EWL_CONTAINER(tree)); if( !selected ) return; /* add support for multiple selections later */ w = ecore_list_first_goto(selected); if( !w ) return; keys = ecore_hash_keys(w->elems); slist = ecore_sheap_new(ecore_str_compare, ecore_list_count(keys)); while( (key = ecore_list_next(keys)) ) ecore_sheap_insert(slist, key); ecore_list_destroy(keys); ecore_sheap_sort(slist); sheap = slist; elems = w->elems; sheap_stack = ecore_list_new(); elems_stack = ecore_list_new(); prow_stack = ecore_list_new(); prow = NULL; while( (key = ecore_sheap_extract(sheap)) ) { Ewler_Widget_Elem *elem; Ewl_Widget *row_items[2], *row; Ewl_Widget *text, *entry; int len; elem = ecore_hash_get(elems, key); text = ewl_text_new(key); len = ewl_text_length_get(EWL_TEXT(text)); ewl_text_cursor_position_set(EWL_TEXT(text), 0); if( elem->changed ) ewl_text_color_apply(EWL_TEXT(text), 255, 0, 0, 255, len); switch( elem->spec->type ) { case EWLER_SPEC_ELEM_STRUCT: entry = NULL; break; case EWLER_SPEC_ELEM_ENUM: entry = ewl_combo_new(elem_to_s(elem)); if( elem->items ) ecore_hash_destroy(elem->items); elem->items = ecore_hash_new(ecore_direct_hash, ecore_direct_compare); keys = ecore_hash_keys(elem->spec->info.edata.map_rev); while( (key = ecore_list_next(keys)) ) { Ewl_Widget *combo_item; int value; value = (int) ecore_hash_get(elem->spec->info.edata.map_rev, key); combo_item = ewl_menu_item_new(NULL, key); ecore_hash_set(elem->items, (void *) value, combo_item); ewl_container_child_append(EWL_CONTAINER(entry), combo_item); ewl_widget_show(combo_item); } ecore_list_destroy(keys); ewl_callback_append(entry, EWL_CALLBACK_VALUE_CHANGED, combo_value_changed, elem); break; default: entry = ewl_entry_new(elem_to_s(elem)); if( !elem->spec->modifiable ) ewl_entry_editable_set(EWL_ENTRY(entry), false); ewl_callback_append(entry, EWL_CALLBACK_VALUE_CHANGED, entry_value_changed, elem); ewl_callback_append(entry, EWL_CALLBACK_DESELECT, entry_value_changed, elem); ewl_callback_append(entry, EWL_CALLBACK_FOCUS_OUT, entry_focus_out, elem); break; } elem->text = text; elem->entry = entry; row_items[0] = text; row_items[1] = entry; row = ewl_tree_row_add(EWL_TREE(tree), EWL_ROW(prow), row_items); ewl_widget_show(text); if( entry ) ewl_widget_show(entry); if( elem->spec->type == EWLER_SPEC_ELEM_STRUCT ) { ecore_list_prepend(prow_stack, prow); ecore_list_prepend(sheap_stack, sheap); ecore_list_prepend(elems_stack, elems); prow = row; elems = elem->info.children; /* TODO: check for indexed struct */ keys = ecore_hash_keys(elems); sheap = ecore_sheap_new(ecore_str_compare, ecore_list_count(keys)); while( (key = ecore_list_next(keys)) ) ecore_sheap_insert(sheap, key); ecore_list_destroy(keys); ecore_sheap_sort(sheap); } if( sheap->size == 0 && ecore_list_count(sheap_stack) ) { ecore_sheap_destroy(sheap); prow = ecore_list_first_remove(prow_stack); sheap = ecore_list_first_remove(sheap_stack); elems = ecore_list_first_remove(elems_stack); } } ecore_list_destroy(sheap_stack); ecore_list_destroy(elems_stack); ecore_sheap_destroy(slist); }