1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 static void
_click_me(void * data,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)6 _click_me(void *data, Evas_Object *obj EINA_UNUSED,
7           void *event_info EINA_UNUSED)
8 {
9    Elm_Object_Item *it = data;
10    Eina_Bool disabled = elm_object_item_disabled_get(it);
11    printf("The first item is now %s\n", disabled ? "enabled" : "disabled");
12    elm_object_item_disabled_set(it, !disabled);
13 }
14 
15 void
test_main_menu(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)16 test_main_menu(void *data EINA_UNUSED,
17                Evas_Object *obj EINA_UNUSED,
18                void *event_info EINA_UNUSED)
19 {
20    Evas_Object *win, *menu, *label, *bx;
21    Elm_Object_Item *menu_it, *menu_it1;
22    char *s;
23    Eina_Bool enabled = EINA_TRUE;
24 
25    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
26 
27    win = elm_win_util_standard_add("menu", "Menu");
28    elm_win_autodel_set(win, EINA_TRUE);
29 
30    bx = elm_box_add(win);
31    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
32    elm_win_resize_object_add(win, bx);
33    evas_object_show(bx);
34 
35    label = elm_label_add(win);
36    elm_object_text_set(label, "Note: the D-Bus menu example requires support from the "
37                               "desktop environment to display the application menu");
38    evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
39    evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
40    elm_label_line_wrap_set(label, ELM_WRAP_WORD);
41    elm_box_pack_end(bx, label);
42    evas_object_show(label);
43 
44    s = getenv("ELM_DISABLE_EXTERNAL_MENU");
45    if (s)
46      enabled = !atoi(s);
47 
48    if (!enabled)
49      {
50         label = elm_label_add(win);
51         elm_object_text_set(label, "(ELM_DISABLE_EXTERNAL_MENU environment "
52                             "variable is set. Using local menu instead)");
53         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
54         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
55         elm_label_line_wrap_set(label, ELM_WRAP_WORD);
56         elm_box_pack_end(bx, label);
57         evas_object_show(label);
58      }
59 
60    menu = elm_win_main_menu_get(win);
61 
62    menu_it = elm_menu_item_add(menu, NULL, NULL, "first item", NULL, NULL);
63    elm_menu_item_add(menu, menu_it, "elementary", "first item", NULL, NULL);
64    menu_it1 = elm_menu_item_add(menu, menu_it, NULL, "submenu", NULL, NULL);
65    elm_menu_item_add(menu, menu_it1, NULL, "first item", NULL, NULL);
66    elm_menu_item_add(menu, menu_it1, "gimp", "second item", NULL, NULL);
67 
68    menu_it = elm_menu_item_add(menu, NULL, NULL, "second item", NULL, NULL);
69    menu_it1 = elm_menu_item_add(menu, menu_it, NULL, "disabled item", NULL, NULL);
70    elm_object_item_disabled_set(menu_it1, EINA_TRUE);
71    elm_menu_item_separator_add(menu, menu_it);
72    elm_menu_item_add(menu, menu_it, NULL, "click me :-)", _click_me, menu_it1);
73    elm_menu_item_add(menu, menu_it, "applications-email-panel", "third item", NULL, NULL);
74    menu_it1 = elm_menu_item_add(menu, menu_it, NULL, "sub menu", NULL, NULL);
75    elm_menu_item_add(menu, menu_it1, NULL, "first item", NULL, NULL);
76 
77    evas_object_resize(win, 250, 350);
78    evas_object_show(win);
79 }
80