From f06600fc292cb82d48719e1b089080376f885f70 Mon Sep 17 00:00:00 2001 From: Cedric Bail Date: Sun, 12 Mar 2017 15:36:17 -0700 Subject: [PATCH] elementary: refactor code to avoid duplication in elm_code_widget. --- src/lib/elementary/elm_code_widget.c | 76 +++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/src/lib/elementary/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c index 1e69df8..bc89223 100644 --- a/src/lib/elementary/elm_code_widget.c +++ b/src/lib/elementary/elm_code_widget.c @@ -386,15 +386,12 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) } static void -_elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row, +_elm_code_widget_fill_range(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, + unsigned int first_row, unsigned int last_row, Elm_Code_Line *newline) { Elm_Code_Line *line; unsigned int y; - Elm_Code_Widget_Data *pd; - - pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - _elm_code_widget_resize(widget, newline); // if called from new line cb, no need to update whole range unless visible if (newline && !elm_obj_code_widget_line_visible_get(widget, newline)) @@ -411,29 +408,52 @@ _elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, uns _elm_code_widget_fill_line(widget, line); } } - static void -_elm_code_widget_refresh(Elm_Code_Widget *widget, Elm_Code_Line *line) +_elm_code_widget_fill_update(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row, + Elm_Code_Line *newline) { - Evas_Coord scroll_y, scroll_h, oy; - unsigned int first_row, last_row; - Elm_Code_Widget_Data *pd; + _elm_code_widget_resize(widget, newline); pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + _elm_code_widget_fill_range(widget, pd, first_row, last_row, newline); +} + +static Eina_Bool +_elm_code_widget_viewport_get(Elm_Code_Widget *widget, + Elm_Code_Widget_Data *pd, + unsigned int *first_row, + unsigned int *last_row) +{ + Evas_Coord scroll_y, scroll_h, oy; + evas_object_geometry_get(widget, NULL, &oy, NULL, NULL); elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h); if (scroll_h == 0) - return; + return EINA_FALSE; - elm_code_widget_position_at_coordinates_get(widget, 0, oy, &first_row, NULL); - elm_code_widget_position_at_coordinates_get(widget, 0, oy + scroll_h, &last_row, NULL); + elm_code_widget_position_at_coordinates_get(widget, 0, oy, first_row, NULL); + elm_code_widget_position_at_coordinates_get(widget, 0, oy + scroll_h, last_row, NULL); - if (last_row > elm_code_file_lines_get(pd->code->file)) - last_row = elm_code_file_lines_get(pd->code->file); + if (last_row && *last_row > elm_code_file_lines_get(pd->code->file)) + *last_row = elm_code_file_lines_get(pd->code->file); - _elm_code_widget_fill_range(widget, first_row, last_row, line); + return EINA_TRUE; +} + +static void +_elm_code_widget_refresh(Elm_Code_Widget *widget, Elm_Code_Line *line) +{ + unsigned int first_row, last_row; + + Elm_Code_Widget_Data *pd; + + pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + if (!_elm_code_widget_viewport_get(widget, pd, &first_row, &last_row)) + return ; + + _elm_code_widget_fill_update(widget, first_row, last_row, line); } static void @@ -443,7 +463,7 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - _elm_code_widget_fill_range(widget, 1, elm_code_file_lines_get(pd->code->file), NULL); + _elm_code_widget_fill_update(widget, 1, elm_code_file_lines_get(pd->code->file), NULL); } static void @@ -1946,28 +1966,12 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) if (!newline) { - Evas_Coord scroll_y, scroll_h, oy; unsigned int first_row, last_row; - unsigned int y; - evas_object_geometry_get(widget, NULL, &oy, NULL, NULL); - elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h); - if (scroll_h == 0) - return; - - elm_code_widget_position_at_coordinates_get(widget, 0, oy, &first_row, NULL); - elm_code_widget_position_at_coordinates_get(widget, 0, oy + scroll_h, &last_row, NULL); - if (last_row > elm_code_file_lines_get(pd->code->file)) - last_row = elm_code_file_lines_get(pd->code->file); + if (!_elm_code_widget_viewport_get(widget, pd, &first_row, &last_row)) + return ; - // cursor will be shown if it should be visible - evas_object_hide(pd->cursor_rect); - for (y = first_row; y <= last_row; y++) - { - line = elm_code_file_line_get(pd->code->file, y); - if (line) - _elm_code_widget_fill_line(widget, line); - } + _elm_code_widget_fill_range(widget, pd, first_row, last_row, NULL); return; } -- 2.7.4