summaryrefslogtreecommitdiff
path: root/legacy/elm_code/src/lib/widget/elm_code_widget.c
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2016-03-31 15:42:30 +0100
committerAndy Williams <andy@andywilliams.me>2016-03-31 15:42:30 +0100
commita1a9064a1663ea15db6f26d6c7f08164c82ff8d2 (patch)
treed59ffa7df8c2125397a5973e62b4bf957610bace /legacy/elm_code/src/lib/widget/elm_code_widget.c
parentbf0a5ae4f541314f2a08739cf202f69e8f4fbe27 (diff)
parentc9fb87d551f3f0186e3d987a97bfce7f8a8113a3 (diff)
[editor] Split out lines from a standard grid in rendering
Move errors to inline within the editor.
Diffstat (limited to '')
-rw-r--r--legacy/elm_code/src/lib/widget/elm_code_widget.c482
1 files changed, 280 insertions, 202 deletions
diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c
index 1b91391f05..a5ca616f3d 100644
--- a/legacy/elm_code/src/lib/widget/elm_code_widget.c
+++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c
@@ -50,6 +50,8 @@ Eina_Unicode status_icons[] = {
50 } \ 50 } \
51} while (0) 51} while (0)
52 52
53static void _elm_code_widget_resize(Elm_Code_Widget *widget);
54
53EAPI Evas_Object * 55EAPI Evas_Object *
54elm_code_widget_add(Evas_Object *parent, Elm_Code *code) 56elm_code_widget_add(Evas_Object *parent, Elm_Code *code)
55{ 57{
@@ -90,62 +92,36 @@ _elm_code_widget_class_constructor(Eo_Class *klass EINA_UNUSED)
90 92
91} 93}
92 94
93static void 95void
94_elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y) 96_elm_code_widget_cell_size_get(Elm_Code_Widget *widget, Evas_Coord *width, Evas_Coord *height)
95{ 97{
96 Elm_Code_Widget_Data *pd; 98 Elm_Code_Widget_Data *pd;
97 Evas_Coord x, y, w, h; 99 Evas_Object *grid;
100 Evas_Coord w, h;
98 101
99 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 102 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
100 103
101 elm_scroller_region_get(pd->scroller, &x, &y, &w, &h); 104 grid = eina_list_nth(pd->grids, 0);
102 x += by_x; 105 evas_object_textgrid_cell_size_get(grid, &w, &h);
103 y += by_y; 106 if (w == 0) w = 5;
104 elm_scroller_region_show(pd->scroller, x, y, w, h); 107 if (h == 0) h = 10;
108
109 if (width) *width = w;
110 if (height) *height = h;
105} 111}
106 112
107static void 113static void
108_elm_code_widget_resize(Elm_Code_Widget *widget) 114_elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y)
109{ 115{
110 Elm_Code_Line *line;
111 Eina_List *item;
112 Evas_Coord ww, wh, old_width, old_height;
113 int w, h, cw, ch, gutter;
114 unsigned int line_width;
115 Elm_Code_Widget_Data *pd; 116 Elm_Code_Widget_Data *pd;
117 Evas_Coord x, y, w, h;
116 118
117 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 119 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
118 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
119
120 if (!pd->code)
121 return;
122
123 evas_object_geometry_get(widget, NULL, NULL, &ww, &wh);
124 evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch);
125 old_width = ww;
126 old_height = wh;
127
128 w = 0;
129 h = elm_code_file_lines_get(pd->code->file);
130 EINA_LIST_FOREACH(pd->code->file->lines, item, line)
131 {
132 line_width = elm_code_widget_line_text_column_width_get(widget, line);
133 if ((int) line_width + gutter + 1 > w)
134 w = (int) line_width + gutter + 1;
135 }
136
137 if (w*cw > ww)
138 ww = w*cw;
139 if (h*ch > wh)
140 wh = h*ch;
141 120
142 evas_object_textgrid_size_set(pd->grid, ww/cw+1, wh/ch+1); 121 elm_scroller_region_get(pd->scroller, &x, &y, &w, &h);
143 evas_object_size_hint_min_set(pd->grid, w*cw, h*ch); 122 x += by_x;
144 123 y += by_y;
145 if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0) 124 elm_scroller_region_show(pd->scroller, x, y, w, h);
146 _elm_code_widget_scroll_by(widget,
147 (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0,
148 (pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0);
149} 125}
150 126
151static void 127static void
@@ -216,7 +192,7 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
216 int width, Elm_Code_Status_Type status, int line) 192 int width, Elm_Code_Status_Type status, int line)
217{ 193{
218 char *number = NULL; 194 char *number = NULL;
219 int w, gutter, g; 195 int gutter, g;
220 Elm_Code_Widget_Data *pd; 196 Elm_Code_Widget_Data *pd;
221 197
222 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 198 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
@@ -224,7 +200,6 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
224 200
225 if (width < gutter) 201 if (width < gutter)
226 return; 202 return;
227 evas_object_textgrid_size_get(pd->grid, &w, NULL);
228 203
229 cells[gutter-1].codepoint = status_icons[status]; 204 cells[gutter-1].codepoint = status_icons[status];
230 cells[gutter-1].bold = 1; 205 cells[gutter-1].bold = 1;
@@ -336,16 +311,20 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line)
336{ 311{
337 char *chr; 312 char *chr;
338 Eina_Unicode unichr; 313 Eina_Unicode unichr;
339 unsigned int length, x, charwidth, i; 314 unsigned int length, x, charwidth, i, w;
340 int w, chrpos, gutter; 315 int chrpos, gutter;
316 Evas_Object *grid, *status;
341 Evas_Textgrid_Cell *cells; 317 Evas_Textgrid_Cell *cells;
342 Elm_Code_Widget_Data *pd; 318 Elm_Code_Widget_Data *pd;
343 319
344 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 320 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
345 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); 321 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
322 if (eina_list_count(pd->grids) < line->number)
323 return;
346 324
347 evas_object_textgrid_size_get(pd->grid, &w, NULL); 325 w = elm_code_widget_columns_get(widget);
348 cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); 326 grid = eina_list_nth(pd->grids, line->number - 1);
327 cells = evas_object_textgrid_cellrow_get(grid, 0);
349 328
350 _elm_code_widget_fill_gutter(widget, cells, w, line->status, line->number); 329 _elm_code_widget_fill_gutter(widget, cells, w, line->status, line->number);
351 _elm_code_widget_fill_line_tokens(widget, cells, w, line); 330 _elm_code_widget_fill_line_tokens(widget, cells, w, line);
@@ -383,51 +362,41 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line)
383 if (line->number < elm_code_file_lines_get(line->file)) 362 if (line->number < elm_code_file_lines_get(line->file))
384 _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); 363 _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]);
385 364
386 evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); 365 evas_object_textgrid_update_add(grid, 0, 0, w, 1);
387}
388
389static void
390_elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number)
391{
392 unsigned int x;
393 int w, gutter;
394 Evas_Textgrid_Cell *cells;
395 Elm_Code_Widget_Data *pd;
396 366
397 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 367 // add a status below the line if needed (and remove those no longer needed)
398 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); 368 status = evas_object_data_get(grid, "status");
399 369 if (line->status_text)
400 evas_object_textgrid_size_get(pd->grid, &w, NULL); 370 {
401 cells = evas_object_textgrid_cellrow_get(pd->grid, number - 1); 371 if (!status)
402 _elm_code_widget_fill_gutter(widget, cells, w, ELM_CODE_STATUS_TYPE_DEFAULT, 0); 372 {
373 status = elm_label_add(pd->gridbox);
374 evas_object_size_hint_weight_set(status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
375 evas_object_size_hint_align_set(status, 0.05, EVAS_HINT_FILL);
376 evas_object_show(status);
403 377
404 for (x = gutter; x < (unsigned int) w; x++) 378 elm_box_pack_after(pd->gridbox, status, grid);
379 evas_object_data_set(grid, "status", status);
380 }
381 elm_object_text_set(status, line->status_text);
382 }
383 else if (status)
405 { 384 {
406 cells[x].codepoint = 0; 385 elm_box_unpack(pd->gridbox, status);
407 if (pd->editable && pd->focussed && pd->cursor_line == number) 386 evas_object_hide(status);
408 cells[x].bg = ELM_CODE_STATUS_TYPE_CURRENT; 387 evas_object_data_set(grid, "status", NULL);
409 else if (pd->line_width_marker == x - gutter + 1)
410 cells[x].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG;
411 else
412 cells[x].bg = ELM_CODE_STATUS_TYPE_DEFAULT;
413 } 388 }
414
415 _elm_code_widget_fill_cursor(widget, number, cells, gutter, w);
416 evas_object_textgrid_update_add(pd->grid, 0, number - 1, w, 1);
417} 389}
418 390
419static void 391static void
420_elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row) 392_elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row)
421{ 393{
422 Elm_Code_Line *line; 394 Elm_Code_Line *line;
423 int h;
424 unsigned int y; 395 unsigned int y;
425 Elm_Code_Widget_Data *pd; 396 Elm_Code_Widget_Data *pd;
426 397
427 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 398 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
428
429 _elm_code_widget_resize(widget); 399 _elm_code_widget_resize(widget);
430 h = elm_code_widget_lines_visible_get(widget);
431 400
432 for (y = first_row; y <= last_row; y++) 401 for (y = first_row; y <= last_row; y++)
433 { 402 {
@@ -435,10 +404,6 @@ _elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, uns
435 404
436 _elm_code_widget_fill_line(widget, line); 405 _elm_code_widget_fill_line(widget, line);
437 } 406 }
438 for (; y <= (unsigned int) h; y++)
439 {
440 _elm_code_widget_empty_line(widget, y);
441 }
442} 407}
443 408
444static void 409static void
@@ -451,7 +416,7 @@ _elm_code_widget_refresh(Elm_Code_Widget *widget)
451 416
452 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 417 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
453 418
454 evas_object_textgrid_cell_size_get(pd->grid, NULL, &ch); 419 _elm_code_widget_cell_size_get(widget, NULL, &ch);
455 elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h); 420 elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h);
456 421
457 first_row = scroll_y / ch + 1; 422 first_row = scroll_y / ch + 1;
@@ -600,7 +565,7 @@ _elm_code_widget_cursor_ensure_visible(Elm_Code_Widget *widget)
600 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 565 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
601 566
602 elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh); 567 elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh);
603 evas_object_textgrid_cell_size_get(pd->grid, &cellw, &cellh); 568 _elm_code_widget_cell_size_get(widget, &cellw, &cellh);
604 569
605 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); 570 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
606 curx = (pd->cursor_col + gutter - 1) * cellw; 571 curx = (pd->cursor_col + gutter - 1) * cellw;
@@ -634,8 +599,6 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd,
634 code = pd->code; 599 code = pd->code;
635 if (oldrow <= elm_code_file_lines_get(code->file)) 600 if (oldrow <= elm_code_file_lines_get(code->file))
636 _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, oldrow)); 601 _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, oldrow));
637 else
638 _elm_code_widget_empty_line(widget, oldrow);
639 } 602 }
640 _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, pd->cursor_line)); 603 _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, pd->cursor_line));
641} 604}
@@ -645,19 +608,37 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W
645 Evas_Coord x, Evas_Coord y, 608 Evas_Coord x, Evas_Coord y,
646 unsigned int *row, int *col) 609 unsigned int *row, int *col)
647{ 610{
611 Eina_List *item;
648 Elm_Code_Line *line; 612 Elm_Code_Line *line;
649 Evas_Coord ox, oy, sx, sy; 613 Evas_Coord ox, oy, sx, sy, rowy;
614 Evas_Object *grid;
650 int cw, ch, gutter; 615 int cw, ch, gutter;
651 unsigned int number; 616 unsigned int guess, number;
652 617
653 evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); 618 evas_object_geometry_get(widget, &ox, &oy, NULL, NULL);
654 elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL); 619 elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL);
655 x = x + sx - ox; 620 x = x + sx - ox;
656 y = y + sy - oy; 621 y = y + sy - oy;
657 622
658 evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); 623 _elm_code_widget_cell_size_get(widget, &cw, &ch);
659 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); 624 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
660 number = ((double) y / ch) + 1; 625
626 guess = ((double) y / ch) + 1;
627 number = guess;
628
629 // unfortunately EINA_LIST_REVERSE_FOREACH skips to the end of the list...
630 for (item = eina_list_nth_list(pd->grids, guess - 1), grid = eina_list_data_get(item);
631 item;
632 item = eina_list_prev(item), grid = eina_list_data_get(item))
633 {
634 evas_object_geometry_get(grid, NULL, &rowy, NULL, NULL);
635
636 if (rowy - oy < y)
637 break;
638
639 number--;
640 }
641
661 if (col) 642 if (col)
662 *col = ((double) x / cw) - gutter + 1; 643 *col = ((double) x / cw) - gutter + 1;
663 if (row) 644 if (row)
@@ -755,24 +736,15 @@ _elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj
755{ 736{
756 Elm_Code_Widget *widget; 737 Elm_Code_Widget *widget;
757 Elm_Code_Widget_Data *pd; 738 Elm_Code_Widget_Data *pd;
758 Elm_Code_Line *line;
759 Evas_Event_Mouse_Move *event; 739 Evas_Event_Mouse_Move *event;
760 unsigned int row; 740 unsigned int row;
761 int col; 741 int col;
762 Eina_Bool hasline;
763 742
764 widget = (Elm_Code_Widget *)data; 743 widget = (Elm_Code_Widget *)data;
765 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); 744 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
766 event = (Evas_Event_Mouse_Move *)event_info; 745 event = (Evas_Event_Mouse_Move *)event_info;
767 746
768 hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col); 747 _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col);
769 if (!hasline)
770 _elm_code_widget_tooltip_text_set(widget, NULL);
771 else
772 {
773 line = elm_code_file_line_get(pd->code->file, row);
774 _elm_code_widget_tooltip_text_set(widget, line->status_text);
775 }
776 748
777 if (!pd->editable || !event->buttons) 749 if (!pd->editable || !event->buttons)
778 return; 750 return;
@@ -1406,6 +1378,182 @@ _elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED,
1406 return EINA_TRUE; 1378 return EINA_TRUE;
1407} 1379}
1408 1380
1381static void
1382_elm_code_widget_setup_palette(Evas_Object *o)
1383{
1384 double feint = 0.5;
1385
1386 // setup status colors
1387 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT,
1388 36, 36, 36, 255);
1389 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CURRENT,
1390 12, 12, 12, 255);
1391 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_IGNORED,
1392 36, 36, 36, 255);
1393 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_NOTE,
1394 255, 153, 0, 255);
1395 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_WARNING,
1396 255, 153, 0, 255);
1397 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR,
1398 205, 54, 54, 255);
1399 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FATAL,
1400 205, 54, 54, 255);
1401
1402 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED,
1403 36, 96, 36, 255);
1404 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED,
1405 96, 36, 36, 255);
1406 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED,
1407 36, 36, 96, 255);
1408
1409 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_PASSED,
1410 54, 96, 54, 255);
1411 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED,
1412 96, 54, 54, 255);
1413
1414 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_TODO,
1415 54, 54, 96, 255);
1416
1417 // setup token colors
1418 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT,
1419 205, 205, 205, 255);
1420 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT,
1421 51, 153, 255, 255);
1422 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_STRING,
1423 255, 90, 53, 255);
1424 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_NUMBER,
1425 212, 212, 42, 255);
1426 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_BRACE,
1427 101, 101, 101, 255);
1428 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_TYPE,
1429 51, 153, 255, 255);
1430 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CLASS,
1431 114, 170, 212, 255);
1432 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_FUNCTION,
1433 114, 170, 212, 255);
1434 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PARAM,
1435 255, 255, 255, 255);
1436 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_KEYWORD,
1437 255, 153, 0, 255);
1438 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PREPROCESSOR,
1439 0, 176, 0, 255);
1440
1441 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED,
1442 54, 255, 54, 255);
1443 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_REMOVED,
1444 255, 54, 54, 255);
1445 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED,
1446 54, 54, 255, 255);
1447
1448 // other styles that the widget uses
1449 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_CURSOR,
1450 205, 205, 54, 255);
1451 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_SELECTION,
1452 51, 153, 255, 255);
1453 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_BG,
1454 75, 75, 75, 255);
1455 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG,
1456 139, 139, 139, 255);
1457 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_WHITESPACE,
1458 101 * feint, 101 * feint, 101 * feint, 255 * feint);
1459}
1460
1461static void
1462_elm_code_widget_ensure_n_grid_rows(Elm_Code_Widget *widget, int rows)
1463{
1464 Evas_Object *grid;
1465 int existing, i;
1466 Elm_Code_Widget_Data *pd;
1467
1468 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
1469 existing = eina_list_count(pd->grids);
1470
1471 // trim unneeded rows in our rendering
1472 if (rows < existing)
1473 {
1474 for (i = existing - rows; i > 0; i--)
1475 {
1476 grid = eina_list_data_get(eina_list_last(pd->grids));
1477 evas_object_hide(grid);
1478 elm_box_unpack(pd->gridbox, grid);
1479 pd->grids = eina_list_remove_list(pd->grids, eina_list_last(pd->grids));
1480 }
1481 rows = existing;
1482 }
1483
1484 if (rows == existing)
1485 return;
1486
1487 for (int i = existing; i < rows; i++)
1488 {
1489 grid = evas_object_textgrid_add(pd->gridbox);
1490 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, 0.0);
1491 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, 0.0);
1492 evas_object_show(grid);
1493 _elm_code_widget_setup_palette(grid);
1494
1495 elm_box_pack_end(pd->gridbox, grid);
1496 pd->grids = eina_list_append(pd->grids, grid);
1497
1498 evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_DOWN, _elm_code_widget_mouse_down_cb, widget);
1499 evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_MOVE, _elm_code_widget_mouse_move_cb, widget);
1500 evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_mouse_up_cb, widget);
1501
1502 evas_object_textgrid_font_set(grid, pd->font_name, pd->font_size * elm_config_scale_get());
1503 }
1504}
1505
1506static void
1507_elm_code_widget_resize(Elm_Code_Widget *widget)
1508{
1509 Elm_Code_Line *line;
1510 Eina_List *item;
1511 Evas_Object *grid;
1512 Evas_Coord ww, wh, old_width, old_height;
1513 int w, h, cw, ch, gutter;
1514 unsigned int line_width;
1515 Elm_Code_Widget_Data *pd;
1516
1517 pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
1518 gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
1519
1520 if (!pd->code)
1521 return;
1522
1523 evas_object_geometry_get(widget, NULL, NULL, &ww, &wh);
1524
1525 old_width = ww;
1526 old_height = wh;
1527
1528 w = 0;
1529 h = elm_code_file_lines_get(pd->code->file);
1530 EINA_LIST_FOREACH(pd->code->file->lines, item, line)
1531 {
1532 line_width = elm_code_widget_line_text_column_width_get(widget, line);
1533 if ((int) line_width + gutter + 1 > w)
1534 w = (int) line_width + gutter + 1;
1535 }
1536
1537 _elm_code_widget_ensure_n_grid_rows(widget, h);
1538 _elm_code_widget_cell_size_get(widget, &cw, &ch);
1539 if (w*cw > ww)
1540 ww = w*cw;
1541 if (h*ch > wh)
1542 wh = h*ch;
1543 pd->col_count = ww/cw + 1;
1544
1545 EINA_LIST_FOREACH(pd->grids, item, grid)
1546 {
1547 evas_object_textgrid_size_set(grid, pd->col_count, 1);
1548 evas_object_size_hint_min_set(grid, w*cw, ch);
1549 }
1550
1551 if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0)
1552 _elm_code_widget_scroll_by(widget,
1553 (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0,
1554 (pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0);
1555}
1556
1409EOAPI void 1557EOAPI void
1410_elm_code_widget_line_refresh(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line) 1558_elm_code_widget_line_refresh(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line)
1411{ 1559{
@@ -1413,12 +1561,12 @@ _elm_code_widget_line_refresh(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm
1413} 1561}
1414 1562
1415EOAPI Eina_Bool 1563EOAPI Eina_Bool
1416_elm_code_widget_line_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line) 1564_elm_code_widget_line_visible_get(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code_Line *line)
1417{ 1565{
1418 Evas_Coord cellh, viewy, viewh; 1566 Evas_Coord cellh, viewy, viewh;
1419 1567
1420 elm_scroller_region_get(pd->scroller, NULL, &viewy, NULL, &viewh); 1568 elm_scroller_region_get(pd->scroller, NULL, &viewy, NULL, &viewh);
1421 evas_object_textgrid_cell_size_get(pd->grid, NULL, &cellh); 1569 _elm_code_widget_cell_size_get(obj, NULL, &cellh);
1422 1570
1423 if (((int)line->number - 1) * cellh > viewy + viewh || (int)line->number * cellh < viewy) 1571 if (((int)line->number - 1) * cellh > viewy + viewh || (int)line->number * cellh < viewy)
1424 return EINA_FALSE; 1572 return EINA_FALSE;
@@ -1427,25 +1575,31 @@ _elm_code_widget_line_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd,
1427} 1575}
1428 1576
1429EOAPI unsigned int 1577EOAPI unsigned int
1430_elm_code_widget_lines_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) 1578_elm_code_widget_lines_visible_get(Eo *obj, Elm_Code_Widget_Data *pd)
1431{ 1579{
1432 Evas_Coord cellh, viewh; 1580 Evas_Coord cellh, viewh;
1433 1581
1434 elm_scroller_region_get(pd->scroller, NULL, NULL, NULL, &viewh); 1582 elm_scroller_region_get(pd->scroller, NULL, NULL, NULL, &viewh);
1435 evas_object_textgrid_cell_size_get(pd->grid, NULL, &cellh); 1583 _elm_code_widget_cell_size_get(obj, NULL, &cellh);
1436 1584
1437 return viewh / cellh; 1585 return viewh / cellh + 1;
1438} 1586}
1439 1587
1440EOLIAN static void 1588EOLIAN static void
1441_elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, 1589_elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd,
1442 const char *name, Evas_Font_Size size) 1590 const char *name, Evas_Font_Size size)
1443{ 1591{
1592 Eina_List *item;
1593 Evas_Object *grid;
1594
1444 const char *face = name; 1595 const char *face = name;
1445 if (!face) 1596 if (!face)
1446 face = "Mono"; 1597 face = "Mono";
1447 1598
1448 evas_object_textgrid_font_set(pd->grid, face, size * elm_config_scale_get()); 1599 EINA_LIST_FOREACH(pd->grids, item, grid)
1600 {
1601 evas_object_textgrid_font_set(grid, face, size * elm_config_scale_get());
1602 }
1449 if (pd->font_name) 1603 if (pd->font_name)
1450 eina_stringshare_del((char *)pd->font_name); 1604 eina_stringshare_del((char *)pd->font_name);
1451 pd->font_name = eina_stringshare_add(face); 1605 pd->font_name = eina_stringshare_add(face);
@@ -1462,6 +1616,12 @@ _elm_code_widget_font_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd,
1462 *size = pd->font_size; 1616 *size = pd->font_size;
1463} 1617}
1464 1618
1619EOLIAN static unsigned int
1620_elm_code_widget_columns_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
1621{
1622 return pd->col_count;
1623}
1624
1465EOLIAN static void 1625EOLIAN static void
1466_elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code *code) 1626_elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code *code)
1467{ 1627{
@@ -1594,91 +1754,10 @@ _elm_code_widget_cursor_position_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *
1594 *line = pd->cursor_line; 1754 *line = pd->cursor_line;
1595} 1755}
1596 1756
1597static void
1598_elm_code_widget_setup_palette(Evas_Object *o)
1599{
1600 double feint = 0.5;
1601
1602 // setup status colors
1603 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT,
1604 36, 36, 36, 255);
1605 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CURRENT,
1606 12, 12, 12, 255);
1607 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_IGNORED,
1608 36, 36, 36, 255);
1609 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_NOTE,
1610 255, 153, 0, 255);
1611 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_WARNING,
1612 255, 153, 0, 255);
1613 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR,
1614 205, 54, 54, 255);
1615 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FATAL,
1616 205, 54, 54, 255);
1617
1618 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED,
1619 36, 96, 36, 255);
1620 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED,
1621 96, 36, 36, 255);
1622 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED,
1623 36, 36, 96, 255);
1624
1625 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_PASSED,
1626 54, 96, 54, 255);
1627 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED,
1628 96, 54, 54, 255);
1629
1630 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_TODO,
1631 54, 54, 96, 255);
1632
1633 // setup token colors
1634 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT,
1635 205, 205, 205, 255);
1636 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT,
1637 51, 153, 255, 255);
1638 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_STRING,
1639 255, 90, 53, 255);
1640 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_NUMBER,
1641 212, 212, 42, 255);
1642 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_BRACE,
1643 101, 101, 101, 255);
1644 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_TYPE,
1645 51, 153, 255, 255);
1646 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CLASS,
1647 114, 170, 212, 255);
1648 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_FUNCTION,
1649 114, 170, 212, 255);
1650 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PARAM,
1651 255, 255, 255, 255);
1652 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_KEYWORD,
1653 255, 153, 0, 255);
1654 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PREPROCESSOR,
1655 0, 176, 0, 255);
1656
1657
1658 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED,
1659 54, 255, 54, 255);
1660 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_REMOVED,
1661 255, 54, 54, 255);
1662 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED,
1663 54, 54, 255, 255);
1664
1665 // other styles that the widget uses
1666 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_CURSOR,
1667 205, 205, 54, 255);
1668 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_SELECTION,
1669 51, 153, 255, 255);
1670 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_BG,
1671 75, 75, 75, 255);
1672 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG,
1673 139, 139, 139, 255);
1674 evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_WHITESPACE,
1675 101 * feint, 101 * feint, 101 * feint, 255 * feint);
1676}
1677
1678EOLIAN static void 1757EOLIAN static void
1679_elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) 1758_elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd)
1680{ 1759{
1681 Evas_Object *grid, *scroller; 1760 Evas_Object *background, *gridrows, *scroller;
1682 1761
1683 evas_obj_smart_add(eo_super(obj, ELM_CODE_WIDGET_CLASS)); 1762 evas_obj_smart_add(eo_super(obj, ELM_CODE_WIDGET_CLASS));
1684 elm_object_focus_allow_set(obj, EINA_TRUE); 1763 elm_object_focus_allow_set(obj, EINA_TRUE);
@@ -1693,19 +1772,20 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd)
1693 elm_object_focus_allow_set(scroller, EINA_FALSE); 1772 elm_object_focus_allow_set(scroller, EINA_FALSE);
1694 pd->scroller = scroller; 1773 pd->scroller = scroller;
1695 1774
1696 grid = evas_object_textgrid_add(obj); 1775 background = elm_bg_add(scroller);
1697 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 1776 evas_object_color_set(background, 145, 145, 145, 255);
1698 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); 1777 evas_object_size_hint_weight_set(background, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1699 evas_object_show(grid); 1778 evas_object_size_hint_align_set(background, EVAS_HINT_FILL, EVAS_HINT_FILL);
1700 _elm_code_widget_tooltip_add(obj); 1779 evas_object_show(background);
1701 elm_object_content_set(scroller, grid); 1780 elm_object_part_content_set(scroller, "elm.swallow.background", background);
1702 pd->grid = grid; 1781
1703 _elm_code_widget_setup_palette(grid); 1782 gridrows = elm_box_add(scroller);
1783 evas_object_size_hint_weight_set(gridrows, EVAS_HINT_EXPAND, 0.0);
1784 evas_object_size_hint_align_set(gridrows, EVAS_HINT_FILL, 0.0);
1785 elm_object_content_set(scroller, gridrows);
1786 pd->gridbox = gridrows;
1704 1787
1705 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj); 1788 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj);
1706 evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_DOWN, _elm_code_widget_mouse_down_cb, obj);
1707 evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_MOVE, _elm_code_widget_mouse_move_cb, obj);
1708 evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_mouse_up_cb, obj);
1709 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj); 1789 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj);
1710 1790
1711 evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj); 1791 evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj);
@@ -1715,8 +1795,6 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd)
1715 eo_event_callback_add(obj, &ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj); 1795 eo_event_callback_add(obj, &ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj);
1716 eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj); 1796 eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj);
1717 eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj); 1797 eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj);
1718
1719 _elm_code_widget_font_set(obj, pd, NULL, 10);
1720} 1798}
1721 1799
1722#include "elm_code_widget_text.c" 1800#include "elm_code_widget_text.c"