/* vim: set sw=3 ts=3 sts=3 expandtab: */
group {
   name: "ecdb/check";

   script {
      public s;

      public toggle_state() {
         if (get_int(s) == 0)
         {
            set_state(PART:"check", "active", 0.0);
            emit("ecdb,check,checked", "ecdb");
            set_int(s, 1);
         }
         else
         {
            set_state(PART:"check", "default", 0.0);
            emit("ecdb,check,unchecked", "ecdb");
            set_int(s, 0);
         }
      }
   }

   parts {
      part {
         name: "check_base";
         type: IMAGE;

         description {
            state: "default" 0.0;
            min: 20 18;
            max: 20 18;
            fixed: 1 1;
            align: 0.0 0.5;

            rel1 { 
               relative: 0.0 0.0; 
               offset: 2 2; 
            }

            rel2 { 
               relative: 0.0 1.0; 
               offset: 2 -3; 
            }

            image {
               normal: "check_base.png";
            }
         }

         description {
            state: "disabled" 0.0;
            inherit: "default" 0.0;
            color: 255 255 255 128;
         }
      }

      part {
         name: "check_shadow";
         type: IMAGE;

         description {
            state: "default" 0.0;
            color: 255 255 255 128;
            image.normal: "check_shadow.png";

            rel1 { 
               to: "check";
               relative: 0.0 0.0; 
               offset: 0 1; 
            }

            rel2 { 
               to: "check";
               relative: 1.0 1.0; 
               offset: -1 -1; 
            }
         } 

         description {
            state: "focused" 0.0;
            inherit: "default" 0.0;
            color: 255 255 255 255;
            image.normal: "check_focus.png";
   
            rel1 { 
               to: "check";
               relative: 0.0 0.0; 
               offset: 0 0; 
            }
   
            rel2 { 
               to: "check";
               relative: 1.0 1.0; 
               offset: -1 -1; 
            }
         }
   
         description {
            state: "disabled" 0.0;
            inherit: "default" 0.0;
            color: 255 255 255 0;
         }
      }
   
      part {
         name: "check";
   
         description {
            state: "default" 0.0;
            min: 20 18;
            max: 20 18;
            fixed: 1 1;
            align: 0.0 0.5;
   
            rel1 { 
               relative: 0.0 0.0; 
               offset: 2 2; 
            }
      
            rel2 { 
               relative: 0.0 1.0; 
               offset: 2 -3; 
            }
      
            image {
               normal: "check0.png";
            }
         }
      
         description {
            state: "active" 0.0;
            inherit: "default" 0.0;
         
            image {
               normal: "check2.png";
            }
         }
      
         description {
            state: "disabled_unsel" 0.0;
            inherit: "default" 0.0;
            color: 255 255 255 128;
         }

         description {
            state: "disabled_sel" 0.0;
            inherit: "active" 0.0;
            color: 255 255 255 128;
         }
      }

      part {
         name: "ecdb.label";
         type: TEXT;
         
         description {
            state: "default" 0.0;
            color: 60 60 60 255;
            fixed: 1 1;

            rel1 {
               to: "check";
               offset: 25 0;
            }

            rel2 {
               relative: 1.0 1.0;
               to_y: "check";
               offset: -1 0;
            }

            text {
               text: "";
               font: "ecdb/default";
               min: 1 1;
               size: 11;
               align: 0.0 0.5;
            }
         }
      }
   }

   programs {
      program {
         name: "focus_in";
         signal: "ecdb,focus,in";
         signal: "mouse,down,1";
         action: STATE_SET "focused" 0.0;
         source: "*";
         target: "check_shadow";
      }

      program {
         name: "focus_out";
         signal: "ecdb,focus,out";
         action: STATE_SET "default" 0.0;
         source: "ecdb";
         target: "check_shadow";
      }

      program {
         name: "clicked";
         signal: "mouse,down,1";
         source: "*";

         script {
            toggle_state();
         }
      }

      program {
         name: "disabled";
         signal: "ecdb,disable";
         source: "ecdb";
         action: STATE_SET "disabled" 0.0;
         target: "check_base";
         target: "check_shadow";
      }

      program {
         name: "disabled_check";
         signal: "ecdb,disable";
         source: "ecdb";

         script {
            if (get_int(s) == 1)
               set_state(PART:"check", "disabled_sel",
                           0.0);
            else
               set_state(PART:"check",
                     "disabled_unsel", 0.0);
         }
      }

      program {
         name: "enabled";
         signal: "ecdb,enable";
         source: "ecdb";
         action: STATE_SET "default" 0.0;
         target: "check_base";
         target: "check_shadow";
      }

      program {
         name: "enabled_check";
         signal: "ecdb,enable";
         source: "ecdb";
         
         script {
            if (get_int(s) == 1)
               set_state(PART:"check", "active", 0.0);
            else
               set_state(PART:"check", "default", 0.0);
         }
      }

      program {
         name: "check_off";
         signal: "ecdb,check,off";
         source: "ecdb";

         script {
            set_int(s, 0);
         }

         action: STATE_SET "default" 0.0;
         target: "check";
      }

      program {
         name: "check_on";
         signal: "ecdb,check,on";
         source: "ecdb";

         script {
            set_int(s, 1);
         }

         action: STATE_SET "active" 0.0;
         target: "check";
      }
   }
}
