MIN/MAX macros -> elm_priv.h
authordiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 3 Dec 2011 22:51:12 +0000 (22:51 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 3 Dec 2011 22:51:12 +0000 (22:51 +0000)
+elm_win_center
+elm_win_screen_constrain_get/set

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@65859 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/Elementary.h.in
src/lib/elm_priv.h
src/lib/elm_win.c

index a437aab..6d2cedb 100644 (file)
@@ -4546,6 +4546,22 @@ extern "C" {
     */
    EAPI Eina_Bool    elm_win_focus_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
    /**
+    * Constrain the maximum width and height of a window to the width and height of its screen
+    *
+    * When @p constrain is true, @p obj will never resize larger than the screen.
+    * @param obj The window object
+    * @param constrain EINA_TRUE to restrict the window's maximum size, EINA_FALSE to disable restriction
+    */
+   EAPI void         elm_win_screen_constrain_set(Evas_Object *obj, Eina_Bool constrain) EINA_ARG_NONNULL(1);
+   /**
+    * Retrieve the constraints on the maximum width and height of a window relative to the width and height of its screen
+    *
+    * When this function returns true, @p obj will never resize larger than the screen.
+    * @param obj The window object
+    * @return EINA_TRUE to restrict the window's maximum size, EINA_FALSE to disable restriction
+    */
+   EAPI Eina_Bool    elm_win_screen_constrain_get(Evas_Object *obj) EINA_ARG_NONNULL(1);
+   /**
     * Get screen geometry details for the screen that a window is on
     * @param obj The window to query
     * @param x where to return the horizontal offset value. May be NULL.
index 65d2ec2..f7a874e 100644 (file)
@@ -95,6 +95,11 @@ extern const char *_elm_engines[];
 #define ELM_ACCESS_MODE_OFF 0
 #define ELM_ACCESS_MODE_ON 1
 
+#undef MIN
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+#undef MAX
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+
 struct _Elm_Config
 {
    int            config_version;
index 8713dfe..6eedc60 100644 (file)
@@ -25,6 +25,7 @@ struct _Elm_Win
       int shot_counter;
    } shot;
    Eina_Bool autodel : 1;
+   Eina_Bool constrain : 1;
    int *autodel_clear, rot;
    int show_count;
    struct {
@@ -640,6 +641,13 @@ _elm_win_obj_callback_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, v
         evas_object_geometry_get(obj, NULL, NULL, &w, &h);
         if (w < 1) w = 1;
         if (h < 1) h = 1;
+        if (win->constrain)
+          {
+             int sw, sh;
+             ecore_evas_screen_geometry_get(win->ee, NULL, NULL, &sw, &sh);
+             w = MIN(w, sw);
+             h = MIN(h, sh);
+          }
         evas_object_image_size_set(win->img_obj, w, h);
      }
 }
@@ -673,6 +681,13 @@ _elm_win_resize_job(void *data)
 
    win->deferred_resize_job = NULL;
    ecore_evas_request_geometry_get(win->ee, NULL, NULL, &w, &h);
+   if (win->constrain)
+     {
+        int sw, sh;
+        ecore_evas_screen_geometry_get(win->ee, NULL, NULL, &sw, &sh);
+        w = MIN(w, sw);
+        h = MIN(h, sh);
+     }
    evas_object_resize(win->win_obj, w, h);
    if (win->frame_obj)
      {
@@ -1755,6 +1770,23 @@ elm_win_raise(Evas_Object *obj)
 }
 
 EAPI void
+elm_win_center(Evas_Object *obj, Eina_Bool h, Eina_Bool v)
+{
+   Elm_Win *win;
+   int win_w, win_h, screen_w, screen_h, nx, ny;
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   win = elm_widget_data_get(obj);
+   if (!win) return;
+   ecore_evas_screen_geometry_get(win->ee, NULL, NULL, &screen_w, &screen_h);
+   evas_object_geometry_get(obj, NULL, NULL, &win_w, &win_h);
+   if (h) nx = win_w >= screen_w ? 0 : (screen_w / 2) - (win_w / 2);
+   else nx = win->screen.x;
+   if (v) ny = win_h >= screen_h ? 0 : (screen_h / 2) - (win_h / 2);
+   else ny = win->screen.y;
+   evas_object_move(obj, nx, ny);
+}
+
+EAPI void
 elm_win_borderless_set(Evas_Object *obj, Eina_Bool borderless)
 {
    Elm_Win *win;
@@ -2186,6 +2218,26 @@ elm_win_focus_get(const Evas_Object *obj)
 }
 
 EAPI void
+elm_win_screen_constrain_set(Evas_Object *obj, Eina_Bool constrain)
+{
+   Elm_Win *win;
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   win = elm_widget_data_get(obj);
+   if (!win) return;
+   win->constrain = !!constrain;
+}
+
+EAPI Eina_Bool
+elm_win_screen_constrain_get(Evas_Object *obj)
+{
+   Elm_Win *win;
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   win = elm_widget_data_get(obj);
+   if (!win) return EINA_FALSE;
+   return win->constrain;
+}
+
+EAPI void
 elm_win_screen_size_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
 {
    Elm_Win *win;