elementary/widget - revised orientation mode code.
authorChunEon Park <hermet@hermet.pe.kr>
Tue, 19 Feb 2013 08:22:15 +0000 (08:22 +0000)
committerChunEon Park <hermet@hermet.pe.kr>
Tue, 19 Feb 2013 08:22:15 +0000 (08:22 +0000)
now if applying the orientation style is failed, it tries to apply the original style. if it fails again then default theme.

also it fixed a logic error when theme changed is happened.

It will try to apply the original style if the orientation style is invalid on theme changing.

SVN revision: 84082

src/lib/elm_priv.h
src/lib/elm_slider.c
src/lib/elm_theme.c
src/lib/elm_widget.c
src/lib/elm_widget.h
src/lib/elm_win.c
src/lib/els_cursor.c
src/lib/els_tooltip.c
src/lib/elu_ews_wm.c

index 3d12ebb..39a54a3 100644 (file)
@@ -291,19 +291,23 @@ void                 _elm_win_translate(void);
 
 Ecore_X_Window       _elm_ee_xwin_get(const Ecore_Evas *ee);
 
-Eina_Bool            _elm_theme_object_set(Evas_Object *parent,
+int                  _elm_theme_object_set(Evas_Object *parent,
                                            Evas_Object *o,
                                            const char *clas,
                                            const char *group,
-                                           const char *style);
+                                           const char *style,
+                                           Eina_Bool orient_on,
+                                           int orient_mode);
 Eina_Bool            _elm_theme_object_icon_set(Evas_Object *o,
                                                 const char *group,
                                                 const char *style);
-Eina_Bool            _elm_theme_set(Elm_Theme *th,
+int                  _elm_theme_set(Elm_Theme *th,
                                     Evas_Object *o,
                                     const char *clas,
                                     const char *group,
-                                    const char *style);
+                                    const char *style,
+                                    Eina_Bool orient_on,
+                                    int orient_mode);
 Eina_Bool            _elm_theme_icon_set(Elm_Theme *th,
                                          Evas_Object *o,
                                          const char *group,
index 06958e9..3653583 100644 (file)
@@ -438,7 +438,7 @@ _elm_slider_smart_theme(Eo *obj, void *_pd, va_list *list)
         if (sd->popup)
           _elm_theme_set(NULL, sd->popup,
                          "slider", "horizontal/popup",
-                         elm_widget_style_get(obj));
+                         elm_widget_style_get(obj), EINA_FALSE, 0);
      }
    else
      {
@@ -446,7 +446,7 @@ _elm_slider_smart_theme(Eo *obj, void *_pd, va_list *list)
         if (sd->popup)
           _elm_theme_set(NULL, sd->popup,
                          "slider", "vertical/popup",
-                         elm_widget_style_get(obj));
+                         elm_widget_style_get(obj), EINA_FALSE, 0);
      }
 
    eo_do_super(obj, elm_wdg_theme(&int_ret));
@@ -784,7 +784,7 @@ _elm_slider_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
         priv->popup = edje_object_add(evas_object_evas_get(obj));
         _elm_theme_set(NULL, priv->popup,
                        "slider", "horizontal/popup",
-                       elm_widget_style_get(obj));
+                       elm_widget_style_get(obj), EINA_FALSE, 0);
         edje_object_scale_set(priv->popup, elm_widget_scale_get(obj) *
                               elm_config_scale_get());
         edje_object_signal_callback_add(priv->popup, "popup,hide,done", "elm",
index c09af85..85c3353 100644 (file)
@@ -223,18 +223,18 @@ _elm_theme_reload(void *data __UNUSED__, Evas_Object *obj,
         evas_object_event_callback_add(elm, EVAS_CALLBACK_DEL, _elm_theme_idler_clean, NULL);
         evas_object_data_set(elm, "elm-theme-reload-idler", ecore_idler_add(_elm_theme_reload_idler, elm));
      }
-}                  
+}
 
-Eina_Bool
-_elm_theme_object_set(Evas_Object *parent, Evas_Object *o, const char *clas, const char *group, const char *style)
+int
+_elm_theme_object_set(Evas_Object *parent, Evas_Object *o, const char *clas, const char *group, const char *style, Eina_Bool orient_on, int orient_mode)
 {
    Elm_Theme *th = NULL;
    void *test;
-   Eina_Bool success;
+   int ret;
 
    if (parent) th = elm_widget_theme_get(parent);
-   success = _elm_theme_set(th, o, clas, group, style);
-   if (!success) return EINA_FALSE;
+   ret = _elm_theme_set(th, o, clas, group, style, orient_on, orient_mode);
+   if (ret == -1) return -1;
 
    test = evas_object_data_get(o, "edje,theme,watcher");
    if (!test)
@@ -243,7 +243,7 @@ _elm_theme_object_set(Evas_Object *parent, Evas_Object *o, const char *clas, con
                                         _elm_theme_reload, NULL);
         evas_object_data_set(o, "edje,theme,watcher", (void*) -1);
      }
-   return EINA_TRUE;
+   return ret;
 }
 
 /* only issued by elm_icon.c */
@@ -257,33 +257,57 @@ _elm_theme_object_icon_set(Evas_Object *o,
    return _elm_theme_icon_set(th, o, group, style);
 }
 
-Eina_Bool
-_elm_theme_set(Elm_Theme *th, Evas_Object *o, const char *clas, const char *group, const char *style)
+int
+_elm_theme_set(Elm_Theme *th, Evas_Object *o, const char *clas, const char *group, const char *style, Eina_Bool orient_on, int orient_mode)
 {
    const char *file;
    char buf2[1024];
-   Eina_Bool ok;
 
-   if ((!clas) || (!group) || (!style)) return EINA_FALSE;
+   if ((!clas) || (!group) || (!style)) return -1;
    if (!th) th = &(theme_default);
+
+   //First Try. Apply orient mode.
+   if (orient_mode > 0)
+     {
+        snprintf(buf2, sizeof(buf2), "elm/%s/%s/%d/%s", clas, group,
+                 orient_mode, style);
+        file = _elm_theme_group_file_find(th, buf2);
+        if (file)
+          {
+             if (edje_object_file_set(o, file, buf2)) return orient_mode;
+             else
+               {
+                  DBG("could not set theme group '%s' from file '%s': %s",
+                      buf2, file,
+                      edje_load_error_str(edje_object_load_error_get(o)));
+               }
+          }
+        if (orient_on && evas_object_data_get(o, "edje,theme,watcher"))
+          return orient_mode;
+     }
+
+   //Second Try. Use the default group.
    snprintf(buf2, sizeof(buf2), "elm/%s/%s/%s", clas, group, style);
    file = _elm_theme_group_file_find(th, buf2);
    if (file)
      {
-        ok = edje_object_file_set(o, file, buf2);
-        if (ok) return EINA_TRUE;
+        if (edje_object_file_set(o, file, buf2)) return 0;
         else
-          DBG("could not set theme group '%s' from file '%s': %s",
-              buf2, file, edje_load_error_str(edje_object_load_error_get(o)));
+          {
+             DBG("could not set theme group '%s' from file '%s': %s",
+                 buf2, file, edje_load_error_str(edje_object_load_error_get(o)));
+          }
      }
+
+   //Third Try. Use the elementary default theme.
    snprintf(buf2, sizeof(buf2), "elm/%s/%s/default", clas, group);
    file = _elm_theme_group_file_find(th, buf2);
-   if (!file) return EINA_FALSE;
-   ok = edje_object_file_set(o, file, buf2);
-   if (!ok)
-     DBG("could not set theme group '%s' from file '%s': %s",
-         buf2, file, edje_load_error_str(edje_object_load_error_get(o)));
-   return ok;
+   if (!file) return -1;
+   if (edje_object_file_set(o, file, buf2)) return 0;
+   DBG("could not set theme group '%s' from file '%s': %s",
+       buf2, file, edje_load_error_str(edje_object_load_error_get(o)));
+
+   return -1;
 }
 
 Eina_Bool
index 253e351..dd8746f 100644 (file)
@@ -4072,45 +4072,20 @@ _elm_widget_theme_object_set(Eo *obj, void *_pd EINA_UNUSED, va_list *list)
    const char *welement = va_arg(*list, const char *);
    const char *wstyle = va_arg(*list, const char *);
    Eina_Bool *ret = va_arg(*list, Eina_Bool *);
-   Eina_Bool ret2 = EINA_FALSE;
    Elm_Widget_Smart_Data *sd = _pd;
-   char buf[128];
+   int ret2;
 
-   //Apply orientation styles.
-   if (welement)
+   ret2 = _elm_theme_object_set(obj, edj, wname, welement, wstyle,
+                                sd->orient_on, sd->orient_mode);
+   if (ret2 != -1)
      {
-        switch (sd->orient_mode)
-          {
-             case 90:
-               snprintf(buf, sizeof(buf), "%s/90", welement);
-               break;
-             case 180:
-               snprintf(buf, sizeof(buf), "%s/180", welement);
-               break;
-             case 270:
-               snprintf(buf, sizeof(buf), "%s/270", welement);
-               break;
-             default:
-               strncpy(buf, welement, sizeof(buf));
-               break;
-          }
-        ret2 = _elm_theme_object_set(obj, edj, wname, buf, wstyle);
-     }
-   //Fallback. Apply a default if the style doesnt applied anything.
-   //Otherwise, use the previous one.
-   if (!ret2)
-     {
-        if (!evas_object_data_get(edj, "edje,theme,watcher"))
-          ret2 = _elm_theme_object_set(obj, edj, wname, welement, wstyle);
-        else
-          ret2 = EINA_TRUE;
-        strncpy(buf, "elm,state,orient,0", sizeof(buf));
+        char buf[128];
+        snprintf(buf, sizeof(buf), "elm,state,orient,%d", ret2);
+        elm_object_signal_emit(obj, buf, "elm");
+        if (ret) *ret = EINA_TRUE;
      }
-   else
-     snprintf(buf, sizeof(buf), "elm,state,orient,%d", sd->orient_mode);
-   elm_object_signal_emit(obj, buf, "elm");
 
-   if (ret) *ret = ret2;
+   if (ret) *ret = EINA_FALSE;
 }
 
 static void
@@ -4546,7 +4521,9 @@ _elm_widget_orientation_set(Eo *obj __UNUSED__, void *_pd, va_list *list)
    EINA_LIST_FOREACH (sd->subobjs, l, child)
      elm_widget_orientation_set(child, orient_mode);
 
+   sd->orient_on = EINA_TRUE;
    eo_do(obj, elm_wdg_theme(NULL));
+   sd->orient_on = EINA_FALSE;
 
    if (ret) *ret = EINA_TRUE;
 }
index 9aed6a8..aa5197a 100644 (file)
@@ -412,6 +412,7 @@ typedef struct _Elm_Widget_Smart_Data
 
    int                           frozen;
    int                           orient_mode; /* -1 is disabled */
+   Eina_Bool                     orient_on : 1;
 
    Eina_Bool                     drag_x_locked : 1;
    Eina_Bool                     drag_y_locked : 1;
index 5abdefa..b9fe9a1 100644 (file)
@@ -2947,7 +2947,8 @@ _win_constructor(Eo *obj, void *_pd, va_list *list)
         Evas_Coord mw = 1, mh = 1, hx = 0, hy = 0;
 
         sd->pointer.obj = o = edje_object_add(ecore_evas_get(tmp_sd.ee));
-        _elm_theme_object_set(obj, o, "pointer", "base", "default");
+        _elm_theme_object_set(obj, o, "pointer", "base", "default", EINA_FALSE,
+                              0);
         edje_object_size_min_calc(o, &mw, &mh);
         evas_object_resize(o, mw, mh);
         edje_object_part_geometry_get(o, "elm.swallow.hotspot",
@@ -2963,7 +2964,8 @@ _win_constructor(Eo *obj, void *_pd, va_list *list)
      }
 
    sd->layout = edje_object_add(sd->evas);
-   _elm_theme_object_set(obj, sd->layout, "win", "base", "default");
+   _elm_theme_object_set(obj, sd->layout, "win", "base", "default",
+                         EINA_FALSE, 0);
    sd->box = evas_object_box_add(sd->evas);
    evas_object_box_layout_set(sd->box, _window_layout_stack, obj, NULL);
    edje_object_part_swallow(sd->layout, "elm.swallow.contents", sd->box);
index c44b342..7c75d33 100644 (file)
@@ -174,8 +174,9 @@ _elm_cursor_obj_add(Evas_Object *obj, Elm_Cursor *cur)
    if (!cur->obj)
      return EINA_FALSE;
 
-   if (!_elm_theme_object_set(obj, cur->obj, "cursor", cur->cursor_name,
-                              cur->style ? cur->style : "default"))
+   if (_elm_theme_object_set(obj, cur->obj, "cursor", cur->cursor_name,
+                             cur->style ? cur->style : "default", EINA_FALSE,
+                             0) == -1)
      {
         evas_object_del(cur->obj);
         cur->obj = NULL;
@@ -478,8 +479,8 @@ elm_object_cursor_style_set(Evas_Object *obj, const char *style)
      }
    else
      {
-        if (!_elm_theme_object_set(obj, cur->obj, "cursor", cur->cursor_name,
-                                   style))
+        if (_elm_theme_object_set(obj, cur->obj, "cursor", cur->cursor_name,
+                                   style, EINA_FALSE, 0) == -1)
           ERR("Could not apply the theme to the cursor style=%s", style);
         else
           _elm_cursor_set_hot_spots(cur);
@@ -501,8 +502,9 @@ void
 elm_cursor_theme(Elm_Cursor *cur)
 {
    if ((!cur) || (!cur->obj)) return;
-   if (!_elm_theme_object_set(cur->eventarea, cur->obj, "cursor",
-                              cur->cursor_name, cur->style))
+   if (_elm_theme_object_set(cur->eventarea, cur->obj, "cursor",
+                              cur->cursor_name, cur->style, EINA_FALSE, 0)
+       == -1)
      ERR("Could not apply the theme to the cursor style=%s", cur->style);
    else
      _elm_cursor_set_hot_spots(cur);
index e371d38..29643a5 100644 (file)
@@ -275,7 +275,9 @@ _elm_tooltip_reconfigure(Elm_Tooltip *tt)
      {
         const char *style = tt->style ? tt->style : "default";
         const char *str;
-        if (!_elm_theme_object_set(tt->tt_win ? NULL : tt->owner, tt->tooltip, "tooltip", "base", style))
+        if (_elm_theme_object_set(tt->tt_win ? NULL : tt->owner, tt->tooltip,
+                                  "tooltip", "base", style, EINA_FALSE, 0)
+            == -1)
           {
              ERR("Could not apply the theme to the tooltip! style=%s", style);
              if (tt->tt_win) evas_object_del(tt->tt_win);
index 15fdb65..d09e0a4 100644 (file)
@@ -169,7 +169,8 @@ _elm_ews_border_config_apply(Ecore_Evas *ee, Evas_Object *o, Elm_Theme *th)
    if (ecore_evas_borderless_get(ee))
      style = "borderless";
 
-   _elm_theme_set(th, o, "ews", "decoration", style ? style : "default");
+   _elm_theme_set(th, o, "ews", "decoration", style ? style : "default",
+                  EINA_FALSE, 0);
 
    if (ecore_evas_shaped_get(ee) || ecore_evas_alpha_get(ee) ||
        ecore_evas_transparent_get(ee))
@@ -446,7 +447,8 @@ _elm_ews_wm_rescale(Elm_Theme *th, Eina_Bool use_theme)
           _elm_ews_wm_border_theme_set(*(void**)tp->key, tp->data, NULL);
 
         if (_ews_bg)
-          _elm_theme_set(NULL, _ews_bg, "ews", "background", "default");
+          _elm_theme_set(NULL, _ews_bg, "ews", "background", "default",
+                         EINA_FALSE, 0);
      }
    else
      {
@@ -454,7 +456,8 @@ _elm_ews_wm_rescale(Elm_Theme *th, Eina_Bool use_theme)
           _elm_ews_wm_border_theme_set(*(void**)tp->key, tp->data, th);
 
         if (_ews_bg)
-          _elm_theme_set(th, _ews_bg, "ews", "background", "default");
+          _elm_theme_set(th, _ews_bg, "ews", "background", "default",
+                         EINA_FALSE, 0);
      }
 
    eina_iterator_free(it);
@@ -477,7 +480,8 @@ _elm_ews_wm_init(void)
    o = edje_object_add(e);
    if (!o) return EINA_FALSE;
 
-   if (!_elm_theme_set(NULL, o, "ews", "background", "default"))
+   if (_elm_theme_set(NULL, o, "ews", "background", "default", EINA_FALSE, 0)
+       == -1)
      {
         ERR("Could not set background theme, fallback to rectangle");
         evas_object_del(o);