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

using CommonHelpers;

namespace UserWin {

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

[CLSCompliant(false)]
public const uint
   WM_MOUSEMOVE         = 0x0200,
   WM_LBUTTONDOWN       = 0x0201,
   WM_LBUTTONUP         = 0x0202,
   WM_LBUTTONDBLCLK     = 0x0203,
   WM_RBUTTONDOWN       = 0x0204,
   WM_RBUTTONUP         = 0x0205,
   WM_RBUTTONDBLCLK     = 0x0206,
   WM_MBUTTONDOWN       = 0x0207,
   WM_MBUTTONUP         = 0x0208,
   WM_MBUTTONDBLCLK     = 0x0209,
   WM_MOUSEWHEEL        = 0x020A,

   WM_NCMOUSEMOVE       = 0x00A0,
   WM_NCMBUTTONDBLCLK   = 0x00A9,
   WM_NCXBUTTONDOWN     = 0x00AB,
   WM_NCXBUTTONDBLCLK   = 0x00AD,
   WM_NCMOUSEHOVER      = 0x02A0,
   WM_NCMOUSELEAVE      = 0x02A2,

   WM_KEYDOWN           = 0x0100,
   WM_KEYUP             = 0x0101,
   WM_CHAR              = 0x0102,
   WM_DEADCHAR          = 0x0103,
   WM_SYSKEYDOWN        = 0x0104,
   WM_SYSKEYUP          = 0x0105,
   WM_SYSCHAR           = 0x0106,
   WM_SYSDEADCHAR       = 0x0107;

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

public static bool IsKeyboardMessage(int message)
{
   return IsKeyboardMessage( unchecked( (uint)message ) );
}

public static bool IsMouseMessage(int message)
{
   return IsMouseMessage( unchecked( (uint)message ) );
}

public static bool IsMouseMessage(int message,bool accountNCMessages)
{
   return IsMouseMessage( unchecked( (uint)message ), accountNCMessages );
}

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

public static bool IsGestureMessage(int message)
{
   return IsGestureMessage( unchecked( (uint)message ) );
}

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

public static bool IsInputMessage(int message)
{
   return IsInputMessage( unchecked( (uint)message ) );
}

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

[CLSCompliant(false)]
public static bool IsKeyboardMessage(uint message)
{
   return
      HOps.IsBetween( message, Win32.WM_KEYFIRST, Win32.WM_KEYLAST );
}

[CLSCompliant(false)]
public static bool IsMouseMessage(uint message)
{
   return IsMouseMessage( message, false );
}

[CLSCompliant(false)]
public static bool IsMouseMessage(uint message,bool accountNCMessages)
{
   return
      HOps.IsBetween( message, Win32.WM_MOUSEFIRST, Win32.WM_MOUSELAST ) ||
      accountNCMessages && IsNCMouseMessage( message );
}

[CLSCompliant(false)]
public static bool IsNCMouseMessage(uint message)
{
   return
      HOps.IsBetween( message, 0x00A0u, 0x00A9u ) || // WM_NCMOUSEMOVE   .. WM_NCMBUTTONDBLCLK
      HOps.IsBetween( message, 0x00ABu, 0x00ADu ) || // WM_NCXBUTTONDOWN .. WM_NCXBUTTONDBLCLK
      HOps.IsOneOf  ( message, 0x02A0u, 0x02A2u ); // WM_NCMOUSEHOVER, WM_NCMOUSELEAVE
}

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

[CLSCompliant(false)]
public static bool IsGestureMessage(uint message)
{
   return HOps.IsOneOf( (int)message, 0x0119, 0x011A ); // WM_GESTURE, WM_GESTURENOTIFY
}

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

[CLSCompliant(false)]
public static bool IsInputMessage(uint message)
{
   return
      IsKeyboardMessage( message ) ||
      IsMouseMessage( message, true ) ||
      IsGestureMessage( message );
}

[CLSCompliant(false)]
public static bool IsClientInputMessage(uint message)
{
   return
      IsKeyboardMessage( message ) ||
      IsMouseMessage( message ) ||
      IsGestureMessage( message );
}

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

public static void ProcessMessageQueueWithoutInput()
{
   HProgram.VerifyInMainThread();
   Win32_MSG msg;
   while ( Win32.PeekMessage( out msg, IntPtr.Zero, 0, 0, Win32.PM_REMOVE ) )
      if ( !IsInputMessage( msg.message ) )
         Win32.DispatchMessage( ref msg );
}

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

static UXWMInputHelpers()
{
   UserWin_Library.Access();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // UXWMInputHelpers
//**************************************************************************************************

} // UserWin
