summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-03-12 15:36:17 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-03-12 15:36:17 -0700
commitf06600fc292cb82d48719e1b089080376f885f70 (patch)
tree6d2bd8116ab92948c921d9b7c1d7f4017edd7eee
parent81c2c88e99c4b958aed30de6319b6f0b2e6b0770 (diff)
elementary: refactor code to avoid duplication in elm_code_widget.
-rw-r--r--src/lib/elementary/elm_code_widget.c76
1 files changed, 40 insertions, 36 deletions
diff --git a/src/lib/elementary/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c
index 1e69df8c9b..bc89223f74 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)
386} 386}
387 387
388static void 388static void
389_elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row, 389_elm_code_widget_fill_range(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd,
390 unsigned int first_row, unsigned int last_row,
390 Elm_Code_Line *newline) 391 Elm_Code_Line *newline)
391{ 392{
392 Elm_Code_Line *line; 393 Elm_Code_Line *line;
393 unsigned int y; 394 unsigned int y;
394 Elm_Code_Widget_Data *pd;
395
396 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
397 _elm_code_widget_resize(widget, newline);
398 395
399 // if called from new line cb, no need to update whole range unless visible 396 // if called from new line cb, no need to update whole range unless visible
400 if (newline && !elm_obj_code_widget_line_visible_get(widget, newline)) 397 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
411 _elm_code_widget_fill_line(widget, line); 408 _elm_code_widget_fill_line(widget, line);
412 } 409 }
413} 410}
414
415static void 411static void
416_elm_code_widget_refresh(Elm_Code_Widget *widget, Elm_Code_Line *line) 412_elm_code_widget_fill_update(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row,
413 Elm_Code_Line *newline)
417{ 414{
418 Evas_Coord scroll_y, scroll_h, oy;
419 unsigned int first_row, last_row;
420
421 Elm_Code_Widget_Data *pd; 415 Elm_Code_Widget_Data *pd;
422 416
417 _elm_code_widget_resize(widget, newline);
423 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 418 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
424 419
420 _elm_code_widget_fill_range(widget, pd, first_row, last_row, newline);
421}
422
423static Eina_Bool
424_elm_code_widget_viewport_get(Elm_Code_Widget *widget,
425 Elm_Code_Widget_Data *pd,
426 unsigned int *first_row,
427 unsigned int *last_row)
428{
429 Evas_Coord scroll_y, scroll_h, oy;
430
425 evas_object_geometry_get(widget, NULL, &oy, NULL, NULL); 431 evas_object_geometry_get(widget, NULL, &oy, NULL, NULL);
426 elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h); 432 elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h);
427 if (scroll_h == 0) 433 if (scroll_h == 0)
428 return; 434 return EINA_FALSE;
429 435
430 elm_code_widget_position_at_coordinates_get(widget, 0, oy, &first_row, NULL); 436 elm_code_widget_position_at_coordinates_get(widget, 0, oy, first_row, NULL);
431 elm_code_widget_position_at_coordinates_get(widget, 0, oy + scroll_h, &last_row, NULL); 437 elm_code_widget_position_at_coordinates_get(widget, 0, oy + scroll_h, last_row, NULL);
432 438
433 if (last_row > elm_code_file_lines_get(pd->code->file)) 439 if (last_row && *last_row > elm_code_file_lines_get(pd->code->file))
434 last_row = elm_code_file_lines_get(pd->code->file); 440 *last_row = elm_code_file_lines_get(pd->code->file);
435 441
436 _elm_code_widget_fill_range(widget, first_row, last_row, line); 442 return EINA_TRUE;
443}
444
445static void
446_elm_code_widget_refresh(Elm_Code_Widget *widget, Elm_Code_Line *line)
447{
448 unsigned int first_row, last_row;
449
450 Elm_Code_Widget_Data *pd;
451
452 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
453 if (!_elm_code_widget_viewport_get(widget, pd, &first_row, &last_row))
454 return ;
455
456 _elm_code_widget_fill_update(widget, first_row, last_row, line);
437} 457}
438 458
439static void 459static void
@@ -443,7 +463,7 @@ _elm_code_widget_fill(Elm_Code_Widget *widget)
443 463
444 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 464 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
445 465
446 _elm_code_widget_fill_range(widget, 1, elm_code_file_lines_get(pd->code->file), NULL); 466 _elm_code_widget_fill_update(widget, 1, elm_code_file_lines_get(pd->code->file), NULL);
447} 467}
448 468
449static void 469static void
@@ -1946,28 +1966,12 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline)
1946 1966
1947 if (!newline) 1967 if (!newline)
1948 { 1968 {
1949 Evas_Coord scroll_y, scroll_h, oy;
1950 unsigned int first_row, last_row; 1969 unsigned int first_row, last_row;
1951 unsigned int y;
1952 1970
1953 evas_object_geometry_get(widget, NULL, &oy, NULL, NULL); 1971 if (!_elm_code_widget_viewport_get(widget, pd, &first_row, &last_row))
1954 elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h); 1972 return ;
1955 if (scroll_h == 0)
1956 return;
1957
1958 elm_code_widget_position_at_coordinates_get(widget, 0, oy, &first_row, NULL);
1959 elm_code_widget_position_at_coordinates_get(widget, 0, oy + scroll_h, &last_row, NULL);
1960 if (last_row > elm_code_file_lines_get(pd->code->file))
1961 last_row = elm_code_file_lines_get(pd->code->file);
1962 1973
1963 // cursor will be shown if it should be visible 1974 _elm_code_widget_fill_range(widget, pd, first_row, last_row, NULL);
1964 evas_object_hide(pd->cursor_rect);
1965 for (y = first_row; y <= last_row; y++)
1966 {
1967 line = elm_code_file_line_get(pd->code->file, y);
1968 if (line)
1969 _elm_code_widget_fill_line(widget, line);
1970 }
1971 1975
1972 return; 1976 return;
1973 } 1977 }