// 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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PTZController.Logic;

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

        private void EditForm_Load(object sender, EventArgs e)
        {
            helpProvider1.HelpNamespace = ProductInfo.HelpFile;
            
            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
                {
                    Spt.Share.Controls.ctlSkinButton button = ctls[0] as Spt.Share.Controls.ctlSkinButton;

                    button.Caption = m_customs[i].Name;
                    button.Tag = i;

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

        private void userButton_Click(object sender, EventArgs e)
        {
            Spt.Share.Controls.ctlSkinButton btn = sender as Spt.Share.Controls.ctlSkinButton;
            ItemForm f = new ItemForm();
            int n = (int) btn.Tag;

            f.Cameras = Cameras;
            f.Item = m_customs[n];

            if (f.ShowDialog() == DialogResult.OK)
            {
                m_customs[n] = f.Item;
                btn.Caption = f.Item.Name;

                _buttonToolTips.SetToolTip(btn, f.Item.Description);
            }
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private CameraItemList m_cameras;

        public CameraItemList Cameras
        {
            get { return m_cameras; }
            set { m_cameras = value; }
        }

        private CustomItem[] m_customs;

        public CustomItem[] Customs
        {
            get { return m_customs; }
            set { m_customs = value; }
        }
    }
}