2016-06-02 17:19:08 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
2015-01-23 14:55:13 -08:00
|
|
|
#endif
|
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2015-01-26 11:46:30 -08:00
|
|
|
#include "elm_code_private.h"
|
2015-04-04 10:17:01 -07:00
|
|
|
#include "elm_code_widget_private.h"
|
2015-01-23 14:55:13 -08:00
|
|
|
|
2016-10-18 03:34:12 -07:00
|
|
|
/* FIXME: hoversel is deprecated in EO APIs */
|
|
|
|
#include "elm_hoversel.eo.h"
|
|
|
|
|
2015-06-02 00:22:36 -07:00
|
|
|
#define MY_CLASS ELM_CODE_WIDGET_CLASS
|
|
|
|
|
2015-01-29 06:05:20 -08:00
|
|
|
typedef enum {
|
|
|
|
ELM_CODE_WIDGET_COLOR_GUTTER_BG = ELM_CODE_TOKEN_TYPE_COUNT,
|
|
|
|
ELM_CODE_WIDGET_COLOR_GUTTER_FG,
|
2015-02-28 06:59:42 -08:00
|
|
|
ELM_CODE_WIDGET_COLOR_WHITESPACE,
|
2015-03-17 15:42:03 -07:00
|
|
|
ELM_CODE_WIDGET_COLOR_SELECTION,
|
2015-01-29 06:05:20 -08:00
|
|
|
|
|
|
|
ELM_CODE_WIDGET_COLOR_COUNT
|
|
|
|
} Elm_Code_Widget_Colors;
|
|
|
|
|
2015-01-26 11:05:34 -08:00
|
|
|
Eina_Unicode status_icons[] = {
|
2015-01-24 14:07:00 -08:00
|
|
|
' ',
|
2015-02-23 16:26:58 -08:00
|
|
|
' ',
|
|
|
|
' ',
|
|
|
|
' ',
|
|
|
|
'!',
|
2015-01-24 14:07:00 -08:00
|
|
|
'!',
|
2016-01-16 10:21:32 -08:00
|
|
|
'!',
|
2015-01-24 14:07:00 -08:00
|
|
|
|
|
|
|
'+',
|
|
|
|
'-',
|
|
|
|
' ',
|
|
|
|
|
|
|
|
0x2713,
|
|
|
|
0x2717,
|
|
|
|
|
2016-02-21 09:51:56 -08:00
|
|
|
0x2691,
|
2016-01-16 10:21:32 -08:00
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2015-02-27 07:07:38 -08:00
|
|
|
#define EO_CONSTRUCTOR_CHECK_RETURN(obj) do { \
|
|
|
|
Eina_Bool finalized; \
|
2015-03-17 01:45:04 -07:00
|
|
|
\
|
2016-08-10 07:23:04 -07:00
|
|
|
finalized = efl_finalized_get(obj); \
|
2015-03-17 01:45:04 -07:00
|
|
|
if (finalized) \
|
2015-02-28 05:22:38 -08:00
|
|
|
{ \
|
|
|
|
ERR("This function is only allowed during construction."); \
|
|
|
|
return; \
|
2015-02-27 07:07:38 -08:00
|
|
|
} \
|
|
|
|
} while (0)
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-05-16 03:28:11 -07:00
|
|
|
static void _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline);
|
2016-03-29 19:58:39 -07:00
|
|
|
|
2015-06-02 00:22:36 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_code_widget_add(Evas_Object *parent, Elm_Code *code)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
|
2016-03-09 16:06:50 -08:00
|
|
|
Evas_Object *obj = NULL;
|
2016-09-05 08:57:35 -07:00
|
|
|
obj = efl_add(MY_CLASS, parent, elm_obj_code_widget_code_set(efl_added, code));
|
2015-06-02 00:22:36 -07:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2015-05-20 06:18:20 -07:00
|
|
|
EOLIAN static Eo *
|
2016-08-10 07:23:04 -07:00
|
|
|
_elm_code_widget_efl_object_constructor(Eo *obj, Elm_Code_Widget_Data *pd)
|
2015-01-23 14:55:13 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
obj = efl_constructor(efl_super(obj, ELM_CODE_WIDGET_CLASS));
|
2015-01-24 14:07:00 -08:00
|
|
|
|
|
|
|
pd->cursor_line = 1;
|
|
|
|
pd->cursor_col = 1;
|
2015-03-29 12:12:28 -07:00
|
|
|
|
|
|
|
pd->tabstop = 8;
|
2015-05-20 06:18:20 -07:00
|
|
|
|
|
|
|
return obj;
|
2015-01-23 14:55:13 -08:00
|
|
|
}
|
|
|
|
|
2015-02-28 05:22:38 -08:00
|
|
|
EOLIAN static Eo *
|
2016-08-10 07:23:04 -07:00
|
|
|
_elm_code_widget_efl_object_finalize(Eo *obj, Elm_Code_Widget_Data *pd)
|
2015-02-28 05:22:38 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
obj = efl_finalize(efl_super(obj, ELM_CODE_WIDGET_CLASS));
|
2015-02-28 05:22:38 -08:00
|
|
|
|
|
|
|
if (pd->code)
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
ERR("Elm_Code_Widget cannot finalize without calling elm_code_widget_code_set.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-23 14:55:13 -08:00
|
|
|
EOLIAN static void
|
2016-08-10 07:23:04 -07:00
|
|
|
_elm_code_widget_class_constructor(Efl_Class *klass EINA_UNUSED)
|
2015-01-23 14:55:13 -08:00
|
|
|
{
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2015-01-23 14:55:13 -08:00
|
|
|
}
|
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
void
|
|
|
|
_elm_code_widget_cell_size_get(Elm_Code_Widget *widget, Evas_Coord *width, Evas_Coord *height)
|
2015-01-28 06:16:46 -08:00
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
2016-03-29 19:58:39 -07:00
|
|
|
Evas_Object *grid;
|
2016-05-16 02:03:25 -07:00
|
|
|
Evas_Coord w = 0, h = 0;
|
2015-01-28 06:16:46 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-01-28 06:16:46 -08:00
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
grid = eina_list_nth(pd->grids, 0);
|
|
|
|
evas_object_textgrid_cell_size_get(grid, &w, &h);
|
|
|
|
if (w == 0) w = 5;
|
|
|
|
if (h == 0) h = 10;
|
|
|
|
|
|
|
|
if (width) *width = w;
|
|
|
|
if (height) *height = h;
|
2015-01-28 06:16:46 -08:00
|
|
|
}
|
|
|
|
|
2015-02-22 15:38:54 -08:00
|
|
|
static void
|
2016-03-29 19:58:39 -07:00
|
|
|
_elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y)
|
2015-01-23 14:55:13 -08:00
|
|
|
{
|
2015-01-27 16:39:56 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2016-03-29 19:58:39 -07:00
|
|
|
Evas_Coord x, y, w, h;
|
2015-01-27 16:39:56 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-01-27 16:39:56 -08:00
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
elm_scroller_region_get(pd->scroller, &x, &y, &w, &h);
|
|
|
|
x += by_x;
|
|
|
|
y += by_y;
|
|
|
|
elm_scroller_region_show(pd->scroller, x, y, w, h);
|
2015-01-23 14:55:13 -08:00
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
static void
|
|
|
|
_elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start, int end, Elm_Code_Token_Type type)
|
2015-01-23 14:55:13 -08:00
|
|
|
{
|
2015-01-24 14:07:00 -08:00
|
|
|
int x;
|
2015-01-23 14:55:13 -08:00
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
for (x = start; x <= end && x < count; x++)
|
|
|
|
{
|
2015-06-03 13:29:31 -07:00
|
|
|
cells[x - 1].fg = type;
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
2015-01-23 14:55:13 -08:00
|
|
|
}
|
|
|
|
|
2015-02-23 13:52:49 -08:00
|
|
|
static unsigned int
|
2015-10-10 12:00:43 -07:00
|
|
|
_elm_code_widget_status_type_get(Elm_Code_Widget *widget, Elm_Code_Line *line, unsigned int col)
|
2015-02-23 13:52:49 -08:00
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-02-23 13:52:49 -08:00
|
|
|
|
2015-10-10 12:00:43 -07:00
|
|
|
if (line->status != ELM_CODE_STATUS_TYPE_DEFAULT)
|
|
|
|
return line->status;
|
|
|
|
|
|
|
|
if (pd->editable && pd->focussed && pd->cursor_line == line->number)
|
|
|
|
return ELM_CODE_STATUS_TYPE_CURRENT;
|
2015-02-23 13:52:49 -08:00
|
|
|
|
2016-09-01 13:43:57 -07:00
|
|
|
if (pd->line_width_marker > 0 && pd->line_width_marker == col-1)
|
2015-02-23 13:52:49 -08:00
|
|
|
return ELM_CODE_WIDGET_COLOR_GUTTER_BG;
|
|
|
|
|
|
|
|
return ELM_CODE_STATUS_TYPE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
static void
|
2015-01-28 16:36:28 -08:00
|
|
|
_elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
|
|
|
|
unsigned int count, Elm_Code_Line *line)
|
2015-01-23 14:55:13 -08:00
|
|
|
{
|
2015-01-24 14:07:00 -08:00
|
|
|
Eina_List *item;
|
|
|
|
Elm_Code_Token *token;
|
2015-03-14 09:42:56 -07:00
|
|
|
unsigned int start, end, length, offset;
|
|
|
|
unsigned int token_start_col, token_end_col;
|
2015-01-23 14:55:13 -08:00
|
|
|
|
2016-03-09 16:06:50 -08:00
|
|
|
offset = elm_obj_code_widget_text_left_gutter_width_get(widget);
|
2015-03-14 09:42:56 -07:00
|
|
|
start = offset;
|
2015-06-03 13:29:31 -07:00
|
|
|
length = elm_code_widget_line_text_column_width_get(widget, line) + offset;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH(line->tokens, item, token)
|
|
|
|
{
|
2015-06-03 13:29:31 -07:00
|
|
|
token_start_col = elm_code_widget_line_text_column_width_to_position(widget, line, token->start) + offset;
|
|
|
|
token_end_col = elm_code_widget_line_text_column_width_to_position(widget, line, token->end) + offset;
|
2015-03-14 09:42:56 -07:00
|
|
|
|
|
|
|
if (token_start_col > start)
|
|
|
|
_elm_code_widget_fill_line_token(cells, count, start, token_start_col, ELM_CODE_TOKEN_TYPE_DEFAULT);
|
2015-01-24 14:07:00 -08:00
|
|
|
|
|
|
|
// TODO handle a token starting before the previous finishes
|
2015-03-14 09:42:56 -07:00
|
|
|
end = token_end_col;
|
2015-09-20 02:39:33 -07:00
|
|
|
if (token->continues)
|
2015-03-14 09:42:56 -07:00
|
|
|
end = length + offset;
|
|
|
|
_elm_code_widget_fill_line_token(cells, count, token_start_col, end, token->type);
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2015-03-14 09:42:56 -07:00
|
|
|
start = end + 1;
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
_elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-02-22 15:38:54 -08:00
|
|
|
_elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells,
|
2015-08-23 15:23:07 -07:00
|
|
|
int width, Elm_Code_Status_Type status, int line)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
2015-02-22 15:38:54 -08:00
|
|
|
char *number = NULL;
|
2016-03-29 19:58:39 -07:00
|
|
|
int gutter, g;
|
2015-01-27 16:39:56 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-06-09 14:31:57 -07:00
|
|
|
gutter = elm_code_widget_text_left_gutter_width_get(widget);
|
2015-01-27 16:39:56 -08:00
|
|
|
|
2015-08-23 15:23:07 -07:00
|
|
|
if (width < gutter)
|
|
|
|
return;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2015-02-22 15:38:54 -08:00
|
|
|
cells[gutter-1].codepoint = status_icons[status];
|
2015-01-29 06:05:20 -08:00
|
|
|
cells[gutter-1].bold = 1;
|
|
|
|
cells[gutter-1].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG;
|
2015-02-22 15:38:54 -08:00
|
|
|
cells[gutter-1].bg = (status == ELM_CODE_STATUS_TYPE_DEFAULT) ? ELM_CODE_WIDGET_COLOR_GUTTER_BG : status;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2015-01-28 16:50:07 -08:00
|
|
|
if (pd->show_line_numbers)
|
2015-01-28 16:36:28 -08:00
|
|
|
{
|
2015-02-22 15:38:54 -08:00
|
|
|
if (line > 0)
|
|
|
|
{
|
|
|
|
number = malloc(sizeof(char) * gutter);
|
|
|
|
snprintf(number, gutter, "%*d", gutter - 1, line);
|
|
|
|
}
|
2015-01-29 06:05:20 -08:00
|
|
|
for (g = 0; g < gutter - 1; g++)
|
2015-01-28 16:50:07 -08:00
|
|
|
{
|
2015-02-22 15:38:54 -08:00
|
|
|
if (number)
|
|
|
|
cells[g].codepoint = *(number + g);
|
|
|
|
else
|
|
|
|
cells[g].codepoint = 0;
|
|
|
|
|
2015-01-29 06:05:20 -08:00
|
|
|
cells[g].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG;
|
|
|
|
cells[g].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG;
|
2015-01-28 16:50:07 -08:00
|
|
|
}
|
2015-02-22 15:38:54 -08:00
|
|
|
|
|
|
|
if (number)
|
|
|
|
free(number);
|
2015-01-28 16:36:28 -08:00
|
|
|
}
|
2015-02-22 15:38:54 -08:00
|
|
|
}
|
|
|
|
|
2015-02-28 06:59:42 -08:00
|
|
|
static void
|
2015-03-17 15:42:03 -07:00
|
|
|
_elm_code_widget_fill_whitespace(Elm_Code_Widget *widget, Eina_Unicode character, Evas_Textgrid_Cell *cell)
|
2015-02-28 06:59:42 -08:00
|
|
|
{
|
2015-03-17 15:42:03 -07:00
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-17 15:42:03 -07:00
|
|
|
if (!pd->show_whitespace)
|
2015-03-29 12:12:28 -07:00
|
|
|
{
|
|
|
|
if (character== '\t')
|
|
|
|
cell->codepoint = 0;
|
|
|
|
return;
|
|
|
|
}
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2015-02-28 06:59:42 -08:00
|
|
|
switch (character)
|
|
|
|
{
|
|
|
|
case ' ':
|
|
|
|
cell->codepoint = 0x00b7;
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
cell->codepoint = 0x2192;
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
cell->codepoint = 0x23ce;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell->fg = ELM_CODE_WIDGET_COLOR_WHITESPACE;
|
|
|
|
}
|
|
|
|
|
2015-03-17 15:42:03 -07:00
|
|
|
static void
|
2016-12-09 07:53:38 -08:00
|
|
|
_elm_code_widget_fill_cursor(Elm_Code_Widget *widget, unsigned int number, int gutter, int w)
|
2015-03-17 15:42:03 -07:00
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
2016-12-09 07:53:38 -08:00
|
|
|
Evas_Coord cx, cy, cw, ch;
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2015-06-10 15:33:46 -07:00
|
|
|
if (pd->editable && pd->focussed && pd->cursor_line == number)
|
2015-03-17 15:42:03 -07:00
|
|
|
{
|
2016-12-09 07:53:38 -08:00
|
|
|
if (pd->cursor_col + gutter - 1 >= (unsigned int) w)
|
|
|
|
return;
|
|
|
|
|
|
|
|
elm_code_widget_geometry_for_position_get(widget, pd->cursor_line, pd->cursor_col, &cx, &cy, &cw, &ch);
|
|
|
|
|
|
|
|
if (!pd->cursor_rect)
|
|
|
|
{
|
2016-12-09 15:25:42 -08:00
|
|
|
pd->cursor_rect = elm_layout_add(widget);
|
2016-12-09 07:53:38 -08:00
|
|
|
|
2016-12-09 15:25:42 -08:00
|
|
|
elm_layout_theme_set(pd->cursor_rect, "entry", "cursor", elm_widget_style_get(widget));
|
|
|
|
elm_layout_signal_emit(pd->cursor_rect, "elm,action,focus", "elm");
|
2016-12-09 07:53:38 -08:00
|
|
|
|
2016-12-09 15:25:42 -08:00
|
|
|
evas_object_resize(pd->cursor_rect, cw/8, ch);
|
2016-12-09 07:53:38 -08:00
|
|
|
evas_object_show(pd->cursor_rect);
|
|
|
|
}
|
|
|
|
|
2016-12-09 16:44:18 -08:00
|
|
|
evas_object_move(pd->cursor_rect, cx, cy);
|
2015-03-17 15:42:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_fill_selection(Elm_Code_Widget *widget, Elm_Code_Line *line, Evas_Textgrid_Cell *cells,
|
|
|
|
int gutter, int w)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
unsigned int x, start, end;
|
2015-09-16 04:32:25 -07:00
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-17 15:42:03 -07:00
|
|
|
if (!pd->selection)
|
|
|
|
return;
|
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
selection = elm_code_widget_selection_normalized_get(widget);
|
|
|
|
if (selection->start_line > line->number || selection->end_line < line->number)
|
|
|
|
{
|
|
|
|
free(selection);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
start = selection->start_col;
|
|
|
|
if (selection->start_line < line->number)
|
2015-03-17 15:42:03 -07:00
|
|
|
start = 1;
|
2015-09-16 04:32:25 -07:00
|
|
|
end = selection->end_col;
|
|
|
|
if (selection->end_line > line->number)
|
2015-03-17 15:42:03 -07:00
|
|
|
end = w;
|
2015-09-16 04:32:25 -07:00
|
|
|
free(selection);
|
2015-03-17 15:42:03 -07:00
|
|
|
|
|
|
|
for (x = gutter + start - 1; x < gutter + end && x < (unsigned int) w; x++)
|
|
|
|
cells[x].bg = ELM_CODE_WIDGET_COLOR_SELECTION;
|
|
|
|
}
|
|
|
|
|
2015-02-22 15:38:54 -08:00
|
|
|
static void
|
|
|
|
_elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
char *chr;
|
2015-03-07 11:48:02 -08:00
|
|
|
Eina_Unicode unichr;
|
2016-03-29 19:58:39 -07:00
|
|
|
unsigned int length, x, charwidth, i, w;
|
|
|
|
int chrpos, gutter;
|
2016-09-01 15:15:34 -07:00
|
|
|
Evas_Object *grid;
|
2015-02-22 15:38:54 -08:00
|
|
|
Evas_Textgrid_Cell *cells;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-03-09 16:06:50 -08:00
|
|
|
gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
|
2016-03-29 19:58:39 -07:00
|
|
|
if (eina_list_count(pd->grids) < line->number)
|
|
|
|
return;
|
2015-02-22 15:38:54 -08:00
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
w = elm_code_widget_columns_get(widget);
|
|
|
|
grid = eina_list_nth(pd->grids, line->number - 1);
|
|
|
|
cells = evas_object_textgrid_cellrow_get(grid, 0);
|
2015-02-22 15:38:54 -08:00
|
|
|
|
2015-08-23 15:23:07 -07:00
|
|
|
_elm_code_widget_fill_gutter(widget, cells, w, line->status, line->number);
|
2015-02-28 06:59:42 -08:00
|
|
|
_elm_code_widget_fill_line_tokens(widget, cells, w, line);
|
2015-01-28 16:36:28 -08:00
|
|
|
|
2015-06-03 13:29:31 -07:00
|
|
|
length = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-03-07 11:48:02 -08:00
|
|
|
chrpos = 0;
|
2015-03-14 09:42:56 -07:00
|
|
|
chr = (char *)elm_code_line_text_get(line, NULL);
|
2015-03-07 11:48:02 -08:00
|
|
|
|
2015-03-29 12:12:28 -07:00
|
|
|
for (x = gutter; x < (unsigned int) w && x < length + gutter; x+=charwidth)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
2015-03-07 11:48:02 -08:00
|
|
|
unichr = eina_unicode_utf8_next_get(chr, &chrpos);
|
|
|
|
|
|
|
|
cells[x].codepoint = unichr;
|
2015-10-10 12:00:43 -07:00
|
|
|
cells[x].bg = _elm_code_widget_status_type_get(widget, line, x - gutter + 1);
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2015-03-29 12:12:28 -07:00
|
|
|
charwidth = 1;
|
|
|
|
if (unichr == '\t')
|
2015-06-08 15:13:03 -07:00
|
|
|
charwidth = elm_code_widget_text_tabwidth_at_column_get(widget, x - gutter + 1);
|
2015-03-29 12:12:28 -07:00
|
|
|
for (i = x + 1; i < x + charwidth; i++)
|
|
|
|
{
|
|
|
|
cells[i].codepoint = 0;
|
2015-10-10 12:00:43 -07:00
|
|
|
cells[i].bg = _elm_code_widget_status_type_get(widget, line, i - gutter + 1);
|
2015-03-29 12:12:28 -07:00
|
|
|
}
|
|
|
|
|
2015-03-17 15:42:03 -07:00
|
|
|
_elm_code_widget_fill_whitespace(widget, unichr, &cells[x]);
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
for (; x < (unsigned int) w; x++)
|
|
|
|
{
|
|
|
|
cells[x].codepoint = 0;
|
2015-10-10 12:00:43 -07:00
|
|
|
cells[x].bg = _elm_code_widget_status_type_get(widget, line, x - gutter + 1);
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
|
2015-03-17 15:42:03 -07:00
|
|
|
_elm_code_widget_fill_selection(widget, line, cells, gutter, w);
|
2016-12-09 07:53:38 -08:00
|
|
|
_elm_code_widget_fill_cursor(widget, line->number, gutter, w);
|
2015-03-18 15:18:34 -07:00
|
|
|
if (line->number < elm_code_file_lines_get(line->file))
|
|
|
|
_elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]);
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-09-01 15:15:34 -07:00
|
|
|
elm_object_tooltip_text_set(grid, line->status_text);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_update_add(grid, 0, 0, w, 1);
|
2015-02-22 15:38:54 -08:00
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
static void
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row,
|
|
|
|
Elm_Code_Line *newline)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
unsigned int y;
|
2015-01-27 16:39:56 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-05-16 03:28:11 -07:00
|
|
|
_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))
|
|
|
|
return;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-02-25 07:50:34 -08:00
|
|
|
for (y = first_row; y <= last_row; y++)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
|
|
|
line = elm_code_file_line_get(pd->code->file, y);
|
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
_elm_code_widget_fill_line(widget, line);
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 07:50:34 -08:00
|
|
|
static void
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_refresh(Elm_Code_Widget *widget, Elm_Code_Line *line)
|
2016-02-25 07:50:34 -08:00
|
|
|
{
|
2016-04-28 14:51:03 -07:00
|
|
|
Evas_Coord scroll_y, scroll_h, oy;
|
2016-02-25 07:50:34 -08:00
|
|
|
unsigned int first_row, last_row;
|
|
|
|
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-02-25 07:50:34 -08:00
|
|
|
|
2016-04-28 14:51:03 -07:00
|
|
|
evas_object_geometry_get(widget, NULL, &oy, NULL, NULL);
|
2016-02-25 07:50:34 -08:00
|
|
|
elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h);
|
2016-04-28 14:51:03 -07:00
|
|
|
if (scroll_h == 0)
|
|
|
|
return;
|
2016-02-25 07:50:34 -08:00
|
|
|
|
2016-04-28 14:51:03 -07:00
|
|
|
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);
|
2016-02-25 07:50:34 -08:00
|
|
|
|
|
|
|
if (last_row > elm_code_file_lines_get(pd->code->file))
|
|
|
|
last_row = elm_code_file_lines_get(pd->code->file);
|
|
|
|
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_fill_range(widget, first_row, last_row, line);
|
2016-02-25 07:50:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_fill(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-02-25 07:50:34 -08:00
|
|
|
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_fill_range(widget, 1, elm_code_file_lines_get(pd->code->file), NULL);
|
2016-02-25 07:50:34 -08:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_elm_code_widget_line_cb(void *data, const Efl_Event *event)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
2015-04-02 14:48:23 -07:00
|
|
|
Elm_Code_Line *line;
|
2015-01-27 16:39:56 -08:00
|
|
|
Elm_Code_Widget *widget;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-04-13 18:48:33 -07:00
|
|
|
line = (Elm_Code_Line *)event->info;
|
2015-01-27 16:39:56 -08:00
|
|
|
widget = (Elm_Code_Widget *)data;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_refresh(widget, line);
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_elm_code_widget_file_cb(void *data, const Efl_Event *event EINA_UNUSED)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
2015-01-27 16:39:56 -08:00
|
|
|
Elm_Code_Widget *widget;
|
2015-01-23 14:55:13 -08:00
|
|
|
|
2015-01-27 16:39:56 -08:00
|
|
|
widget = (Elm_Code_Widget *)data;
|
2015-01-23 14:55:13 -08:00
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
_elm_code_widget_fill(widget);
|
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_elm_code_widget_selection_cb(void *data, const Efl_Event *event EINA_UNUSED)
|
2015-03-18 15:24:56 -07:00
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
|
|
|
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_refresh(widget, NULL);
|
2016-02-25 07:50:34 -08:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_elm_code_widget_selection_clear_cb(void *data, const Efl_Event *event EINA_UNUSED)
|
2016-02-25 07:50:34 -08:00
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
_elm_code_widget_fill(widget);
|
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
static void
|
2015-01-26 11:05:34 -08:00
|
|
|
_elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
2015-01-24 14:07:00 -08:00
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
2015-01-27 16:39:56 -08:00
|
|
|
Elm_Code_Widget *widget;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2015-01-27 16:39:56 -08:00
|
|
|
widget = (Elm_Code_Widget *)data;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_refresh(widget, NULL);
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, const char *key)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-02-14 10:49:51 -08:00
|
|
|
line = elm_code_file_line_get(pd->code->file, pd->cursor_line);
|
|
|
|
|
|
|
|
if (!line)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
if (!strcmp(key, "Up"))
|
|
|
|
return pd->cursor_line > 1;
|
|
|
|
else if (!strcmp(key, "Down"))
|
|
|
|
return pd->cursor_line < elm_code_file_lines_get(pd->code->file);
|
|
|
|
else if (!strcmp(key, "Left"))
|
2015-05-05 14:38:02 -07:00
|
|
|
return pd->cursor_col > 1 || pd->cursor_line > 1;
|
2015-02-14 10:49:51 -08:00
|
|
|
else if (!strcmp(key, "Right"))
|
2015-06-03 13:29:31 -07:00
|
|
|
return pd->cursor_col < elm_code_widget_line_text_column_width_get(widget, line) + 1 ||
|
2015-05-05 14:38:02 -07:00
|
|
|
pd->cursor_line < elm_code_file_lines_get(pd->code->file);
|
2015-02-14 10:49:51 -08:00
|
|
|
else
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_update_focus_directions(Elm_Code_Widget *obj)
|
|
|
|
{
|
|
|
|
if (_elm_code_widget_cursor_key_will_move(obj, "Up"))
|
|
|
|
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_UP);
|
|
|
|
else
|
|
|
|
elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_UP);
|
|
|
|
|
|
|
|
if (_elm_code_widget_cursor_key_will_move(obj, "Down"))
|
|
|
|
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_DOWN);
|
|
|
|
else
|
|
|
|
elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_DOWN);
|
|
|
|
|
|
|
|
if (_elm_code_widget_cursor_key_will_move(obj, "Left"))
|
|
|
|
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_LEFT);
|
|
|
|
else
|
|
|
|
elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_LEFT);
|
|
|
|
|
|
|
|
if (_elm_code_widget_cursor_key_will_move(obj, "Right"))
|
|
|
|
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_RIGHT);
|
|
|
|
else
|
|
|
|
elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_RIGHT);
|
|
|
|
|
|
|
|
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_PREVIOUS);
|
|
|
|
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_NEXT);
|
|
|
|
}
|
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
static void
|
|
|
|
_elm_code_widget_cursor_ensure_visible(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Evas_Coord viewx, viewy, vieww, viewh, cellw, cellh;
|
2016-04-28 14:32:43 -07:00
|
|
|
Evas_Coord curx, cury, oy, rowy;
|
|
|
|
Evas_Object *grid;
|
2015-02-19 13:16:18 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-04-04 11:01:05 -07:00
|
|
|
int gutter;
|
2015-02-19 13:16:18 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-02-19 13:16:18 -08:00
|
|
|
|
2016-04-28 14:32:43 -07:00
|
|
|
evas_object_geometry_get(widget, NULL, &oy, NULL, NULL);
|
2015-02-19 13:16:18 -08:00
|
|
|
elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh);
|
2016-03-29 19:58:39 -07:00
|
|
|
_elm_code_widget_cell_size_get(widget, &cellw, &cellh);
|
2015-02-19 13:16:18 -08:00
|
|
|
|
2016-04-28 14:32:43 -07:00
|
|
|
grid = eina_list_data_get(eina_list_nth_list(pd->grids, pd->cursor_line - 1));
|
|
|
|
evas_object_geometry_get(grid, NULL, &rowy, NULL, NULL);
|
|
|
|
|
2016-03-09 16:06:50 -08:00
|
|
|
gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
|
2015-04-04 11:01:05 -07:00
|
|
|
curx = (pd->cursor_col + gutter - 1) * cellw;
|
2016-04-28 14:32:43 -07:00
|
|
|
cury = rowy + viewy - oy;
|
2015-02-19 13:16:18 -08:00
|
|
|
|
|
|
|
if (curx >= viewx && cury >= viewy && curx + cellw <= viewx + vieww && cury + cellh <= viewy + viewh)
|
|
|
|
return;
|
|
|
|
|
|
|
|
elm_scroller_region_show(pd->scroller, curx, cury, cellw, cellh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line,
|
|
|
|
Eina_Bool was_key)
|
|
|
|
{
|
2015-03-08 04:07:29 -07:00
|
|
|
Elm_Code *code;
|
2016-10-08 06:44:02 -07:00
|
|
|
Elm_Code_Line *line_obj;
|
|
|
|
unsigned int oldrow, position;
|
2015-02-19 13:16:18 -08:00
|
|
|
|
|
|
|
oldrow = pd->cursor_line;
|
|
|
|
pd->cursor_col = col;
|
|
|
|
pd->cursor_line = line;
|
|
|
|
|
2016-10-08 06:44:02 -07:00
|
|
|
code = pd->code;
|
|
|
|
line_obj = elm_code_file_line_get(code->file, line);
|
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line_obj, col);
|
|
|
|
if (elm_code_line_text_get(line_obj, NULL)[position] == '\t')
|
|
|
|
pd->cursor_col = elm_code_widget_line_text_column_width_to_position(widget, line_obj, position);
|
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
if (!was_key)
|
|
|
|
_elm_code_widget_update_focus_directions(widget);
|
|
|
|
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CURSOR_CHANGED, widget);
|
2015-02-19 13:16:18 -08:00
|
|
|
_elm_code_widget_cursor_ensure_visible(widget);
|
|
|
|
|
|
|
|
if (oldrow != pd->cursor_line)
|
2015-03-08 04:07:29 -07:00
|
|
|
{
|
|
|
|
if (oldrow <= elm_code_file_lines_get(code->file))
|
|
|
|
_elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, oldrow));
|
|
|
|
}
|
2015-02-19 13:16:18 -08:00
|
|
|
_elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, pd->cursor_line));
|
2016-12-09 15:25:42 -08:00
|
|
|
elm_layout_signal_emit(pd->cursor_rect, "elm,action,show,cursor", "elm");
|
2015-02-19 13:16:18 -08:00
|
|
|
}
|
|
|
|
|
2016-12-09 15:25:42 -08:00
|
|
|
|
2016-04-07 09:44:12 -07:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd,
|
2015-03-18 15:24:56 -07:00
|
|
|
Evas_Coord x, Evas_Coord y,
|
2015-03-27 16:54:28 -07:00
|
|
|
unsigned int *row, int *col)
|
2015-03-18 15:24:56 -07:00
|
|
|
{
|
2016-04-07 09:44:12 -07:00
|
|
|
Elm_Code_Widget *widget;
|
2016-03-29 19:58:39 -07:00
|
|
|
Eina_List *item;
|
2015-03-18 15:24:56 -07:00
|
|
|
Elm_Code_Line *line;
|
2016-03-29 19:58:39 -07:00
|
|
|
Evas_Coord ox, oy, sx, sy, rowy;
|
|
|
|
Evas_Object *grid;
|
2015-04-04 11:01:05 -07:00
|
|
|
int cw, ch, gutter;
|
2016-03-29 19:58:39 -07:00
|
|
|
unsigned int guess, number;
|
2015-03-18 15:24:56 -07:00
|
|
|
|
2016-04-07 09:44:12 -07:00
|
|
|
widget = (Elm_Code_Widget *)obj;
|
2015-03-18 15:24:56 -07:00
|
|
|
evas_object_geometry_get(widget, &ox, &oy, NULL, NULL);
|
|
|
|
elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL);
|
|
|
|
x = x + sx - ox;
|
|
|
|
y = y + sy - oy;
|
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
_elm_code_widget_cell_size_get(widget, &cw, &ch);
|
2016-03-09 16:06:50 -08:00
|
|
|
gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
|
2016-03-29 19:58:39 -07:00
|
|
|
|
|
|
|
guess = ((double) y / ch) + 1;
|
|
|
|
number = guess;
|
|
|
|
|
|
|
|
// unfortunately EINA_LIST_REVERSE_FOREACH skips to the end of the list...
|
|
|
|
for (item = eina_list_nth_list(pd->grids, guess - 1), grid = eina_list_data_get(item);
|
|
|
|
item;
|
|
|
|
item = eina_list_prev(item), grid = eina_list_data_get(item))
|
|
|
|
{
|
|
|
|
evas_object_geometry_get(grid, NULL, &rowy, NULL, NULL);
|
|
|
|
|
2016-04-28 14:51:03 -07:00
|
|
|
if (rowy + sy - oy - 1<= y)
|
2016-03-29 19:58:39 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
number--;
|
|
|
|
}
|
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
if (col)
|
2015-04-04 11:01:05 -07:00
|
|
|
*col = ((double) x / cw) - gutter + 1;
|
2015-03-18 15:24:56 -07:00
|
|
|
if (row)
|
2015-03-27 16:54:28 -07:00
|
|
|
*row = number;
|
2015-03-18 15:24:56 -07:00
|
|
|
|
2015-03-27 16:54:28 -07:00
|
|
|
line = elm_code_file_line_get(pd->code->file, number);
|
2015-03-18 15:24:56 -07:00
|
|
|
return !!line;
|
|
|
|
}
|
|
|
|
|
2016-12-09 07:53:38 -08:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_code_widget_geometry_for_position_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, unsigned int row, int col,
|
|
|
|
Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
|
|
|
|
{
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
Evas_Object *grid;
|
|
|
|
Evas_Coord cellw;
|
|
|
|
unsigned int length;
|
|
|
|
int gutter;
|
|
|
|
|
|
|
|
line = elm_code_file_line_get(pd->code->file, row);
|
|
|
|
if (!line)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
elm_code_line_text_get(line, &length);
|
|
|
|
_elm_code_widget_cell_size_get(widget, &cellw, h);
|
|
|
|
gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
|
|
|
|
|
|
|
|
grid = eina_list_nth(pd->grids, row - 1);
|
|
|
|
evas_object_geometry_get(grid, x, y, NULL, NULL);
|
|
|
|
if (x)
|
2016-12-09 16:44:18 -08:00
|
|
|
*x += (col - 1 + gutter) * cellw;
|
2016-12-09 07:53:38 -08:00
|
|
|
if (w)
|
|
|
|
*w = cellw;
|
|
|
|
|
|
|
|
return !!line && col <= (int) length;
|
|
|
|
}
|
|
|
|
|
2016-09-01 15:15:34 -07:00
|
|
|
static void
|
|
|
|
_elm_code_widget_status_toggle(Elm_Code_Widget *widget, Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
Evas_Object *status, *grid;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
|
|
|
// add a status below the line if needed (and remove those no longer needed)
|
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
|
|
|
grid = eina_list_nth(pd->grids, line->number - 1);
|
|
|
|
status = evas_object_data_get(grid, "status");
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
elm_box_unpack(pd->gridbox, status);
|
|
|
|
evas_object_hide(status);
|
|
|
|
evas_object_data_set(grid, "status", NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = elm_label_add(pd->gridbox);
|
|
|
|
evas_object_size_hint_weight_set(status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(status, 0.05, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(status);
|
|
|
|
|
|
|
|
elm_box_pack_after(pd->gridbox, status, grid);
|
|
|
|
evas_object_data_set(grid, "status", status);
|
|
|
|
elm_object_text_set(status, line->status_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-11 10:47:05 -07:00
|
|
|
static void
|
|
|
|
_popup_menu_dismissed_cb(void *data, const Efl_Event *event EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
|
|
|
|
|
|
|
if (pd->hoversel) evas_object_hide(pd->hoversel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_popup_menu_cut_cb(void *data,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
|
|
|
|
|
|
|
elm_code_widget_selection_cut(widget);
|
|
|
|
if (pd->hoversel) evas_object_hide(pd->hoversel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_popup_menu_copy_cb(void *data,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
|
|
|
|
|
|
|
elm_code_widget_selection_copy(widget);
|
|
|
|
if (pd->hoversel) evas_object_hide(pd->hoversel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_popup_menu_paste_cb(void *data,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
|
|
|
|
|
|
|
elm_code_widget_selection_paste(widget);
|
|
|
|
if (pd->hoversel) evas_object_hide(pd->hoversel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_popup_menu_cancel_cb(void *data,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
|
|
|
|
|
|
|
elm_code_widget_selection_clear(widget);
|
|
|
|
if (pd->hoversel) evas_object_hide(pd->hoversel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_popup_menu_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Evas_Object *top;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)obj;
|
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
|
|
|
|
|
|
|
if (pd->hoversel) evas_object_del(pd->hoversel);
|
|
|
|
|
|
|
|
pd->hoversel = elm_hoversel_add(obj);
|
|
|
|
elm_widget_sub_object_add(obj, pd->hoversel);
|
|
|
|
top = elm_widget_top_get(obj);
|
|
|
|
|
|
|
|
if (top) elm_hoversel_hover_parent_set(pd->hoversel, top);
|
|
|
|
|
|
|
|
efl_event_callback_add
|
|
|
|
(pd->hoversel, ELM_HOVERSEL_EVENT_DISMISSED, _popup_menu_dismissed_cb, obj);
|
|
|
|
if (pd->selection)
|
|
|
|
{
|
|
|
|
if (pd->editable)
|
|
|
|
{
|
|
|
|
elm_hoversel_item_add
|
|
|
|
(pd->hoversel, "Cut", NULL, ELM_ICON_NONE,
|
|
|
|
_popup_menu_cut_cb, obj);
|
|
|
|
}
|
|
|
|
elm_hoversel_item_add
|
|
|
|
(pd->hoversel, "Copy", NULL, ELM_ICON_NONE,
|
|
|
|
_popup_menu_copy_cb, obj);
|
|
|
|
if (pd->editable)
|
2016-12-02 16:55:02 -08:00
|
|
|
{
|
2016-09-11 10:47:05 -07:00
|
|
|
elm_hoversel_item_add
|
|
|
|
(pd->hoversel, "Paste", NULL, ELM_ICON_NONE,
|
|
|
|
_popup_menu_paste_cb, obj);
|
|
|
|
}
|
|
|
|
elm_hoversel_item_add
|
|
|
|
(pd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
|
|
|
|
_popup_menu_cancel_cb, obj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pd->editable)
|
|
|
|
{
|
|
|
|
if (pd->editable)
|
|
|
|
elm_hoversel_item_add
|
|
|
|
(pd->hoversel, "Paste", NULL, ELM_ICON_NONE,
|
|
|
|
_popup_menu_paste_cb, obj);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
elm_hoversel_item_add
|
|
|
|
(pd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
|
|
|
|
_popup_menu_cancel_cb, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pd->hoversel)
|
|
|
|
{
|
|
|
|
evas_object_move(pd->hoversel, x, y);
|
|
|
|
evas_object_show(pd->hoversel);
|
|
|
|
elm_hoversel_hover_begin(pd->hoversel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
static void
|
2015-03-27 16:54:28 -07:00
|
|
|
_elm_code_widget_clicked_gutter_cb(Elm_Code_Widget *widget, unsigned int row)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
2015-01-26 11:05:34 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-24 14:07:00 -08:00
|
|
|
Elm_Code_Line *line;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-01-25 09:18:21 -08:00
|
|
|
|
2015-03-27 16:54:28 -07:00
|
|
|
line = elm_code_file_line_get(pd->code->file, row);
|
|
|
|
if (!line)
|
2015-02-19 13:16:18 -08:00
|
|
|
return;
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2016-09-01 15:15:34 -07:00
|
|
|
if (line->status_text)
|
|
|
|
{
|
|
|
|
_elm_code_widget_status_toggle(widget, line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_LINE_GUTTER_CLICKED, line);
|
2015-03-27 16:54:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, unsigned int row, unsigned int col)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Line *line;
|
2015-03-29 12:12:28 -07:00
|
|
|
unsigned int column_width;
|
2015-03-27 16:54:28 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-27 16:54:28 -07:00
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
line = elm_code_file_line_get(pd->code->file, row);
|
2015-03-27 16:54:28 -07:00
|
|
|
if (!line)
|
|
|
|
return;
|
2015-06-03 13:29:31 -07:00
|
|
|
column_width = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-03-27 16:54:28 -07:00
|
|
|
|
2015-03-29 12:12:28 -07:00
|
|
|
if (col > column_width + 1)
|
|
|
|
col = column_width + 1;
|
2015-03-27 16:54:28 -07:00
|
|
|
else if (col <= 0)
|
2015-02-19 13:16:18 -08:00
|
|
|
col = 1;
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
_elm_code_widget_cursor_move(widget, pd, col, row, EINA_FALSE);
|
2015-01-25 15:15:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-03-27 16:54:28 -07:00
|
|
|
_elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, unsigned int row)
|
2015-01-25 15:15:37 -08:00
|
|
|
{
|
2015-01-26 11:05:34 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-25 15:15:37 -08:00
|
|
|
Elm_Code_Line *line;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-27 16:54:28 -07:00
|
|
|
line = elm_code_file_line_get(pd->code->file, row);
|
|
|
|
if (!line)
|
2015-03-18 15:24:56 -07:00
|
|
|
return;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_LINE_CLICKED, line);
|
2015-01-23 14:55:13 -08:00
|
|
|
}
|
|
|
|
|
2015-01-25 15:15:37 -08:00
|
|
|
static void
|
2015-03-18 15:24:56 -07:00
|
|
|
_elm_code_widget_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
2016-02-15 14:54:12 -08:00
|
|
|
void *event_info)
|
2015-03-18 15:24:56 -07:00
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Evas_Event_Mouse_Down *event;
|
2016-09-11 11:10:04 -07:00
|
|
|
Eina_Bool ctrl;
|
2015-03-27 16:54:28 -07:00
|
|
|
unsigned int row;
|
|
|
|
int col;
|
2015-03-18 15:24:56 -07:00
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-18 15:24:56 -07:00
|
|
|
event = (Evas_Event_Mouse_Down *)event_info;
|
2016-02-15 14:54:12 -08:00
|
|
|
_elm_code_widget_position_at_coordinates_get(widget, pd, event->canvas.x, event->canvas.y, &row, &col);
|
2015-03-18 15:24:56 -07:00
|
|
|
|
2016-09-11 11:10:04 -07:00
|
|
|
ctrl = evas_key_modifier_is_set(event->modifiers, "Control");
|
|
|
|
if (event->button == 3 && !ctrl)
|
2016-09-11 10:47:05 -07:00
|
|
|
{
|
|
|
|
_popup_menu_show(widget, event->canvas.x, event->canvas.y);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2016-02-15 14:54:12 -08:00
|
|
|
if (event->flags & EVAS_BUTTON_TRIPLE_CLICK)
|
|
|
|
{
|
|
|
|
elm_code_widget_selection_select_line(widget, row);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (event->flags & EVAS_BUTTON_DOUBLE_CLICK)
|
|
|
|
{
|
|
|
|
elm_code_widget_selection_select_word(widget, row, col);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-25 07:50:34 -08:00
|
|
|
if (pd->editable)
|
|
|
|
_elm_code_widget_clicked_editable_cb(widget, row, (unsigned int) col);
|
2015-03-18 15:24:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Evas_Event_Mouse_Move *event;
|
2015-03-27 16:54:28 -07:00
|
|
|
unsigned int row;
|
|
|
|
int col;
|
2015-03-18 15:24:56 -07:00
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-18 15:24:56 -07:00
|
|
|
event = (Evas_Event_Mouse_Move *)event_info;
|
|
|
|
|
2016-03-30 08:44:50 -07:00
|
|
|
_elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col);
|
2015-04-04 09:51:39 -07:00
|
|
|
|
2016-02-25 07:50:34 -08:00
|
|
|
if (!pd->editable || !event->buttons)
|
2015-03-18 15:24:56 -07:00
|
|
|
return;
|
|
|
|
|
2016-02-25 07:50:34 -08:00
|
|
|
if (!pd->selection)
|
|
|
|
if (col > 0 && row <= elm_code_file_lines_get(pd->code->file))
|
|
|
|
elm_code_widget_selection_start(widget, row, col);
|
2015-03-18 15:24:56 -07:00
|
|
|
elm_code_widget_selection_end(widget, row, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
2015-01-25 15:15:37 -08:00
|
|
|
void *event_info)
|
|
|
|
{
|
2015-01-26 11:05:34 -08:00
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-25 15:15:37 -08:00
|
|
|
Evas_Event_Mouse_Up *event;
|
2015-03-18 15:24:56 -07:00
|
|
|
Evas_Coord x, y;
|
2015-03-27 16:54:28 -07:00
|
|
|
unsigned int row;
|
|
|
|
int col;
|
|
|
|
Eina_Bool hasline;
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2015-01-26 11:05:34 -08:00
|
|
|
widget = (Elm_Code_Widget *)data;
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-01-25 15:15:37 -08:00
|
|
|
event = (Evas_Event_Mouse_Up *)event_info;
|
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
if (pd->selection)
|
|
|
|
{
|
|
|
|
if (pd->selection->start_line == pd->selection->end_line &&
|
|
|
|
pd->selection->start_col == pd->selection->end_col)
|
|
|
|
elm_code_widget_selection_clear(widget);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
x = event->canvas.x;
|
|
|
|
y = event->canvas.y;
|
2015-03-27 16:54:28 -07:00
|
|
|
hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, &col);
|
|
|
|
if (!hasline)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (col <= 0)
|
|
|
|
_elm_code_widget_clicked_gutter_cb(widget, row);
|
|
|
|
else if (pd->editable)
|
|
|
|
_elm_code_widget_clicked_editable_cb(widget, row, (unsigned int) col);
|
2015-01-25 15:15:37 -08:00
|
|
|
else
|
2015-03-27 16:54:28 -07:00
|
|
|
_elm_code_widget_clicked_readonly_cb(widget, row);
|
2015-01-25 15:15:37 -08:00
|
|
|
}
|
|
|
|
|
2015-05-05 14:38:02 -07:00
|
|
|
static void
|
|
|
|
_elm_code_widget_cursor_move_home(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-06-07 15:13:26 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2015-05-05 14:38:02 -07:00
|
|
|
|
|
|
|
if (pd->cursor_col <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_elm_code_widget_cursor_move(widget, pd, 1, pd->cursor_line, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_cursor_move_end(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
unsigned int lastcol;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-06-07 15:13:26 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2015-05-05 14:38:02 -07:00
|
|
|
|
|
|
|
line = elm_code_file_line_get(pd->code->file, pd->cursor_line);
|
2015-06-03 13:29:31 -07:00
|
|
|
lastcol = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-05-05 14:38:02 -07:00
|
|
|
if (pd->cursor_col > lastcol + 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_elm_code_widget_cursor_move(widget, pd, lastcol + 1, pd->cursor_line, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
2015-01-25 15:15:37 -08:00
|
|
|
static void
|
2015-01-26 11:05:34 -08:00
|
|
|
_elm_code_widget_cursor_move_up(Elm_Code_Widget *widget)
|
2015-01-25 15:15:37 -08:00
|
|
|
{
|
2015-01-26 11:05:34 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-26 11:46:30 -08:00
|
|
|
Elm_Code_Line *line;
|
2015-03-29 12:12:28 -07:00
|
|
|
unsigned int row, col, column_width;
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-02-19 13:16:18 -08:00
|
|
|
row = pd->cursor_line;
|
|
|
|
col = pd->cursor_col;
|
2015-06-07 15:13:26 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
if (pd->cursor_line <= 1)
|
|
|
|
return;
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
row--;
|
|
|
|
line = elm_code_file_line_get(pd->code->file, row);
|
2015-06-03 13:29:31 -07:00
|
|
|
column_width = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-03-29 12:12:28 -07:00
|
|
|
if (col > column_width + 1)
|
|
|
|
col = column_width + 1;
|
2015-01-26 11:46:30 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
_elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE);
|
2015-01-25 15:15:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-26 11:05:34 -08:00
|
|
|
_elm_code_widget_cursor_move_down(Elm_Code_Widget *widget)
|
2015-01-25 15:15:37 -08:00
|
|
|
{
|
2015-01-26 11:05:34 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-26 11:46:30 -08:00
|
|
|
Elm_Code_Line *line;
|
2015-03-29 12:12:28 -07:00
|
|
|
unsigned int row, col, column_width;
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-02-19 13:16:18 -08:00
|
|
|
row = pd->cursor_line;
|
|
|
|
col = pd->cursor_col;
|
2015-06-07 15:13:26 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
if (pd->cursor_line >= elm_code_file_lines_get(pd->code->file))
|
|
|
|
return;
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
row++;
|
|
|
|
line = elm_code_file_line_get(pd->code->file, row);
|
2015-06-03 13:29:31 -07:00
|
|
|
column_width = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-03-29 12:12:28 -07:00
|
|
|
if (col > column_width + 1)
|
|
|
|
col = column_width + 1;
|
2015-01-26 11:46:30 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
_elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE);
|
2015-01-26 11:46:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_cursor_move_left(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-06-07 15:13:26 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2015-01-26 11:46:30 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
if (pd->cursor_col <= 1)
|
2015-05-05 14:38:02 -07:00
|
|
|
{
|
|
|
|
if (pd->cursor_line > 1)
|
|
|
|
{
|
|
|
|
_elm_code_widget_cursor_move_up(widget);
|
|
|
|
_elm_code_widget_cursor_move_end(widget);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-01-26 11:46:30 -08:00
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
_elm_code_widget_cursor_move(widget, pd, pd->cursor_col-1, pd->cursor_line, EINA_TRUE);
|
2015-01-26 11:46:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_cursor_move_right(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Line *line;
|
2016-10-08 06:44:02 -07:00
|
|
|
unsigned int position, next_col;
|
2015-01-26 11:46:30 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-06-07 15:13:26 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2015-01-26 11:46:30 -08:00
|
|
|
|
|
|
|
line = elm_code_file_line_get(pd->code->file, pd->cursor_line);
|
2015-06-03 13:29:31 -07:00
|
|
|
if (pd->cursor_col > elm_code_widget_line_text_column_width_get(widget, line))
|
2015-05-05 14:38:02 -07:00
|
|
|
{
|
|
|
|
if (pd->cursor_line < elm_code_file_lines_get(pd->code->file))
|
|
|
|
{
|
|
|
|
_elm_code_widget_cursor_move_down(widget);
|
|
|
|
_elm_code_widget_cursor_move_home(widget);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-01-26 11:46:30 -08:00
|
|
|
|
2016-10-08 06:44:02 -07:00
|
|
|
next_col = pd->cursor_col + 1;
|
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line, pd->cursor_col);
|
|
|
|
if (elm_code_line_text_get(line, NULL)[position] == '\t')
|
|
|
|
next_col = pd->cursor_col + pd->tabstop;
|
|
|
|
|
|
|
|
_elm_code_widget_cursor_move(widget, pd, next_col, pd->cursor_line, EINA_TRUE);
|
2015-01-25 15:15:37 -08:00
|
|
|
}
|
|
|
|
|
2015-05-12 15:15:25 -07:00
|
|
|
static unsigned int
|
|
|
|
_elm_code_widget_cursor_move_page_height_get(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
unsigned int lines;
|
|
|
|
|
2016-03-09 16:06:50 -08:00
|
|
|
lines = elm_obj_code_widget_lines_visible_get(widget);
|
2015-05-12 15:15:25 -07:00
|
|
|
return lines * 0.85;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_cursor_move_pageup(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
unsigned int row, col, column_width;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-05-12 15:15:25 -07:00
|
|
|
row = pd->cursor_line;
|
|
|
|
col = pd->cursor_col;
|
|
|
|
|
2015-06-07 15:13:26 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2015-05-12 15:15:25 -07:00
|
|
|
if (pd->cursor_line <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (row > _elm_code_widget_cursor_move_page_height_get(widget))
|
|
|
|
row -= _elm_code_widget_cursor_move_page_height_get(widget);
|
|
|
|
else
|
|
|
|
row = 1;
|
|
|
|
|
|
|
|
line = elm_code_file_line_get(pd->code->file, row);
|
2015-06-03 13:29:31 -07:00
|
|
|
column_width = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-05-12 15:15:25 -07:00
|
|
|
if (col > column_width + 1)
|
|
|
|
col = column_width + 1;
|
|
|
|
|
|
|
|
_elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_cursor_move_pagedown(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
unsigned int row, col, column_width;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-05-12 15:15:25 -07:00
|
|
|
row = pd->cursor_line;
|
|
|
|
col = pd->cursor_col;
|
|
|
|
|
2015-06-07 15:13:26 -07:00
|
|
|
elm_code_widget_selection_clear(widget);
|
2015-05-12 15:15:25 -07:00
|
|
|
if (pd->cursor_line >= elm_code_file_lines_get(pd->code->file))
|
|
|
|
return;
|
|
|
|
|
|
|
|
row += _elm_code_widget_cursor_move_page_height_get(widget);
|
|
|
|
if (row > elm_code_file_lines_get(pd->code->file))
|
|
|
|
row = elm_code_file_lines_get(pd->code->file);
|
|
|
|
|
|
|
|
line = elm_code_file_line_get(pd->code->file, row);
|
2015-06-03 13:29:31 -07:00
|
|
|
column_width = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-05-12 15:15:25 -07:00
|
|
|
if (col > column_width + 1)
|
|
|
|
col = column_width + 1;
|
|
|
|
|
|
|
|
_elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
2015-03-28 08:17:08 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_elm_code_widget_delete_selection(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-09-16 04:32:25 -07:00
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
2015-03-28 08:17:08 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-28 08:17:08 -07:00
|
|
|
|
|
|
|
if (!pd->selection)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
selection = elm_code_widget_selection_normalized_get(widget);
|
2015-03-28 08:17:08 -07:00
|
|
|
elm_code_widget_selection_delete(widget);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_code_widget_cursor_position_set(widget, selection->start_line, selection->start_col);
|
2015-09-16 04:32:25 -07:00
|
|
|
free(selection);
|
|
|
|
|
2015-03-28 08:17:08 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2016-02-21 10:11:33 -08:00
|
|
|
static Elm_Code_Widget_Change_Info *
|
2016-02-21 15:46:10 -08:00
|
|
|
_elm_code_widget_change_create(unsigned int start_col, unsigned int start_line,
|
|
|
|
unsigned int end_col, unsigned int end_line,
|
|
|
|
const char *text, unsigned int length, Eina_Bool insert)
|
2016-02-21 10:11:33 -08:00
|
|
|
{
|
|
|
|
Elm_Code_Widget_Change_Info *info;
|
|
|
|
|
|
|
|
info = calloc(1, sizeof(*info));
|
2016-02-21 15:46:10 -08:00
|
|
|
info->insert = insert;
|
2016-02-21 10:11:33 -08:00
|
|
|
|
|
|
|
info->start_col = start_col;
|
|
|
|
info->start_line = start_line;
|
|
|
|
info->end_col = end_col;
|
|
|
|
info->end_line = end_line;
|
|
|
|
|
|
|
|
info->content = malloc((length + 1) * sizeof(char));
|
2016-02-21 15:46:10 -08:00
|
|
|
strncpy(info->content, text, length);
|
|
|
|
info->content[length] = '\0';
|
2016-02-21 10:11:33 -08:00
|
|
|
info->length = length;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2015-02-22 12:07:08 -08:00
|
|
|
static void
|
2016-02-21 10:11:33 -08:00
|
|
|
_elm_code_widget_change_free(Elm_Code_Widget_Change_Info *info)
|
|
|
|
{
|
|
|
|
free((char *)info->content);
|
|
|
|
free(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-14 14:47:22 -07:00
|
|
|
_elm_code_widget_text_at_cursor_insert_do(Elm_Code_Widget *widget, const char *text, int length, Eina_Bool undo)
|
2015-02-22 12:07:08 -08:00
|
|
|
{
|
|
|
|
Elm_Code *code;
|
|
|
|
Elm_Code_Line *line;
|
2016-02-21 10:11:33 -08:00
|
|
|
Elm_Code_Widget_Change_Info *change;
|
2016-12-02 16:55:02 -08:00
|
|
|
unsigned int row, col, position, col_width, curlen, indent, count;
|
|
|
|
char *curtext, *leading;
|
2015-03-30 12:07:45 -07:00
|
|
|
|
2015-03-28 08:17:08 -07:00
|
|
|
_elm_code_widget_delete_selection(widget);
|
2016-03-09 16:06:50 -08:00
|
|
|
code = elm_obj_code_widget_code_get(widget);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &row, &col);
|
2015-02-22 12:07:08 -08:00
|
|
|
line = elm_code_file_line_get(code->file, row);
|
2015-06-10 15:33:46 -07:00
|
|
|
if (line == NULL)
|
|
|
|
{
|
|
|
|
elm_code_file_line_append(code->file, "", 0, NULL);
|
|
|
|
row = elm_code_file_lines_get(code->file);
|
|
|
|
line = elm_code_file_line_get(code->file, row);
|
|
|
|
}
|
2016-12-02 16:55:02 -08:00
|
|
|
if (text[0] == '}')
|
|
|
|
{
|
|
|
|
curtext = (char *)elm_code_line_text_get(line, &curlen);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
while (count < curlen)
|
|
|
|
{
|
2016-12-03 07:59:40 -08:00
|
|
|
if (*curtext != ' ' && *curtext != '\t')
|
|
|
|
break;
|
2016-12-02 16:55:02 -08:00
|
|
|
|
|
|
|
count++;
|
|
|
|
curtext++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count + 1 == col)
|
|
|
|
{
|
|
|
|
leading = elm_code_line_indent_matching_braces_get(line);
|
|
|
|
elm_code_line_text_leading_whitespace_strip(line);
|
|
|
|
elm_code_line_text_insert(line, 0, leading, strlen(leading));
|
|
|
|
|
|
|
|
indent = elm_obj_code_widget_line_text_column_width_to_position(
|
|
|
|
widget, line, strlen(leading));
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_set(widget, row, indent);
|
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &row, &col);
|
2016-12-02 16:55:02 -08:00
|
|
|
free(leading);
|
|
|
|
}
|
|
|
|
}
|
2015-02-22 12:07:08 -08:00
|
|
|
|
2015-06-03 13:29:31 -07:00
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
|
|
|
|
elm_code_line_text_insert(line, position, text, length);
|
|
|
|
col_width = elm_code_widget_line_text_column_width_to_position(widget, line, position + length) -
|
|
|
|
elm_code_widget_line_text_column_width_to_position(widget, line, position);
|
2015-03-30 12:07:45 -07:00
|
|
|
|
2016-05-17 09:25:28 -07:00
|
|
|
// a workaround for when the cursor position would be off the line width
|
|
|
|
_elm_code_widget_resize(widget, line);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_set(widget, row, col + col_width);
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
|
2016-02-21 10:11:33 -08:00
|
|
|
|
2016-06-14 14:47:22 -07:00
|
|
|
if (undo)
|
|
|
|
{
|
|
|
|
change = _elm_code_widget_change_create(col, row, col + col_width - 1, row, text, length, EINA_TRUE);
|
|
|
|
_elm_code_widget_undo_change_add(widget, change);
|
|
|
|
_elm_code_widget_change_free(change);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text, int length)
|
|
|
|
{
|
|
|
|
_elm_code_widget_text_at_cursor_insert_do(widget, text, length, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_elm_code_widget_text_at_cursor_insert_no_undo(Elm_Code_Widget *widget, const char *text, int length)
|
|
|
|
{
|
|
|
|
_elm_code_widget_text_at_cursor_insert_do(widget, text, length, EINA_FALSE);
|
2015-02-22 12:07:08 -08:00
|
|
|
}
|
|
|
|
|
2016-02-08 16:32:16 -08:00
|
|
|
static void
|
|
|
|
_elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
2016-02-21 10:11:33 -08:00
|
|
|
unsigned int col, row, rem;
|
2016-02-08 16:32:16 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-02-08 16:32:16 -08:00
|
|
|
if (!pd->tab_inserts_spaces)
|
|
|
|
{
|
|
|
|
_elm_code_widget_text_at_cursor_insert(widget, "\t", 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &row, &col);
|
2016-02-21 10:11:33 -08:00
|
|
|
rem = (col - 1) % pd->tabstop;
|
2016-02-08 16:32:16 -08:00
|
|
|
|
2016-02-21 10:11:33 -08:00
|
|
|
while (rem < pd->tabstop)
|
2016-02-08 16:32:16 -08:00
|
|
|
{
|
|
|
|
_elm_code_widget_text_at_cursor_insert(widget, " ", 1);
|
2016-02-21 10:11:33 -08:00
|
|
|
rem++;
|
2016-02-08 16:32:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 10:11:33 -08:00
|
|
|
void
|
2015-02-28 06:20:32 -08:00
|
|
|
_elm_code_widget_newline(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code *code;
|
2015-04-19 07:00:10 -07:00
|
|
|
Elm_Code_Line *line;
|
2016-02-21 10:11:33 -08:00
|
|
|
Elm_Code_Widget_Change_Info *change;
|
2016-11-27 15:13:42 -08:00
|
|
|
unsigned int row, col, position, oldlen, width, indent;
|
|
|
|
char *oldtext, *leading;
|
2015-02-28 06:20:32 -08:00
|
|
|
|
2015-03-28 08:17:08 -07:00
|
|
|
_elm_code_widget_delete_selection(widget);
|
2016-03-09 16:06:50 -08:00
|
|
|
code = elm_obj_code_widget_code_get(widget);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &row, &col);
|
2015-02-28 06:20:32 -08:00
|
|
|
line = elm_code_file_line_get(code->file, row);
|
2015-06-10 15:33:46 -07:00
|
|
|
if (line == NULL)
|
|
|
|
{
|
|
|
|
elm_code_file_line_append(code->file, "", 0, NULL);
|
|
|
|
row = elm_code_file_lines_get(code->file);
|
|
|
|
line = elm_code_file_line_get(code->file, row);
|
|
|
|
}
|
2015-09-16 02:44:38 -07:00
|
|
|
oldtext = (char *) elm_code_line_text_get(line, &oldlen);
|
|
|
|
oldtext = strndup(oldtext, oldlen);
|
2015-02-28 06:20:32 -08:00
|
|
|
|
2015-06-03 13:29:31 -07:00
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
|
2015-04-19 07:00:10 -07:00
|
|
|
elm_code_line_split_at(line, position);
|
2016-02-21 10:11:33 -08:00
|
|
|
width = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-02-28 06:20:32 -08:00
|
|
|
|
2015-06-07 15:11:25 -07:00
|
|
|
line = elm_code_file_line_get(code->file, row + 1);
|
2016-12-03 07:59:40 -08:00
|
|
|
leading = elm_code_line_indent_get(line);
|
2015-10-10 14:09:02 -07:00
|
|
|
elm_code_line_text_leading_whitespace_strip(line);
|
2016-11-27 15:13:42 -08:00
|
|
|
elm_code_line_text_insert(line, 0, leading, strlen(leading));
|
2015-09-16 02:44:38 -07:00
|
|
|
free(oldtext);
|
2015-06-07 15:11:25 -07:00
|
|
|
|
2016-11-27 15:13:42 -08:00
|
|
|
indent = elm_obj_code_widget_line_text_column_width_to_position(widget, line,
|
|
|
|
strlen(leading));
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_set(widget, row + 1, indent);
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
|
2016-11-29 05:35:52 -08:00
|
|
|
free(leading);
|
2016-02-21 10:11:33 -08:00
|
|
|
|
2016-02-21 15:46:10 -08:00
|
|
|
change = _elm_code_widget_change_create(width + 1, row, indent - 1, row + 1, "\n", 1, EINA_TRUE);
|
2016-02-21 10:11:33 -08:00
|
|
|
_elm_code_widget_undo_change_add(widget, change);
|
|
|
|
_elm_code_widget_change_free(change);
|
2015-02-28 06:20:32 -08:00
|
|
|
}
|
|
|
|
|
2015-03-08 03:33:07 -07:00
|
|
|
static void
|
|
|
|
_elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline)
|
|
|
|
{
|
|
|
|
Elm_Code *code;
|
2015-09-20 02:59:52 -07:00
|
|
|
Elm_Code_Line *line, *oldline;
|
|
|
|
unsigned int row, col, oldlength, position;
|
2015-03-08 03:33:07 -07:00
|
|
|
|
2016-03-09 16:06:50 -08:00
|
|
|
code = elm_obj_code_widget_code_get(widget);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &row, &col);
|
2015-03-08 03:33:07 -07:00
|
|
|
line = elm_code_file_line_get(code->file, row);
|
|
|
|
|
|
|
|
if (nextline)
|
|
|
|
{
|
2015-09-20 02:59:52 -07:00
|
|
|
elm_code_line_merge_down(line);
|
2015-03-08 03:33:07 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-20 02:59:52 -07:00
|
|
|
oldline = elm_code_file_line_get(code->file, row - 1);
|
|
|
|
elm_code_line_text_get(oldline, &oldlength);
|
|
|
|
elm_code_line_merge_up(line);
|
2015-03-08 03:33:07 -07:00
|
|
|
|
2015-09-20 02:59:52 -07:00
|
|
|
position = elm_code_widget_line_text_column_width_to_position(widget, oldline, oldlength);
|
2015-03-30 12:07:45 -07:00
|
|
|
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_set(widget, row - 1, position);
|
2015-03-30 12:07:45 -07:00
|
|
|
}
|
2015-03-21 13:04:12 -07:00
|
|
|
// TODO construct and pass a change object
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
|
2015-03-08 03:33:07 -07:00
|
|
|
}
|
|
|
|
|
2016-02-21 15:46:10 -08:00
|
|
|
void
|
2015-03-08 00:44:26 -08:00
|
|
|
_elm_code_widget_backspace(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code *code;
|
|
|
|
Elm_Code_Line *line;
|
2016-02-21 15:46:10 -08:00
|
|
|
Elm_Code_Widget_Change_Info *change;
|
2016-05-18 15:36:47 -07:00
|
|
|
unsigned int row, col, position, start_col, end_col, char_width;
|
2016-02-21 15:46:10 -08:00
|
|
|
const char *text;
|
2015-03-08 00:44:26 -08:00
|
|
|
|
2015-03-28 08:17:08 -07:00
|
|
|
if (_elm_code_widget_delete_selection(widget))
|
2016-02-21 15:46:10 -08:00
|
|
|
return; // TODO fire the change and log it
|
2015-03-28 08:17:08 -07:00
|
|
|
|
2016-03-09 16:06:50 -08:00
|
|
|
code = elm_obj_code_widget_code_get(widget);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &row, &col);
|
2015-03-08 00:44:26 -08:00
|
|
|
|
|
|
|
if (col <= 1)
|
2015-03-08 03:33:07 -07:00
|
|
|
{
|
|
|
|
if (row == 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_elm_code_widget_backspaceline(widget, EINA_FALSE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-08 00:44:26 -08:00
|
|
|
line = elm_code_file_line_get(code->file, row);
|
|
|
|
|
2015-06-08 15:13:03 -07:00
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
|
2016-05-18 15:36:47 -07:00
|
|
|
end_col = elm_code_widget_line_text_column_width_to_position(widget, line, position);
|
2015-06-08 15:13:03 -07:00
|
|
|
start_col = elm_code_widget_line_text_column_width_to_position(widget, line,
|
|
|
|
elm_code_widget_line_text_position_for_column_get(widget, line, col - 1));
|
|
|
|
char_width = position - elm_code_widget_line_text_position_for_column_get(widget, line, start_col);
|
2015-04-07 15:09:16 -07:00
|
|
|
|
2016-05-18 15:36:47 -07:00
|
|
|
text = elm_code_widget_text_between_positions_get(widget, start_col, row, end_col, row);
|
2015-06-08 15:13:03 -07:00
|
|
|
elm_code_line_text_remove(line, position - char_width, char_width);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_set(widget, row, start_col);
|
2015-03-21 13:04:12 -07:00
|
|
|
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
|
2016-02-21 15:46:10 -08:00
|
|
|
|
2016-05-18 15:36:47 -07:00
|
|
|
change = _elm_code_widget_change_create(start_col, row, end_col, row, text, char_width, EINA_FALSE);
|
2016-02-21 15:46:10 -08:00
|
|
|
_elm_code_widget_undo_change_add(widget, change);
|
|
|
|
_elm_code_widget_change_free(change);
|
2015-03-08 00:44:26 -08:00
|
|
|
}
|
|
|
|
|
2016-02-21 15:46:10 -08:00
|
|
|
void
|
2015-03-08 00:44:26 -08:00
|
|
|
_elm_code_widget_delete(Elm_Code_Widget *widget)
|
|
|
|
{
|
|
|
|
Elm_Code *code;
|
|
|
|
Elm_Code_Line *line;
|
2016-02-21 15:46:10 -08:00
|
|
|
Elm_Code_Widget_Change_Info *change;
|
2016-05-18 15:36:47 -07:00
|
|
|
unsigned int row, col, position, char_width, start_col, end_col;
|
2016-02-21 15:46:10 -08:00
|
|
|
const char *text;
|
2015-03-08 00:44:26 -08:00
|
|
|
|
2015-03-28 08:17:08 -07:00
|
|
|
if (_elm_code_widget_delete_selection(widget))
|
2016-02-21 15:46:10 -08:00
|
|
|
return; // TODO fire the change and log it
|
2015-03-28 08:17:08 -07:00
|
|
|
|
2016-03-09 16:06:50 -08:00
|
|
|
code = elm_obj_code_widget_code_get(widget);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &row, &col);
|
2015-03-08 00:44:26 -08:00
|
|
|
line = elm_code_file_line_get(code->file, row);
|
2015-06-03 13:29:31 -07:00
|
|
|
if (col > elm_code_widget_line_text_column_width_get(widget, line))
|
2015-03-08 03:33:07 -07:00
|
|
|
{
|
|
|
|
if (row == elm_code_file_lines_get(code->file))
|
|
|
|
return;
|
|
|
|
|
|
|
|
_elm_code_widget_backspaceline(widget, EINA_TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-08 00:44:26 -08:00
|
|
|
|
2015-06-03 13:29:31 -07:00
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
|
|
|
|
char_width = elm_code_widget_line_text_position_for_column_get(widget, line, col + 1) - position;
|
2016-05-18 15:36:47 -07:00
|
|
|
if (char_width == 0) // a partial tab
|
|
|
|
char_width = 1;
|
2015-06-03 13:29:31 -07:00
|
|
|
start_col = elm_code_widget_line_text_column_width_to_position(widget, line, position);
|
2016-05-18 15:36:47 -07:00
|
|
|
end_col = elm_code_widget_line_text_column_width_to_position(widget, line, position + char_width);
|
2015-04-07 15:09:16 -07:00
|
|
|
|
2016-05-18 15:36:47 -07:00
|
|
|
text = elm_code_widget_text_between_positions_get(widget, start_col, row, end_col, row);
|
|
|
|
elm_code_line_text_remove(line, position, char_width);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_set(widget, row, start_col);
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
|
2016-02-21 15:46:10 -08:00
|
|
|
|
|
|
|
change = _elm_code_widget_change_create(start_col, row, col, row, text, char_width, EINA_FALSE);
|
|
|
|
_elm_code_widget_undo_change_add(widget, change);
|
|
|
|
_elm_code_widget_change_free(change);
|
2015-03-08 00:44:26 -08:00
|
|
|
}
|
|
|
|
|
2015-03-28 10:57:47 -07:00
|
|
|
static void
|
|
|
|
_elm_code_widget_control_key_down_cb(Elm_Code_Widget *widget, const char *key)
|
|
|
|
{
|
|
|
|
if (!key)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!strcmp("c", key))
|
2015-05-30 02:13:11 -07:00
|
|
|
{
|
|
|
|
elm_code_widget_selection_copy(widget);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("v", key))
|
2015-03-28 10:57:47 -07:00
|
|
|
elm_code_widget_selection_paste(widget);
|
|
|
|
else if (!strcmp("x", key))
|
|
|
|
elm_code_widget_selection_cut(widget);
|
2016-02-21 10:11:33 -08:00
|
|
|
else if (!strcmp("z", key))
|
|
|
|
elm_code_widget_undo(widget);
|
2015-05-30 02:13:11 -07:00
|
|
|
|
2016-03-09 16:06:50 -08:00
|
|
|
// TODO construct and pass a change object for cut and paste
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
|
2015-03-28 10:57:47 -07:00
|
|
|
}
|
|
|
|
|
2015-01-25 15:15:37 -08:00
|
|
|
static void
|
2015-01-26 11:05:34 -08:00
|
|
|
_elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
|
2015-01-25 15:15:37 -08:00
|
|
|
Evas_Object *obj EINA_UNUSED, void *event_info)
|
|
|
|
{
|
2015-01-26 11:05:34 -08:00
|
|
|
Elm_Code_Widget *widget;
|
2015-01-27 06:34:11 -08:00
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-25 15:15:37 -08:00
|
|
|
|
2015-01-26 11:05:34 -08:00
|
|
|
widget = (Elm_Code_Widget *)data;
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-01-25 15:15:37 -08:00
|
|
|
|
|
|
|
Evas_Event_Key_Down *ev = event_info;
|
|
|
|
|
2015-01-27 06:34:11 -08:00
|
|
|
if (!pd->editable)
|
|
|
|
return;
|
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
_elm_code_widget_update_focus_directions((Elm_Code_Widget *)obj);
|
2015-01-27 06:34:11 -08:00
|
|
|
|
2016-09-23 01:51:37 -07:00
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
|
|
|
if (evas_key_modifier_is_set(ev->modifiers, "Super"))
|
|
|
|
#else
|
2015-03-28 10:57:47 -07:00
|
|
|
if (evas_key_modifier_is_set(ev->modifiers, "Control"))
|
2016-09-23 01:51:37 -07:00
|
|
|
#endif
|
2015-03-28 10:57:47 -07:00
|
|
|
{
|
|
|
|
_elm_code_widget_control_key_down_cb(widget, ev->key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-03 12:48:14 -07:00
|
|
|
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
|
|
|
|
|
2015-01-26 11:46:30 -08:00
|
|
|
if (!strcmp(ev->key, "Up"))
|
2015-01-26 11:05:34 -08:00
|
|
|
_elm_code_widget_cursor_move_up(widget);
|
2015-01-26 11:46:30 -08:00
|
|
|
else if (!strcmp(ev->key, "Down"))
|
2015-01-26 11:05:34 -08:00
|
|
|
_elm_code_widget_cursor_move_down(widget);
|
2015-01-26 11:46:30 -08:00
|
|
|
else if (!strcmp(ev->key, "Left"))
|
|
|
|
_elm_code_widget_cursor_move_left(widget);
|
|
|
|
else if (!strcmp(ev->key, "Right"))
|
|
|
|
_elm_code_widget_cursor_move_right(widget);
|
2015-05-05 13:49:21 -07:00
|
|
|
else if (!strcmp(ev->key, "Home"))
|
|
|
|
_elm_code_widget_cursor_move_home(widget);
|
|
|
|
else if (!strcmp(ev->key, "End"))
|
|
|
|
_elm_code_widget_cursor_move_end(widget);
|
2015-05-12 15:15:25 -07:00
|
|
|
else if (!strcmp(ev->key, "Prior"))
|
|
|
|
_elm_code_widget_cursor_move_pageup(widget);
|
|
|
|
else if (!strcmp(ev->key, "Next"))
|
|
|
|
_elm_code_widget_cursor_move_pagedown(widget);
|
2015-02-28 06:20:32 -08:00
|
|
|
|
|
|
|
else if (!strcmp(ev->key, "KP_Enter") || !strcmp(ev->key, "Return"))
|
|
|
|
_elm_code_widget_newline(widget);
|
2015-03-08 00:44:26 -08:00
|
|
|
else if (!strcmp(ev->key, "BackSpace"))
|
|
|
|
_elm_code_widget_backspace(widget);
|
|
|
|
else if (!strcmp(ev->key, "Delete"))
|
|
|
|
_elm_code_widget_delete(widget);
|
2016-02-08 16:32:16 -08:00
|
|
|
else if (!strcmp(ev->key, "Tab"))
|
|
|
|
_elm_code_widget_tab_at_cursor_insert(widget);
|
2015-02-28 06:20:32 -08:00
|
|
|
|
2016-02-21 09:51:56 -08:00
|
|
|
else if (!strcmp(ev->key, "Escape"))
|
|
|
|
DBG("TODO - Escape not yet captured");
|
|
|
|
|
2015-02-26 15:56:10 -08:00
|
|
|
else if (ev->string && strlen(ev->string) == 1)
|
|
|
|
_elm_code_widget_text_at_cursor_insert(widget, ev->string, 1);
|
2015-01-26 11:46:30 -08:00
|
|
|
else
|
2015-02-26 15:56:10 -08:00
|
|
|
INF("Unhandled key %s (%s) (%s)", ev->key, ev->keyname, ev->string);
|
2015-01-26 11:46:30 -08:00
|
|
|
}
|
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
static void
|
|
|
|
_elm_code_widget_focused_event_cb(void *data, Evas_Object *obj,
|
|
|
|
void *event_info EINA_UNUSED)
|
2015-01-26 11:46:30 -08:00
|
|
|
{
|
2015-01-27 06:34:11 -08:00
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-01-27 06:34:11 -08:00
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
pd->focussed = EINA_TRUE;
|
2016-12-09 15:25:42 -08:00
|
|
|
elm_layout_signal_emit(pd->cursor_rect, "elm,action,focus", "elm");
|
2015-01-26 11:46:30 -08:00
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
_elm_code_widget_update_focus_directions(widget);
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_refresh(obj, NULL);
|
2015-01-25 15:15:37 -08:00
|
|
|
}
|
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
static void
|
|
|
|
_elm_code_widget_unfocused_event_cb(void *data, Evas_Object *obj,
|
|
|
|
void *event_info EINA_UNUSED)
|
2015-01-25 09:18:21 -08:00
|
|
|
{
|
2015-02-14 10:49:51 -08:00
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
2015-01-25 09:18:21 -08:00
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
widget = (Elm_Code_Widget *)data;
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-01-25 09:18:21 -08:00
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
pd->focussed = EINA_FALSE;
|
2016-12-09 15:25:42 -08:00
|
|
|
elm_layout_signal_emit(pd->cursor_rect, "elm,action,unfocus", "elm");
|
|
|
|
|
|
|
|
_elm_code_widget_refresh(obj, NULL);
|
2015-01-25 09:18:21 -08:00
|
|
|
}
|
|
|
|
|
2016-05-16 03:59:35 -07:00
|
|
|
static void
|
|
|
|
_elm_code_widget_scroll_event_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget *widget;
|
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
|
|
|
|
|
|
|
_elm_code_widget_refresh(widget, NULL);
|
|
|
|
}
|
|
|
|
|
2015-03-08 00:44:26 -08:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_code_widget_elm_widget_event(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd EINA_UNUSED,
|
|
|
|
Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, void *event_info)
|
|
|
|
{
|
|
|
|
Evas_Event_Key_Down *ev = event_info;
|
|
|
|
|
|
|
|
if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
|
|
|
|
|
|
|
|
if (!strcmp(ev->key, "BackSpace"))
|
|
|
|
{
|
|
|
|
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-10 15:02:45 -08:00
|
|
|
EOLIAN static Eina_Bool
|
2015-02-11 11:13:48 -08:00
|
|
|
_elm_code_widget_elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED,
|
2015-02-10 15:02:45 -08:00
|
|
|
Elm_Code_Widget_Data *pd EINA_UNUSED)
|
|
|
|
{
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eina_Bool
|
2015-02-11 11:13:48 -08:00
|
|
|
_elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED,
|
2015-02-10 15:02:45 -08:00
|
|
|
Elm_Code_Widget_Data *pd EINA_UNUSED)
|
2015-01-23 14:55:13 -08:00
|
|
|
{
|
2015-02-11 14:01:37 -08:00
|
|
|
return EINA_TRUE;
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
static void
|
|
|
|
_elm_code_widget_setup_palette(Evas_Object *o)
|
|
|
|
{
|
|
|
|
double feint = 0.5;
|
|
|
|
|
|
|
|
// setup status colors
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT,
|
|
|
|
36, 36, 36, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CURRENT,
|
|
|
|
12, 12, 12, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_IGNORED,
|
|
|
|
36, 36, 36, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_NOTE,
|
2016-09-01 15:14:11 -07:00
|
|
|
221, 119, 17, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_WARNING,
|
2016-09-01 15:14:11 -07:00
|
|
|
221, 119, 17, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR,
|
2016-09-01 15:14:11 -07:00
|
|
|
204, 17, 17, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FATAL,
|
2016-09-01 15:14:11 -07:00
|
|
|
204, 17, 17, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED,
|
|
|
|
36, 96, 36, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED,
|
|
|
|
96, 36, 36, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED,
|
|
|
|
36, 36, 96, 255);
|
|
|
|
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_PASSED,
|
|
|
|
54, 96, 54, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED,
|
|
|
|
96, 54, 54, 255);
|
|
|
|
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_TODO,
|
2016-09-01 15:14:11 -07:00
|
|
|
51, 85, 187, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
|
|
|
|
// setup token colors
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT,
|
2016-08-30 15:22:41 -07:00
|
|
|
187, 187, 187, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT,
|
2016-11-27 16:08:43 -08:00
|
|
|
85, 85, 85, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_STRING,
|
2016-08-30 15:22:41 -07:00
|
|
|
255, 136, 119, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_NUMBER,
|
2016-08-30 15:22:41 -07:00
|
|
|
170, 153, 34, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_BRACE,
|
2016-08-30 15:22:41 -07:00
|
|
|
170, 102, 170, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_TYPE,
|
2016-08-30 15:22:41 -07:00
|
|
|
255, 255, 255, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CLASS,
|
2016-08-30 15:22:41 -07:00
|
|
|
255, 255, 255, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_FUNCTION,
|
|
|
|
255, 255, 255, 255);
|
2016-08-30 15:22:41 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PARAM,
|
|
|
|
187, 187, 187, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_KEYWORD,
|
2016-08-30 15:22:41 -07:00
|
|
|
68, 136, 204, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PREPROCESSOR,
|
2016-08-30 15:22:41 -07:00
|
|
|
102, 255, 85, 255);
|
2016-03-29 19:58:39 -07:00
|
|
|
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED,
|
|
|
|
54, 255, 54, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_REMOVED,
|
|
|
|
255, 54, 54, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED,
|
|
|
|
54, 54, 255, 255);
|
|
|
|
|
|
|
|
// other styles that the widget uses
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_SELECTION,
|
|
|
|
51, 153, 255, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_BG,
|
|
|
|
75, 75, 75, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG,
|
|
|
|
139, 139, 139, 255);
|
|
|
|
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_WHITESPACE,
|
|
|
|
101 * feint, 101 * feint, 101 * feint, 255 * feint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_code_widget_ensure_n_grid_rows(Elm_Code_Widget *widget, int rows)
|
|
|
|
{
|
|
|
|
Evas_Object *grid;
|
|
|
|
int existing, i;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-03-29 19:58:39 -07:00
|
|
|
existing = eina_list_count(pd->grids);
|
|
|
|
|
|
|
|
// trim unneeded rows in our rendering
|
|
|
|
if (rows < existing)
|
|
|
|
{
|
|
|
|
for (i = existing - rows; i > 0; i--)
|
|
|
|
{
|
|
|
|
grid = eina_list_data_get(eina_list_last(pd->grids));
|
|
|
|
evas_object_hide(grid);
|
|
|
|
elm_box_unpack(pd->gridbox, grid);
|
|
|
|
pd->grids = eina_list_remove_list(pd->grids, eina_list_last(pd->grids));
|
|
|
|
}
|
|
|
|
rows = existing;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rows == existing)
|
|
|
|
return;
|
|
|
|
|
2016-04-08 17:48:15 -07:00
|
|
|
for (i = existing; i < rows; i++)
|
2016-03-29 19:58:39 -07:00
|
|
|
{
|
|
|
|
grid = evas_object_textgrid_add(pd->gridbox);
|
|
|
|
evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, 0.0);
|
|
|
|
evas_object_show(grid);
|
|
|
|
_elm_code_widget_setup_palette(grid);
|
|
|
|
|
|
|
|
elm_box_pack_end(pd->gridbox, grid);
|
|
|
|
pd->grids = eina_list_append(pd->grids, grid);
|
|
|
|
|
|
|
|
evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_DOWN, _elm_code_widget_mouse_down_cb, widget);
|
|
|
|
evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_MOVE, _elm_code_widget_mouse_move_cb, widget);
|
|
|
|
evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_mouse_up_cb, widget);
|
|
|
|
|
|
|
|
evas_object_textgrid_font_set(grid, pd->font_name, pd->font_size * elm_config_scale_get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 03:28:11 -07:00
|
|
|
_elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline)
|
2016-03-29 19:58:39 -07:00
|
|
|
{
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
Eina_List *item;
|
|
|
|
Evas_Object *grid;
|
|
|
|
Evas_Coord ww, wh, old_width, old_height;
|
|
|
|
int w, h, cw, ch, gutter;
|
|
|
|
unsigned int line_width;
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-03-29 19:58:39 -07:00
|
|
|
gutter = elm_obj_code_widget_text_left_gutter_width_get(widget);
|
|
|
|
|
|
|
|
if (!pd->code)
|
|
|
|
return;
|
|
|
|
|
|
|
|
evas_object_geometry_get(widget, NULL, NULL, &ww, &wh);
|
|
|
|
|
|
|
|
old_width = ww;
|
|
|
|
old_height = wh;
|
|
|
|
w = 0;
|
|
|
|
h = elm_code_file_lines_get(pd->code->file);
|
2016-05-16 03:28:11 -07:00
|
|
|
|
|
|
|
if (newline)
|
2016-03-29 19:58:39 -07:00
|
|
|
{
|
2016-05-16 03:28:11 -07:00
|
|
|
line = eina_list_data_get(pd->code->file->lines);
|
|
|
|
if (line)
|
|
|
|
{
|
|
|
|
line_width = elm_code_widget_line_text_column_width_get(widget, newline);
|
|
|
|
w = (int) line_width + gutter + 1;
|
|
|
|
}
|
2016-03-29 19:58:39 -07:00
|
|
|
line_width = elm_code_widget_line_text_column_width_get(widget, line);
|
|
|
|
if ((int) line_width + gutter + 1 > w)
|
2016-05-16 03:52:35 -07:00
|
|
|
{
|
|
|
|
w = (int) line_width + gutter + 1;
|
|
|
|
}
|
2016-03-29 19:58:39 -07:00
|
|
|
}
|
2016-05-16 03:28:11 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(pd->code->file->lines, item, line)
|
|
|
|
{
|
|
|
|
line_width = elm_code_widget_line_text_column_width_get(widget, line);
|
|
|
|
if ((int) line_width + gutter + 1 > w)
|
|
|
|
w = (int) line_width + gutter + 1;
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 19:58:39 -07:00
|
|
|
|
|
|
|
_elm_code_widget_ensure_n_grid_rows(widget, h);
|
|
|
|
_elm_code_widget_cell_size_get(widget, &cw, &ch);
|
|
|
|
if (w*cw > ww)
|
|
|
|
ww = w*cw;
|
|
|
|
if (h*ch > wh)
|
|
|
|
wh = h*ch;
|
|
|
|
pd->col_count = ww/cw + 1;
|
|
|
|
|
2016-05-17 15:20:35 -07:00
|
|
|
EINA_LIST_FOREACH(pd->grids, item, grid)
|
2016-03-29 19:58:39 -07:00
|
|
|
{
|
|
|
|
evas_object_textgrid_size_set(grid, pd->col_count, 1);
|
|
|
|
evas_object_size_hint_min_set(grid, w*cw, ch);
|
|
|
|
}
|
|
|
|
|
2016-05-16 07:15:21 -07:00
|
|
|
if (!newline) return;
|
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0)
|
|
|
|
_elm_code_widget_scroll_by(widget,
|
|
|
|
(pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0,
|
|
|
|
(pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0);
|
|
|
|
}
|
|
|
|
|
2015-02-21 09:30:17 -08:00
|
|
|
EOAPI void
|
|
|
|
_elm_code_widget_line_refresh(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
_elm_code_widget_fill_line(obj, line);
|
|
|
|
}
|
|
|
|
|
2015-04-02 14:48:23 -07:00
|
|
|
EOAPI Eina_Bool
|
2016-03-29 19:58:39 -07:00
|
|
|
_elm_code_widget_line_visible_get(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code_Line *line)
|
2015-04-02 14:48:23 -07:00
|
|
|
{
|
|
|
|
Evas_Coord cellh, viewy, viewh;
|
|
|
|
|
|
|
|
elm_scroller_region_get(pd->scroller, NULL, &viewy, NULL, &viewh);
|
2016-03-29 19:58:39 -07:00
|
|
|
_elm_code_widget_cell_size_get(obj, NULL, &cellh);
|
2015-04-02 14:48:23 -07:00
|
|
|
|
|
|
|
if (((int)line->number - 1) * cellh > viewy + viewh || (int)line->number * cellh < viewy)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
return EINA_TRUE;;
|
|
|
|
}
|
|
|
|
|
2015-05-12 15:15:25 -07:00
|
|
|
EOAPI unsigned int
|
2016-03-29 19:58:39 -07:00
|
|
|
_elm_code_widget_lines_visible_get(Eo *obj, Elm_Code_Widget_Data *pd)
|
2015-05-12 15:15:25 -07:00
|
|
|
{
|
|
|
|
Evas_Coord cellh, viewh;
|
|
|
|
|
|
|
|
elm_scroller_region_get(pd->scroller, NULL, NULL, NULL, &viewh);
|
2016-03-29 19:58:39 -07:00
|
|
|
_elm_code_widget_cell_size_get(obj, NULL, &cellh);
|
2015-05-12 15:15:25 -07:00
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
return viewh / cellh + 1;
|
2015-05-12 15:15:25 -07:00
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
EOLIAN static void
|
2015-05-31 13:18:18 -07:00
|
|
|
_elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd,
|
|
|
|
const char *name, Evas_Font_Size size)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
2016-03-29 19:58:39 -07:00
|
|
|
Eina_List *item;
|
|
|
|
Evas_Object *grid;
|
|
|
|
|
2015-05-31 13:18:18 -07:00
|
|
|
const char *face = name;
|
2015-05-24 10:39:57 -07:00
|
|
|
if (!face)
|
|
|
|
face = "Mono";
|
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
EINA_LIST_FOREACH(pd->grids, item, grid)
|
|
|
|
{
|
|
|
|
evas_object_textgrid_font_set(grid, face, size * elm_config_scale_get());
|
|
|
|
}
|
2015-05-24 10:39:57 -07:00
|
|
|
if (pd->font_name)
|
2015-05-31 13:18:18 -07:00
|
|
|
eina_stringshare_del((char *)pd->font_name);
|
|
|
|
pd->font_name = eina_stringshare_add(face);
|
2015-05-24 10:39:57 -07:00
|
|
|
pd->font_size = size;
|
2015-01-23 14:55:13 -08:00
|
|
|
}
|
|
|
|
|
2015-05-24 10:39:57 -07:00
|
|
|
EOLIAN static void
|
2015-05-31 13:18:18 -07:00
|
|
|
_elm_code_widget_font_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd,
|
|
|
|
const char **name, Evas_Font_Size *size)
|
2015-01-23 14:55:13 -08:00
|
|
|
{
|
2015-05-24 10:39:57 -07:00
|
|
|
if (name)
|
|
|
|
*name = strdup((const char *)pd->font_name);
|
|
|
|
if (size)
|
|
|
|
*size = pd->font_size;
|
2015-01-23 14:55:13 -08:00
|
|
|
}
|
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
EOLIAN static unsigned int
|
|
|
|
_elm_code_widget_columns_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
|
|
|
{
|
|
|
|
return pd->col_count;
|
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
EOLIAN static void
|
2015-02-28 05:22:38 -08:00
|
|
|
_elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code *code)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
2015-02-28 05:22:38 -08:00
|
|
|
EO_CONSTRUCTOR_CHECK_RETURN(obj);
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
pd->code = code;
|
|
|
|
|
2015-01-26 11:05:34 -08:00
|
|
|
code->widgets = eina_list_append(code->widgets, obj);
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Elm_Code *
|
2015-01-26 11:05:34 -08:00
|
|
|
_elm_code_widget_code_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
|
|
|
return pd->code;
|
|
|
|
}
|
|
|
|
|
2015-01-28 06:16:46 -08:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_code_widget_gravity_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, double x, double y)
|
|
|
|
{
|
|
|
|
pd->gravity_x = x;
|
|
|
|
pd->gravity_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_elm_code_widget_gravity_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, double *x, double *y)
|
|
|
|
{
|
|
|
|
*x = pd->gravity_x;
|
|
|
|
*y = pd->gravity_y;
|
|
|
|
}
|
|
|
|
|
2015-05-30 02:26:51 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_code_widget_policy_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
|
|
|
|
{
|
|
|
|
elm_scroller_policy_set(pd->scroller, policy_h, policy_v);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_elm_code_widget_policy_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
|
|
|
|
{
|
|
|
|
elm_scroller_policy_get(pd->scroller, policy_h, policy_v);
|
|
|
|
}
|
|
|
|
|
2015-03-29 12:12:28 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_code_widget_tabstop_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, unsigned int tabstop)
|
|
|
|
{
|
|
|
|
pd->tabstop = tabstop;
|
|
|
|
_elm_code_widget_fill(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static unsigned int
|
|
|
|
_elm_code_widget_tabstop_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
|
|
|
{
|
|
|
|
return pd->tabstop;
|
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
EOLIAN static void
|
2015-01-27 06:34:11 -08:00
|
|
|
_elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
|
|
|
pd->editable = editable;
|
2015-01-27 06:34:11 -08:00
|
|
|
elm_object_focus_allow_set(obj, editable);
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eina_Bool
|
2015-01-26 11:05:34 -08:00
|
|
|
_elm_code_widget_editable_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
|
|
|
return pd->editable;
|
|
|
|
}
|
|
|
|
|
2015-01-28 16:36:28 -08:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_code_widget_line_numbers_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Eina_Bool line_numbers)
|
|
|
|
{
|
|
|
|
pd->show_line_numbers = line_numbers;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_code_widget_line_numbers_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
|
|
|
{
|
|
|
|
return pd->show_line_numbers;
|
|
|
|
}
|
|
|
|
|
2015-02-23 13:52:49 -08:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_code_widget_line_width_marker_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col)
|
|
|
|
{
|
|
|
|
pd->line_width_marker = col;
|
|
|
|
_elm_code_widget_fill(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static unsigned int
|
|
|
|
_elm_code_widget_line_width_marker_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
|
|
|
{
|
|
|
|
return pd->line_width_marker;
|
|
|
|
}
|
|
|
|
|
2015-02-28 06:59:42 -08:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_code_widget_show_whitespace_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool show)
|
|
|
|
{
|
|
|
|
pd->show_whitespace = show;
|
|
|
|
_elm_code_widget_fill(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_code_widget_show_whitespace_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
|
|
|
{
|
|
|
|
return pd->show_whitespace;
|
|
|
|
}
|
|
|
|
|
2016-02-08 16:32:16 -08:00
|
|
|
EOLIAN static void
|
2016-02-25 07:50:34 -08:00
|
|
|
_elm_code_widget_tab_inserts_spaces_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd,
|
|
|
|
Eina_Bool spaces)
|
2016-02-08 16:32:16 -08:00
|
|
|
{
|
|
|
|
pd->tab_inserts_spaces = spaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_code_widget_tab_inserts_spaces_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
|
|
|
{
|
|
|
|
return pd->tab_inserts_spaces;
|
|
|
|
}
|
|
|
|
|
2015-02-19 13:16:18 -08:00
|
|
|
EOLIAN static void
|
2016-12-12 00:29:51 -08:00
|
|
|
_elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int row, unsigned int col)
|
2015-02-19 13:16:18 -08:00
|
|
|
{
|
2016-12-12 00:29:51 -08:00
|
|
|
_elm_code_widget_cursor_move(obj, pd, row, col, EINA_FALSE);
|
2015-02-19 13:16:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
2016-12-12 00:29:51 -08:00
|
|
|
_elm_code_widget_cursor_position_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, unsigned int *row, unsigned int *col)
|
2015-02-19 13:16:18 -08:00
|
|
|
{
|
2016-12-12 00:29:51 -08:00
|
|
|
*row = pd->cursor_line;
|
2015-02-19 13:16:18 -08:00
|
|
|
*col = pd->cursor_col;
|
|
|
|
}
|
|
|
|
|
2015-01-24 14:07:00 -08:00
|
|
|
EOLIAN static void
|
2016-06-17 01:26:08 -07:00
|
|
|
_elm_code_widget_efl_canvas_group_group_add(Eo *obj, Elm_Code_Widget_Data *pd)
|
2015-01-24 14:07:00 -08:00
|
|
|
{
|
2016-03-29 19:58:39 -07:00
|
|
|
Evas_Object *background, *gridrows, *scroller;
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_canvas_group_add(efl_super(obj, ELM_CODE_WIDGET_CLASS));
|
2015-01-25 15:15:37 -08:00
|
|
|
elm_object_focus_allow_set(obj, EINA_TRUE);
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2016-12-09 15:25:42 -08:00
|
|
|
if (!elm_layout_theme_set(obj, "code", "layout", elm_widget_style_get(obj)))
|
2016-06-22 20:57:46 -07:00
|
|
|
CRI("Failed to set layout!");
|
2015-02-14 10:49:51 -08:00
|
|
|
|
2015-01-26 08:28:04 -08:00
|
|
|
scroller = elm_scroller_add(obj);
|
|
|
|
evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(scroller);
|
2015-02-14 10:49:51 -08:00
|
|
|
elm_layout_content_set(obj, "elm.swallow.content", scroller);
|
|
|
|
elm_object_focus_allow_set(scroller, EINA_FALSE);
|
2015-01-28 06:16:46 -08:00
|
|
|
pd->scroller = scroller;
|
2015-01-26 08:28:04 -08:00
|
|
|
|
2016-03-29 19:58:39 -07:00
|
|
|
background = elm_bg_add(scroller);
|
|
|
|
evas_object_color_set(background, 145, 145, 145, 255);
|
|
|
|
evas_object_size_hint_weight_set(background, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(background, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(background);
|
|
|
|
elm_object_part_content_set(scroller, "elm.swallow.background", background);
|
|
|
|
|
|
|
|
gridrows = elm_box_add(scroller);
|
|
|
|
evas_object_size_hint_weight_set(gridrows, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
evas_object_size_hint_align_set(gridrows, EVAS_HINT_FILL, 0.0);
|
|
|
|
elm_object_content_set(scroller, gridrows);
|
|
|
|
pd->gridbox = gridrows;
|
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj);
|
2015-01-26 11:05:34 -08:00
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj);
|
2015-01-24 14:07:00 -08:00
|
|
|
|
2015-02-14 10:49:51 -08:00
|
|
|
evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj);
|
|
|
|
evas_object_smart_callback_add(obj, "unfocused", _elm_code_widget_unfocused_event_cb, obj);
|
2016-05-16 03:59:35 -07:00
|
|
|
evas_object_smart_callback_add(scroller, "scroll", _elm_code_widget_scroll_event_cb, obj);
|
2015-01-26 11:46:30 -08:00
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(obj, &ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_widget_line_cb, obj);
|
|
|
|
efl_event_callback_add(obj, &ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj);
|
|
|
|
efl_event_callback_add(obj, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj);
|
|
|
|
efl_event_callback_add(obj, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj);
|
2015-01-24 14:07:00 -08:00
|
|
|
}
|
|
|
|
|
2015-04-04 11:01:05 -07:00
|
|
|
#include "elm_code_widget_text.c"
|
2016-02-21 10:11:33 -08:00
|
|
|
#include "elm_code_widget_undo.c"
|
2015-01-26 11:05:34 -08:00
|
|
|
#include "elm_code_widget.eo.c"
|