语言

Menu
Sites
Language
To Get Currently active window Evas object.

I need to open a popup on currently active window can i get the hanle (Evas_Object for that).

查看选择的答案

响应

5 回复
Alex Dem

Hi,
If you look at native samples all they have such struct

typedef struct appdata {
    Evas_Object *win;
//...
} appdata_s;

appdata_s struct is last incoming parameter in ui_app_main() main loop method and comes into all callbacks (create/terminate etc)

Pointer to window is stored there (after win was created):

    ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);

and could be extracted during lifetime of application and be used if it is necessary.
Alexey.

rohit sijwali

Actually i want to create a popup and show the web view and that will be a shared library. I want to call that function from unity.

Alex Dem

Hi,
But I did not face api to get pointer to currently active window.
Alexey.

Mark as answer
pius lee

You can create new window by passing null to first parameter of elm_win_add().

I make a snippet for you.

P.S. ) don't miss make close method for popup window, if you miss it, it would be nightmare for your user.

https://developer.tizen.org/community/code-snippet/native-code-snippet/new-popup-window-webview-shared-object

popupso.h

#ifndef _POPUPSO_H_
#define _POPUPSO_H_

#include <stdbool.h>
#include <tizen.h>

typedef void (*Popup_Close_Cb)(bool checked, void *data);
EXPORT_API bool webview_popup(const char* url, Popup_Close_Cb cb, void *data);

#endif // _POPUPSO_H_

 

popupso.c

#include "popupso.h"
#include <Elementary.h>
#include <EWebKit.h>
#include <dlog.h>
#include <efl_extension.h>

#ifdef  LOG_TAG
#undef  LOG_TAG
#endif
#define LOG_TAG "popupso"

#define PADDINGH 0.1
#define PADDINGV 0.2

static void win_back_cb(void *data, Evas_Object *obj, void *event_info)
{
    evas_object_del(obj);
}

static void close_cb(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *popup_win = data;
	Evas_Object *check = evas_object_data_get(popup_win, "_checkbox");
	Popup_Close_Cb cb = evas_object_data_get(popup_win, "_cb");
	void *user_data = evas_object_data_get(popup_win, "_data");
	Eina_Bool checked = elm_check_state_get(check);

	evas_object_del(popup_win);
	cb(checked, user_data);
}

bool webview_popup(const char *url, Popup_Close_Cb cb, void *data)
{
	Evas_Object *popup_win = elm_win_add(NULL, "TestWindow", ELM_WIN_DIALOG_BASIC);
	// very important! if you don't make it close on back, user can't close it until push check or another button.
	eext_object_event_callback_add(popup_win, EEXT_CALLBACK_BACK, win_back_cb, NULL);

	int w,h;
	elm_win_screen_size_get(popup_win, NULL, NULL, &w, &h);
	evas_object_move(popup_win, 0, 0);
	int pw = w - w*PADDINGH, ph = h - h*PADDINGV;
	evas_object_resize(popup_win, pw, ph);

	Evas_Object *bg = elm_bg_add(popup_win);
	elm_bg_color_set(bg, 255, 255, 255);
	evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
	elm_win_resize_object_add(popup_win, bg);
	evas_object_show(bg);

	Evas_Object *vbox = elm_box_add(popup_win);
	evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
	evas_object_size_hint_min_set(vbox, pw, ph);
	elm_win_resize_object_add(popup_win, vbox);
	evas_object_show(vbox);

	Evas_Object *webview = ewk_view_add(evas_object_evas_get(popup_win));
	evas_object_size_hint_align_set(webview, EVAS_HINT_FILL, EVAS_HINT_FILL);
	ewk_view_url_set(webview, url);
	elm_box_pack_end(vbox, webview);
	evas_object_show(webview);

	Evas_Object *hbox = elm_box_add(vbox);
	elm_box_horizontal_set(hbox, EINA_TRUE);
	evas_object_size_hint_align_set(webview, EVAS_HINT_FILL, 1.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	Evas_Object *label = elm_label_add(hbox);
	elm_object_text_set(label, "don't open in today ");
	evas_object_size_hint_align_set(label, 1.0, 0.5);
	elm_box_pack_end(hbox, label);
	evas_object_show(label);

	Evas_Object *check = elm_check_add(hbox);
	evas_object_size_hint_align_set(check, 1.0, 0.5);
	elm_box_pack_end(hbox, check);
	evas_object_smart_callback_add(check, "changed", close_cb, popup_win);
	evas_object_show(check);

	evas_object_data_set(popup_win, "_checkbox", check);
	evas_object_data_set(popup_win, "_cb", cb);
	evas_object_data_set(popup_win, "_data", data);

	int bottom_h, label_h, check_h;
	evas_object_geometry_get(label, NULL, NULL, NULL, &label_h);
	evas_object_geometry_get(check, NULL, NULL, NULL, &check_h);
	bottom_h = label_h > check_h ? label_h : check_h;

	/* webview don't have default minimum size
	 * so if you don't set webview's minimum size,
	 * webview will be not show.
	 */
	evas_object_size_hint_min_set(webview, pw, ph - bottom_h);
	evas_object_show(popup_win);

	return true;
}

 

rohit sijwali

Thanks Bro.