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

using WF = System.Windows.Forms;
using DRW = System.Drawing;

using CommonHelpers;

namespace WFX {

//**************************************************************************************************
/// <summary>
/// </summary>
public static partial class Control {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static WF.Control GetFocus()
{
   IntPtr focusedHandle = Win32.GetFocus();
   return focusedHandle != IntPtr.Zero ?
      WF.Control.FromHandle( focusedHandle ) : null;
}

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

public static bool IsWindowEnabled(WF.Control control)
{
   HArgChecking.VerifyNotNull( control );
   return control.Visible && Win32.IsWindowEnabled( control.Handle );
}

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

public static DRW.Rectangle BoundsToStreen(WF.Control control)
{
   return (control.Parent ?? control).RectangleToScreen( control.Bounds );
}

public static DRW.Rectangle ClientBoundsToStreen(WF.Control control)
{
   return (control.Parent ?? control).RectangleToScreen( control.ClientRectangle );
}

public static DRW.Rectangle DisplayBoundsToStreen(WF.Control control)
{
   return (control.Parent ?? control).RectangleToScreen( control.DisplayRectangle );
}

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

public static bool IsMouseWithin(WF.Control control)
{
   return BoundsToStreen( control ).Contains( WF.Cursor.Position );
}

public static bool IsMouseWithinClientRectangle(WF.Control control)
{
   return ClientBoundsToStreen( control ).Contains( WF.Cursor.Position );
}

public static bool IsMouseWithinDisplayRectangle(WF.Control control)
{
   return DisplayBoundsToStreen( control ).Contains( WF.Cursor.Position );
}

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

public static void SetBoldFont(WF.Control control)
{
   SetBoldFont( control, true );
}

public static void SetBoldFont(WF.Control control,bool bold)
{
   HArgChecking.VerifyNotNull( control );
   control.Font = Font.CreateBold( control.Font, bold );
}

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

public static void AlterFontStyle(WF.Control control,[HOptional] DRW.FontStyle stylesToAdd)
{
   AlterFontStyle( control, stylesToAdd, 0 );
}

public static void AlterFontStyle( WF.Control control,
                                   [HOptional] DRW.FontStyle stylesToAdd,
                                   [HOptional] DRW.FontStyle stylesToRemove )
{
   HArgChecking.VerifyNotNull( control );
   control.Font = Font.CreateAltered( control.Font, stylesToAdd, stylesToRemove );
}

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

public static void SetFontStyle(WF.Control control,DRW.FontStyle style)
{
   HArgChecking.VerifyNotNull( control );
   control.Font = new DRW.Font( control.Font, style );
}

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

public static void InvalidateUpdate(WF.Control control)
{
   HArgChecking.VerifyNotNull( control ); control.Invalidate(); control.Update();
}

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

static Control()
{
   WFX_Library.Access();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // Control
//**************************************************************************************************

} // WFX
