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

using System.Windows.Input;

using CommonHelpers;

namespace UserWin {

//**************************************************************************************************
partial class UXAppWaiting {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public UXAppWaiting(): this(UXAppWaitingStatus.Neutral)
{}

public UXAppWaiting([HOptional] string caption)
   :this( new UXAppWaitingStatus(caption) )
{}

public UXAppWaiting(string captionFmt,params object[] parameters)
   :this( string.Format(captionFmt,parameters) )
{}

public UXAppWaiting([HOptional] UXAppWaitingStatus status)
   :this( status, false )
{}

public UXAppWaiting(bool isSuspended,bool isSuppressedForBackoff=true)
   :this( null, isSuspended )
{
   _SuppressBackOff_ = isSuppressedForBackoff;
}

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

public UXAppWaitingStatus InitialStatus
{
   get { VerifyActive(); return _InitialStatus_; }
}

public string InitialCaption
{
   get { VerifyActive(); return _InitialStatus_.Caption; }
}

public UXAppWaitingStatus PreviousStatus
{
   get { VerifyActive(); return _PreviousStatus_; }
}

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

public void RevertStatusToInitial()
{
   DisplayStatus( _InitialStatus_ );
}

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

protected override void OnDispose(bool synchronous)
{
   HProgram.VerifyInMainThread();
   if ( !_SuppressBackOff_ )
   {
      VerifyActive();
      _IsInDispose_ = true;
      try
         { DisplayStatus(_PreviousStatus_); }
      finally
         { _IsInDispose_ = false; }
      _CurrentInstance_ = _PreviousInstance_;
   }
}

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

UXAppWaiting([HOptional] UXAppWaitingStatus status,bool isSuspended)
{
   VerifyActive();
   UXAppWaitingStatus stat;
   if ( status != null )
      stat = status;
   else
   {
      stat = CurrentStatus.Duplicate();
      stat._IsSuspended_ = isSuspended;
   }
   _PreviousStatus_ = _CurrentStatus_;
   _PreviousInstance_ = HOps.Exchange( ref _CurrentInstance_, this );
   SetStatus( stat!=UXAppWaitingStatus.Neutral ? stat : CurrentStatus );
   _InitialStatus_ = _CurrentStatus_;
   ShowStatus();
   ValidateDisposable();
}

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

UXAppWaitingStatus
   _InitialStatus_,
   _PreviousStatus_;
UXAppWaiting
   _PreviousInstance_;
bool
   _SuppressBackOff_;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // UXAppWaiting
//**************************************************************************************************

} // UserWin
