Elementary widget: Fixed NULL checking in elm_widget_show_region_set
[framework/uifw/elementary.git] / src / lib / elm_widget.c
index 1ef0892..6d766bb 100644 (file)
@@ -61,7 +61,7 @@ struct _Smart_Data
    const char    *style;
    unsigned int   focus_order;
    Eina_Bool      focus_order_on_calc;
-   
+
    int            child_drag_x_locked;
    int            child_drag_y_locked;
 
@@ -69,7 +69,7 @@ struct _Smart_Data
 
    Eina_Bool      drag_x_locked : 1;
    Eina_Bool      drag_y_locked : 1;
-   
+
    Eina_Bool      can_focus : 1;
    Eina_Bool      child_can_focus : 1;
    Eina_Bool      focused : 1;
@@ -77,6 +77,7 @@ struct _Smart_Data
    Eina_Bool      highlight_in_theme : 1;
    Eina_Bool      disabled : 1;
    Eina_Bool      is_mirrored : 1;
+   Eina_Bool      mirrored_auto_mode : 1; /* This is TRUE by default */
 
    Eina_List     *focus_chain;
    Eina_List     *event_cb;
@@ -180,7 +181,7 @@ static void
 _sub_obj_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
 {
    Evas_Object *o = obj;
-   do 
+   do
      {
         if (_elm_widget_is(o)) break;
         o = evas_object_smart_parent_get(o);
@@ -306,7 +307,7 @@ void
 _elm_widget_type_clear(void)
 {
    const char **ptr;
-   
+
    EINA_LIST_FREE(widtypes, ptr)
      {
         eina_stringshare_del(*ptr);
@@ -562,6 +563,61 @@ elm_widget_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
      }
 }
 
+/**
+ * @internal
+ * Resets the mirrored mode from the system mirror mode for widgets that are in
+ * automatic mirroring mode. This function does not call elm_widget_theme.
+ *
+ * @param obj The widget.
+ * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
+ */
+void
+_elm_widget_mirrored_reload(Evas_Object *obj)
+{
+   API_ENTRY return;
+   Eina_Bool mirrored = elm_mirrored_get();
+   if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
+     {
+       sd->is_mirrored = mirrored;
+     }
+}
+
+/**
+ * Returns the widget's mirrored mode setting.
+ *
+ * @param obj The widget.
+ * @return mirrored mode setting of the object.
+ *
+ **/
+EAPI Eina_Bool
+elm_widget_mirrored_automatic_get(const Evas_Object *obj)
+{
+   API_ENTRY return EINA_FALSE;
+   return sd->mirrored_auto_mode;
+}
+
+/**
+ * Sets the widget's mirrored mode setting.
+ * When widget in automatic mode, it follows the system mirrored mode set by
+ * elm_mirrored_set().
+ * @param obj The widget.
+ * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
+ */
+EAPI void
+elm_widget_mirrored_automatic_set(Evas_Object *obj, Eina_Bool automatic)
+{
+   API_ENTRY return;
+   if (sd->mirrored_auto_mode != automatic)
+     {
+       sd->mirrored_auto_mode = automatic;
+
+        if (automatic)
+          {
+             elm_widget_mirrored_set(obj, elm_mirrored_get());
+          }
+     }
+}
+
 EAPI void
 elm_widget_on_focus_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
 {
@@ -659,7 +715,8 @@ elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
           {
              if (sd2->parent_obj == obj)
                return;
-             elm_widget_sub_object_del(sd2->parent_obj, sobj);
+             if (sd2->parent_obj)
+               elm_widget_sub_object_del(sd2->parent_obj, sobj);
              sd2->parent_obj = obj;
              if (!sd->child_can_focus && (_is_focusable(sobj)))
                sd->child_can_focus = EINA_TRUE;
@@ -671,7 +728,7 @@ elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
         if (data)
           {
              if (data == obj) return;
-             evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL, 
+             evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
                                             _sub_obj_del);
           }
      }
@@ -729,7 +786,7 @@ elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
      }
    else
      sd->subobjs = eina_list_remove(sd->subobjs, sobj);
-   evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, 
+   evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
                                        _sub_obj_del, sd);
    evas_object_smart_callback_call(obj, "sub-object-del", sobj);
 }
@@ -1532,11 +1589,9 @@ elm_widget_focus_steal(Evas_Object *obj)
      {
        parent = elm_widget_parent_get(parent);
        sd = evas_object_smart_data_get(parent);
-       if (elm_widget_focus_get(sd->resize_obj))
-          {
-             elm_widget_focused_object_clear(sd->resize_obj);
-          }
-       else
+        if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
+          elm_widget_focused_object_clear(sd->resize_obj);
+        else
          {
             const Eina_List *l;
             Evas_Object *child;
@@ -1618,11 +1673,11 @@ elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Co
 
    do
      {
-        parent_obj = sd->parent_obj; 
-        child_obj = sd->obj;
+        parent_obj = sd->parent_obj;
+        if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
         sd = evas_object_smart_data_get(parent_obj);
-
-        if ((!parent_obj) || (!sd) || (!_elm_widget_is(parent_obj))) break;
+        if (!sd) break;
+        child_obj = sd->obj;
 
         evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
         evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
@@ -1806,7 +1861,7 @@ EAPI void
 elm_widget_style_set(Evas_Object *obj, const char *style)
 {
    API_ENTRY return;
-   
+
    if (eina_stringshare_replace(&sd->style, style))
       elm_widget_theme(obj);
 }
@@ -2456,6 +2511,7 @@ _smart_add(Evas_Object *obj)
    sd->obj = obj;
    sd->x = sd->y = sd->w = sd->h = 0;
    sd->can_focus = 1;
+   sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
    evas_object_smart_data_set(obj, sd);
 }
 
@@ -2464,7 +2520,7 @@ _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina
 {
    const Eina_List *l;
    Evas_Object *child, *ret, *best;
-   
+
    API_ENTRY return NULL;
    if (!evas_object_visible_get(obj)) return NULL;
    best = NULL;
@@ -2479,7 +2535,11 @@ _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina
         if (!ret) continue;
         best = ret;
      }
-   if ((can_focus_only) && (!elm_widget_can_focus_get(best))) return NULL;
+   if (can_focus_only)
+     {
+        if ((!best) || (!elm_widget_can_focus_get(best)))
+         return NULL;
+     }
    return best;
 }
 
@@ -2489,7 +2549,7 @@ _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only)
    Evas_Object *top;
    Evas_Object *newest = NULL;
    unsigned int newest_focus_order = 0;
-   
+
    INTERNAL_ENTRY;
 
    if (!sd->focused) return;