找回密码
 立即注册
查看: 3236|回复: 0

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

[复制链接]
发表于 2015-8-17 15:26:08 | 显示全部楼层 |阅读模式
您可以创建新的共享对象的弹出窗口(webview)。 (你必须使用tizen ui应用程序)。
  1. /*
  2. * HEADER of popup function
  3. * popupso.h
  4. */

  5. #ifndef _POPUPSO_H_
  6. #define _POPUPSO_H_

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

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

  11. #endif // _POPUPSO_H_



  12. /*
  13. * implementation of popup function
  14. * popupso.c
  15. */
  16. #include "popupso.h"
  17. #include <Elementary.h>
  18. #include <EWebKit.h>
  19. #include <dlog.h>
  20. #include <efl_extension.h>

  21. #ifdef  LOG_TAG
  22. #undef  LOG_TAG
  23. #endif
  24. #define LOG_TAG "popupso"

  25. #define PADDINGH 0.1
  26. #define PADDINGV 0.2

  27. static void win_back_cb(void *data, Evas_Object *obj, void *event_info)
  28. {
  29.         evas_object_del(obj);
  30. }

  31. static void close_cb(void *data, Evas_Object *obj, void *event_info)
  32. {
  33.         Evas_Object *popup_win = data;
  34.         Evas_Object *check = evas_object_data_get(popup_win, "_checkbox");
  35.         Popup_Close_Cb cb = evas_object_data_get(popup_win, "_cb");
  36.         void *user_data = evas_object_data_get(popup_win, "_data");
  37.         Eina_Bool checked = elm_check_state_get(check);

  38.         evas_object_del(popup_win);
  39.         cb(checked, user_data);
  40. }

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

  46.         int w,h;
  47.         elm_win_screen_size_get(popup_win, NULL, NULL, &w, &h);
  48.         evas_object_move(popup_win, 0, 0);
  49.         int pw = w - w*PADDINGH, ph = h - h*PADDINGV;
  50.         evas_object_resize(popup_win, pw, ph);

  51.         Evas_Object *bg = elm_bg_add(popup_win);
  52.         elm_bg_color_set(bg, 255, 255, 255);
  53.         evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
  54.         elm_win_resize_object_add(popup_win, bg);
  55.         evas_object_show(bg);

  56.         Evas_Object *vbox = elm_box_add(popup_win);
  57.         evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
  58.         evas_object_size_hint_min_set(vbox, pw, ph);
  59.         elm_win_resize_object_add(popup_win, vbox);
  60.         evas_object_show(vbox);

  61.         Evas_Object *webview = ewk_view_add(evas_object_evas_get(popup_win));
  62.         evas_object_size_hint_align_set(webview, EVAS_HINT_FILL, EVAS_HINT_FILL);
  63.         ewk_view_url_set(webview, url);
  64.         elm_box_pack_end(vbox, webview);
  65.         evas_object_show(webview);

  66.         Evas_Object *hbox = elm_box_add(vbox);
  67.         elm_box_horizontal_set(hbox, EINA_TRUE);
  68.         evas_object_size_hint_align_set(webview, EVAS_HINT_FILL, 1.0);
  69.         elm_box_pack_end(vbox, hbox);
  70.         evas_object_show(hbox);

  71.         Evas_Object *label = elm_label_add(hbox);
  72.         elm_object_text_set(label, "don't open in today ");
  73.         evas_object_size_hint_align_set(label, 1.0, 0.5);
  74.         elm_box_pack_end(hbox, label);
  75.         evas_object_show(label);

  76.         Evas_Object *check = elm_check_add(hbox);
  77.         evas_object_size_hint_align_set(check, 1.0, 0.5);
  78.         elm_box_pack_end(hbox, check);
  79.         evas_object_smart_callback_add(check, "changed", close_cb, popup_win);
  80.         evas_object_show(check);

  81.         evas_object_data_set(popup_win, "_checkbox", check);
  82.         evas_object_data_set(popup_win, "_cb", cb);
  83.         evas_object_data_set(popup_win, "_data", data);

  84.         int bottom_h, label_h, check_h;
  85.         evas_object_geometry_get(label, NULL, NULL, NULL, &label_h);
  86.         evas_object_geometry_get(check, NULL, NULL, NULL, &check_h);
  87.         bottom_h = label_h > check_h ? label_h : check_h;

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

  94.         return true;
  95. }
复制代码


欢迎来到泰泽网:http://www.tizennet.com/ 泰泽论坛:http://bbs.tizennet.com/ 好没有内涵哦,快到设置中更改这个无聊的签名吧!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|泰泽应用|泰泽论坛|泰泽网|小黑屋|Archiver|手机版|泰泽邮箱|泰泽网 ( 蜀ICP备13024062号-1 )

GMT+8, 2024-11-24 19:51 , Processed in 0.049234 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表