From 159c47d340b0e418b50ca22b4dda99e4412af50a Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 26 Jan 2015 14:00:37 +0000 Subject: [PATCH] Port everything to use new widget API. Remove old widget API --- elm_code/lib/Elm_Code.h | 2 +- elm_code/lib/Makefile.am | 3 +- elm_code/lib/elm_code_diff_widget.c | 21 +- elm_code/lib/elm_code_widget.c | 289 -------------------------- elm_code/lib/elm_code_widget.h | 100 --------- elm_code/tests/Makefile.am | 2 + elm_code/tests/elm_code_test_widget.c | 2 +- src/bin/edi_consolepanel.c | 8 +- src/bin/edi_logpanel.c | 8 +- src/tests/edi_test_content_provider.c | 2 +- 10 files changed, 29 insertions(+), 408 deletions(-) delete mode 100644 elm_code/lib/elm_code_widget.c delete mode 100644 elm_code/lib/elm_code_widget.h diff --git a/elm_code/lib/Elm_Code.h b/elm_code/lib/Elm_Code.h index 35071a2..8a30dfe 100644 --- a/elm_code/lib/Elm_Code.h +++ b/elm_code/lib/Elm_Code.h @@ -34,7 +34,7 @@ #include "elm_code_common.h" #include "elm_code_file.h" #include "elm_code_parse.h" -#include "elm_code_widget.h" +#include "elm_code_widget2.eo.h" #include "elm_code_diff_widget.h" #ifdef __cplusplus diff --git a/elm_code/lib/Makefile.am b/elm_code/lib/Makefile.am index 193b9e4..bf84811 100644 --- a/elm_code/lib/Makefile.am +++ b/elm_code/lib/Makefile.am @@ -12,7 +12,7 @@ lib_LTLIBRARIES = libelm_code.la includes_HEADERS = \ elm_code_file.h \ elm_code_parse.h \ -elm_code_widget.h \ +elm_code_widget2.eo.h \ elm_code_diff_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ @@ -20,7 +20,6 @@ includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ elm_code_file.c \ elm_code_parse.c \ -elm_code_widget.c \ elm_code_widget2.c \ elm_code_diff_widget.c \ elm_code.c \ diff --git a/elm_code/lib/elm_code_diff_widget.c b/elm_code/lib/elm_code_diff_widget.c index f008159..3db4fbb 100644 --- a/elm_code/lib/elm_code_diff_widget.c +++ b/elm_code/lib/elm_code_diff_widget.c @@ -80,7 +80,8 @@ static void _elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) { Elm_Code *wcode1, *wcode2; - Evas_Object *widget_left, *widget_right, *hbox; + Elm_Code_Widget2 *widget_left, *widget_right; + Evas_Object *hbox; hbox = elm_panes_add(parent); evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -90,7 +91,9 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // left side of diff wcode1 = elm_code_create(); - widget_left = elm_code_widget_add(parent, wcode1); + widget_left = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + eo_do(widget_left, + elm_code_widget2_code_set(wcode1)); evas_object_size_hint_weight_set(widget_left, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(widget_left, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -100,7 +103,9 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // right side of diff wcode2 = elm_code_create(); - widget_right = elm_code_widget_add(parent, wcode2); + widget_right = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + eo_do(widget_right, + elm_code_widget2_code_set(wcode2)); evas_object_size_hint_weight_set(widget_right, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(widget_right, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -114,11 +119,11 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) EAPI void elm_code_diff_widget_font_size_set(Evas_Object *widget, int size) { - Evas_Object *child; + Elm_Code_Widget2 *child; - child = evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); - elm_code_widget_font_size_set(child, size); - child = evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); - elm_code_widget_font_size_set(child, size); + child = (Elm_Code_Widget2 *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); + eo_do(child, elm_code_widget2_font_size_set(size)); + child = (Elm_Code_Widget2 *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); + eo_do(child, elm_code_widget2_font_size_set(size)); } diff --git a/elm_code/lib/elm_code_widget.c b/elm_code/lib/elm_code_widget.c deleted file mode 100644 index d91412a..0000000 --- a/elm_code/lib/elm_code_widget.c +++ /dev/null @@ -1,289 +0,0 @@ -#ifdef HAVE_CONFIG -# include "config.h" -#endif - -#include "Elm_Code.h" - -#include "elm_code_private.h" - -EAPI const Eo_Event_Description ELM_CODE_WIDGET_EVENT_LINE_CLICKED = - EO_EVENT_DESCRIPTION("line,clicked", ""); - -Eina_Unicode status_icons[] = { - ' ', - '!', - - '+', - '-', - ' ', - - 0x2713, - 0x2717, - - 0 -}; - -static Eina_Bool -_elm_code_widget_resize(Evas_Object *o) -{ - int w, h, cw, ch; - - evas_object_geometry_get(o, NULL, NULL, &w, &h); - evas_object_textgrid_cell_size_get(o, &cw, &ch); - evas_object_textgrid_size_set(o, ceil(((double) w) / cw), - ceil(((double) h) / ch)); - - return h > 0 && w > 0; -} - -static void -_elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start, int end, Elm_Code_Token_Type type) -{ - int x; - - for (x = start; x <= end && x < count; x++) - { - cells[x].fg = type; - } -} - -static void -_elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) -{ - Eina_List *item; - Elm_Code_Token *token; - int start, length; - - start = 1; - length = line->length; - - EINA_LIST_FOREACH(line->tokens, item, token) - { - - _elm_code_widget_fill_line_token(cells, count, start, token->start, ELM_CODE_TOKEN_TYPE_DEFAULT); - - // TODO handle a token starting before the previous finishes - _elm_code_widget_fill_line_token(cells, count, token->start, token->end, token->type); - - start = token->end + 1; - } - - _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); -} - -static void -_elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) -{ - char *chr; - unsigned int length, x; - int w; - ELM_CODE_WIDGET_DATA_GET(o, widget); - - if (!_elm_code_widget_resize(o)) - return; - - length = line->length; - evas_object_textgrid_size_get(o, &w, NULL); - - cells[0].codepoint = status_icons[line->status]; - cells[0].bold = 1; - cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - cells[0].bg = line->status; - - if (line->modified) - chr = line->modified; - else - chr = (char *)line->content; - for (x = 1; x < (unsigned int) w && x <= length; x++) - { - cells[x].codepoint = *chr; - cells[x].bg = line->status; - - chr++; - } - for (; x < (unsigned int) w; x++) - { - cells[x].codepoint = 0; - cells[x].bg = line->status; - } - - _elm_code_widget_fill_line_tokens(cells, w, line); - if (widget->editable && widget->cursor_line == line->number) - { - if (widget->cursor_col < (unsigned int) w) - cells[widget->cursor_col].bg = ELM_CODE_TOKEN_TYPE_CURSOR; - } - - evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); -} - -static void -_elm_code_widget_fill(Evas_Object *o, Elm_Code *code) -{ - Elm_Code_Line *line; - Evas_Textgrid_Cell *cells; - int w, h; - unsigned int y; - - if (!_elm_code_widget_resize(o)) - return; - evas_object_textgrid_size_get(o, &w, &h); - - for (y = 1; y <= (unsigned int) h && y <= elm_code_file_lines_get(code->file); y++) - { - line = elm_code_file_line_get(code->file, y); - - cells = evas_object_textgrid_cellrow_get(o, y - 1); - _elm_code_widget_fill_line(o, cells, line); - } -} - -static Eina_Bool -_elm_code_widget_line_cb(void *data EINA_UNUSED, Eo *obj, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info) -{ - Elm_Code_Line *line; - Evas_Object *o; - int h; - - Evas_Textgrid_Cell *cells; - - line = (Elm_Code_Line *)event_info; - o = (Evas_Object *)obj; - - evas_object_textgrid_size_get(o, NULL, &h); - - if (line->number > (unsigned int) h) - return EINA_TRUE; - - cells = evas_object_textgrid_cellrow_get(o, line->number - 1); - _elm_code_widget_fill_line(o, cells, line); - - return EINA_TRUE; -} - - -static Eina_Bool -_elm_code_widget_file_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - Evas_Object *o; - Elm_Code *code; - - code = (Elm_Code *)data; - o = (Evas_Object *)obj; - - _elm_code_widget_fill(o, code); - return EINA_TRUE; -} - -static void -_elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, - void *event_info EINA_UNUSED) -{ - Elm_Code *code; - - code = (Elm_Code *)data; - - _elm_code_widget_fill(obj, code); -} - -static void -_elm_code_widget_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, - void *event_info) -{ - Elm_Code *code; - Elm_Code_Line *line; - Evas_Event_Mouse_Up *event; - Evas_Coord y; - int ch; - unsigned int row; - - code = (Elm_Code *)data; - event = (Evas_Event_Mouse_Up *)event_info; - y = event->canvas.y; - - evas_object_textgrid_cell_size_get(obj, NULL, &ch); - row = ((double) y / ch) + 1; - - line = elm_code_file_line_get(code->file, row); - if (line) - elm_code_callback_fire(code, &ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line); -} - -EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) -{ - Evas_Object *o; - Elm_Code_Widget *widget; - - o = evas_object_textgrid_add(parent); - - // 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_ERROR, - 205, 54, 54, 255); - - 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); - - // setup token colors - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, - 205, 205, 205, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT, - 54, 205, 255, 255); - - 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); - - // the style for a cursor - this is a special token and will be applied to the background - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CURSOR, - 205, 205, 54, 255); - evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, code); - - eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); - eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, code)); - - widget = calloc(1, sizeof(*widget)); - widget->code = code; - widget->cursor_line = 1; - widget->cursor_col = 1; - evas_object_data_set(o, ELM_CODE_WIDGET_DATA_KEY, widget); - code->widgets = eina_list_append(code->widgets, o); - - elm_code_widget_font_size_set(o, 10); - return o; -} - -EAPI void -elm_code_widget_font_size_set(Evas_Object *obj, Evas_Font_Size size) -{ - ELM_CODE_WIDGET_DATA_GET(obj, widget); - - widget->font_size = size; - evas_object_textgrid_font_set(obj, "Mono", size * elm_config_scale_get()); -} - -EAPI void -elm_code_widget_editable_set(Evas_Object *obj, Eina_Bool editable) -{ - ELM_CODE_WIDGET_DATA_GET(obj, widget); - - widget->editable = editable; -} - - diff --git a/elm_code/lib/elm_code_widget.h b/elm_code/lib/elm_code_widget.h deleted file mode 100644 index 1a17203..0000000 --- a/elm_code/lib/elm_code_widget.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef ELM_CODE_WIDGET_H_ -# define ELM_CODE_WIDGET_H_ - -EAPI extern const Eo_Event_Description ELM_CODE_WIDGET_EVENT_LINE_CLICKED; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file - * @brief These routines are used for rendering instances of Elm Code. - */ - -typedef struct _Elm_Code_Widget -{ - Elm_Code *code; - - Evas_Font_Size font_size; - unsigned int cursor_line, cursor_col; - Eina_Bool editable; - -} Elm_Code_Widget; - -#define ELM_CODE_WIDGET_DATA_KEY "Elm_Code_Widget" -#define ELM_CODE_WIDGET_DATA_GET(o, ptr, ...) \ - Elm_Code_Widget *ptr; \ - ptr = evas_object_data_get(o, ELM_CODE_WIDGET_DATA_KEY); - -#define ELM_CODE_WIDGET_DATA_GET_OR_RETURN(o, ptr, ...) \ - Elm_Code_Widget *ptr; \ - ptr = evas_object_data_get(o, ELM_CODE_WIDGET_DATA_KEY);\ - if (EINA_UNLIKELY(!ptr)) \ - { \ - CRI("no widget data for object %p (%s)", \ - o, evas_object_type_get(o)); \ - return __VA_ARGS__; \ - } - -/** - * @brief UI Loading functions. - * @defgroup Init Creating a widget to render an Elm Code backend - * - * @{ - * - * Functions for UI loading. - * - */ - -EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); - -/** - * @} - * - * @brief UI Manipulation functions. - * @defgroup UI Manage aspects of an Elm_Code widget - * - * @{ - * - * Functions for UI manipulation. - * - */ - -/** - * Set the font size of a widget - * - * Change the size of the monospaced font used by this widget instance. - * 10 pt is the default font size for an elm_code widget. - * - * @param widget The widget to change - * @param size The font size to set on this widget - * - * @ingroup UI - */ -EAPI void elm_code_widget_font_size_set(Evas_Object *widget, Evas_Font_Size size); - -/** - * Set this widget to be editable - * - * An editable widget displays a cursor and accepts user input. - * It will also accept focus. - * If EINA_FALSE is passed this widget will return to being read-only. - * EINA_FALSE is the default value for editable. - * - * @param widget The widget to change - * @param editable Whether or not this widget should be editable - * - * @ingroup UI - */ -EAPI void elm_code_widget_editable_set(Evas_Object *widget, Eina_Bool editable); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* ELM_CODE_WIDGET_H_ */ diff --git a/elm_code/tests/Makefile.am b/elm_code/tests/Makefile.am index 2f63f38..712c389 100644 --- a/elm_code/tests/Makefile.am +++ b/elm_code/tests/Makefile.am @@ -12,6 +12,8 @@ elm_code_test_widget.c \ elm_code_suite.c elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ +-DEFL_BETA_API_SUPPORT \ +-DEFL_EO_API_SUPPORT \ -DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/tests/\" \ -DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/tests/\" \ -DEFL_BETA_API_SUPPORT \ diff --git a/elm_code/tests/elm_code_test_widget.c b/elm_code/tests/elm_code_test_widget.c index 6efdce8..3b598a9 100644 --- a/elm_code/tests/elm_code_test_widget.c +++ b/elm_code/tests/elm_code_test_widget.c @@ -4,7 +4,7 @@ #include "elm_code_suite.h" -#include "elm_code_widget.c" +#include "elm_code_widget2.c" static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { diff --git a/src/bin/edi_consolepanel.c b/src/bin/edi_consolepanel.c index 0a300eb..a92fffc 100644 --- a/src/bin/edi_consolepanel.c +++ b/src/bin/edi_consolepanel.c @@ -336,13 +336,15 @@ EAPI void edi_consolepanel_add(Evas_Object *parent) EAPI void edi_testpanel_add(Evas_Object *parent) { Elm_Code *code; - Evas_Object *widget; + Elm_Code_Widget2 *widget; code = elm_code_create(); _edi_test_code = code; - widget = elm_code_widget_add(parent, code); - elm_code_widget_font_size_set(widget, _edi_cfg->font.size); + widget = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + eo_do(widget, + elm_code_widget2_code_set(code); + elm_code_widget2_font_size_set(_edi_cfg->font.size)); evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL); diff --git a/src/bin/edi_logpanel.c b/src/bin/edi_logpanel.c index ebb0c02..2e32a61 100644 --- a/src/bin/edi_logpanel.c +++ b/src/bin/edi_logpanel.c @@ -40,12 +40,14 @@ static void _print_cb(const Eina_Log_Domain *domain, EAPI void edi_logpanel_add(Evas_Object *parent) { - Evas_Object *widget; + Elm_Code_Widget2 *widget; Elm_Code *code; code = elm_code_create(); - widget = elm_code_widget_add(parent, code); - elm_code_widget_font_size_set(widget, _edi_cfg->font.size); + widget = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + eo_do(widget, + elm_code_widget2_code_set(code); + elm_code_widget2_font_size_set(_edi_cfg->font.size)); evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(widget); diff --git a/src/tests/edi_test_content_provider.c b/src/tests/edi_test_content_provider.c index 8e8a570..3f0a82b 100644 --- a/src/tests/edi_test_content_provider.c +++ b/src/tests/edi_test_content_provider.c @@ -7,7 +7,7 @@ #include "edi_suite.h" // Add some no-op methods here so linking works without having to import the whole UI! -EAPI Evas_Object *edi_editor_add(Evas_Object *parent EINA_UNUSED, Edi_Mainview_Item *item EINA_UNUSED) +EAPI Evas_Object *_edi_editor_add(Evas_Object *parent EINA_UNUSED, Edi_Mainview_Item *item EINA_UNUSED) { return NULL; }