elm_code: focus: block focus leaving text area when editable.

As well as setting when we should not have focus leave us a theme has been added.
This allows us to extend from elm_entry which is better suited to us.
This commit is contained in:
Andy Williams 2015-02-14 18:49:51 +00:00
parent 8032f0fcd6
commit f6f19be6cb
42 changed files with 157 additions and 107 deletions

10
.gitignore vendored
View File

@ -66,9 +66,9 @@ po/stamp-po
/src/tests/test-suite.log
/src/tests/check-results.xml
/elm_code/bin/elm_code_test
/elm_code/src/bin/elm_code_test
/elm_code/tests/elm_code_suite
/elm_code/tests/elm_code_suite.*
/elm_code/tests/test-suite.log
/elm_code/tests/check-results.xml
/elm_code/src/tests/elm_code_suite
/elm_code/src/tests/elm_code_suite.*
/elm_code/src/tests/test-suite.log
/elm_code/src/tests/check-results.xml

View File

@ -76,7 +76,7 @@ endif
if EFL_HAVE_TESTS
TESTS = elm_code/tests/elm_code_suite src/tests/edi_suite
TESTS = elm_code/src/tests/elm_code_suite src/tests/edi_suite
lcov-check:
if EFL_HAVE_LCOV

View File

@ -118,9 +118,13 @@ src/bin/Makefile
src/lib/Makefile
src/tests/Makefile
elm_code/Makefile
elm_code/lib/Makefile
elm_code/bin/Makefile
elm_code/tests/Makefile
elm_code/data/Makefile
elm_code/data/themes/Makefile
elm_code/data/themes/default/Makefile
elm_code/src/Makefile
elm_code/src/lib/Makefile
elm_code/src/bin/Makefile
elm_code/src/tests/Makefile
doc/edi.1
])
AC_OUTPUT

View File

@ -1,4 +1,4 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = lib bin tests
SUBDIRS = src data

View File

@ -0,0 +1,4 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = themes

View File

@ -0,0 +1,4 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = default

View File

@ -0,0 +1,20 @@
AUTOMAKE_OPTIONS = subdir-objects
MAINTAINERCLEANFILES = Makefile.in
EXTRA_DIST = \
default.edc
include ../../../../Makefile_Edje_Helper.am
filesdir = $(datadir)/$(PACKAGE)/themes
files_DATA = elm_code.edj
elm_code.edj: Makefile $(EXTRA_DIST)
$(AM_V_EDJ)$(EDJE_CC) $(EDJE_CC_FLAGS) \
-id ${top_srcdir}/elm_code/data/themes/default/images \
-sd ${top_srcdir}/elm_code/data/themes/default/sounds \
$(top_srcdir)/elm_code/data/themes/default/default.edc \
$(top_builddir)/elm_code/data/themes/default/elm_code.edj
clean-local:
rm -f *.edj

View File

@ -0,0 +1,19 @@
collections {
/* simple layout to pack our scrolling content into an elm_layout */
group { name: "elm_code/layout/default";
parts {
part { name: "elm.swallow.content"; type: SWALLOW;
description { state: "default" 0.0;
align: 0.5 0.0;
fixed: 0 1;
rel2 {
relative: 1.0 1.0;
offset: 0 0;
}
}
}
}
}
}

4
elm_code/src/Makefile.am Normal file
View File

@ -0,0 +1,4 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = lib bin tests

View File

@ -6,7 +6,7 @@ AM_CPPFLAGS = \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
-I$(top_srcdir)/elm_code/lib/ \
-I$(top_srcdir)/elm_code/src/lib/ \
-DLOCALEDIR=\"$(datadir)/locale\" \
-DEFL_BETA_API_SUPPORT \
@EFL_CFLAGS@
@ -15,7 +15,7 @@ elm_code_test_SOURCES = \
elm_code_test_main.c \
elm_code_test_private.h
elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la
elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/src/lib/libelm_code.la
elm_code_test_LDFLAGS = @EFL_LTLIBRARY_FLAGS@

View File

@ -3,12 +3,13 @@ MAINTAINERCLEANFILES = Makefile.in
CLEANFILES=
EOLIAN_FLAGS = @DEPS_EOLIAN_FLAGS@ \
-I$(top_srcdir)/elm_code/lib
-I$(top_srcdir)/elm_code/src/lib
include $(top_srcdir)/Makefile_Eolian_Helper.am
AM_CPPFLAGS = \
-I$(top_srcdir)/elm_code/lib \
-I$(top_srcdir)/elm_code/src/lib \
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
-DEFL_BETA_API_SUPPORT \
-DEFL_EO_API_SUPPORT \
@EFL_CFLAGS@ \

View File

@ -35,7 +35,6 @@ typedef struct
double gravity_x, gravity_y;
unsigned int cursor_line, cursor_col;
Eina_Bool cursor_move_vetoed;
Eina_Bool editable, focussed;
Eina_Bool show_line_numbers;
} Elm_Code_Widget_Data;

View File

@ -35,7 +35,6 @@ _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUS
pd->cursor_line = 1;
pd->cursor_col = 1;
pd->cursor_move_vetoed = EINA_TRUE;
}
EOLIAN static void
@ -271,6 +270,57 @@ _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EIN
_elm_code_widget_fill(widget);
}
static Eina_Bool
_elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, const char *key)
{
Elm_Code_Widget_Data *pd;
Elm_Code_Line *line;
pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
line = elm_code_file_line_get(pd->code->file, pd->cursor_line);
if (!line)
return EINA_FALSE;
if (!strcmp(key, "Up"))
return pd->cursor_line > 1;
else if (!strcmp(key, "Down"))
return pd->cursor_line < elm_code_file_lines_get(pd->code->file);
else if (!strcmp(key, "Left"))
return pd->cursor_col > 1;
else if (!strcmp(key, "Right"))
return pd->cursor_col < (unsigned int) line->length + 1;
else
return EINA_FALSE;
}
static void
_elm_code_widget_update_focus_directions(Elm_Code_Widget *obj)
{
if (_elm_code_widget_cursor_key_will_move(obj, "Up"))
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_UP);
else
elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_UP);
if (_elm_code_widget_cursor_key_will_move(obj, "Down"))
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_DOWN);
else
elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_DOWN);
if (_elm_code_widget_cursor_key_will_move(obj, "Left"))
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_LEFT);
else
elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_LEFT);
if (_elm_code_widget_cursor_key_will_move(obj, "Right"))
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_RIGHT);
else
elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_RIGHT);
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_PREVIOUS);
elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_NEXT);
}
static void
_elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas_Coord y)
{
@ -298,6 +348,7 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas
if (pd->cursor_col == 0)
pd->cursor_col = 1;
_elm_code_widget_update_focus_directions(widget);
_elm_code_widget_fill(widget);
}
@ -407,42 +458,6 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget)
_elm_code_widget_fill(widget);
}
static Eina_Bool
_elm_code_widget_cursor_key_can_control(Evas_Event_Key_Down *event)
{
if (!strcmp(event->key, "Up"))
return EINA_TRUE;
else if (!strcmp(event->key, "Down"))
return EINA_TRUE;
else if (!strcmp(event->key, "Left"))
return EINA_TRUE;
else if (!strcmp(event->key, "Right"))
return EINA_TRUE;
else
return EINA_FALSE;
}
static Eina_Bool
_elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, Evas_Event_Key_Down *event)
{
Elm_Code_Widget_Data *pd;
Elm_Code_Line *line;
pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
line = elm_code_file_line_get(pd->code->file, pd->cursor_line);
if (!strcmp(event->key, "Up"))
return pd->cursor_line > 1;
else if (!strcmp(event->key, "Down"))
return pd->cursor_line < elm_code_file_lines_get(pd->code->file);
else if (!strcmp(event->key, "Left"))
return pd->cursor_col > 1;
else if (!strcmp(event->key, "Right"))
return pd->cursor_col < (unsigned int) line->length + 1;
else
return EINA_FALSE;
}
static void
_elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event_info)
@ -458,12 +473,7 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
if (!pd->editable)
return;
pd->cursor_move_vetoed = EINA_TRUE;
if (_elm_code_widget_cursor_key_can_control(ev) && !_elm_code_widget_cursor_key_will_move(widget, ev))
{
pd->cursor_move_vetoed = EINA_FALSE;
return;
}
_elm_code_widget_update_focus_directions(widget);
if (!strcmp(ev->key, "Up"))
_elm_code_widget_cursor_move_up(widget);
@ -477,48 +487,34 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
INF("Unhandled key %s", ev->key);
}
static Eina_Bool
_elm_code_widget_event_veto_cb(void *data, Evas_Object *obj EINA_UNUSED,
Evas_Object *src EINA_UNUSED, Evas_Callback_Type type,
void *event_info EINA_UNUSED)
static void
_elm_code_widget_focused_event_cb(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
Elm_Code_Widget *widget;
Elm_Code_Widget_Data *pd;
Eina_Bool vetoed;
widget = (Elm_Code_Widget *)data;
pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
if (!pd->editable)
return EINA_FALSE;
pd->focussed = EINA_TRUE;
vetoed = EINA_TRUE;
if (type == EVAS_CALLBACK_KEY_DOWN)
{
vetoed = pd->cursor_move_vetoed;
pd->cursor_move_vetoed = EINA_TRUE;
}
return vetoed;
_elm_code_widget_update_focus_directions(widget);
_elm_code_widget_fill(obj);
}
EOLIAN static Eina_Bool
_elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd)
static void
_elm_code_widget_unfocused_event_cb(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
Eina_Bool int_ret;
Elm_Code_Widget *widget;
Elm_Code_Widget_Data *pd;
if (!pd->editable)
return EINA_FALSE;
eo_do_super(obj, ELM_CODE_WIDGET_CLASS, int_ret = elm_obj_widget_on_focus());
if (!int_ret)
return EINA_TRUE;
pd->focussed = elm_widget_focus_get(obj);
widget = (Elm_Code_Widget *)data;
pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
pd->focussed = EINA_FALSE;
_elm_code_widget_fill(obj);
return pd->focussed;
}
EOLIAN static Eina_Bool
@ -652,11 +648,14 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd)
eo_do_super(obj, ELM_CODE_WIDGET_CLASS, evas_obj_smart_add());
elm_object_focus_allow_set(obj, EINA_TRUE);
elm_layout_file_set(obj, PACKAGE_DATA_DIR "/themes/elm_code.edj", "elm_code/layout/default");
scroller = elm_scroller_add(obj);
evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(scroller);
elm_box_pack_end(obj, scroller);
elm_layout_content_set(obj, "elm.swallow.content", scroller);
elm_object_focus_allow_set(scroller, EINA_FALSE);
pd->scroller = scroller;
grid = evas_object_textgrid_add(obj);
@ -667,11 +666,12 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd)
pd->grid = grid;
_elm_code_widget_setup_palette(grid);
evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj);
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj);
evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, obj);
evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj);
elm_object_event_callback_add(obj, _elm_code_widget_event_veto_cb, obj);
evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj);
evas_object_smart_callback_add(obj, "unfocused", _elm_code_widget_unfocused_event_cb, obj);
eo_do(obj,
eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, obj);

View File

@ -1,4 +1,4 @@
class Elm_Code_Widget (Elm_Box, Elm_Interface_Atspi_Text)
class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text)
{
eo_prefix: elm_code_widget;
properties {
@ -110,7 +110,6 @@ class Elm_Code_Widget (Elm_Box, Elm_Interface_Atspi_Text)
class.constructor;
Eo.Base.constructor;
Evas.Object_Smart.add;
Elm_Widget.on_focus;
Elm_Widget.focus_next_manager_is;
Elm_Widget.focus_direction_manager_is;
}

View File

@ -47,9 +47,6 @@ void _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd);
void _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd);
Eina_Bool _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd);
Eina_Bool _elm_code_widget_elm_widget_focus_next_manager_is(Eo *obj, Elm_Code_Widget_Data *pd);
@ -59,7 +56,6 @@ Eina_Bool _elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj, Elm_Co
static Eo_Op_Description _elm_code_widget_op_desc[] = {
EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget_eo_base_constructor),
EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget_evas_object_smart_add),
EO_OP_FUNC_OVERRIDE(elm_obj_widget_on_focus, _elm_code_widget_elm_widget_on_focus),
EO_OP_FUNC_OVERRIDE(elm_obj_widget_focus_next_manager_is, _elm_code_widget_elm_widget_focus_next_manager_is),
EO_OP_FUNC_OVERRIDE(elm_obj_widget_focus_direction_manager_is, _elm_code_widget_elm_widget_focus_direction_manager_is),
EO_OP_FUNC(elm_code_widget_code_set, _elm_code_widget_code_set, "Set the underlying code object that this widget renders"),
@ -91,4 +87,4 @@ static const Eo_Class_Description _elm_code_widget_class_desc = {
NULL
};
EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL);
EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_LAYOUT_CLASS, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL);

View File

@ -13,19 +13,19 @@ elm_code_test_parse.c \
elm_code_test_widget.c \
elm_code_suite.c
elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \
elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \
-DEFL_BETA_API_SUPPORT \
-DEFL_EO_API_SUPPORT \
-I$(top_srcdir)/elm_code/lib \
-DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/tests/\" \
-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/tests/\" \
-I$(top_srcdir)/elm_code/src/lib \
-DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/src/tests/\" \
-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/src/tests/\" \
-DTESTS_DIR=\"$(abspath $(srcdir))/\" \
-DEFL_BETA_API_SUPPORT \
@EFL_CFLAGS@ \
@CHECK_CFLAGS@
elm_code_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la
elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/lib/libelm_code.la
elm_code_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/elm_code/src/lib/libelm_code.la
elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/src/lib/libelm_code.la
testdir = $(PACKAGE_TESTS_DIR)
test_DATA = \

View File

@ -11,7 +11,7 @@ AM_CPPFLAGS = \
-DLOCALEDIR=\"$(datadir)/locale\" \
-I$(top_srcdir)/src/lib \
-I$(top_srcdir)/src/bin \
-I$(top_srcdir)/elm_code/lib \
-I$(top_srcdir)/elm_code/src/lib \
-I$(top_builddir)/src/lib \
-DEFL_BETA_API_SUPPORT \
@EFL_CFLAGS@
@ -42,7 +42,7 @@ mainview/edi_mainview.c \
edi_main.c \
edi_private.h
edi_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la $(top_builddir)/src/lib/libedi.la $(LTLIBINTL)
edi_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/src/lib/libelm_code.la $(top_builddir)/src/lib/libedi.la $(LTLIBINTL)
edi_build_SOURCES = \
edi_build_main.c

View File

@ -12,7 +12,7 @@ edi_suite.c
edi_suite_CPPFLAGS = -I$(top_builddir)/src/lib/ -I$(top_builddir)/src/bin/ \
-I$(top_srcdir)/src/lib \
-I$(top_srcdir)/elm_code/lib \
-I$(top_srcdir)/elm_code/src/lib \
-I$(top_srcdir)/src/bin \
-DPACKAGE_TESTS_DIR=\"$(top_srcdir)/src/tests/\" \
-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/src/tests/\" \
@ -20,8 +20,8 @@ edi_suite_CPPFLAGS = -I$(top_builddir)/src/lib/ -I$(top_builddir)/src/bin/ \
@EFL_CFLAGS@ \
@CHECK_CFLAGS@
edi_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/src/lib/libedi.la $(top_builddir)/elm_code/lib/libelm_code.la
edi_suite_DEPENDENCIES = $(top_builddir)/src/lib/libedi.la $(top_builddir)/elm_code/lib/libelm_code.la
edi_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/src/lib/libedi.la $(top_builddir)/elm_code/src/lib/libelm_code.la
edi_suite_DEPENDENCIES = $(top_builddir)/src/lib/libedi.la $(top_builddir)/elm_code/src/lib/libelm_code.la
endif