流星悟语 发表于 2015-8-17 15:26:08

新弹出窗口(webview)共享对象代码

您可以创建新的共享对象的弹出窗口(webview)。 (你必须使用tizen ui应用程序)。
/*
* HEADER of popup function
* 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_



/*
* implementation of popup function
* popupso.c
*/
#include "popupso.h"
#include <Elementary.h>
#include <EWebKit.h>
#include <dlog.h>
#include <efl_extension.h>

#ifdefLOG_TAG
#undefLOG_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;
}


页: [1]
查看完整版本: 新弹出窗口(webview)共享对象代码