using System.Windows.Forms;
using FastReport.Utils;
using FastReport.Design.PageDesigners.Code;

namespace FastReport.Forms
{
    internal class FRXPageOptions : DesignerOptionsPage
    {
        private FRXPageDesigner editor;
        private NumericUpDown udTabSize;
        private Label lblTabSize;
        private CheckBox cbUseSpaces;
        private CheckBox cbEnableFRXPage;

        private void InitializeComponent()
        {
            this.cbUseSpaces = new CheckBox();
            this.udTabSize = new NumericUpDown();
            this.lblTabSize = new Label();
            this.cbEnableFRXPage = new CheckBox();
            this.tc1.SuspendLayout();
            this.tab1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.udTabSize)).BeginInit();
            this.SuspendLayout();
            // 
            // tab1
            // 
            this.tab1.Controls.Add(this.udTabSize);
            this.tab1.Controls.Add(this.lblTabSize);
            this.tab1.Controls.Add(this.cbUseSpaces);
            this.tab1.Controls.Add(this.cbEnableFRXPage);
            // 
            // cbEnableFRXPage
            // 
            this.cbEnableFRXPage.AutoSize = true;
            this.cbEnableFRXPage.Location = new System.Drawing.Point(16, 16);
            this.cbEnableFRXPage.Name = "cbEnableFRXPage";
            this.cbEnableFRXPage.Size = new System.Drawing.Size(130, 17);
            this.cbEnableFRXPage.TabIndex = 1;
            this.cbEnableFRXPage.Text = "Enable";
            this.cbEnableFRXPage.UseVisualStyleBackColor = true;
            // 
            // cbUseSpaces
            // 
            this.cbUseSpaces.AutoSize = true;
            this.cbUseSpaces.Location = new System.Drawing.Point(16, 40);
            this.cbUseSpaces.Name = "cbUseSpaces";
            this.cbUseSpaces.Size = new System.Drawing.Size(130, 17);
            this.cbUseSpaces.TabIndex = 1;
            this.cbUseSpaces.Text = "Use spaces to fill tabs";
            this.cbUseSpaces.UseVisualStyleBackColor = true;
            // 
            // udTabSize
            // 
            this.udTabSize.Location = new System.Drawing.Point(199, 64);
            this.udTabSize.Maximum = new decimal(new int[] {
        16,
        0,
        0,
        0});
            this.udTabSize.Minimum = new decimal(new int[] {
        1,
        0,
        0,
        0});
            this.udTabSize.Name = "udTabSize";
            this.udTabSize.Size = new System.Drawing.Size(76, 21);
            this.udTabSize.TabIndex = 5;
            this.udTabSize.Value = new decimal(new int[] {
        1,
        0,
        0,
        0});
            // 
            // lblTabSize
            // 
            this.lblTabSize.AutoSize = true;
            this.lblTabSize.Location = new System.Drawing.Point(16, 66);
            this.lblTabSize.Name = "lblTabSize";
            this.lblTabSize.Size = new System.Drawing.Size(50, 13);
            this.lblTabSize.TabIndex = 4;
            this.lblTabSize.Text = "Tab size:";
            // 
            // CodePageOptions
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
            this.ClientSize = new System.Drawing.Size(389, 313);
            this.Name = "FRXPageOptions";
            this.tc1.ResumeLayout(false);
            this.tab1.ResumeLayout(false);
            this.tab1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.udTabSize)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        public void Localize()
        {
            MyRes res = new MyRes("Forms,CodePageOptions");
            tab1.Text = Res.Get("Forms,FRXPageOptions");
            cbEnableFRXPage.Text = Res.Get("Forms,FRXPageOptions,Enable");
            cbUseSpaces.Text = res.Get("UseSpaces");
            lblTabSize.Text = res.Get("TabSize");
        }

        public override void Init()
        {
            cbUseSpaces.Checked = FRXPageSettings.UseSpaces;
            udTabSize.Value = FRXPageSettings.TabSize;
            cbEnableFRXPage.Checked = FRXPageSettings.Enable;
        }

        public override void Done(DialogResult result)
        {
            if (result == DialogResult.OK)
            {
                FRXPageSettings.UseSpaces = cbUseSpaces.Checked;
                FRXPageSettings.Enable = cbEnableFRXPage.Checked;
                FRXPageSettings.TabSize = (int)udTabSize.Value;
                editor.UpdateOptions();
                editor.Designer.ActiveReportTab.InitPages(editor.Designer.ActiveReportTab.ActivePageIndex);
            }
        }

        public FRXPageOptions(FRXPageDesigner editor) : base()
        {
            this.editor = editor;
            InitializeComponent();
            Localize();
        }
    }
}
