Enlightenment CVS committal
Author : jethomas
Project : e17
Module : libs/ewl
Dir : e17/libs/ewl/src/lib
Modified Files:
ewl_entry.c ewl_text.c ewl_text.h
Log Message:
Add keybindings for shift+arrow keys and don't delete selected text when you
press the arrow keys.
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_entry.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -3 -r1.91 -r1.92
--- ewl_entry.c 9 Jul 2008 23:29:35 -0000 1.91
+++ ewl_entry.c 13 Jul 2008 00:05:41 -0000 1.92
@@ -373,6 +373,7 @@
{
Ewl_Event_Key *event;
Ewl_Entry *e;
+ Ewl_Text_Trigger *sel;
DENTER_FUNCTION(DLEVEL_STABLE);
DCHECK_PARAM_PTR(w);
@@ -380,35 +381,44 @@
event = ev;
e = EWL_ENTRY(w);
+ sel = EWL_TEXT_TRIGGER(EWL_TEXT(w)->selection);
/* reset the cursor blink */
ewl_widget_state_set(EWL_WIDGET(e->cursor), "noblink",
EWL_STATE_PERSISTENT);
- if (!event->keyname)
+ if ((!event->keyname) || (!event->keyname[0]))
+ DRETURN(DLEVEL_STABLE);
+
+ /* If we are holding shift and key pressed isn't a character,
+ * then this is a selection event
+ */
+ if ((event->modifiers & EWL_KEY_MODIFIER_SHIFT) &&
+ ((event->keyname[1] != '\0') &&
+ (event->keyname[0] >= 0)))
DRETURN(DLEVEL_STABLE);
if (!strcmp(event->keyname, "Left"))
{
- ewl_entry_selection_clear(e);
+ if (sel) ewl_text_trigger_length_set(sel, 0);
ewl_entry_cursor_move_left(e);
}
else if (!strcmp(event->keyname, "Right"))
{
- ewl_entry_selection_clear(e);
+ if (sel) ewl_text_trigger_length_set(sel, 0);
ewl_entry_cursor_move_right(e);
}
else if (!strcmp(event->keyname, "Up"))
{
- ewl_entry_selection_clear(e);
+ if (sel) ewl_text_trigger_length_set(sel, 0);
ewl_entry_cursor_move_up(e);
}
else if (!strcmp(event->keyname, "Down"))
{
- ewl_entry_selection_clear(e);
+ if (sel) ewl_text_trigger_length_set(sel, 0);
ewl_entry_cursor_move_down(e);
}
@@ -447,6 +457,11 @@
ewl_entry_cursor_position_get(
EWL_ENTRY_CURSOR(e->cursor)));
}
+
+ if (sel)
+ ewl_text_trigger_base_set(sel,
+ ewl_entry_cursor_position_get(
+ EWL_ENTRY_CURSOR(e->cursor)));
DLEAVE_FUNCTION(DLEVEL_STABLE);
}
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text.c,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -3 -r1.202 -r1.203
--- ewl_text.c 6 Jul 2008 04:18:52 -0000 1.202
+++ ewl_text.c 13 Jul 2008 00:05:41 -0000 1.203
@@ -831,6 +831,8 @@
ewl_text_cb_mouse_down, NULL);
ewl_callback_append(EWL_WIDGET(t), EWL_CALLBACK_MOUSE_UP,
ewl_text_cb_mouse_up, NULL);
+ ewl_callback_append(EWL_WIDGET(t), EWL_CALLBACK_KEY_DOWN,
+ ewl_text_cb_key_down, NULL);
}
else
{
@@ -838,6 +840,8 @@
ewl_text_cb_mouse_down);
ewl_callback_del(EWL_WIDGET(t), EWL_CALLBACK_MOUSE_UP,
ewl_text_cb_mouse_up);
+ ewl_callback_del(EWL_WIDGET(t), EWL_CALLBACK_KEY_DOWN,
+ ewl_text_cb_key_down);
}
DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -3479,6 +3483,7 @@
event->y);
char_idx = ewl_text_coord_index_map(EWL_TEXT(w), event->x, event->y);
+ ewl_text_cursor_position_set(t, char_idx);
modifiers = ewl_ev_modifiers_get();
if (modifiers & EWL_KEY_MODIFIER_SHIFT)
{
@@ -3515,6 +3520,8 @@
Ewl_Text *t;
Ewl_Event_Mouse *event;
unsigned int modifiers;
+ unsigned int char_idx = 0;
+
DENTER_FUNCTION(DLEVEL_STABLE);
DCHECK_PARAM_PTR(w);
@@ -3527,16 +3534,13 @@
t->in_select = FALSE;
ewl_callback_del(w, EWL_CALLBACK_MOUSE_MOVE, ewl_text_cb_mouse_move);
+ char_idx = ewl_text_coord_index_map(t, event->x, event->y);
+ ewl_text_cursor_position_set(t, char_idx);
modifiers = ewl_ev_modifiers_get();
if (modifiers & EWL_KEY_MODIFIER_SHIFT)
- {
- unsigned int char_idx = 0;
-
- char_idx = ewl_text_coord_index_map(EWL_TEXT(w), event->x,
event->y);
ewl_text_selection_select_to(EWL_TEXT_TRIGGER(t->selection),
char_idx);
- }
ewl_text_trigger_position(t, EWL_TEXT_TRIGGER(t->selection));
DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -3571,6 +3575,76 @@
ewl_text_selection_select_to(EWL_TEXT_TRIGGER(t->selection),
char_idx);
ewl_text_trigger_position(t, EWL_TEXT_TRIGGER(t->selection));
}
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+void
+ewl_text_cb_key_down(Ewl_Widget *w, void *ev, void *data __UNUSED__)
+{
+ Ewl_Text *t;
+ Ewl_Event_Key *event;
+ Ewl_Text_Trigger *sel;
+ unsigned int pos = 0;
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR(w);
+ DCHECK_TYPE(w, EWL_TEXT_TYPE);
+
+ t = EWL_TEXT(w);
+ event = ev;
+
+ if ((!event->keyname) || (!event->keyname[0]))
+ DRETURN(DLEVEL_STABLE);
+
+ if ((!(event->modifiers & EWL_KEY_MODIFIER_SHIFT)) ||
+ (event->keyname[1] == '\0'))
+ DRETURN(DLEVEL_STABLE);
+
+ if (!t->selection)
+ {
+ t->selection = ewl_text_selection_new(t);
+
+ /* This can happen after key/mouse actions, so default to
+ * wherever the cursor is at this point, not 0
+ */
+ ewl_text_trigger_base_set(EWL_TEXT_TRIGGER(t->selection),
+ ewl_text_cursor_position_get(t));
+
+ /* Same problem as mouse_down... place it inside the
+ * text widget */
+ ewl_object_position_request(EWL_OBJECT(t->selection),
+ CURRENT_X(w) + 1, CURRENT_Y(w) + 1);
+ }
+
+ sel = EWL_TEXT_TRIGGER(t->selection);
+
+ if (!strcmp(event->keyname, "Left"))
+ {
+ pos = t->cursor_position;
+ if (pos > 0) pos--;
+ }
+
+ else if (!strcmp(event->keyname, "Right"))
+ {
+ pos = t->cursor_position;
+ if (pos < t->length.chars) pos++;
+ }
+
+ else if (!strcmp(event->keyname, "Up"))
+ pos = ewl_text_cursor_position_line_up_get(t);
+
+ else if (!strcmp(event->keyname, "Down"))
+ pos = ewl_text_cursor_position_line_down_get(t);
+ else
+ DRETURN(DLEVEL_STABLE);
+
+ /* Resize the selection */
+
+ ewl_text_selection_select_to(sel, pos);
+ ewl_text_trigger_position(t, sel);
+ ewl_text_cursor_position_set(t, pos);
+ ewl_widget_configure(w);
DLEAVE_FUNCTION(DLEVEL_STABLE);
}
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -3 -r1.65 -r1.66
--- ewl_text.h 5 Jul 2008 18:03:53 -0000 1.65
+++ ewl_text.h 13 Jul 2008 00:05:41 -0000 1.66
@@ -304,6 +304,7 @@
void ewl_text_cb_mouse_down(Ewl_Widget *w, void *ev, void *data);
void ewl_text_cb_mouse_up(Ewl_Widget *w, void *ev, void *data);
void ewl_text_cb_mouse_move(Ewl_Widget *w, void *ev, void *data);
+void ewl_text_cb_key_down(Ewl_Widget *w, void *ev, void *data);
void ewl_text_cb_child_add(Ewl_Container *c, Ewl_Widget *w);
void ewl_text_cb_child_remove(Ewl_Container *c, Ewl_Widget *w, int idx);
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs