OleDragSource.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Avalonia.Win32.Interop;
  5. namespace Avalonia.Win32
  6. {
  7. class OleDragSource : IDropSource
  8. {
  9. private const int DRAGDROP_S_USEDEFAULTCURSORS = 0x00040102;
  10. private const int DRAGDROP_S_DROP = 0x00040100;
  11. private const int DRAGDROP_S_CANCEL = 0x00040101;
  12. private const int KEYSTATE_LEFTMB = 1;
  13. private const int KEYSTATE_MIDDLEMB = 16;
  14. private const int KEYSTATE_RIGHTMB = 2;
  15. private static readonly int[] MOUSE_BUTTONS = new int[] { KEYSTATE_LEFTMB, KEYSTATE_MIDDLEMB, KEYSTATE_RIGHTMB };
  16. public int QueryContinueDrag(int fEscapePressed, int grfKeyState)
  17. {
  18. if (fEscapePressed != 0)
  19. return DRAGDROP_S_CANCEL;
  20. int pressedMouseButtons = MOUSE_BUTTONS.Where(mb => (grfKeyState & mb) == mb).Count();
  21. if (pressedMouseButtons >= 2)
  22. return DRAGDROP_S_CANCEL;
  23. if (pressedMouseButtons == 0)
  24. return DRAGDROP_S_DROP;
  25. return unchecked((int)UnmanagedMethods.HRESULT.S_OK);
  26. }
  27. public int GiveFeedback(int dwEffect)
  28. {
  29. return DRAGDROP_S_USEDEFAULTCURSORS;
  30. }
  31. }
  32. }