using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using C1.Silverlight;
using C1.Silverlight.Toolbar;

namespace Toolbar
{
  public partial class ToolbarCommands : UserControl
  {
    public ToolbarCommands()
    {
      InitializeComponent();

      Loaded += (se, ev) =>
        {
      foreach (var key in Resources.Keys)
      {
        var cmd = Resources[key] as C1ToolbarCommand;
        if (cmd != null)
        {
          CommandManager.RegisterClassCommandBinding(GetType(), new CommandBinding(
            cmd, (s, e) => Execute(cmd.LabelTitle), (s, e) => e.CanExecute = true));
        }
      }
      CommandManager.InvalidateRequerySuggested();
        };
    }

    void Execute(string text)
    {
      tb.Text += text + "\n";
      tb.SelectionStart = tb.Text.Length;
    }

    private void C1Toolbar_HelpClick(object sender, EventArgs e)
    {
      Execute("Help clicked");
    }

    private void fg_Click(object sender, RoutedEventArgs e)
    {
      tb.Foreground = new SolidColorBrush(fgcp.SelectedColor);
      Execute("Foreground changed - button");
    }

    private void fgcp_SelectedColorChanged(object sender, PropertyChangedEventArgs<Color> e)
    {
      fg.IsDropDownOpen = false;
      tb.Foreground = new SolidColorBrush(fgcp.SelectedColor);
      Execute("Foreground changed - dropdown");
    }

    private void bg_Click(object sender, RoutedEventArgs e)
    {
      tb.Background = new SolidColorBrush(bgcp.SelectedColor);
      Execute("Background changed - button");
    }

    private void bgcp_SelectedColorChanged(object sender, PropertyChangedEventArgs<Color> e)
    {
      bg.IsDropDownOpen = false;
      tb.Background = new SolidColorBrush(bgcp.SelectedColor);
      Execute("Background changed - dropdown");
    }

    private void C1ToolbarGroup_DialogLauncherClick(object sender, EventArgs e)
    {
      var tbgroup = (C1ToolbarGroup)sender;
      MessageBox.Show(tbgroup.Header.ToString() + " Dialog");
    }
  }
}
