/* A utility function to delete a range of text from the editable object. * It doesn't update the position of the cursor, nor the selection... */ static int _e_editable_text_delete(Evas_Object *editable, int start, int end) { E_Editable_Smart_Data *sd; int start_id = 0, end_id = 0, i = 0; if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return 0; start = E_CLAMP(start, 0, sd->unicode_length); end = E_CLAMP(end, 0, sd->unicode_length); if (end <= start) return 0; for (i = 0; i < end; i++) { end_id = evas_string_char_next_get(sd->text, end_id, NULL); if (i < start) start_id = end_id; } if (end_id <= start_id) return 0; memmove(&sd->text[start_id], &sd->text[end_id], sd->char_length - end_id); sd->char_length -= (end_id - start_id); sd->unicode_length -= (end - start); sd->text[sd->char_length] = '\0'; _e_editable_text_update(editable); return (end - start); }
/** * Gets a range of the text of the editable object, from position @a start to * position @a end * * @param editable an editable object * @param start the start position of the text range to get * @param end the end position of the text range to get * @return Returns the range of text. The returned string will have to be freed */ EAPI char * e_editable_text_range_get(Evas_Object *editable, int start, int end) { E_Editable_Smart_Data *sd; char *range; int start_id = 0, end_id = 0, i; if (evas_object_smart_smart_get(editable) != _e_editable_smart) SMARTERR(NULL); if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return NULL; start = E_CLAMP(start, 0, sd->unicode_length); end = E_CLAMP(end, 0, sd->unicode_length); if (end <= start) return NULL; for (i = 0; i < end; i++) { end_id = evas_string_char_next_get(sd->text, end_id, NULL); if (i < start) start_id = end_id; } if (end_id <= start_id) return NULL; range = malloc((end_id - start_id + 1) * sizeof(char)); strncpy(range, &sd->text[start_id], end_id - start_id); range[end_id - start_id] = '\0'; return range; }
/** * Moves the selection bound of the editable object to the given position * * @param editable an editable object * @param pos the position where to move the selection bound */ EAPI void e_editable_selection_pos_set(Evas_Object *editable, int pos) { E_Editable_Smart_Data *sd; if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; pos = E_CLAMP(pos, 0, sd->unicode_length); if (sd->selection_pos == pos) return; sd->selection_pos = pos; _e_editable_selection_update(editable); }
/** * Moves the cursor of the editable object to the given position * * @param editable an editable object * @param pos the position where to move the cursor */ EAPI void e_editable_cursor_pos_set(Evas_Object *editable, int pos) { E_Editable_Smart_Data *sd; if (evas_object_smart_smart_get(editable) != _e_editable_smart) SMARTERRNR(); if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; pos = E_CLAMP(pos, 0, sd->unicode_length); if (sd->cursor_pos == pos) return; sd->cursor_pos = pos; _e_editable_cursor_update(editable); }
static void _systray_xembed_restack(Instance_Xembed *xembed) { E_Layer layer; E_Shelf *es = xembed->inst->gcc->gadcon->shelf; if (es) { layer = e_comp_canvas_layer_map_to(e_comp_canvas_layer_map(es->cfg->layer) + 1); } else layer = E_LAYER_CLIENT_DESKTOP; layer = E_CLAMP(layer, E_LAYER_CLIENT_DESKTOP, E_LAYER_CLIENT_ABOVE); evas_object_layer_set(xembed->ec->frame, layer); }
static int _win_auto_size_calc(int max, int min) { const float *itr, scales[] = {0.25, 0.3, 0.5, 0.75, 0.8, 0.9, 0.95, -1}; for (itr = scales; *itr > 0; itr++) { int value = *itr * max; if (value > min) /* not >=, try a bit larger */ { if (min > 10) value = E_CLAMP(value, min, min * 1.5); return value; } } return min; }