forked from enlightenment/edi
Passing Eo events from Elm_Code to the Evas_Object when the backend data changes. Track a list of all widgets connected to the Elm_Code so we can signal them all. Add API to change status of a line which will refresh the widget too.
This commit is contained in:
parent
051e03ba99
commit
fdccc03a4a
|
@ -34,6 +34,7 @@ PKG_CHECK_MODULES([EFL],
|
|||
evas >= 1.8.0
|
||||
ecore >= 1.8.0
|
||||
edje >= 1.8.0
|
||||
eo >= 1.8.0
|
||||
elementary >= 1.8.0
|
||||
eio >= 1.8.0
|
||||
])
|
||||
|
|
|
@ -107,6 +107,21 @@ EAPI Elm_Code *elm_code_create(Elm_Code_File *file);
|
|||
*/
|
||||
EAPI void elm_code_free(Elm_Code *code);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
* @brief Callbacks and message passing.
|
||||
* @defgroup Callbacks Managing the information flow between Elm_Code objects and Evas_Object widgets
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* Managing the callbacks and other behaviours that cross the backend - frontend divide.
|
||||
*/
|
||||
|
||||
|
||||
EAPI void elm_code_callback_fire(Elm_Code *code, const char *signal, void *data);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
#include <Eo.h>
|
||||
|
||||
#include "Elm_Code.h"
|
||||
|
||||
#include "elm_code_private.h"
|
||||
|
@ -64,6 +67,7 @@ elm_code_create(Elm_Code_File *file)
|
|||
|
||||
ret = calloc(1, sizeof(Elm_Code));
|
||||
ret->file = file;
|
||||
file->parent = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -71,8 +75,30 @@ elm_code_create(Elm_Code_File *file)
|
|||
EAPI void
|
||||
elm_code_free(Elm_Code *code)
|
||||
{
|
||||
Eina_List *item;
|
||||
Evas_Object *widget;
|
||||
|
||||
if (code->file)
|
||||
free(code->file);
|
||||
elm_code_file_free(code->file);
|
||||
|
||||
EINA_LIST_FOREACH(code->widgets, item, widget)
|
||||
{
|
||||
evas_object_hide(widget);
|
||||
evas_object_del(widget);
|
||||
}
|
||||
|
||||
free(code);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_code_callback_fire(Elm_Code *code, const char *signal, void *data)
|
||||
{
|
||||
Eina_List *item;
|
||||
Evas_Object *widget;
|
||||
|
||||
EINA_LIST_FOREACH(code->widgets, item, widget)
|
||||
{
|
||||
eo_do(widget, eo_event_callback_call(ELM_CODE_EVENT_LINE_SET_DONE, data));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
|
||||
#include <Eina.h>
|
||||
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
#include <Eo.h>
|
||||
|
||||
#define ELM_CODE_EVENT_LINE_SET_DONE "line,set,done"
|
||||
//EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE =
|
||||
// EO_EVENT_DESCRIPTION("line,set,done", "");
|
||||
|
||||
typedef enum {
|
||||
ELM_CODE_STATUS_TYPE_DEFAULT = 0,
|
||||
ELM_CODE_STATUS_TYPE_ERROR,
|
||||
|
@ -17,13 +24,14 @@ typedef enum {
|
|||
ELM_CODE_TOKEN_TYPE_COUNT
|
||||
} Elm_Code_Token_Type;
|
||||
|
||||
|
||||
#include "elm_code_file.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Common data structures and constants.
|
||||
|
|
|
@ -31,6 +31,9 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con
|
|||
line->content[length] = 0;
|
||||
|
||||
file->lines = eina_list_append(file->lines, line);
|
||||
|
||||
if (file->parent)
|
||||
elm_code_callback_fire(file->parent, ELM_CODE_EVENT_LINE_SET_DONE, line);
|
||||
}
|
||||
|
||||
EAPI Elm_Code_File *elm_code_file_new()
|
||||
|
@ -136,3 +139,18 @@ EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int numb
|
|||
return NULL;
|
||||
return line->content;
|
||||
}
|
||||
|
||||
EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int number, Elm_Code_Status_Type status)
|
||||
{
|
||||
Elm_Code_Line *line;
|
||||
|
||||
line = elm_code_file_line_get(file, number);
|
||||
|
||||
if (!line)
|
||||
return;
|
||||
|
||||
line->status = status;
|
||||
|
||||
if (file->parent)
|
||||
elm_code_callback_fire(file->parent, ELM_CODE_EVENT_LINE_SET_DONE, line);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ typedef struct _Elm_Code_Line
|
|||
|
||||
typedef struct _Elm_Code_File
|
||||
{
|
||||
void *parent;
|
||||
|
||||
Eina_List *lines;
|
||||
Eina_File *file;
|
||||
|
||||
|
@ -72,6 +74,8 @@ EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int lin
|
|||
|
||||
EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int line);
|
||||
|
||||
EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int line, Elm_Code_Status_Type status);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
#include <Eo.h>
|
||||
|
||||
#include <Elementary.h>
|
||||
|
||||
#include "elm_code_widget.h"
|
||||
|
@ -12,7 +15,8 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code)
|
|||
{
|
||||
Elm_Code_Line *line;
|
||||
Evas_Textgrid_Cell *cells;
|
||||
const char *content, *chr;
|
||||
const char *content;
|
||||
char *chr;
|
||||
unsigned int length;
|
||||
int w, h, cw, ch;
|
||||
unsigned int x, y;
|
||||
|
@ -41,11 +45,47 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code)
|
|||
chr++;
|
||||
}
|
||||
}
|
||||
|
||||
evas_object_textgrid_update_add(o, 0, 0, w, h);
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_code_widget_resize_cb(void *data, EINA_UNUSED Evas *e, Evas_Object *obj,
|
||||
EINA_UNUSED void *event_info)
|
||||
_elm_code_widget_line_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED,
|
||||
void *event_info)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_Line *line;
|
||||
Evas_Object *o;
|
||||
|
||||
Evas_Textgrid_Cell *cells;
|
||||
char *chr;
|
||||
unsigned int length, x;
|
||||
int w;
|
||||
|
||||
code = (Elm_Code *)data;
|
||||
line = (Elm_Code_Line *)event_info;
|
||||
o = (Evas_Object *)obj;
|
||||
|
||||
cells = evas_object_textgrid_cellrow_get(o, line->number - 1);
|
||||
length = strlen(line->content);
|
||||
evas_object_textgrid_size_get(o, &w, NULL);
|
||||
|
||||
chr = line->content;
|
||||
for (x = 0; x < (unsigned int) w && x < length; x++)
|
||||
{
|
||||
cells[x].codepoint = *chr;
|
||||
cells[x].bg = line->status;
|
||||
cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT;
|
||||
|
||||
chr++;
|
||||
}
|
||||
|
||||
evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj,
|
||||
void *event_info EINA_UNUSED)
|
||||
{
|
||||
Elm_Code *code;
|
||||
|
||||
|
@ -72,6 +112,10 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code)
|
|||
205, 205, 205, 255);
|
||||
|
||||
evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code);
|
||||
|
||||
eo_do(o,eo_event_callback_add(ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code));
|
||||
|
||||
code->widgets = eina_list_append(code->widgets, o);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ void print_cb(const Eina_Log_Domain *domain,
|
|||
EINA_UNUSED void *data,
|
||||
va_list args)
|
||||
{
|
||||
Elm_Code_Line *code_line;
|
||||
unsigned int printed, line_count, buffer_len = 512;
|
||||
char buffer [buffer_len];
|
||||
|
||||
|
@ -33,9 +32,8 @@ void print_cb(const Eina_Log_Domain *domain,
|
|||
if (level <= EINA_LOG_LEVEL_ERR)
|
||||
{
|
||||
line_count = elm_code_file_lines_get(_elm_code->file);
|
||||
code_line = elm_code_file_line_get(_elm_code->file, line_count);
|
||||
|
||||
code_line->status = ELM_CODE_STATUS_TYPE_ERROR;
|
||||
elm_code_file_line_status_set(_elm_code->file, line_count, ELM_CODE_STATUS_TYPE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue