Enlightenment CVS committal

Author  : dj2
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_text.c ewl_text.h 


Log Message:
- change the trigger code a bit. remove the trigger_add and trigger_del
  calls. You now just ewl_container_child_append the trigger into the text
  and it will figure it out from there

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_text.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- ewl_text.c  21 Jul 2005 00:47:58 -0000      1.10
+++ ewl_text.c  21 Jul 2005 04:04:32 -0000      1.11
@@ -44,6 +44,9 @@
 static void ewl_text_triggers_shift(Ewl_Text *t, unsigned int pos, 
                                                        unsigned int len);
 
+static void ewl_text_trigger_add(Ewl_Text *t, Ewl_Text_Trigger *trigger);
+static void ewl_text_trigger_del(Ewl_Text *t, Ewl_Text_Trigger *trigger);
+
 /**
  * @param text: The text to set into the widget
  * @return Returns a new Ewl_Text widget on success, NULL on failure.
@@ -112,6 +115,11 @@
        ewl_callback_append(EWL_WIDGET(t), EWL_CALLBACK_DESTROY,
                                        ewl_text_cb_destroy, NULL);
 
+       ewl_container_add_notify_set(EWL_CONTAINER(t), 
+                                       ewl_text_cb_child_add);
+       ewl_container_remove_notify_set(EWL_CONTAINER(t), 
+                                       ewl_text_cb_child_del);
+
        DRETURN_INT(TRUE, DLEVEL_STABLE);
 }
 
@@ -1716,98 +1724,6 @@
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
-/**
- * @param t: The Ewl_Text into which to add the trigger
- * @param trigger: The Ewl_Text_Trigger to add to the text
- * @return Returns TRUE on successfull addition or FALSE on failure
- *
- * This will add the given trigger. The trigger must have size greater then
- * 0, the trigger must not run over the end of the text and two triggers can
- * not overlap.
- */
-unsigned int
-ewl_text_trigger_add(Ewl_Text *t, Ewl_Text_Trigger *trigger)
-{
-       Ewl_Text_Trigger *cur;
-
-       DENTER_FUNCTION(DLEVEL_STABLE);
-       DCHECK_PARAM_PTR_RET("t", t, FALSE);
-       DCHECK_PARAM_PTR_RET("trigger", trigger, FALSE);
-
-       /* if we have no length, we start past the end of the text, or we
-        * extend past the end of the text then return an error */
-       if ((trigger->len == 0) || (trigger->pos > t->length)
-                       || ((trigger->pos + trigger->len) > t->length))
-       {
-               DRETURN_INT(FALSE, DLEVEL_STABLE);
-       }
-
-       trigger->parent = t;
-
-       ecore_list_goto_first(t->triggers);
-       while ((cur = ecore_list_next(t->triggers)))
-       {
-               if (trigger->pos < cur->pos)
-               {
-                       if ((trigger->pos + trigger->len) < cur->pos)
-                               break;
-                       /* overlapping triggers */
-                       DWARNING("Overlapping triggers are not allowed.\n");
-                       DRETURN_INT(FALSE, DLEVEL_STABLE);
-               }
-
-               if ((trigger->pos > (cur->pos + cur->len)))
-                       continue;
-
-               /* do not allow overlapping triggers */
-               if ((trigger->pos >= cur->pos) && (trigger->pos <= (cur->pos + 
cur->len)))
-               {
-                       DWARNING("Overlapping triggers are not allowed.\n");
-                       DRETURN_INT(FALSE, DLEVEL_STABLE);
-               }
-       }
-
-       if (cur)
-       {
-               /* we need to set our position to the one before the one we 
-                * are on because the _next callin the while will have
-                * advanced usto the next node, but we want to insert
-                * at the one before that */
-               ecore_list_goto_index(t->triggers, 
ecore_list_index(t->triggers) - 1);
-                ecore_list_insert(t->triggers, trigger);
-       }
-       else 
-               ecore_list_append(t->triggers, trigger);
-
-       /* we have to append this to the text so it will get cleaned up when
-        * the text widget is destroyed */
-       ewl_container_child_append(EWL_CONTAINER(t), EWL_WIDGET(trigger));
-
-       DRETURN_INT(TRUE, DLEVEL_STABLE);
-}
-
-/**
- * @param t: The Ewl_Text to remove the trigger from
- * @param trigger: The Ewl_Text_Trigger to remove
- *
- * This will remove the trigger from the text, but will NOT free the
- * trigger.
- */
-void
-ewl_text_trigger_del(Ewl_Text *t, Ewl_Text_Trigger *trigger)
-{
-       DENTER_FUNCTION(DLEVEL_STABLE);
-       DCHECK_PARAM_PTR("t", t);
-       DCHECK_PARAM_PTR("trigger", trigger);
-
-       ecore_list_goto(t->triggers, trigger);
-       ecore_list_remove(t->triggers);
-
-       trigger->parent = NULL;
-
-       DLEAVE_FUNCTION(DLEVEL_STABLE);
-}
-
 static void
 ewl_text_triggers_remove(Ewl_Text *t)
 {
@@ -1882,16 +1798,30 @@
 int
 ewl_text_trigger_init(Ewl_Text_Trigger *trigger, Ewl_Text_Trigger_Type type)
 {
+       char *type_str;
+
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR_RET("trigger", trigger, FALSE);
 
-       if (!ewl_widget_init(EWL_WIDGET(trigger), "trigger"))
+       if (type == EWL_TEXT_TRIGGER_TYPE_TRIGGER)
+               type_str = strdup("trigger");
+       else if (type == EWL_TEXT_TRIGGER_TYPE_SELECTION)
+               type_str = strdup("selection");
+       else
        {
                DRETURN_INT(FALSE, DLEVEL_STABLE);
        }
-       ewl_widget_inherit(EWL_WIDGET(trigger), "trigger");
+
+       if (!ewl_widget_init(EWL_WIDGET(trigger), type_str))
+       {
+               DRETURN_INT(FALSE, DLEVEL_STABLE);
+       }
+       ewl_widget_inherit(EWL_WIDGET(trigger), type_str);
 
        trigger->areas = ecore_list_new();
+       trigger->type = type;
+
+       FREE(type_str);
 
        DRETURN_INT(TRUE, DLEVEL_STABLE);
 }
@@ -2180,6 +2110,126 @@
 }
 
 void
+ewl_text_cb_child_add(Ewl_Container *c, Ewl_Widget *w)
+{
+       char *appearance;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("c", c);
+       DCHECK_PARAM_PTR("w", w);
+
+       if (!(appearance = ewl_widget_appearance_get(w))) 
+       {
+               DRETURN(DLEVEL_STABLE);
+       }
+
+       /* if this is a trigger then add it as such */
+       if ((!strcmp(appearance, "trigger")) 
+                       || (!strcmp(appearance, "selection")))
+               ewl_text_trigger_add(EWL_TEXT(c), EWL_TEXT_TRIGGER(w));
+
+       FREE(appearance);
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+void
+ewl_text_cb_child_del(Ewl_Container *c, Ewl_Widget *w)
+{
+       char *appearance;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("c", c);
+       DCHECK_PARAM_PTR("w", w);
+
+       if (!(appearance = ewl_widget_appearance_get(w)))
+       {
+               DRETURN(DLEVEL_STABLE);
+       }
+
+       /* if this is a trigger, remove it as such */
+       if ((!strcmp(appearance, "trigger")) 
+                       || (!strcmp(appearance, "selection")))
+               ewl_text_trigger_del(EWL_TEXT(c), EWL_TEXT_TRIGGER(w));
+
+       FREE(appearance);
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+static void
+ewl_text_trigger_add(Ewl_Text *t, Ewl_Text_Trigger *trigger)
+{
+       Ewl_Text_Trigger *cur;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("t", t);
+       DCHECK_PARAM_PTR("trigger", trigger);
+
+       /* if we have no length, we start past the end of the text, or we
+        * extend past the end of the text then return an error */
+       if ((trigger->len == 0) || (trigger->pos > t->length)
+                       || ((trigger->pos + trigger->len) > t->length))
+       {
+               DRETURN(DLEVEL_STABLE);
+       }
+
+       trigger->parent = t;
+
+       ecore_list_goto_first(t->triggers);
+       while ((cur = ecore_list_next(t->triggers)))
+       {
+               if (trigger->pos < cur->pos)
+               {
+                       if ((trigger->pos + trigger->len) < cur->pos)
+                               break;
+                       /* overlapping triggers */
+                       DWARNING("Overlapping triggers are not allowed.\n");
+                       DRETURN(DLEVEL_STABLE);
+               }
+
+               if ((trigger->pos > (cur->pos + cur->len)))
+                       continue;
+
+               /* do not allow overlapping triggers */
+               if ((trigger->pos >= cur->pos) && (trigger->pos <= (cur->pos + 
cur->len)))
+               {
+                       DWARNING("Overlapping triggers are not allowed.\n");
+                       DRETURN(DLEVEL_STABLE);
+               }
+       }
+
+       if (cur)
+       {
+               /* we need to set our position to the one before the one we 
+                * are on because the _next callin the while will have
+                * advanced usto the next node, but we want to insert
+                * at the one before that */
+               ecore_list_goto_index(t->triggers, 
ecore_list_index(t->triggers) - 1);
+                ecore_list_insert(t->triggers, trigger);
+       }
+       else 
+               ecore_list_append(t->triggers, trigger);
+
+       DRETURN(DLEVEL_STABLE);
+}
+
+static void
+ewl_text_trigger_del(Ewl_Text *t, Ewl_Text_Trigger *trigger)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("t", t);
+       DCHECK_PARAM_PTR("trigger", trigger);
+
+       ecore_list_goto(t->triggers, trigger);
+       ecore_list_remove(t->triggers);
+
+       trigger->parent = NULL;
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+void
 ewl_text_cb_configure(Ewl_Widget *w, void *ev, void *data)
 {
        Ewl_Text *t;
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_text.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- ewl_text.h  21 Jul 2005 00:47:58 -0000      1.7
+++ ewl_text.h  21 Jul 2005 04:04:33 -0000      1.8
@@ -176,9 +176,6 @@
                                                        unsigned int *b, 
unsigned int *a,
                                                        unsigned int idx);
 
-unsigned int    ewl_text_trigger_add(Ewl_Text *t, Ewl_Text_Trigger *trigger);
-void            ewl_text_trigger_del(Ewl_Text *t, Ewl_Text_Trigger *trigger);
-
 /*
  * Trigger stuf
  */
@@ -226,6 +223,9 @@
 void ewl_text_cb_hide(Ewl_Widget *w, void *ev, void *data);
 void ewl_text_cb_destroy(Ewl_Widget *w, void *ev, void *data);
 
+void ewl_text_cb_child_add(Ewl_Container *c, Ewl_Widget *w);
+void ewl_text_cb_child_del(Ewl_Container *c, Ewl_Widget *w);
+
 void ewl_text_trigger_cb_focus_in(Ewl_Widget *w, void *ev, void *data);
 void ewl_text_trigger_cb_focus_out(Ewl_Widget *w, void *ev, void *data);
 void ewl_text_trigger_cb_mouse_up(Ewl_Widget *w, void *ev, void *data);




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to