From d3b755cbe6a15b3cc42311704144378755665553 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sat, 3 Dec 2011 22:51:12 +0000 Subject: [PATCH] MIN/MAX macros -> elm_priv.h +elm_win_center +elm_win_screen_constrain_get/set SVN revision: 65859 --- legacy/elementary/src/lib/Elementary.h.in | 16 +++++++ legacy/elementary/src/lib/elm_priv.h | 5 +++ legacy/elementary/src/lib/elm_win.c | 52 +++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/legacy/elementary/src/lib/Elementary.h.in b/legacy/elementary/src/lib/Elementary.h.in index a437aab66c..6d2cedb7eb 100644 --- a/legacy/elementary/src/lib/Elementary.h.in +++ b/legacy/elementary/src/lib/Elementary.h.in @@ -4545,6 +4545,22 @@ extern "C" { * @return EINA_TRUE if the window exists and has focus, else EINA_FALSE */ 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 diff --git a/legacy/elementary/src/lib/elm_priv.h b/legacy/elementary/src/lib/elm_priv.h index 65d2ec2730..f7a874e2d0 100644 --- a/legacy/elementary/src/lib/elm_priv.h +++ b/legacy/elementary/src/lib/elm_priv.h @@ -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; diff --git a/legacy/elementary/src/lib/elm_win.c b/legacy/elementary/src/lib/elm_win.c index 8713dfe2e4..6eedc60ec7 100644 --- a/legacy/elementary/src/lib/elm_win.c +++ b/legacy/elementary/src/lib/elm_win.c @@ -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) { @@ -1754,6 +1769,23 @@ elm_win_raise(Evas_Object *obj) ecore_evas_raise(win->ee); } +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) { @@ -2185,6 +2217,26 @@ elm_win_focus_get(const Evas_Object *obj) return ecore_evas_focus_get(win->ee); } +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) {