//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//
// UserWin satellite library | Author: Sergei Y.Kitáev
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.ComponentModel;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;

using CommonHelpers;

namespace UserWin {

//**************************************************************************************************
/// <summary>
/// </summary>
public class UXBusyOverlay: ContentControl {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[DefaultValue(_IsMovableDefault_)]
public bool IsMovable
{
   get { return GetIsMovable(this); }
   set { SetIsMovable(this,value); }
}

//--------------------------------------------------------------------------------------------------

[DefaultValue(_IsMovableDefault_)]
public static readonly DependencyProperty IsMovableProperty;

public static bool GetIsMovable(UXBusyOverlay element)
{
   return (bool)element.GetValue( IsMovableProperty );
}

public static void SetIsMovable(UXBusyOverlay element,bool value)
{
   element.SetValue( IsMovableProperty, value );
}

//==================================================================================================

protected override void OnInitialized(EventArgs e)
{
   base.OnInitialized(e);

   if (!DesignerProperties.GetIsInDesignMode(this))
   {
      UpdateContentTemplate();
      Focusable = IsTabStop = false;
      UXApplication.BusyStateChangedHandler += UpdateContentTemplate;
   }
   else
      Visibility = Visibility.Collapsed;
}

//==================================================================================================

void UpdateContentTemplate()
{
   UpdateContentTemplate( false );
}

void UpdateContentTemplate(bool instantAppearance)
{
   if (!DesignerProperties.GetIsInDesignMode(this))
      ContentTemplate = (DataTemplate)FindResource(
         IsMovable && !UXAppWaiting.IsSuspended ?
            instantAppearance ?
               UXResourceKeys.BusyOverlayInstantMovableDataTemplate :
               UXResourceKeys.BusyOverlayMovableDataTemplate :
            instantAppearance ?
               UXResourceKeys.BusyOverlayInstantDataTemplate :
               UXResourceKeys.BusyOverlayDataTemplate );
}

//==================================================================================================

static UXBusyOverlay()
{
   UserWin_Library.Access();

   IsMovableProperty = DependencyProperty.Register(
      "IsMovable", typeof(bool), typeof(UXBusyOverlay),
      new FrameworkPropertyMetadata( _IsMovableDefault_, OnIsMovableChanged ) );
}

//--------------------------------------------------------------------------------------------------

static void OnIsMovableChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
{
   ((UXBusyOverlay)d).UpdateContentTemplate();
}

//--------------------------------------------------------------------------------------------------

const bool
   _IsMovableDefault_ = true;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // UXBusyOverlay
//**************************************************************************************************

} // UserWin
