using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace XFEditorCtrlSample
{
    /// <summary>
    /// Sample form class
    /// </summary>
    public partial class Form1 : Form
    {
        /// <summary>
        /// Creates a new instance of Form1
        /// </summary>
        public Form1()
        {
            InitializeComponent();
        }

        private void openFileBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = "fo";
            dlg.Filter = "XSL-FO Documents (*.fo)|*.fo|XFD Template Documents (*.xfd)|*.xfd|All Files (*.*)|*.*";
            dlg.ShowDialog();
            dlg.Multiselect = false;
            if (dlg.FileNames.Length > 0)
            {
                editorCtrl.LoadFile(dlg.FileNames[0]);
                editorCtrl.Focus();
            }
        }

        private void loadXSLFOBtn_Click(object sender, EventArgs e)
        {
            String xml = "<fo:root xmlns:fo='http://www.w3.org/1999/XSL/Format'>\n" +
                                "\t<fo:layout-master-set>\n" +
                                "\t\t<fo:simple-page-master master-name='all-pages'>\n" +
                                "\t\t\t<fo:region-body region-name='xsl-region-body' margin='0.7in'/>\n" +
                                "\t\t</fo:simple-page-master>\n" +
                                "\t</fo:layout-master-set>\n" +
                                "\t<fo:page-sequence master-reference='all-pages'>\n" +
                                "\t\t<fo:flow flow-name='xsl-region-body'>\n" +
                                "\t\t\t<fo:block>Hello World!</fo:block>\n" +
                                "\t\t</fo:flow>\n" +
                                "\t</fo:page-sequence>\n" +
                                "</fo:root>\n";

            editorCtrl.LoadXml(xml, "");
            editorCtrl.Focus();
        }

        private void loadXFDBtn_Click(object sender, EventArgs e)
        {
            String xml = "<xfd:document xmlns:xfd='http://www.ecrion.com/xfd/1.0' xmlns:fo='http://www.w3.org/1999/XSL/Format' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xf='http://www.ecrion.com/xf/1.0'>\n" +
                                "\t<fo:layout-master-set>\n" +
                                "\t\t<fo:simple-page-master master-name='all-pages'>\n" +
                                "\t\t\t<fo:region-body region-name='xsl-region-body' margin='0.7in'/>\n" +
                                "\t\t</fo:simple-page-master>\n" +
                                "\t</fo:layout-master-set>\n" +
                                "\t<fo:page-sequence master-reference='all-pages'>\n" +
                                "\t\t<fo:flow flow-name='xsl-region-body'>\n" +
                                "\t\t\t<fo:block>Hello World!</fo:block>\n" +
                                "\t\t</fo:flow>\n" +
                                "\t</fo:page-sequence>\n" +
                                "</xfd:document>\n";

            editorCtrl.LoadXml(xml, "");
            editorCtrl.Focus();
        }

        private void signature_Click(object sender, EventArgs e)
        {
            String xml = "<fo:block>Sincerely,</fo:block>" + 
			                "<fo:block font-weight='bold'>John Smith</fo:block>" + 
			                "<fo:block font-size='10pt'>marketing advisor</fo:block>";

            editorCtrl.InsertXml(xml);
            editorCtrl.Focus();
        }

        private void activateForm(object sender, System.EventArgs e)
        {
            editorCtrl.Focus();
        }
    }
}