aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/elementary/test_dayselector.c
blob: 16259e32fa7f5a4141b9538c32bd8d8e8f038516 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifdef HAVE_CONFIG_H
#include "elementary_config.h"
#endif
#include <Elementary.h>

static void _changed_cb(void* data EINA_UNUSED, Evas_Object* obj, void* event_info)
{
   char buf[256];
   Elm_Dayselector_Day day = (Elm_Dayselector_Day) event_info;
   Eina_Bool checked = elm_dayselector_day_selected_get(obj, day);

   switch(day)
     {
      case ELM_DAYSELECTOR_SUN:
         snprintf(buf, sizeof(buf), "%s", "Sun");
         break;
      case ELM_DAYSELECTOR_MON:
         snprintf(buf, sizeof(buf), "%s", "Mon");
         break;
      case ELM_DAYSELECTOR_TUE:
         snprintf(buf, sizeof(buf), "%s", "Tue");
         break;
      case ELM_DAYSELECTOR_WED:
        snprintf(buf, sizeof(buf), "%s", "Wed");
        break;
      case ELM_DAYSELECTOR_THU:
         snprintf(buf, sizeof(buf), "%s", "Thu");
         break;
      case ELM_DAYSELECTOR_FRI:
         snprintf(buf, sizeof(buf), "%s", "Fri");
         break;
      case ELM_DAYSELECTOR_SAT:
         snprintf(buf, sizeof(buf), "%s", "Sat");
         break;
      default:
         snprintf(buf, sizeof(buf), "%s", "???");
         break;
     }
   fprintf(stderr, "%s = %d\n", buf, checked);
}

void
test_dayselector(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win, *bx, *dayselector, *monday;
   Eina_List *weekdays_list;
   const char *weekday;
   const char *weekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
   const char *weekdays2[] = {"S", "M", "T", "W", "T", "F", "S"};

   win = elm_win_util_standard_add("dayselector", "Day Selector");
   elm_win_autodel_set(win, EINA_TRUE);

   bx = elm_box_add(win);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas_object_show(bx);

   // Default
   dayselector = elm_dayselector_add(bx);
   evas_object_size_hint_weight_set(dayselector, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(dayselector, EVAS_HINT_FILL, 0.5);
   elm_box_pack_end(bx, dayselector);
   evas_object_show(dayselector);
   evas_object_smart_callback_add(dayselector, "dayselector,changed",
                                  _changed_cb, NULL);

   //Sunday first
   dayselector = elm_dayselector_add(bx);
   evas_object_size_hint_weight_set(dayselector, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(dayselector, EVAS_HINT_FILL, 0.5);
   elm_box_pack_end(bx, dayselector);
   evas_object_show(dayselector);
   evas_object_smart_callback_add(dayselector, "dayselector,changed",
                                  _changed_cb, NULL);
   elm_dayselector_weekdays_names_set(dayselector, weekdays);
   elm_dayselector_week_start_set(dayselector, ELM_DAYSELECTOR_SUN);

   //Special Style
   dayselector = elm_dayselector_add(bx);
   evas_object_size_hint_weight_set(dayselector, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(dayselector, EVAS_HINT_FILL, 0.5);
   elm_dayselector_week_start_set(dayselector, ELM_DAYSELECTOR_MON);
   elm_box_pack_end(bx, dayselector);
   evas_object_show(dayselector);
   evas_object_smart_callback_add(dayselector, "dayselector,changed",
                                  _changed_cb, NULL);
   monday = elm_object_part_content_get(dayselector, "day0");
   elm_object_signal_emit(monday, "elm,type,weekend,style1", "");

   //Setting weekday name
   dayselector = elm_dayselector_add(bx);
   evas_object_size_hint_weight_set(dayselector, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(dayselector, EVAS_HINT_FILL, 0.5);
   elm_dayselector_weekdays_names_set(dayselector, weekdays2);
   elm_box_pack_end(bx, dayselector);
   evas_object_show(dayselector);
   evas_object_smart_callback_add(dayselector, "dayselector,changed",
                                  _changed_cb, NULL);

   weekdays_list = elm_dayselector_weekdays_names_get(dayselector);

   fprintf(stderr, "User set weekday names to: ");
   EINA_LIST_FREE(weekdays_list, weekday)
     {
        fprintf(stderr, "%s\n", weekday);
        eina_stringshare_del(weekday);
     }

   //Disabled
   dayselector = elm_dayselector_add(bx);
   evas_object_size_hint_weight_set(dayselector, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(dayselector, EVAS_HINT_FILL, 0.5);
   elm_box_pack_end(bx, dayselector);
   evas_object_show(dayselector);
   elm_object_disabled_set(dayselector, EINA_TRUE);

   evas_object_resize(win, 350, 150);
   evas_object_show(win);
}