using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BulkPrinting
{
    public class ObservedForm : Form
    {
        public ObservedForm()
        {
            KeyPreview = true;

            Load += ObservedForm_Load;
            FormClosed += ObservedForm_FormClosed;
            MouseMove += ObservedForm_MouseMove;
            KeyDown += ObservedForm_KeyDown;
        }

        protected virtual void OnUserActivity()
        {
            BatchForm BatchForm = (BatchForm)Application.OpenForms["BatchForm"];
            BatchForm.ResetTimer();
        }

        private void ObservedForm_Load(object sender, EventArgs e)
        {
            foreach (Control ObservedControl in this.Controls)
            {
                ObservedControl.MouseMove += ObservedForm_MouseMove;
                ObservedControl.KeyDown += ObservedForm_KeyDown;
            }
        }

        private void ObservedForm_MouseMove(object sender, MouseEventArgs e)
        {
            OnUserActivity();
        }

        private void ObservedForm_KeyDown(object sender, KeyEventArgs e)
        {
            OnUserActivity();
        }

        private void ObservedForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Load -= ObservedForm_Load;
            FormClosed -= ObservedForm_FormClosed;
            MouseMove -= ObservedForm_MouseMove;
            KeyDown -= ObservedForm_KeyDown;
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ObservedForm));
            this.SuspendLayout();
            // 
            // ObservedForm
            // 
            this.ClientSize = new System.Drawing.Size(284, 261);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "ObservedForm";
            this.ResumeLayout(false);

        }
    }
}
