widget: Simplify code with rectangle (EO)
authorJean-Philippe Andre <jp.andre@samsung.com>
Tue, 29 Aug 2017 05:29:45 +0000 (14:29 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Tue, 29 Aug 2017 05:30:39 +0000 (14:30 +0900)
This replaces x,y,w,h with a rectangle in parts of the focus_region
code.

Ref T5363

src/lib/elementary/efl_ui_text.c
src/lib/elementary/elm_conform.c
src/lib/elementary/elm_entry.c
src/lib/elementary/elm_gengrid.c
src/lib/elementary/elm_panel.c
src/lib/elementary/elm_widget.c
src/lib/elementary/elm_widget.eo
src/lib/elementary/elm_widget.h

index dc3fadb..46da72e 100644 (file)
@@ -1203,28 +1203,28 @@ _efl_ui_text_elm_widget_on_focus(Eo *obj, Efl_Ui_Text_Data *sd, Elm_Object_Item
 }
 
 EOLIAN static Eina_Bool
-_efl_ui_text_elm_widget_focus_region_get(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
+_efl_ui_text_elm_widget_focus_region_get(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd, Eina_Rectangle *r)
 {
    Evas_Coord edje_x, edje_y, elm_x, elm_y;
 
+   EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE);
    efl_text_cursor_geometry_get(obj,
          efl_text_cursor_get(obj, EFL_TEXT_CURSOR_GET_MAIN),
          EFL_TEXT_CURSOR_TYPE_BEFORE,
-         x, y, w, h,
+         &r->x, &r->y, &r->w, &r->h,
          NULL, NULL, NULL, NULL);
 
    if (sd->single_line)
      {
-        evas_object_geometry_get(sd->entry_edje, NULL, NULL, NULL, h);
-        if (y) *y = 0;
+        evas_object_geometry_get(sd->entry_edje, NULL, NULL, NULL, &r->h);
+        r->y = 0;
      }
 
    evas_object_geometry_get(sd->entry_edje, &edje_x, &edje_y, NULL, NULL);
-
    evas_object_geometry_get(obj, &elm_x, &elm_y, NULL, NULL);
 
-   if (x) *x += edje_x - elm_x;
-   if (y) *y += edje_y - elm_y;
+   r->x += edje_x - elm_x;
+   r->y += edje_y - elm_y;
 
    return EINA_TRUE;
 }
index c7cb1f7..25b1e49 100644 (file)
@@ -663,14 +663,14 @@ _show_region_job(void *data)
    focus_obj = elm_widget_focused_object_get(data);
    if (focus_obj)
      {
-        Evas_Coord x, y, w, h;
+        Eina_Rectangle r;
 
-        elm_widget_focus_region_get(focus_obj, &x, &y, &w, &h);
+        elm_widget_focus_region_get(focus_obj, &r);
 
-        if (h < _elm_config->finger_size)
-          h = _elm_config->finger_size;
+        if (r.h < _elm_config->finger_size)
+          r.h = _elm_config->finger_size;
 
-        elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
+        elm_widget_show_region_set(focus_obj, r.x, r.y, r.w, r.h, EINA_TRUE);
      }
 
    sd->show_region_job = NULL;
index b45fae5..b9b0cb2 100644 (file)
@@ -1309,12 +1309,13 @@ _elm_entry_elm_widget_on_focus(Eo *obj, Elm_Entry_Data *sd, Elm_Object_Item *ite
 }
 
 EOLIAN static Eina_Bool
-_elm_entry_elm_widget_focus_region_get(Eo *obj, Elm_Entry_Data *sd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
+_elm_entry_elm_widget_focus_region_get(Eo *obj, Elm_Entry_Data *sd, Eina_Rectangle *r)
 {
    Evas_Coord cx, cy, cw, ch;
    Evas_Coord edx, edy;
    Evas_Coord elx, ely, elw, elh;
 
+   EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE);
    edje_object_part_text_cursor_geometry_get
      (sd->entry_edje, "elm.text", &cx, &cy, &cw, &ch);
 
@@ -1329,19 +1330,12 @@ _elm_entry_elm_widget_focus_region_get(Eo *obj, Elm_Entry_Data *sd, Evas_Coord *
      }
    evas_object_geometry_get(obj, &elx, &ely, &elw, &elh);
 
-   if (x)
-     {    
-       *x = cx + edx - elx;
-       if ((cw < elw) && (*x + cw > elw)) *x = elw - cw;
-     }
-   if (y)
-     {    
-       *y = cy + edy - ely;
-       if ((ch < elh) && (*y + ch > elh)) *y = elh - ch;
-     }
-   if (w) *w = cw;
-   if (h) *h = ch;
-
+   r->x = cx + edx - elx;
+   if ((cw < elw) && (r->x + cw > elw)) r->x = elw - cw;
+   r->y = cy + edy - ely;
+   if ((ch < elh) && (r->y + ch > elh)) r->y = elh - ch;
+   r->w = cw;
+   r->h = ch;
 
    return EINA_TRUE;
 }
index c2d35c4..d0a837b 100644 (file)
@@ -3540,24 +3540,25 @@ _elm_gengrid_elm_widget_on_focus(Eo *obj, Elm_Gengrid_Data *sd, Elm_Object_Item
 }
 
 EOLIAN static Eina_Bool
-_elm_gengrid_elm_widget_focus_region_get(Eo *obj, Elm_Gengrid_Data *sd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
+_elm_gengrid_elm_widget_focus_region_get(Eo *obj, Elm_Gengrid_Data *sd, Eina_Rectangle *r)
 {
+   EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE);
    if (!sd->focused_item) goto end;
    if (elm_object_focus_region_show_mode_get(obj) == ELM_FOCUS_REGION_SHOW_ITEM)
      {
         Evas_Coord vx, vy;
         ELM_GENGRID_ITEM_DATA_GET(sd->focused_item, focus_it);
-        evas_object_geometry_get(VIEW(focus_it), x, y, w, h);
+        evas_object_geometry_get(VIEW(focus_it), &r->x, &r->y, &r->w, &r->h);
         evas_object_geometry_get(obj, &vx, &vy, NULL, NULL);
 
-        *x -= vx;
-        *y -= vy;
+        r->x -= vx;
+        r->y -= vy;
 
         return EINA_TRUE;
      }
 
 end:
-   return elm_obj_widget_focus_region_get(efl_super(obj, MY_CLASS), x, y, w, h);
+   return elm_obj_widget_focus_region_get(efl_super(obj, MY_CLASS), r);
 }
 
 static Eina_Bool _elm_gengrid_smart_focus_next_enable = EINA_FALSE;
index c388e58..7b95f27 100644 (file)
@@ -1107,24 +1107,19 @@ _elm_panel_toggle(Eo *obj, Elm_Panel_Data *_pd EINA_UNUSED)
 }
 
 EOLIAN static Eina_Bool
-_elm_panel_elm_widget_focus_region_get(Eo *obj,
-                                      Elm_Panel_Data *sd,
-                                      Evas_Coord *x,
-                                      Evas_Coord *y,
-                                      Evas_Coord *w,
-                                      Evas_Coord *h)
+_elm_panel_elm_widget_focus_region_get(Eo *obj, Elm_Panel_Data *sd, Eina_Rectangle *r)
 {
-   elm_interface_scrollable_content_pos_get(obj, x, y);
-   evas_object_geometry_get(obj, NULL, NULL, w, h);
+   elm_interface_scrollable_content_pos_get(obj, &r->x, &r->y);
+   evas_object_geometry_get(obj, NULL, NULL, &r->w, &r->h);
    switch (sd->orient)
      {
       case ELM_PANEL_ORIENT_TOP:
       case ELM_PANEL_ORIENT_BOTTOM:
-         *h = *h * sd->content_size_ratio;
+         r->h *= sd->content_size_ratio;
          break;
       case ELM_PANEL_ORIENT_LEFT:
       case ELM_PANEL_ORIENT_RIGHT:
-         *w = *w * sd->content_size_ratio;
+         r->w *= sd->content_size_ratio;
          break;
      }
    return EINA_TRUE;
index cf85604..0b2c7c1 100644 (file)
@@ -1031,13 +1031,14 @@ _propagate_event_legacy(Eo *parent, const Efl_Event *event, Eo *obj, Elm_Event_C
 EOLIAN static void
 _elm_widget_focus_region_show(const Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
 {
-   Evas_Coord x, y, w, h, ox, oy;
+   Evas_Coord ox, oy;
+   Eina_Rectangle r;
    Evas_Object *o;
 
    o = elm_widget_parent_get(obj);
    if (!o) return;
 
-   if (!elm_widget_focus_region_get(obj, &x, &y, &w, &h))
+   if (!elm_widget_focus_region_get(obj, &r))
      return;
 
    evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
@@ -1054,28 +1055,28 @@ _elm_widget_focus_region_show(const Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNU
 
              // Get the object's on_focus_region position relative to the scroller.
              Evas_Coord rx, ry;
-             rx = ox + x - px + sx;
-             ry = oy + y - py + sy;
+             rx = ox + r.x - px + sx;
+             ry = oy + r.y - py + sy;
 
              switch (_elm_config->focus_autoscroll_mode)
                {
                 case ELM_FOCUS_AUTOSCROLL_MODE_SHOW:
-                   elm_interface_scrollable_content_region_show(o, rx, ry, w, h);
+                   elm_interface_scrollable_content_region_show(o, rx, ry, r.w, r.h);
                    break;
                 case ELM_FOCUS_AUTOSCROLL_MODE_BRING_IN:
-                   elm_interface_scrollable_region_bring_in(o, rx, ry, w, h);
+                   elm_interface_scrollable_region_bring_in(o, rx, ry, r.w, r.h);
                    break;
                 default:
                    break;
                }
 
-             elm_widget_focus_region_get(o, &x, &y, &w, &h);
+             elm_widget_focus_region_get(o, &r);
              evas_object_geometry_get(o, &ox, &oy, NULL, NULL);
           }
         else
           {
-             x += ox - px;
-             y += oy - py;
+             r.x += ox - px;
+             r.y += oy - py;
              ox = px;
              oy = py;
           }
@@ -3476,12 +3477,13 @@ _elm_widget_show_region_get(const Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd
  * @ingroup Widget
  */
 EOLIAN static Eina_Bool
-_elm_widget_focus_region_get(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
+_elm_widget_focus_region_get(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Eina_Rectangle *r)
 {
-   efl_gfx_size_get(obj, w, h);
-   if (x) *x = 0;
-   if (y) *y = 0;
-   if ((*w <= 0) || (*h <= 0)) return EINA_FALSE;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE);
+   efl_gfx_size_get(obj, &r->w, &r->h);
+   r->x = 0;
+   r->y = 0;
+   if ((r->w <= 0) || (r->h <= 0)) return EINA_FALSE;
    return EINA_TRUE;
 }
 
index 92fed41..8c62d96 100644 (file)
@@ -496,7 +496,6 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
          [[Pop scroller freeze]]
       }
 
-      /* Old focus API. FIXME: Needs massive clean up! */
       @property focus_region {
          [[Region to show when focus changes within this widget.
 
@@ -517,12 +516,11 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
             return: bool; [[If $false, @.focus_region_show will not do anything.]]
          }
          values {
-            x: int; [[X coordinate]]
-            y: int; [[Y coordinate]]
-            w: int; [[Width]]
-            h: int; [[Height]]
+            region: Eina.Rectangle; [[The relative region to show.]]
          }
       }
+
+      /* Old focus API. FIXME: Needs massive clean up! */
       @property focus_order {
          [[Focus order property]]
          get {
index 4e062e4..89bdc94 100644 (file)
@@ -721,7 +721,7 @@ EAPI void             elm_widget_disabled_set(Evas_Object *obj, Eina_Bool disabl
 EAPI Eina_Bool        elm_widget_disabled_get(const Evas_Object *obj);
 EAPI void             elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool forceshow);
 EAPI void             elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
-EAPI Eina_Bool        elm_widget_focus_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
+EAPI Eina_Bool        elm_widget_focus_region_get(const Evas_Object *obj, Eina_Rectangle *r);
 EAPI void             elm_widget_focus_region_show(const Evas_Object *obj);
 EAPI void             elm_widget_scroll_hold_push(Evas_Object *obj);
 EAPI void             elm_widget_scroll_hold_pop(Evas_Object *obj);