Korero – Rev 1

Subversion Repositories:
Rev:
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Media;
using System.Threading.Tasks;
using System.Windows.Forms;
using Korero.Utilities;

namespace Korero.Notifications
{
    public partial class NotificationForm : Form
    {
        #region Public Enums, Properties and Fields

        public int Index { get; }

        #endregion

        #region Private Delegates, Events, Enums, Properties, Indexers and Fields

        private readonly Action _clickAction;

        private Point _displayLocation;

        #endregion

        #region Constructors, Destructors and Finalizers

        public NotificationForm()
        {
            InitializeComponent();
            Utilities.WindowState.FormTracker.Track(this);
        }

        public NotificationForm(int index, string title, string text, int milliseconds) : this()
        {
            Index = index;

            readOnlyRichTextBox1.InvokeIfRequired(richTextBox => { richTextBox.Text = title; });
            richTextBox1.InvokeIfRequired(richTextBox => { richTextBox.Text = text; });

            Task.Delay(milliseconds).ContinueWith(task =>
                this.InvokeIfRequired(form => form.Close()));
        }

        public NotificationForm(int index, string title, string message, int timeout, UnmanagedMemoryStream sound) :
            this(index, title, message, timeout)
        {
            using (var soundPlayer = new SoundPlayer(sound))
            {
                soundPlayer.Play();
            }
        }

        public NotificationForm(int index, string title, string message, int timeout, UnmanagedMemoryStream sound,
                                Action action) : this(index, title, message, timeout, sound)
        {
            _clickAction = action;
        }

        #endregion

        #region Private Overrides

        protected override void OnLoad(EventArgs e)
        {
            Location = _displayLocation;
            base.OnLoad(e);
        }

        protected override bool ShowWithoutActivation => true;

        #endregion

        #region Event Handlers

        private void PictureBox2_Click(object sender, EventArgs e)
        {
            this.InvokeIfRequired(form => { form.Close(); });
        }

        private void RichTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            Process.Start(e.LinkText);
        }

        private void ReadOnlyRichTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            Process.Start(e.LinkText);
        }

        private void ReadONlyRichTextBox1_Click(object sender, EventArgs e)
        {
            _clickAction?.Invoke();
        }

        private void RichTextBox1_Click(object sender, EventArgs e)
        {
            _clickAction?.Invoke();
        }

        private void PictureBox1_Click(object sender, EventArgs e)
        {
            _clickAction?.Invoke();
        }

        private void NotificationForm_Click(object sender, EventArgs e)
        {
            _clickAction?.Invoke();
        }

        #endregion

        #region Public Methods

        public void UpdateLocation(int x, int y)
        {
            _displayLocation = new Point(x, y);
        }

        #endregion
    }
}

Generated by GNU Enscript 1.6.5.90.