using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using C1.Silverlight.RichTextBox;
using System.Windows.Controls.Primitives;
using System.Windows.Interop;
using System.Runtime.InteropServices;
using C1.Silverlight;

namespace RichTextBoxSamples.Tools
{
    /// <summary>
    /// Interaction logic for InsertTableTool.xaml
    /// </summary>
    public partial class InsertTableTool : UserControl
    {
        public C1Window window
        {
            get;
            set;
        }

        public C1RichTextBox RichTextBox
        {
            get;
            set;
        }

        public InsertTableTool()
        {
            this.InitializeComponent();
           
        }

        public void Show()
        {
            window = new C1Window();
            window.Content = this;
            window.ShowMaximizeButton = false;
            window.ShowMinimizeButton = false;
            window.Header = "Insert Table";
            window.CenterOnScreen();
            window.ShowModal();
        }

        public void Close()
        {
            window.Close();
        }

        private void btnInsertTable_Click(object sender, RoutedEventArgs e)
        {
            int rows = (int)numRowsBox.Value;
            int cols = (int)numColsBox.Value;
            if (RichTextBox != null && rows > 0 && cols > 0)
                RichTextBox.Selection.Start.InsertTable(rows, cols);
            Close();
        }
    }
}
