//----------------------------------------------------------------------------
// AboutForm.cs
//
// About form for C1ReportDesigner application
//
// This is a part of the C1ReportDesigner package.
// Copyright (C) ComponentOne LLC
// All rights reserved.
//
// This source code is intended as a supplement to the
// C1ReportDesigner control and related documentation 
// provided with the product.
// See these sources for detailed information regarding the
// C1ReportDesigner product.
//----------------------------------------------------------------------------
namespace ReportDesignerApp
{
	using System;
	using System.Reflection;
	using System.Windows.Forms;
	using System.Diagnostics;
    using System.Drawing;

	internal class AboutForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button _btnOk;
		private System.Windows.Forms.PictureBox _logo;
		private System.Windows.Forms.PictureBox _art;
		private System.Windows.Forms.Label _prodName;
		private System.Windows.Forms.Label _copyright;
		private System.Windows.Forms.Label _versionCaption;
		private System.Windows.Forms.Label _version;
		private System.Windows.Forms.Label _included;
		private System.Windows.Forms.Label _bar;
		private System.Windows.Forms.Label _c1rVersionCaption;
		private System.Windows.Forms.Label _c1rVersion;
		private System.Windows.Forms.Label _description;

		internal AboutForm()
		{
			// regular initialization
			InitializeComponent();

			// show designer version
			_version.Text = FileVersionInfo.GetVersionInfo(Application.ExecutablePath).FileVersion;

			// show C1Report version
			Assembly a = Assembly.GetAssembly(typeof(C1.C1Report.C1Report));
            Version v = a.GetName().Version;
            _c1rVersion.Text = v.ToString();

            int year = v.Build / 10;
            _copyright.Text = string.Format(_copyright.Text, year);

        }

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm));
            this._btnOk = new System.Windows.Forms.Button();
            this._logo = new System.Windows.Forms.PictureBox();
            this._art = new System.Windows.Forms.PictureBox();
            this._prodName = new System.Windows.Forms.Label();
            this._copyright = new System.Windows.Forms.Label();
            this._versionCaption = new System.Windows.Forms.Label();
            this._version = new System.Windows.Forms.Label();
            this._included = new System.Windows.Forms.Label();
            this._bar = new System.Windows.Forms.Label();
            this._description = new System.Windows.Forms.Label();
            this._c1rVersionCaption = new System.Windows.Forms.Label();
            this._c1rVersion = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this._logo)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this._art)).BeginInit();
            this.SuspendLayout();
            // 
            // _btnOk
            // 
            this._btnOk.BackColor = System.Drawing.SystemColors.Control;
            this._btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
            this._btnOk.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._btnOk.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._btnOk.ForeColor = System.Drawing.Color.Black;
            this._btnOk.Location = new System.Drawing.Point(432, 232);
            this._btnOk.Name = "_btnOk";
            this._btnOk.Size = new System.Drawing.Size(80, 24);
            this._btnOk.TabIndex = 11;
            this._btnOk.Text = "OK";
            this._btnOk.UseVisualStyleBackColor = false;
            // 
            // _logo
            // 
            this._logo.Image = ((System.Drawing.Image)(resources.GetObject("_logo.Image")));
            this._logo.Location = new System.Drawing.Point(208, 8);
            this._logo.Name = "_logo";
            this._logo.Size = new System.Drawing.Size(312, 48);
            this._logo.TabIndex = 4;
            this._logo.TabStop = false;
            // 
            // _art
            // 
            this._art.Image = ((System.Drawing.Image)(resources.GetObject("_art.Image")));
            this._art.Location = new System.Drawing.Point(12, 8);
            this._art.Name = "_art";
            this._art.Size = new System.Drawing.Size(191, 155);
            this._art.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
            this._art.TabIndex = 3;
            this._art.TabStop = false;
            this._art.Paint += new System.Windows.Forms.PaintEventHandler(this._art_Paint);
            // 
            // _prodName
            // 
            this._prodName.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._prodName.ForeColor = System.Drawing.Color.Black;
            this._prodName.Location = new System.Drawing.Point(216, 48);
            this._prodName.Name = "_prodName";
            this._prodName.Size = new System.Drawing.Size(272, 16);
            this._prodName.TabIndex = 0;
            this._prodName.Text = "ComponentOne Report Designer";
            // 
            // _copyright
            // 
            this._copyright.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._copyright.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._copyright.ForeColor = System.Drawing.Color.Black;
            this._copyright.Location = new System.Drawing.Point(8, 240);
            this._copyright.Name = "_copyright";
            this._copyright.Size = new System.Drawing.Size(408, 16);
            this._copyright.TabIndex = 1;
            this._copyright.Text = "Copyright (c) 2002-{0} ComponentOne LLC.";
            // 
            // _versionCaption
            // 
            this._versionCaption.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._versionCaption.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._versionCaption.ForeColor = System.Drawing.Color.Black;
            this._versionCaption.Location = new System.Drawing.Point(216, 160);
            this._versionCaption.Name = "_versionCaption";
            this._versionCaption.Size = new System.Drawing.Size(128, 16);
            this._versionCaption.TabIndex = 15;
            this._versionCaption.Text = "Designer Version:";
            // 
            // _version
            // 
            this._version.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._version.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._version.ForeColor = System.Drawing.Color.Black;
            this._version.Location = new System.Drawing.Point(368, 160);
            this._version.Name = "_version";
            this._version.Size = new System.Drawing.Size(144, 15);
            this._version.TabIndex = 16;
            this._version.Text = "1.1.20021.12345";
            // 
            // _included
            // 
            this._included.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._included.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._included.ForeColor = System.Drawing.Color.Black;
            this._included.Location = new System.Drawing.Point(8, 224);
            this._included.Name = "_included";
            this._included.Size = new System.Drawing.Size(416, 16);
            this._included.TabIndex = 19;
            this._included.Text = "This product is part of the ComponentOne Studio Enterprise.";
            // 
            // _bar
            // 
            this._bar.BackColor = System.Drawing.Color.Black;
            this._bar.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this._bar.ForeColor = System.Drawing.Color.Black;
            this._bar.Location = new System.Drawing.Point(12, 204);
            this._bar.Name = "_bar";
            this._bar.Size = new System.Drawing.Size(500, 3);
            this._bar.TabIndex = 24;
            // 
            // _description
            // 
            this._description.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._description.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._description.Location = new System.Drawing.Point(216, 72);
            this._description.Name = "_description";
            this._description.Size = new System.Drawing.Size(296, 72);
            this._description.TabIndex = 25;
            this._description.Text = "Use the report designer to create new and edit existing report definitions, or im" +
                "port report definitions from Microsoft Access(tm) or Crystal Reports(tm).";
            // 
            // _c1rVersionCaption
            // 
            this._c1rVersionCaption.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._c1rVersionCaption.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._c1rVersionCaption.ForeColor = System.Drawing.Color.Black;
            this._c1rVersionCaption.Location = new System.Drawing.Point(216, 178);
            this._c1rVersionCaption.Name = "_c1rVersionCaption";
            this._c1rVersionCaption.Size = new System.Drawing.Size(128, 16);
            this._c1rVersionCaption.TabIndex = 15;
            this._c1rVersionCaption.Text = "C1Report Version:";
            // 
            // _c1rVersion
            // 
            this._c1rVersion.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._c1rVersion.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this._c1rVersion.ForeColor = System.Drawing.Color.Black;
            this._c1rVersion.Location = new System.Drawing.Point(368, 178);
            this._c1rVersion.Name = "_c1rVersion";
            this._c1rVersion.Size = new System.Drawing.Size(144, 15);
            this._c1rVersion.TabIndex = 16;
            this._c1rVersion.Text = "1.1.20021.12345";
            // 
            // AboutForm
            // 
            this.AcceptButton = this._btnOk;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.BackColor = System.Drawing.Color.White;
            this.CancelButton = this._btnOk;
            this.ClientSize = new System.Drawing.Size(522, 263);
            this.Controls.Add(this._description);
            this.Controls.Add(this._bar);
            this.Controls.Add(this._prodName);
            this.Controls.Add(this._included);
            this.Controls.Add(this._version);
            this.Controls.Add(this._versionCaption);
            this.Controls.Add(this._copyright);
            this.Controls.Add(this._btnOk);
            this.Controls.Add(this._logo);
            this.Controls.Add(this._art);
            this.Controls.Add(this._c1rVersionCaption);
            this.Controls.Add(this._c1rVersion);
            this.ForeColor = System.Drawing.Color.Black;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "AboutForm";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "About ComponentOne Report Designer";
            ((System.ComponentModel.ISupportInitialize)(this._logo)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this._art)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

        // stolen from _Licensing\LicenseProvider.cs <<IP191>>
        private void _art_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
#if CLR40
#else
            DrawWatermark(e.Graphics, _art.ClientRectangle, new string[] { ".NET", "2.x" },
                               "Arial", Color.FromArgb(128, Color.Black));
#endif
        }
        private static void DrawWatermark(Graphics g, Rectangle r, string[] lines, string FontFamily, Color BrushColor)
        {
            const float space = 0.05f;
            Point p = r.Location;
            Size s = r.Size;

            int nLines = lines.Length;
            float fh = (1f - (float)(nLines + 1) * space) / nLines;
            float fhm = fh;
            float em = (int)(s.Height * fh * 72f / g.DpiY);

            // calculate the font size based on height
            Font fnt = new Font(FontFamily, em, FontStyle.Bold);
            Brush br = new SolidBrush(BrushColor);

            int line = 0;
            bool em_changed = false;
            int iterations = 0;

            // check the width of each line using the specified font
            // and adjust as necessary
            foreach (string banner in lines)
            {
                SizeF szf = g.MeasureString(banner, fnt);
                while (iterations < 5 && szf.Width >= s.Width + 4)
                {
                    em = (float)(int)(em * (1f * s.Width) / szf.Width);
                    fnt.Dispose();
                    fnt = new Font(FontFamily, em, FontStyle.Bold);
                    szf = g.MeasureString(banner, fnt);
                    iterations++;
                    em_changed = true;
                }
            }
            if (em_changed)
                fhm = em * g.DpiY / (s.Height * 72f);
#if DEBUG
            Debug.WriteLine("Watermark iterations = " + iterations.ToString());
#endif
            // draw the lines of text to the graphics object.
            line = 0;
            System.Drawing.Text.TextRenderingHint oldTrh = g.TextRenderingHint;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            foreach (string banner in lines)
            {
                SizeF szf = g.MeasureString(banner, fnt);
                int yLocation = (int)(s.Height * ((line + 1) * space + line * fh + 0.5 * (fh - fhm)));
                Point d = new Point(p.X + 1 + (int)(s.Width - szf.Width) / 2, yLocation);
                g.DrawString(banner, fnt, br, d);
                line++;
            }
            g.TextRenderingHint = oldTrh;
            br.Dispose();
            fnt.Dispose();
        }
    }
}
