Enlightenment CVS committal Author : pfritz Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_text.c ewl_text.h ewl_text_fmt.c Log Message: make selection from code possible =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text.c,v retrieving revision 1.178 retrieving revision 1.179 diff -u -3 -r1.178 -r1.179 --- ewl_text.c 19 Aug 2007 18:48:31 -0000 1.178 +++ ewl_text.c 22 Aug 2007 08:41:10 -0000 1.179 @@ -56,6 +56,7 @@ static void ewl_text_trigger_add(Ewl_Text *t, Ewl_Text_Trigger *trigger); +static Ewl_Widget *ewl_text_selection_new(Ewl_Text *t); static void ewl_text_selection_select_to(Ewl_Text_Trigger *s, unsigned int char_idx); @@ -691,15 +692,15 @@ (t->cursor_position >= t->length.chars)) DRETURN(DLEVEL_STABLE); - ewl_text_fmt_char_to_byte(t->formatting.nodes, - t->cursor_position, char_len, - &byte_idx, &byte_len); - /* don't try to delete more then we have after the current cursor * position */ if ((t->length.chars - t->cursor_position) < char_len) char_len = t->length.chars - t->cursor_position; + ewl_text_fmt_char_to_byte(t->formatting.nodes, + t->cursor_position, char_len, + &byte_idx, &byte_len); + t->length.chars -= char_len; if (t->length.chars > 0) { @@ -870,6 +871,61 @@ } /** + * @param t: The text to do the selection on + * @param char_idx: The start position of the selection + * @param char_len: The length of the selection + * @return Returns no value + * @brief Select the text + */ +void +ewl_text_select(Ewl_Text *t, unsigned int char_idx, unsigned int char_len) +{ + Ewl_Text_Trigger *s; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("t", t); + DCHECK_TYPE("t", t, EWL_TEXT_TYPE); + + if (t->length.chars == 0) + DRETURN(DLEVEL_STABLE); + + if (char_idx > t->length.chars) + char_idx = t->length.chars; + + if (char_idx + char_len > t->length.chars) + char_len = t->length.chars - char_idx; + + /* if we haven't already have an selection create one */ + if (!t->selection) + t->selection = ewl_text_selection_new(t); + + s = EWL_TEXT_TRIGGER(t->selection); + ewl_text_trigger_start_pos_set(s, char_idx); + ewl_text_trigger_length_set(s, char_len); + + ewl_text_trigger_position(t, s); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param t: The text to do the selection on + * @return Returns no value + * @brief Select the whole text + */ +void +ewl_text_all_select(Ewl_Text *t) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("t", t); + DCHECK_TYPE("t", t, EWL_TEXT_TYPE); + + ewl_text_select(t, 0, t->length.chars); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** * @param t: The Ewl_Text widget to set the position into * @param char_pos: The position to set * @return Returns no value. @@ -3311,20 +3367,8 @@ if (!t->selection) { - Ewl_Widget *tmp; - - /* create the selection */ - tmp = ewl_text_trigger_new(EWL_TEXT_TRIGGER_TYPE_SELECTION); - ewl_container_child_append(EWL_CONTAINER(t), tmp); - ewl_widget_internal_set(tmp, TRUE); - - t->selection = tmp; - sel = EWL_TEXT_TRIGGER(tmp); - - ewl_text_trigger_start_pos_set(sel, 0); - ewl_text_trigger_length_set(sel, 0); - - ewl_widget_show(tmp); + t->selection = ewl_text_selection_new(t); + sel = EWL_TEXT_TRIGGER(t->selection); } else sel = EWL_TEXT_TRIGGER(t->selection); @@ -3422,6 +3466,28 @@ } DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/* create the selection */ +static Ewl_Widget * +ewl_text_selection_new(Ewl_Text *t) +{ + Ewl_Widget *w; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("t", t, NULL); + DCHECK_TYPE_RET("t", t, EWL_TEXT_TYPE, NULL); + + w = ewl_text_trigger_new(EWL_TEXT_TRIGGER_TYPE_SELECTION); + ewl_container_child_append(EWL_CONTAINER(t), w); + ewl_widget_internal_set(w, TRUE); + + ewl_text_trigger_start_pos_set(EWL_TEXT_TRIGGER(w), 0); + ewl_text_trigger_length_set(EWL_TEXT_TRIGGER(w), 0); + + ewl_widget_show(w); + + DRETURN_PTR(w, DLEVEL_STABLE); } static void =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text.h,v retrieving revision 1.58 retrieving revision 1.59 diff -u -3 -r1.58 -r1.59 --- ewl_text.h 18 Aug 2007 00:26:47 -0000 1.58 +++ ewl_text.h 22 Aug 2007 08:41:10 -0000 1.59 @@ -136,6 +136,9 @@ char *ewl_text_selection_text_get(Ewl_Text *t); unsigned int ewl_text_has_selection(Ewl_Text *t); Ewl_Widget *ewl_text_selection_get(Ewl_Text *t); +void ewl_text_select(Ewl_Text *t, unsigned int char_idx, + unsigned int char_len); +void ewl_text_all_select(Ewl_Text *t); void ewl_text_cursor_position_set(Ewl_Text *t, unsigned int char_pos); =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text_fmt.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- ewl_text_fmt.c 20 Aug 2007 20:30:16 -0000 1.8 +++ ewl_text_fmt.c 22 Aug 2007 08:41:10 -0000 1.9 @@ -382,7 +382,7 @@ DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("fmt", fmt, NULL); - DRETURN_PTR(ecore_dlist_first_goto(fmt->nodes),DLEVEL_STABLE); + DRETURN_PTR(ecore_dlist_first_goto(fmt->nodes), DLEVEL_STABLE); } /** @@ -396,7 +396,7 @@ DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("fmt", fmt, NULL); - DRETURN_PTR(ecore_dlist_current(fmt->nodes),DLEVEL_STABLE); + DRETURN_PTR(ecore_dlist_current(fmt->nodes), DLEVEL_STABLE); } /** ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs