2014-09-30 07:56:16 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Enventor.h>
|
|
|
|
#include "enventor_private.h"
|
2014-08-08 22:29:51 -07:00
|
|
|
#include "template_code.h"
|
2014-08-07 06:32:27 -07:00
|
|
|
|
|
|
|
const char *NAME_SEED = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
const int NAME_SEED_LEN = 52;
|
|
|
|
|
2014-09-30 07:56:16 -07:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Internal method implementation */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2014-08-13 06:14:09 -07:00
|
|
|
static void
|
2016-03-16 22:37:32 -07:00
|
|
|
template_random_string_create(char *paragh, char *buf, int size)
|
2014-08-07 06:32:27 -07:00
|
|
|
{
|
2016-03-16 22:37:32 -07:00
|
|
|
int i, paragh_len = 0;
|
|
|
|
|
|
|
|
if (paragh)
|
|
|
|
paragh_len = strlen(paragh);
|
|
|
|
|
|
|
|
if (paragh_len > 0)
|
|
|
|
{
|
|
|
|
memcpy(buf, paragh, paragh_len);
|
|
|
|
buf[paragh_len++] = '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
buf[paragh_len + i] = NAME_SEED[(rand() % NAME_SEED_LEN)];
|
|
|
|
buf[paragh_len + i] = '\0';
|
2014-08-07 06:32:27 -07:00
|
|
|
}
|
2014-08-08 22:29:51 -07:00
|
|
|
|
2014-08-10 21:48:01 -07:00
|
|
|
static void
|
|
|
|
image_description_add(edit_data *ed)
|
2014-08-08 22:29:51 -07:00
|
|
|
{
|
2014-08-10 21:48:01 -07:00
|
|
|
int cursor_pos;
|
|
|
|
Evas_Object * edit_entry = edit_entry_get(ed);
|
2014-08-08 22:29:51 -07:00
|
|
|
|
2014-08-10 21:48:01 -07:00
|
|
|
Evas_Coord cursor_pos_to_restore = elm_entry_cursor_pos_get(edit_entry_get(ed));
|
2014-08-08 22:29:51 -07:00
|
|
|
|
2014-08-10 21:48:01 -07:00
|
|
|
Eina_Bool images_block = parser_images_pos_get(edit_entry, &cursor_pos);
|
|
|
|
if (cursor_pos == -1) return;
|
2015-02-12 06:01:37 -08:00
|
|
|
|
|
|
|
elm_entry_cursor_pos_set(edit_entry, cursor_pos);
|
|
|
|
elm_entry_cursor_line_begin_set(edit_entry);
|
|
|
|
int cursor_pos1 = elm_entry_cursor_pos_get(edit_entry);
|
|
|
|
int cursor_pos2;
|
2014-08-10 21:48:01 -07:00
|
|
|
if (images_block)
|
2015-02-12 06:01:37 -08:00
|
|
|
{
|
2016-04-01 00:33:34 -07:00
|
|
|
// the first line of TEMPLATE_IMG to check it is already exist
|
|
|
|
const char *template_image_str = TEMPLATE_IMG[0];
|
|
|
|
if (parser_is_image_name(edit_entry, template_image_str))
|
|
|
|
cursor_pos2 = cursor_pos1;
|
|
|
|
else
|
|
|
|
{
|
2016-06-04 21:09:52 -07:00
|
|
|
template_insert(ed, NULL, 0);
|
2016-04-01 00:33:34 -07:00
|
|
|
cursor_pos2 = elm_entry_cursor_pos_get(edit_entry);
|
|
|
|
}
|
2015-02-12 06:01:37 -08:00
|
|
|
}
|
2014-08-10 21:48:01 -07:00
|
|
|
else
|
2015-02-12 06:01:37 -08:00
|
|
|
{
|
2015-12-29 18:36:09 -08:00
|
|
|
int space = edit_cur_indent_depth_get(ed);
|
|
|
|
|
|
|
|
//Alloc Empty spaces
|
|
|
|
char *p = alloca(space + 1);
|
|
|
|
memset(p, ' ', space);
|
|
|
|
p[space] = '\0';
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < (TEMPLATE_IMG_BLOCK_LINE_CNT - 1); i++)
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_IMG_BLOCK[i]);
|
|
|
|
}
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_IMG_BLOCK[i]);
|
|
|
|
|
2015-02-12 06:01:37 -08:00
|
|
|
edit_line_increase(ed, TEMPLATE_IMG_BLOCK_LINE_CNT);
|
|
|
|
cursor_pos2 = elm_entry_cursor_pos_get(edit_entry);
|
|
|
|
edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2);
|
|
|
|
}
|
|
|
|
cursor_pos_to_restore += (cursor_pos2 - cursor_pos1);
|
2014-08-10 21:48:01 -07:00
|
|
|
elm_entry_cursor_pos_set(edit_entry, cursor_pos_to_restore);
|
|
|
|
}
|
|
|
|
|
2014-08-30 02:20:38 -07:00
|
|
|
static void
|
|
|
|
textblock_style_add(edit_data *ed, const char *style_name)
|
|
|
|
{
|
|
|
|
int cursor_pos;
|
|
|
|
Evas_Object * edit_entry = edit_entry_get(ed);
|
|
|
|
Eina_Bool styles_block = parser_styles_pos_get(edit_entry, &cursor_pos);
|
|
|
|
if (cursor_pos == -1) return;
|
|
|
|
int cursor_pos_to_restore = elm_entry_cursor_pos_get(edit_entry_get(ed));
|
|
|
|
|
|
|
|
elm_entry_cursor_pos_set(edit_entry, cursor_pos);
|
|
|
|
elm_entry_cursor_line_begin_set(edit_entry);
|
|
|
|
int cursor_pos1 = elm_entry_cursor_pos_get(edit_entry);
|
|
|
|
|
2015-12-29 21:35:25 -08:00
|
|
|
int space = edit_cur_indent_depth_get(ed);
|
|
|
|
if (styles_block)
|
|
|
|
space -= TAB_SPACE;
|
|
|
|
|
|
|
|
//Alloc Empty spaces
|
|
|
|
char *p = alloca(space + 1);
|
|
|
|
memset(p, ' ', space);
|
|
|
|
p[space] = '\0';
|
|
|
|
|
2014-08-30 02:20:38 -07:00
|
|
|
if (!styles_block)
|
2015-12-29 21:35:25 -08:00
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[0]);
|
|
|
|
}
|
2014-08-30 02:20:38 -07:00
|
|
|
|
|
|
|
int buf_len = strlen(TEMPLATE_TEXTBLOCK_STYLE_BLOCK[1]) + strlen(style_name);
|
|
|
|
char *buf = malloc(buf_len);
|
|
|
|
snprintf(buf, buf_len, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[1], style_name);
|
2015-12-29 21:35:25 -08:00
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2014-08-30 02:20:38 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
2015-12-29 21:35:25 -08:00
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[2]);
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[3]);
|
2014-08-30 02:20:38 -07:00
|
|
|
free(buf);
|
|
|
|
|
|
|
|
if (!styles_block)
|
2015-12-29 21:35:25 -08:00
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[4]);
|
|
|
|
}
|
2014-08-30 02:20:38 -07:00
|
|
|
|
|
|
|
int line_inc = TEMPLATE_TEXTBLOCK_STYLE_LINE_CNT;
|
2016-05-30 22:12:21 -07:00
|
|
|
if (styles_block) line_inc -= 2;
|
2014-08-30 02:20:38 -07:00
|
|
|
edit_line_increase(ed, line_inc);
|
|
|
|
|
|
|
|
int cursor_pos2 = elm_entry_cursor_pos_get(edit_entry);
|
|
|
|
edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2);
|
|
|
|
|
2015-02-12 06:01:37 -08:00
|
|
|
cursor_pos_to_restore += (cursor_pos2 - cursor_pos1);
|
2014-08-30 02:20:38 -07:00
|
|
|
elm_entry_cursor_pos_set(edit_entry, cursor_pos_to_restore);
|
|
|
|
}
|
|
|
|
|
2014-08-10 21:48:01 -07:00
|
|
|
static int
|
2016-07-03 21:59:39 -07:00
|
|
|
template_part_insert_cursor_pos_set(Evas_Object *edit_entry,
|
2014-11-11 23:44:19 -08:00
|
|
|
Enventor_Template_Insert_Type insert_type,
|
2014-08-10 21:48:01 -07:00
|
|
|
const Eina_Stringshare *group_name)
|
|
|
|
{
|
|
|
|
int cursor_pos = -1;
|
2014-11-11 23:44:19 -08:00
|
|
|
if (insert_type == ENVENTOR_TEMPLATE_INSERT_LIVE_EDIT)
|
2014-08-10 21:48:01 -07:00
|
|
|
{
|
|
|
|
cursor_pos = parser_end_of_parts_block_pos_get(edit_entry, group_name);
|
|
|
|
if (cursor_pos != -1)
|
|
|
|
elm_entry_cursor_pos_set(edit_entry, cursor_pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cursor_pos = elm_entry_cursor_pos_get(edit_entry);
|
|
|
|
}
|
|
|
|
elm_entry_cursor_line_begin_set(edit_entry);
|
|
|
|
return cursor_pos;
|
|
|
|
}
|
|
|
|
|
2016-03-03 23:21:14 -08:00
|
|
|
static void
|
|
|
|
select_random_name(Evas_Object *entry, const char* first_line,
|
|
|
|
const char* random_name, int space)
|
|
|
|
{
|
|
|
|
char *matched = strstr(first_line, random_name);
|
|
|
|
if (matched)
|
|
|
|
{
|
|
|
|
int random_name_pos = matched - first_line;
|
|
|
|
random_name_pos += space;
|
|
|
|
elm_entry_cursor_line_begin_set(entry);
|
|
|
|
int line_start = elm_entry_cursor_pos_get(entry);
|
|
|
|
int start = line_start + random_name_pos;
|
|
|
|
int end = start + strlen(random_name);
|
|
|
|
elm_entry_select_region_set(entry, start, end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-13 21:58:06 -07:00
|
|
|
static const char *
|
2016-07-19 04:14:38 -07:00
|
|
|
_posix_fp(double fp, double fp2, const char *fmt)
|
2016-07-13 21:58:06 -07:00
|
|
|
{
|
|
|
|
static Eina_Strbuf *strbuf = NULL;
|
|
|
|
static char storage[16];
|
|
|
|
struct lconv *lconv;
|
|
|
|
|
|
|
|
if (EINA_UNLIKELY(strbuf == NULL))
|
|
|
|
{
|
|
|
|
strbuf = eina_strbuf_manage_new_length(storage, sizeof(storage));
|
|
|
|
if (EINA_UNLIKELY(!strbuf))
|
|
|
|
{
|
|
|
|
storage[0] = '\0';
|
|
|
|
return storage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lconv = localeconv();
|
|
|
|
|
|
|
|
eina_strbuf_reset(strbuf);
|
|
|
|
eina_strbuf_append_printf(strbuf, fmt, fp);
|
2016-07-19 04:14:38 -07:00
|
|
|
eina_strbuf_append(strbuf, " ");
|
|
|
|
eina_strbuf_append_printf(strbuf, fmt, fp2);
|
|
|
|
eina_strbuf_replace_all(strbuf, lconv->decimal_point, ".");
|
2016-07-13 21:58:06 -07:00
|
|
|
|
|
|
|
return eina_strbuf_string_get(strbuf);
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:56:16 -07:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Externally accessible calls */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
Eina_Bool
|
2014-08-13 07:12:51 -07:00
|
|
|
template_part_insert(edit_data *ed, Edje_Part_Type part_type,
|
2016-05-11 05:57:51 -07:00
|
|
|
Enventor_Template_Insert_Type insert_type,
|
|
|
|
Eina_Bool fixed_w, Eina_Bool fixed_h,
|
|
|
|
char *rel1_x_to, char *rel1_y_to,
|
|
|
|
char *rel2_x_to, char *rel2_y_to,
|
|
|
|
float align_x, float align_y, int min_w, int min_h,
|
|
|
|
float rel1_x, float rel1_y, float rel2_x, float rel2_y,
|
2014-09-30 07:56:16 -07:00
|
|
|
const Eina_Stringshare *group_name, char *syntax, size_t n)
|
2014-08-10 21:48:01 -07:00
|
|
|
{
|
|
|
|
Evas_Object *edit_entry = edit_entry_get(ed);
|
2014-11-11 23:44:19 -08:00
|
|
|
|
|
|
|
if (insert_type == ENVENTOR_TEMPLATE_INSERT_LIVE_EDIT)
|
|
|
|
group_name = view_group_name_get(VIEW_DATA);
|
|
|
|
|
2016-07-03 21:59:39 -07:00
|
|
|
int cursor_pos = template_part_insert_cursor_pos_set(edit_entry, insert_type,
|
2014-08-13 06:14:09 -07:00
|
|
|
group_name);
|
2014-09-30 07:56:16 -07:00
|
|
|
if (cursor_pos == -1) return EINA_FALSE;
|
|
|
|
|
2014-08-10 21:48:01 -07:00
|
|
|
int cursor_pos1 = elm_entry_cursor_pos_get(edit_entry);
|
2014-08-08 22:29:51 -07:00
|
|
|
int space = edit_cur_indent_depth_get(ed);
|
|
|
|
|
|
|
|
//Alloc Empty spaces
|
|
|
|
char *p = alloca(space + 1);
|
|
|
|
memset(p, ' ', space);
|
|
|
|
p[space] = '\0';
|
|
|
|
|
2015-06-24 04:27:25 -07:00
|
|
|
int line_cnt = 0;
|
|
|
|
char **t = NULL;
|
2014-08-08 22:29:51 -07:00
|
|
|
char buf[64];
|
2016-06-01 19:57:30 -07:00
|
|
|
char type_name[20] = {0, };
|
2014-08-08 22:29:51 -07:00
|
|
|
|
2014-08-13 07:12:51 -07:00
|
|
|
switch(part_type)
|
2014-08-08 22:29:51 -07:00
|
|
|
{
|
|
|
|
case EDJE_PART_TYPE_RECTANGLE:
|
|
|
|
line_cnt = TEMPLATE_PART_RECT_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_PART_RECT;
|
2015-06-30 00:46:34 -07:00
|
|
|
strncpy(type_name, "rect\0", 5);
|
2014-08-08 22:29:51 -07:00
|
|
|
break;
|
|
|
|
case EDJE_PART_TYPE_TEXT:
|
|
|
|
line_cnt = TEMPLATE_PART_TEXT_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_PART_TEXT;
|
2015-06-30 00:46:34 -07:00
|
|
|
strncpy(type_name, "text\0", 5);
|
2014-08-08 22:29:51 -07:00
|
|
|
break;
|
|
|
|
case EDJE_PART_TYPE_SWALLOW:
|
|
|
|
line_cnt = TEMPLATE_PART_SWALLOW_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_PART_SWALLOW;
|
2015-06-30 00:46:34 -07:00
|
|
|
strncpy(type_name, "swallow\0", 8);
|
2014-08-08 22:29:51 -07:00
|
|
|
break;
|
|
|
|
case EDJE_PART_TYPE_TEXTBLOCK:
|
|
|
|
line_cnt = TEMPLATE_PART_TEXTBLOCK_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_PART_TEXTBLOCK;
|
2015-06-30 00:46:34 -07:00
|
|
|
strncpy(type_name, "textblock\0", 10);
|
2014-08-08 22:29:51 -07:00
|
|
|
break;
|
|
|
|
case EDJE_PART_TYPE_SPACER:
|
|
|
|
line_cnt = TEMPLATE_PART_SPACER_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_PART_SPACER;
|
2015-06-30 00:46:34 -07:00
|
|
|
strncpy(type_name, "spacer\0", 7);
|
2014-08-08 22:29:51 -07:00
|
|
|
break;
|
|
|
|
case EDJE_PART_TYPE_IMAGE:
|
|
|
|
case EDJE_PART_TYPE_NONE:
|
|
|
|
case EDJE_PART_TYPE_GRADIENT:
|
|
|
|
case EDJE_PART_TYPE_GROUP:
|
|
|
|
case EDJE_PART_TYPE_BOX:
|
|
|
|
case EDJE_PART_TYPE_TABLE:
|
|
|
|
case EDJE_PART_TYPE_EXTERNAL:
|
|
|
|
case EDJE_PART_TYPE_PROXY:
|
2015-02-27 00:25:45 -08:00
|
|
|
case EDJE_PART_TYPE_MESH_NODE:
|
|
|
|
case EDJE_PART_TYPE_LIGHT:
|
|
|
|
case EDJE_PART_TYPE_CAMERA:
|
2015-09-15 10:39:51 -07:00
|
|
|
case EDJE_PART_TYPE_SNAPSHOT:
|
2016-06-19 21:42:36 -07:00
|
|
|
case EDJE_PART_TYPE_VECTOR:
|
|
|
|
case EDJE_PART_TYPE_LAST:
|
|
|
|
line_cnt = TEMPLATE_PART_IMAGE_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_PART_IMAGE;
|
|
|
|
strncpy(type_name, "image\0", 6);
|
2015-02-27 00:25:45 -08:00
|
|
|
break;
|
2014-08-08 22:29:51 -07:00
|
|
|
}
|
|
|
|
|
2014-08-13 02:20:42 -07:00
|
|
|
//Insert first line of the part block with generated name.
|
2014-08-13 06:14:09 -07:00
|
|
|
char first_line[40];
|
2016-03-16 22:37:32 -07:00
|
|
|
char random_name[15];
|
|
|
|
template_random_string_create(type_name, random_name, 4);
|
2014-08-30 02:20:38 -07:00
|
|
|
|
2014-08-13 06:35:09 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2015-06-30 00:46:34 -07:00
|
|
|
snprintf(first_line, 40, "%s { \"%s\";<br/>", type_name, random_name);
|
2014-08-10 21:48:01 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, first_line);
|
2014-08-08 22:29:51 -07:00
|
|
|
|
2014-08-13 02:20:42 -07:00
|
|
|
//Insert part body
|
2014-08-08 22:29:51 -07:00
|
|
|
int i;
|
2014-08-11 19:31:06 -07:00
|
|
|
for (i = 0; i < line_cnt; i++)
|
2014-08-08 22:29:51 -07:00
|
|
|
{
|
2014-08-10 21:48:01 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
elm_entry_entry_insert(edit_entry, t[i]);
|
2014-08-08 22:29:51 -07:00
|
|
|
}
|
|
|
|
|
2014-08-30 02:20:38 -07:00
|
|
|
if (part_type == EDJE_PART_TYPE_TEXTBLOCK)
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
snprintf(buf, sizeof(buf), " text.style: \"%s\";<br/>",
|
|
|
|
random_name);
|
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
2016-05-30 22:12:21 -07:00
|
|
|
line_cnt++;
|
2014-08-30 02:20:38 -07:00
|
|
|
}
|
|
|
|
|
2016-05-11 05:57:51 -07:00
|
|
|
//Apply align values
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2016-07-19 04:14:38 -07:00
|
|
|
snprintf(buf, sizeof(buf), " align: %s;<br/>",
|
|
|
|
_posix_fp(align_x, align_y, "%.1f"));
|
2016-05-11 05:57:51 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
line_cnt++;
|
|
|
|
|
|
|
|
//Width is fixed or Height is fixed
|
2016-05-28 09:41:52 -07:00
|
|
|
if (fixed_w || fixed_h)
|
2016-05-11 05:57:51 -07:00
|
|
|
{
|
2016-05-16 07:30:25 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2016-05-28 09:41:52 -07:00
|
|
|
snprintf(buf, sizeof(buf), " fixed: %d %d;<br/>", fixed_w, fixed_h);
|
2016-05-16 07:30:25 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
snprintf(buf, sizeof(buf), " min: %d %d;<br/>", min_w, min_h);
|
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
line_cnt += 2;
|
2016-05-11 05:57:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//If there are some relative_to part then insert relative_to
|
|
|
|
if (rel1_x_to)
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
snprintf(buf, sizeof(buf), " rel1.to_x: \"%s\";<br/>", rel1_x_to);
|
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
line_cnt++;
|
|
|
|
}
|
|
|
|
if (rel1_y_to)
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
snprintf(buf, sizeof(buf), " rel1.to_y: \"%s\";<br/>", rel1_y_to);
|
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
line_cnt++;
|
|
|
|
}
|
|
|
|
if (rel2_x_to)
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
snprintf(buf, sizeof(buf), " rel2.to_x: \"%s\";<br/>", rel2_x_to);
|
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
line_cnt++;
|
|
|
|
}
|
|
|
|
if (rel2_y_to)
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
snprintf(buf, sizeof(buf), " rel2.to_y: \"%s\";<br/>", rel2_y_to);
|
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
line_cnt++;
|
|
|
|
}
|
|
|
|
|
2014-08-13 02:20:42 -07:00
|
|
|
//Insert relatives
|
2014-08-11 19:31:06 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2016-04-17 22:04:28 -07:00
|
|
|
|
|
|
|
//These conditions check whether the relative number is 4 places of decimals or not
|
|
|
|
//Condition 1: relative values are 4 places of decimals
|
|
|
|
if ((int)(rel1_x * 10000 + 0.5) % 100 ||
|
|
|
|
(int)(rel1_y * 10000 + 0.5) % 100 ||
|
|
|
|
(int)(rel2_x * 10000 + 0.5) % 100 ||
|
|
|
|
(int)(rel2_y * 10000 + 0.5) % 100)
|
|
|
|
{
|
2016-07-19 04:14:38 -07:00
|
|
|
snprintf(buf, sizeof(buf), " rel1.relative: %s;<br/>",
|
|
|
|
_posix_fp(rel1_x, rel1_y, "%.4f"));
|
2016-04-17 22:04:28 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2016-07-19 04:14:38 -07:00
|
|
|
snprintf(buf, sizeof(buf), " rel2.relative: %s;<br/>",
|
|
|
|
_posix_fp(rel2_x, rel2_y, "%.4f"));
|
2016-04-17 22:04:28 -07:00
|
|
|
}
|
|
|
|
//Condition 2: relative values are 2 places of decimals
|
|
|
|
else
|
|
|
|
{
|
2016-07-19 04:14:38 -07:00
|
|
|
snprintf(buf, sizeof(buf), " rel1.relative: %s;<br/>",
|
|
|
|
_posix_fp(rel1_x, rel1_y, "%.2f"));
|
2016-04-17 22:04:28 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2016-07-19 04:14:38 -07:00
|
|
|
snprintf(buf, sizeof(buf), " rel2.relative: %s;<br/>",
|
|
|
|
_posix_fp(rel2_x, rel2_y, "%.2f"));
|
2016-04-17 22:04:28 -07:00
|
|
|
}
|
|
|
|
|
2014-08-13 02:20:42 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
2014-08-11 19:31:06 -07:00
|
|
|
|
2014-08-13 06:35:09 -07:00
|
|
|
//Insert the tale of the part that contains closing brackets
|
2014-08-11 19:31:06 -07:00
|
|
|
t = (char **) &TEMPLATE_PART_TALE;
|
|
|
|
for (i = 0; i < TEMPLATE_PART_TALE_LINE_CNT; i++)
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
|
|
|
elm_entry_entry_insert(edit_entry, t[i]);
|
|
|
|
}
|
2014-08-08 22:29:51 -07:00
|
|
|
|
2016-05-30 22:18:34 -07:00
|
|
|
//Add a new line in the end of inserted template
|
|
|
|
elm_entry_entry_insert(edit_entry, "<br/>");
|
2014-08-13 07:12:51 -07:00
|
|
|
|
2016-05-30 22:18:34 -07:00
|
|
|
//Increase (part name + body + relatives + tail) line
|
2014-08-13 07:12:51 -07:00
|
|
|
int line_inc = 1 + line_cnt + 2 + TEMPLATE_PART_TALE_LINE_CNT;
|
|
|
|
edit_line_increase(ed, line_inc);
|
2014-08-13 02:20:42 -07:00
|
|
|
|
2014-08-10 21:48:01 -07:00
|
|
|
int cursor_pos2 = elm_entry_cursor_pos_get(edit_entry);
|
2014-08-08 22:29:51 -07:00
|
|
|
edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2);
|
|
|
|
|
2014-08-10 21:48:01 -07:00
|
|
|
elm_entry_cursor_pos_set(edit_entry, cursor_pos);
|
2014-08-08 22:29:51 -07:00
|
|
|
|
2015-02-11 03:17:07 -08:00
|
|
|
if (part_type == EDJE_PART_TYPE_IMAGE)
|
|
|
|
image_description_add(ed);
|
|
|
|
else if (part_type == EDJE_PART_TYPE_TEXTBLOCK)
|
|
|
|
textblock_style_add(ed, random_name);
|
|
|
|
|
2016-03-03 23:21:14 -08:00
|
|
|
//select random name
|
|
|
|
select_random_name(edit_entry, first_line, random_name, space);
|
|
|
|
|
2014-08-13 03:48:47 -07:00
|
|
|
edit_syntax_color_partial_apply(ed, 0);
|
2014-08-10 21:48:01 -07:00
|
|
|
edit_changed_set(ed, EINA_TRUE);
|
2014-09-30 07:56:16 -07:00
|
|
|
|
2015-06-30 00:46:34 -07:00
|
|
|
strncpy(syntax, type_name, n);
|
|
|
|
|
2014-09-30 07:56:16 -07:00
|
|
|
return EINA_TRUE;
|
2014-08-08 22:29:51 -07:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:56:16 -07:00
|
|
|
Eina_Bool
|
2016-06-04 21:09:52 -07:00
|
|
|
template_insert(edit_data *ed, char *syntax, size_t n)
|
2014-08-13 04:28:43 -07:00
|
|
|
{
|
|
|
|
Evas_Object *entry = edit_entry_get(ed);
|
|
|
|
Eina_Stringshare *paragh = edit_cur_paragh_get(ed);
|
2016-01-28 23:41:59 -08:00
|
|
|
|
2014-09-30 07:56:16 -07:00
|
|
|
Eina_Bool ret = EINA_FALSE;
|
|
|
|
if (!paragh) return EINA_FALSE;
|
2014-08-13 04:28:43 -07:00
|
|
|
|
2016-05-30 22:18:34 -07:00
|
|
|
//Move cursor position to the beginning of the next line to apply indentation
|
|
|
|
elm_entry_cursor_line_end_set(entry);
|
|
|
|
int cursor_line_end_pos = elm_entry_cursor_pos_get(entry);
|
|
|
|
elm_entry_cursor_pos_set(entry, cursor_line_end_pos + 1);
|
|
|
|
|
2014-08-13 04:28:43 -07:00
|
|
|
if (!strcmp(paragh, "parts"))
|
|
|
|
{
|
2014-09-30 07:56:16 -07:00
|
|
|
ret = template_part_insert(ed, EDJE_PART_TYPE_IMAGE,
|
2014-11-11 23:44:19 -08:00
|
|
|
ENVENTOR_TEMPLATE_INSERT_DEFAULT,
|
2016-05-11 05:57:51 -07:00
|
|
|
EINA_FALSE, EINA_FALSE,
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
0.5, 0.5, 0, 0,
|
2014-09-30 07:56:16 -07:00
|
|
|
REL1_X, REL1_Y, REL2_X, REL2_Y, NULL, syntax,
|
|
|
|
n);
|
2014-08-13 04:28:43 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
int line_cnt;
|
|
|
|
char **t = NULL;
|
2016-06-01 19:57:30 -07:00
|
|
|
char first_line[40] = {0, };
|
2016-01-28 23:41:59 -08:00
|
|
|
char random_name[9];
|
|
|
|
int space = edit_cur_indent_depth_get(ed);
|
|
|
|
|
|
|
|
//Alloc Empty spaces
|
|
|
|
char *p = alloca(space + 1);
|
|
|
|
memset(p, ' ', space);
|
|
|
|
p[space] = '\0';
|
|
|
|
|
2016-03-16 22:37:32 -07:00
|
|
|
template_random_string_create(NULL, random_name, 8);
|
2016-01-28 23:41:59 -08:00
|
|
|
elm_entry_cursor_line_begin_set(entry);
|
2014-08-13 04:28:43 -07:00
|
|
|
|
2016-01-26 21:29:40 -08:00
|
|
|
if (!strcmp(paragh, "part") || !strcmp(paragh, "image") ||
|
|
|
|
!strcmp(paragh, "rect") || !strcmp(paragh, "swallow") ||
|
|
|
|
!strcmp(paragh, "text") || !strcmp(paragh, "textblock"))
|
2014-08-13 04:28:43 -07:00
|
|
|
{
|
|
|
|
line_cnt = TEMPLATE_DESC_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_DESC;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Description", n);
|
2016-01-28 23:41:59 -08:00
|
|
|
snprintf(first_line, 40, "desc { \"%s\";<br/>", random_name);
|
2014-08-13 04:28:43 -07:00
|
|
|
}
|
2016-01-26 21:29:40 -08:00
|
|
|
else if (!strcmp(paragh, "spacer"))
|
|
|
|
{
|
|
|
|
line_cnt = TEMPLATE_DESC_SPACER_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_DESC_SPACER;
|
|
|
|
strncpy(syntax, "Description", n);
|
2016-01-28 23:41:59 -08:00
|
|
|
snprintf(first_line, 40, "desc { \"%s\";<br/>", random_name);
|
2016-01-26 21:29:40 -08:00
|
|
|
}
|
2014-08-13 04:28:43 -07:00
|
|
|
else if (!strcmp(paragh, "programs"))
|
|
|
|
{
|
|
|
|
line_cnt = TEMPLATE_PROG_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_PROG;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Program", n);
|
2016-01-28 23:41:59 -08:00
|
|
|
snprintf(first_line, 40, "program { \"%s\";<br/>", random_name);
|
2014-08-13 04:28:43 -07:00
|
|
|
}
|
|
|
|
else if (!strcmp(paragh, "images"))
|
|
|
|
{
|
|
|
|
line_cnt = TEMPLATE_IMG_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_IMG;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Image File", n);
|
2014-08-13 04:28:43 -07:00
|
|
|
}
|
|
|
|
else if (!strcmp(paragh, "collections"))
|
|
|
|
{
|
|
|
|
line_cnt = TEMPLATE_GROUP_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_GROUP;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Group", n);
|
2016-01-28 23:41:59 -08:00
|
|
|
snprintf(first_line, 40, "group { \"%s\";<br/>", random_name);
|
2014-08-13 04:28:43 -07:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:56:16 -07:00
|
|
|
if (!t) goto end;
|
|
|
|
|
2016-03-03 23:17:48 -08:00
|
|
|
int cursor_pos = elm_entry_cursor_pos_get(entry);
|
|
|
|
int cursor_pos1 = elm_entry_cursor_pos_get(entry);
|
|
|
|
|
2016-01-28 23:41:59 -08:00
|
|
|
if (strcmp(paragh, "images"))
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(entry, p);
|
|
|
|
elm_entry_entry_insert(entry, first_line);
|
|
|
|
}
|
|
|
|
|
2014-08-13 04:28:43 -07:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < (line_cnt - 1); i++)
|
|
|
|
{
|
|
|
|
elm_entry_entry_insert(entry, p);
|
|
|
|
elm_entry_entry_insert(entry, t[i]);
|
|
|
|
}
|
|
|
|
elm_entry_entry_insert(entry, p);
|
|
|
|
elm_entry_entry_insert(entry, t[i]);
|
|
|
|
|
2016-05-30 22:18:34 -07:00
|
|
|
//Add a new line in the end of inserted template
|
|
|
|
elm_entry_entry_insert(entry, "<br/>");
|
|
|
|
|
|
|
|
//Increase (template + last new line) line
|
|
|
|
edit_line_increase(ed, line_cnt + 1);
|
2014-08-13 04:28:43 -07:00
|
|
|
|
|
|
|
int cursor_pos2 = elm_entry_cursor_pos_get(entry);
|
|
|
|
edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2);
|
|
|
|
|
2015-02-12 06:01:37 -08:00
|
|
|
if (!strcmp(paragh, "images"))
|
|
|
|
cursor_pos += (cursor_pos2 - cursor_pos1);
|
|
|
|
|
2014-08-13 04:28:43 -07:00
|
|
|
elm_entry_cursor_pos_set(entry, cursor_pos);
|
|
|
|
|
2016-03-03 23:21:14 -08:00
|
|
|
//select random name
|
|
|
|
select_random_name(entry, first_line, random_name, space);
|
|
|
|
|
2014-08-13 04:28:43 -07:00
|
|
|
edit_syntax_color_partial_apply(ed, 0);
|
2016-02-28 23:43:36 -08:00
|
|
|
edit_changed_set(ed, EINA_TRUE);
|
2014-09-30 07:56:16 -07:00
|
|
|
|
|
|
|
ret = EINA_TRUE;
|
2014-08-13 04:28:43 -07:00
|
|
|
|
|
|
|
end:
|
|
|
|
eina_stringshare_del(paragh);
|
2014-09-30 07:56:16 -07:00
|
|
|
|
|
|
|
return ret;
|
2014-08-13 04:28:43 -07:00
|
|
|
}
|