///////////////////////////////////////////////////////////////////////////////
group { name: "elm/segment_control/base/default";
   #define SEGMENT_TYPE_SINGLE 1
   #define SEGMENT_TYPE_LEFT 2
   #define SEGMENT_TYPE_MIDDLE 3
   #define SEGMENT_TYPE_RIGHT 4
   #define SEGMENT_STATE_NORMAL 1
   #define SEGMENT_STATE_PRESSED 2
   #define SEGMENT_STATE_SELECTED 3
   #define SEGMENT_STATUS_ENABLED 0
   #define SEGMENT_STATUS_DISABLED 1
   parts {
      part { name: "bg";
         type: RECT;
         mouse_events: 0;
         description {
            state: "default" 0.0;
            color: 0 0 0 0;
            min: 160 31;
         }
      }
   }
}
group { name: "elm/segment_control/item/default";
   images {
      image: "day_single_press.png" COMP;
      image: "day_single_selected.png" COMP;
      image: "day_single_normal.png" COMP;
      image: "day_left_press.png" COMP;
      image: "day_left_selected.png" COMP;
      image: "day_left_normal.png" COMP;
      image: "day_middle_press.png" COMP;
      image: "day_middle_selected.png" COMP;
      image: "day_middle_normal.png" COMP;
      image: "day_right_press.png" COMP;
      image: "day_right_selected.png" COMP;
      image: "day_right_normal.png" COMP;
   }
   parts {
      part { name: "segment";
         scale: 1;
         description { state: "default" 0.0;
            visible: 0;
            image {
               normal: "day_single_normal.png";
               border: 4 4 3 5;
            }
         }
         description { state: "default_single" 0.0;
            inherit: "default" 0.0;
            visible: 1;
         }
         description { state: "default_left" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_left_normal.png";
               border:  4 1 3 5;
            }
         }
         description { state: "default_right" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_right_normal.png";
               border: 1 4 3 5;
            }
         }
         description { state: "default_middle" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_middle_normal.png";
               border: 1 1 3 5;
            }
         }
         description { state: "pressed_single" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_single_press.png";
               border: 4 4 3 5;
            }
         }
         description { state: "pressed_left" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_left_press.png";
               border:  4 1 3 5;
            }
         }
         description { state: "pressed_right" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_right_press.png";
               border: 1 4 3 5;
            }
         }
         description { state: "pressed_middle" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_middle_press.png";
               border: 1 1 3 5;
            }
         }
         description { state: "selected_single" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_single_selected.png";
               border: 4 4 3 5;
            }
         }
         description { state: "selected_left" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_left_selected.png";
               border:  4 1 3 5;
            }
         }
         description { state: "selected_right" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_right_selected.png";
               border: 1 4 3 5;
            }
         }
         description { state: "selected_middle" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            image {
               normal: "day_middle_selected.png";
               border: 1 1 3 5;
            }
         }
      }
      part { name: "elm.swallow.icon";
         type: SWALLOW;
         scale: 1;
         clip_to: "disabler";
         description { state: "default" 0.0;
            align: 0.5 0.5;
            rel1.offset: 10 3;
            rel2.relative: 0.0 1.0;
            aspect: 1.0 1.0;
            aspect_preference: BOTH;
         }
         description { state: "visible" 0.0;
            inherit: "default" 0.0;
            rel2.relative: 0.25 1.0;
            rel2.offset: -5 -4;
         }
         description { state: "icononly" 0.0;
            inherit: "default" 0.0;
            rel1.offset: 5 2;
            rel2.relative: 1.0 1.0;
            rel2.offset: -5 -4;
         }
      }
      part { name: "elm.text";
         type: TEXT;
         mouse_events: 0;
         scale: 1;
         effect: SHADOW BOTTOM;
         description {
            state: "default" 0.0;
            visible: 0;
            fixed: 1 1;
            min: 1 1;
            rel1 {
               to_x: "elm.swallow.icon";
               relative: 1.0 0.0;
               offset: 0 -1;
            }
            rel2.offset: -6 -2;
            color: FN_COL_DEFAULT;
            text {
               font: FN;
               size: 10;
               min: 0 1;
               text_class: "button";
            }
         }
         description { state: "normal" 0.0;
            inherit: "default" 0.0;
            visible: 1;
         }
         description { state: "pressed" 0.0;
            inherit: "default" 0.0;
            visible: 1;
         }
         description { state: "disabled" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            color: FN_COL_DISABLE;
         }
      }
      part { name: "text2";
         type: TEXT;
         mouse_events: 0;
         scale: 1;
         effect: GLOW;
         description {
            state: "default" 0.0;
            visible: 0;
            fixed: 1 1;
            min: 1 1;
            rel1.to: "elm.text";
            rel2.to: "elm.text";
            text {
               font: FN;
               size: 10;
               min: 0 1;
               text_source: "elm.text";
               text_class: "button";
            }
            color: FN_COL_WHITE_GLOW;
         }
         description { state: "selected" 0.0;
            inherit: "default" 0.0;
            visible: 1;
         }
      }
      part { name: "disabler";
         type: RECT;
         description { state: "default" 0.0;
            rel1.to: "segment";
            rel2.to: "segment";
         }
         description { state: "disabled" 0.0;
            inherit: "default" 0.0;
            color: 255 255 255 64;
         }
      }
   }
   programs {
      script {
         public seg_type; // Single, Left, Middle, Right.
         public seg_state; // Normal/Default, Pressed, Selected.
         public seg_status;// Enabled/Default, Disabled

         public update_state() {
            new type, state, status;
            type = get_int(seg_type);
            state = get_int(seg_state);
            status = get_int(seg_status);

            if (status == SEGMENT_STATUS_ENABLED) {
               if(state == SEGMENT_STATE_NORMAL) {
                  if(type == SEGMENT_TYPE_SINGLE)
                     set_state(PART:"segment", "default_single", 0.0);
                  else if(type == SEGMENT_TYPE_LEFT)
                     set_state(PART:"segment", "default_left", 0.0);
                  else if(type == SEGMENT_TYPE_MIDDLE)
                    set_state(PART:"segment", "default_middle", 0.0);
                  else if(type == SEGMENT_TYPE_RIGHT)
                    set_state(PART:"segment", "default_right", 0.0);
                  set_state(PART:"elm.text", "normal", 0.0);
                  set_state(PART:"text2", "default", 0.0);
               } else if(state == SEGMENT_STATE_PRESSED) {
                  if(type == SEGMENT_TYPE_SINGLE)
                     set_state(PART:"segment", "pressed_single", 0.0);
                  else if(type == SEGMENT_TYPE_LEFT)
                     set_state(PART:"segment", "pressed_left", 0.0);
                  else if(type == SEGMENT_TYPE_MIDDLE)
                     set_state(PART:"segment", "pressed_middle", 0.0);
                  else if(type == SEGMENT_TYPE_RIGHT)
                     set_state(PART:"segment", "pressed_right", 0.0);
                  set_state(PART:"elm.text", "pressed", 0.0);
                  set_state(PART:"text2", "default", 0.0);
               } else if(state == SEGMENT_STATE_SELECTED) {
                  if(type == SEGMENT_TYPE_SINGLE)
                     set_state(PART:"segment", "selected_single", 0.0);
                  else if(type == SEGMENT_TYPE_LEFT)
                    set_state(PART:"segment", "selected_left", 0.0);
                  else if(type == SEGMENT_TYPE_MIDDLE)
                    set_state(PART:"segment", "selected_middle", 0.0);
                  else if(type == SEGMENT_TYPE_RIGHT)
                    set_state(PART:"segment", "selected_right", 0.0);
                  set_state(PART:"elm.text", "default", 0.0);
                  set_state(PART:"text2", "selected", 0.0);
               }
              set_state(PART:"disabler", "default", 0.0);
            } else {
               set_state(PART:"elm.text", "disabled", 0.0);
               set_state(PART:"text2", "normal", 0.0);
               set_state(PART:"disabler", "disabled", 0.0);
               if(type == SEGMENT_TYPE_SINGLE)
                 set_state(PART:"segment", "default_single", 0.0);
               else if(type == SEGMENT_TYPE_LEFT)
                 set_state(PART:"segment", "default_left", 0.0);
               else if(type == SEGMENT_TYPE_MIDDLE)
                 set_state(PART:"segment", "default_middle", 0.0);
               else if(type == SEGMENT_TYPE_RIGHT)
                 set_state(PART:"segment", "default_right", 0.0);
            }
         } 
      }
      program {
         name: "segment_type_s";
         signal: "elm,type,segment,single";
         source: "elm";
         script {
            set_int(seg_type, SEGMENT_TYPE_SINGLE);
            update_state();
         }
      }
      program {
         name: "segment_type_l";
         signal: "elm,type,segment,left";
         source: "elm";
         script {
            set_int(seg_type, SEGMENT_TYPE_LEFT);
            update_state();
         }
      }
      program {
         name: "segment_type_m";
         signal: "elm,type,segment,middle";
         source: "elm";
         script {
            set_int(seg_type, SEGMENT_TYPE_MIDDLE);
            update_state();
         }
      }
      program {
         name: "segment_type_r";
         signal: "elm,type,segment,right";
         source: "elm";
         script {
            set_int(seg_type, SEGMENT_TYPE_RIGHT);
            update_state();
         }
      }
      program {
         name: "normal_segment";
         signal: "elm,state,segment,normal";
         source: "elm";
         script {
            set_int(seg_state, SEGMENT_STATE_NORMAL);
            update_state();
         }
      }
      program {
         name: "pressed_segment";
         signal: "elm,state,segment,pressed";
         source: "elm";
         script {
            set_int(seg_state, SEGMENT_STATE_PRESSED);
            update_state();
         }
      }
      program {
         name: "selected_segment";
         signal: "elm,state,segment,selected";
         source: "elm";
         script {
            set_int(seg_state, SEGMENT_STATE_SELECTED);
            update_state();
         }
      }
      program { name: "disable_segment";
         signal: "elm,state,disabled";
         source: "elm";
         script {
            set_int(seg_status, SEGMENT_STATUS_DISABLED);
            update_state();
         }
      }
      program { name: "enable_segment";
         signal: "elm,state,enabled";
         source: "elm";
         script {
            set_int(seg_status, SEGMENT_STATUS_ENABLED);
            update_state();
         }
      }
      program { name: "text_show";
         signal: "elm,state,text,visible";
         source: "elm";
         script {
            new st[31];
            new Float:vl;
            get_state(PART:"elm.swallow.icon", st, 30, vl);
            if (!strcmp(st, "icononly"))
              set_state(PART:"elm.swallow.icon", "visible", 0.0);
         }
      }
      program { name: "text_hide";
         signal: "elm,state,text,hidden";
         source: "elm";
         script {
            new st[31];
            new Float:vl;
            get_state(PART:"elm.swallow.icon", st, 30, vl);
            if (!strcmp(st, "visible"))
              set_state(PART:"elm.swallow.icon", "icononly", 0.0);
            set_state(PART:"elm.text", "default", 0.0);
            set_state(PART:"text2", "default", 0.0);
         }
      }
      program { name: "icon_show";
         signal: "elm,state,icon,visible";
         source: "elm";
         script {
            new st[31];
            new Float:vl;
            get_state(PART:"elm.text", st, 30, vl);
            if ((!strcmp(st, "normal")) || (!strcmp(st, "selected")))
              set_state(PART:"elm.swallow.icon", "visible", 0.0);
            else
              set_state(PART:"elm.swallow.icon", "icononly", 0.0);
         }
      }
      program { name: "icon_hide";
         signal: "elm,state,icon,hidden";
         source: "elm";
         action:  STATE_SET "default" 0.0;
         target: "elm.swallow.icon";
      }
   }
   #undef SEGMENT_TYPE_SINGLE
   #undef SEGMENT_TYPE_LEFT
   #undef SEGMENT_TYPE_MIDDLE
   #undef SEGMENT_TYPE_RIGHT
   #undef SEGMENT_STATE_NORMAL
   #undef SEGMENT_STATE_PRESSED
   #undef SEGMENT_STATE_SELECTED
   #undef SEGMENT_STATUS_ENABLED
   #undef SEGMENT_STATUS_DISABLED
}
