2014-09-30 07:56:16 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ENVENTOR_BETA_API_SUPPORT 1
|
|
|
|
|
|
|
|
#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
|
2014-08-30 02:20:38 -07:00
|
|
|
template_random_string_create(char *buf, int size)
|
2014-08-07 06:32:27 -07:00
|
|
|
{
|
|
|
|
int i;
|
2014-08-30 02:20:38 -07:00
|
|
|
for (i = 0; i < (size - 1); i++)
|
|
|
|
buf[i] = NAME_SEED[(rand() % NAME_SEED_LEN)];
|
|
|
|
buf[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;
|
|
|
|
if (images_block)
|
|
|
|
{
|
|
|
|
elm_entry_cursor_pos_set(edit_entry, cursor_pos);
|
2014-09-30 07:56:16 -07:00
|
|
|
template_insert(ed, TEMPLATE_INSERT_LIVE_EDIT, NULL, 0);
|
2014-08-10 21:48:01 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_IMG_BLOCK);
|
|
|
|
edit_line_increase(ed, TEMPLATE_IMG_BLOCK_LINE_CNT);
|
|
|
|
int cursor_pos2 = elm_entry_cursor_pos_get(edit_entry);
|
|
|
|
edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!styles_block)
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[0]);
|
|
|
|
|
|
|
|
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);
|
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
if (!styles_block)
|
|
|
|
elm_entry_entry_insert(edit_entry, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[2]);
|
|
|
|
|
|
|
|
int line_inc = TEMPLATE_TEXTBLOCK_STYLE_LINE_CNT;
|
|
|
|
if (!styles_block) line_inc += 2;
|
|
|
|
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);
|
|
|
|
|
|
|
|
elm_entry_cursor_pos_set(edit_entry, cursor_pos_to_restore);
|
|
|
|
}
|
|
|
|
|
2014-08-10 21:48:01 -07:00
|
|
|
static int
|
|
|
|
template_part_insert_cursor_pos_set(edit_data *ed,
|
2014-08-13 07:12:51 -07:00
|
|
|
Template_Insert_Type insert_type,
|
2014-08-10 21:48:01 -07:00
|
|
|
const Eina_Stringshare *group_name)
|
|
|
|
{
|
|
|
|
int cursor_pos = -1;
|
|
|
|
Evas_Object *edit_entry = edit_entry_get(ed);
|
2014-08-13 07:12:51 -07:00
|
|
|
if (insert_type == 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;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
Template_Insert_Type insert_type, 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);
|
|
|
|
int cursor_pos = template_part_insert_cursor_pos_set(ed, 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';
|
|
|
|
|
|
|
|
int line_cnt;
|
|
|
|
char **t;
|
|
|
|
char buf[64];
|
|
|
|
|
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;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Rect", n);
|
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;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Text", n);
|
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;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Swallow", n);
|
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;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Textblock", n);
|
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;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Spacer", n);
|
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:
|
|
|
|
case EDJE_PART_TYPE_LAST:
|
|
|
|
line_cnt = TEMPLATE_PART_IMAGE_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_PART_IMAGE;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Image", n);
|
2014-08-08 22:29:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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];
|
2014-08-30 02:20:38 -07:00
|
|
|
char random_name[9];
|
|
|
|
template_random_string_create(random_name, 9);
|
|
|
|
|
2014-08-13 06:35:09 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2014-08-30 02:20:38 -07:00
|
|
|
snprintf(first_line, 40, "part { name: \"%s\";<br/>", 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);
|
|
|
|
}
|
|
|
|
|
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);
|
2014-08-13 06:35:09 -07:00
|
|
|
snprintf(buf, sizeof(buf), " rel1.relative: %.2f %.2f;<br/>", rel1_x,
|
2014-08-13 07:50:47 -07:00
|
|
|
rel1_y);
|
2014-08-13 02:20:42 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, buf);
|
2014-08-11 19:31:06 -07:00
|
|
|
elm_entry_entry_insert(edit_entry, p);
|
2014-08-13 07:50:47 -07:00
|
|
|
snprintf(buf, sizeof(buf), " rel2.relative: %.2f %.2f;<br/>", rel2_x,
|
2014-08-13 02:20:42 -07:00
|
|
|
rel2_y);
|
|
|
|
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
|
|
|
|
2014-08-13 07:12:51 -07:00
|
|
|
//add new line only in live edit mode
|
|
|
|
if (insert_type == TEMPLATE_INSERT_LIVE_EDIT)
|
|
|
|
elm_entry_entry_insert(edit_entry, "<br/>");
|
|
|
|
|
2014-08-13 06:35:47 -07:00
|
|
|
/* Increase (part name + body + relatives + tail) line. But line increase
|
2014-08-13 07:12:51 -07:00
|
|
|
count should be -1 in entry template insertion because the
|
|
|
|
cursor position would be taken one line additionally. */
|
|
|
|
int line_inc = 1 + line_cnt + 2 + TEMPLATE_PART_TALE_LINE_CNT;
|
|
|
|
if (insert_type == TEMPLATE_INSERT_DEFAULT) line_inc--;
|
|
|
|
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
|
|
|
|
2014-08-30 02:20:38 -07:00
|
|
|
if (insert_type == TEMPLATE_INSERT_LIVE_EDIT)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
return EINA_TRUE;
|
2014-08-08 22:29:51 -07:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:56:16 -07:00
|
|
|
Eina_Bool
|
|
|
|
template_insert(edit_data *ed, Template_Insert_Type insert_type, 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);
|
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
|
|
|
|
|
|
|
if (!strcmp(paragh, "parts"))
|
|
|
|
{
|
2014-09-30 07:56:16 -07:00
|
|
|
ret = template_part_insert(ed, EDJE_PART_TYPE_IMAGE,
|
|
|
|
TEMPLATE_INSERT_DEFAULT,
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!strcmp(paragh, "part"))
|
|
|
|
{
|
|
|
|
line_cnt = TEMPLATE_DESC_LINE_CNT;
|
|
|
|
t = (char **) &TEMPLATE_DESC;
|
2014-09-30 07:56:16 -07:00
|
|
|
strncpy(syntax, "Description", n);
|
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);
|
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);
|
2014-08-13 04:28:43 -07:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:56:16 -07:00
|
|
|
if (!t) goto end;
|
|
|
|
|
2014-08-13 04:28:43 -07:00
|
|
|
int cursor_pos = elm_entry_cursor_pos_get(entry);
|
|
|
|
elm_entry_cursor_line_begin_set(entry);
|
|
|
|
int cursor_pos1 = elm_entry_cursor_pos_get(entry);
|
|
|
|
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 < (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]);
|
|
|
|
|
2014-08-13 07:12:51 -07:00
|
|
|
/* Line increase count should be -1 in entry template insertion because the
|
|
|
|
cursor position would be taken one line additionally. */
|
|
|
|
if (insert_type == TEMPLATE_INSERT_DEFAULT) line_cnt--;
|
|
|
|
edit_line_increase(ed, line_cnt);
|
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);
|
|
|
|
|
|
|
|
elm_entry_cursor_pos_set(entry, cursor_pos);
|
|
|
|
|
|
|
|
edit_syntax_color_partial_apply(ed, 0);
|
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
|
|
|
}
|