// ALL RIGHTS RESERVED:
// ====================
// The contents of this file, and associated files in this directory, are 
// Copyright (C) SPT , all rights reserved, 2009.
// All software Source Code, Images, Database-Design and code, Graphics Design 
// and source files, and related content (collectively referred to as SOURCE) are 
// Copyright (c) SPT, 2009, All Rights Reserved.
// http://SerialPortTool.com

// PTZ Controller is a Registered Trademark of SerialPortTool.com.


using System;
using System.Data;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

using PTZController.Logic;

using Spt.Share.Data;
using Spt.Share.Controls;

namespace PTZController
{
    public partial class CustomizeForm : PanelForm
    {
        public CustomizeForm()
        {
            InitializeComponent();
        }

        private CustomItemList m_customs;

        public CustomItemList Customs
        {
            get { return m_customs; }
            set { m_customs = value; }
        }

        private void CustomizeForm_Load(object sender, EventArgs e)
        {
        }

        public void ApplyCustomData()
        {
            _buttonToolTips.RemoveAll();

            for (int i = 0; i < m_customs.Length; i++)
            {
                string text = string.Format("userButton{0}", i + 1);
                Control[] ctls = Controls.Find(text, false);

                if (ctls.Length == 1) // only 1
                {
                    ctlSkinButton button = ctls[0] as ctlSkinButton;

                    if (button.Caption != m_customs[i].Name)
                    {
                        button.Caption = m_customs[i].Name;
                    }

                    _buttonToolTips.SetToolTip(button, m_customs[i].Description);
                    button.Invalidate();
                }
            }
        }

        private void buttons_Click(object sender, EventArgs e)
        {
            int index = HelpFunction.ParseIndex((sender as ctlSkinButton).Name);
            CustomizeEvent(index - 1);
        }

        public delegate void CustomizeEventHandler(int index);

        private CustomizeEventHandler m_customizeEvent;

        public CustomizeEventHandler CustomizeEvent
        {
            get { return m_customizeEvent; }
            set { m_customizeEvent = value; }
        }

        private void CustomizeForm_Shown(object sender, EventArgs e)
        {
            ApplyCustomData();
        }

        private void CustomizeForm_MouseEnter(object sender, EventArgs e)
        {
            Activate();
        }
	
    }
}