elementary: Add ecore_cocoa backend to elementary
[framework/uifw/elementary.git] / src / lib / elm_win.c
index e414f38..b2c3bd4 100644 (file)
@@ -26,6 +26,7 @@ struct _Elm_Win
    } shot;
    Eina_Bool autodel : 1;
    int *autodel_clear, rot;
+   int show_count;
    struct {
       int x, y;
    } screen;
@@ -77,6 +78,7 @@ static const char SIG_DELETE_REQUEST[] = "delete,request";
 static const char SIG_FOCUS_OUT[] = "focus,out";
 static const char SIG_FOCUS_IN[] = "focus,in";
 static const char SIG_MOVED[] = "moved";
+static const char SIG_THEME_CHANGED[] = "theme,changed";
 
 static const Evas_Smart_Cb_Description _signals[] = {
    {SIG_DELETE_REQUEST, ""},
@@ -146,6 +148,7 @@ _shot_file_get(Elm_Win *win)
                        sprintf(repname + (dotptr - tmp), "%03i",
                                win->shot.shot_counter + 1);
                        strcat(repname, dotptr);
+                       free(tmp);
                        return repname;
                     }
                }
@@ -306,7 +309,13 @@ _elm_win_focus_in(Ecore_Evas *ee)
    if (!obj) return;
    win = elm_widget_data_get(obj);
    if (!win) return;
-   if (!elm_widget_focus_get(win->win_obj))
+   _elm_widget_top_win_focused_set(win->win_obj, EINA_TRUE);
+   if (win->show_count == 1)
+     {
+        elm_object_focus_set(win->win_obj, EINA_TRUE);
+        win->show_count++;
+     }
+   else
      elm_widget_focus_restore(win->win_obj);
    evas_object_smart_callback_call(win->win_obj, SIG_FOCUS_IN, NULL);
    win->focus_highlight.cur.visible = EINA_TRUE;
@@ -330,6 +339,7 @@ _elm_win_focus_out(Ecore_Evas *ee)
    win = elm_widget_data_get(obj);
    if (!win) return;
    elm_object_focus_set(win->win_obj, EINA_FALSE);
+   _elm_widget_top_win_focused_set(win->win_obj, EINA_FALSE);
    evas_object_smart_callback_call(win->win_obj, SIG_FOCUS_OUT, NULL);
    win->focus_highlight.cur.visible = EINA_FALSE;
    _elm_win_focus_highlight_reconfigure_job_start(win);
@@ -433,11 +443,11 @@ _deferred_ecore_evas_free(void *data)
 }
 
 static void
-_elm_win_obj_callback_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
+_elm_win_obj_callback_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
 {
    Elm_Win *win = data;
 
-   elm_object_focus_set(obj, EINA_TRUE);
+   if (!win->show_count) win->show_count++;
    if (win->shot.info) _shot_handle(win);
 }
 
@@ -479,6 +489,8 @@ _elm_win_obj_callback_del(void *data, Evas *e, Evas_Object *obj, void *event_inf
    if (win->deferred_child_eval_job) ecore_job_del(win->deferred_child_eval_job);
    if (win->shot.info) eina_stringshare_del(win->shot.info);
    if (win->shot.timer) ecore_timer_del(win->shot.timer);
+   evas_object_event_callback_del_full(win->win_obj, EVAS_CALLBACK_DEL,
+                                       _elm_win_obj_callback_del, win);
    while (((child = evas_object_bottom_get(win->evas))) &&
           (child != obj))
      {
@@ -660,7 +672,7 @@ _elm_win_resize_job(void *data)
    int w, h;
 
    win->deferred_resize_job = NULL;
-   ecore_evas_geometry_get(win->ee, NULL, NULL, &w, &h);
+   ecore_evas_request_geometry_get(win->ee, NULL, NULL, &w, &h);
    evas_object_resize(win->win_obj, w, h);
    if (win->frame_obj)
      {
@@ -691,7 +703,8 @@ _elm_win_xwindow_get(Elm_Win *win)
             ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE) ||
             ENGINE_COMPARE(ELM_SOFTWARE_SDL) ||
             ENGINE_COMPARE(ELM_SOFTWARE_16_SDL) ||
-            ENGINE_COMPARE(ELM_OPENGL_SDL))
+            ENGINE_COMPARE(ELM_OPENGL_SDL) ||
+           ENGINE_COMPARE(ELM_OPENGL_COCOA))
      {
      }
    else if (ENGINE_COMPARE(ELM_SOFTWARE_16_X11))
@@ -875,6 +888,16 @@ _elm_win_rescale(Elm_Theme *th, Eina_Bool use_theme)
      }
 }
 
+void
+_elm_win_translate(void)
+{
+   const Eina_List *l;
+   Evas_Object *obj;
+
+   EINA_LIST_FOREACH(_elm_win_list, l, obj)
+      elm_widget_translate(obj);
+}
+
 #ifdef HAVE_ELEMENTARY_X
 static Eina_Bool
 _elm_win_client_message(void *data, int type __UNUSED__, void *event)
@@ -1338,12 +1361,13 @@ elm_win_add(Evas_Object *parent, const char *name, Elm_Win_Type type)
 
    win = ELM_NEW(Elm_Win);
 
-#define FALLBACK_TRY(engine)                                              \
-   if (!win->ee)                                                          \
-   do {                                                                   \
-        CRITICAL(engine " engine creation failed. Trying software X11."); \
-        elm_engine_set(ELM_SOFTWARE_X11);                                 \
-        win->ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);       \
+#define FALLBACK_TRY(engine)                                            \
+   if (!win->ee)                                                        \
+      do {                                                              \
+         CRITICAL(engine " engine creation failed. Trying default.");   \
+         win->ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);              \
+         if (win->ee)                                                   \
+            elm_engine_set(ecore_evas_engine_name_get(win->ee));        \
    } while (0)
 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
 
@@ -1377,6 +1401,7 @@ elm_win_add(Evas_Object *parent, const char *name, Elm_Win_Type type)
              win->client_message_handler = ecore_event_handler_add
                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
 #endif
+             FALLBACK_TRY("Sofware X11");
           }
         else if (ENGINE_COMPARE(ELM_SOFTWARE_FB))
           {
@@ -1464,10 +1489,19 @@ elm_win_add(Evas_Object *parent, const char *name, Elm_Win_Type type)
              win->ee = ecore_evas_gl_sdl_new(NULL, 1, 1, 0, 0);
              FALLBACK_TRY("OpenGL SDL");
           }
+        else if (ENGINE_COMPARE(ELM_OPENGL_COCOA))
+          {
+             win->ee = ecore_evas_cocoa_new(NULL, 1, 1, 0, 0);
+             FALLBACK_TRY("OpenGL Cocoa");
+          }
         else if (ENGINE_COMPARE(ELM_BUFFER))
           {
              win->ee = ecore_evas_buffer_new(1, 1);
           }
+        else if (ENGINE_COMPARE(ELM_EWS))
+          {
+             win->ee = ecore_evas_ews_new(0, 0, 1, 1);
+          }
         else if (!strncmp(_elm_config->engine, "shot:", 5))
           {
              win->ee = ecore_evas_buffer_new(1, 1);
@@ -1585,6 +1619,26 @@ elm_win_add(Evas_Object *parent, const char *name, Elm_Win_Type type)
    return win->win_obj;
 }
 
+EAPI Evas_Object *
+elm_win_util_standard_add(const char *name, const char *title)
+{
+   Evas_Object *win, *bg;
+   
+   win = elm_win_add(NULL, name, ELM_WIN_BASIC);
+   if (!win) return NULL;
+   elm_win_title_set(win, title);
+   bg = elm_bg_add(win);
+   if (!bg)
+     {
+        evas_object_del(win);
+        return NULL;
+     }
+   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   elm_win_resize_object_add(win, bg);
+   evas_object_show(bg);
+   return win;
+}
+
 EAPI void
 elm_win_resize_object_add(Evas_Object *obj, Evas_Object *subobj)
 {
@@ -1754,6 +1808,7 @@ elm_win_alpha_set(Evas_Object *obj, Eina_Bool alpha)
    else if (win->img_obj)
      {
         evas_object_image_alpha_set(win->img_obj, alpha);
+        ecore_evas_alpha_set(win->ee, alpha);
      }
    else
      {
@@ -1784,6 +1839,13 @@ elm_win_alpha_get(const Evas_Object *obj)
    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    win = elm_widget_data_get(obj);
    if (!win) return EINA_FALSE;
+   if (win->frame_obj)
+     {
+     }
+   else if (win->img_obj)
+     {
+        return evas_object_image_alpha_get(win->img_obj);
+     }
    return ecore_evas_alpha_get(win->ee);
 }
 
@@ -2415,6 +2477,8 @@ _theme_hook(Evas_Object *obj)
    if (wd->content)
      edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
    _sizing_eval(obj);
+
+   evas_object_smart_callback_call(obj, SIG_THEME_CHANGED, NULL);
 }
 
 static Eina_Bool
@@ -2554,6 +2618,9 @@ elm_win_inwin_content_unset(Evas_Object *obj)
    if (!wd->content) return NULL;
    Evas_Object *content = wd->content;
    elm_widget_sub_object_del(obj, wd->content);
+   evas_object_event_callback_del_full(wd->content,
+                                       EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                       _changed_size_hints, obj);
    edje_object_part_unswallow(wd->frm, wd->content);
    wd->content = NULL;
    return content;
@@ -2580,8 +2647,7 @@ elm_win_xwindow_get(const Evas_Object *obj)
 
    if (!obj) return 0;
    type = elm_widget_type_get(obj);
-   if (!type) return 0;
-   if (type != widtype) return _elm_ee_win_get(obj);
+   if ((!type) || (type != widtype)) return _elm_ee_win_get(obj);
 #ifdef HAVE_ELEMENTARY_X
    win = elm_widget_data_get(obj);
    if (!win) return 0;
@@ -2589,5 +2655,4 @@ elm_win_xwindow_get(const Evas_Object *obj)
    if (win->parent) return elm_win_xwindow_get(win->parent);
 #endif
    return 0;
-   win = NULL;
 }