2015-01-28 16:36:28 -08:00
|
|
|
#ifdef HAVE_CONFIG
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Elm_Code.h"
|
|
|
|
|
2015-04-04 10:17:01 -07:00
|
|
|
#include "elm_code_widget_private.h"
|
2015-01-28 16:36:28 -08:00
|
|
|
|
2015-04-04 11:01:05 -07:00
|
|
|
static int
|
|
|
|
_elm_code_widget_text_line_number_width_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
|
2015-01-28 16:36:28 -08:00
|
|
|
{
|
|
|
|
int max;
|
|
|
|
|
|
|
|
max = elm_code_file_lines_get(pd->code->file);
|
|
|
|
if (max < 1)
|
|
|
|
max = 1;
|
|
|
|
|
2015-01-28 16:50:07 -08:00
|
|
|
return floor(log10(max)) + 1;
|
2015-01-28 16:36:28 -08:00
|
|
|
}
|
|
|
|
|
2015-04-04 11:01:05 -07:00
|
|
|
static int
|
|
|
|
_elm_code_widget_text_left_gutter_width_get(Eo *obj, Elm_Code_Widget_Data *pd)
|
2015-01-28 16:36:28 -08:00
|
|
|
{
|
2015-04-04 11:01:05 -07:00
|
|
|
Elm_Code_Widget *widget;
|
2015-01-28 16:36:28 -08:00
|
|
|
int width = 1; // the status icon, for now
|
|
|
|
|
2015-04-04 11:01:05 -07:00
|
|
|
widget = obj;
|
2015-02-03 05:55:20 -08:00
|
|
|
if (!widget)
|
|
|
|
return width;
|
|
|
|
|
2015-01-28 16:36:28 -08:00
|
|
|
if (pd->show_line_numbers)
|
2015-04-04 11:01:05 -07:00
|
|
|
width += _elm_code_widget_text_line_number_width_get(widget, pd);
|
2015-01-28 16:36:28 -08:00
|
|
|
|
|
|
|
return width;
|
|
|
|
}
|
2015-06-03 13:29:31 -07:00
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
_elm_code_widget_line_text_column_width_to_position(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line, unsigned int position)
|
|
|
|
{
|
|
|
|
Eina_Unicode unicode;
|
|
|
|
unsigned int count = 1;
|
|
|
|
int index = 0;
|
|
|
|
const char *chars;
|
|
|
|
|
|
|
|
if (line->length == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (line->modified)
|
|
|
|
chars = line->modified;
|
|
|
|
else
|
|
|
|
chars = line->content;
|
|
|
|
if (position > line->length)
|
|
|
|
position = line->length;
|
|
|
|
|
|
|
|
while ((unsigned int) index < position)
|
|
|
|
{
|
|
|
|
unicode = eina_unicode_utf8_next_get(chars, &index);
|
|
|
|
if (unicode == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (unicode == '\t')
|
|
|
|
count += elm_code_text_tabwidth_at_position(count, pd->tabstop);
|
|
|
|
else
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
_elm_code_widget_line_text_column_width_get(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
return _elm_code_widget_line_text_column_width_to_position(obj, pd, line, line->length) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
_elm_code_widget_line_text_position_for_column_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line, unsigned int column)
|
|
|
|
{
|
|
|
|
Eina_Unicode unicode;
|
|
|
|
unsigned int count = 1;
|
|
|
|
int index = 0;
|
|
|
|
const char *chars;
|
|
|
|
|
|
|
|
if (line->length == 0 || column == 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (line->modified)
|
|
|
|
chars = line->modified;
|
|
|
|
else
|
|
|
|
chars = line->content;
|
|
|
|
|
|
|
|
while ((unsigned int) count < column && index < (int) line->length)
|
|
|
|
{
|
|
|
|
unicode = eina_unicode_utf8_next_get(chars, &index);
|
|
|
|
|
|
|
|
if (unicode == 0)
|
|
|
|
return line->length;
|
|
|
|
else if (unicode == '\t')
|
|
|
|
count += elm_code_text_tabwidth_at_position(count, pd->tabstop);
|
|
|
|
else
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (unsigned int) index;
|
|
|
|
}
|