Browse Source

Merge pull request #2551 from MarkusKgit/NoneCursor_Issue_#2378

Add None to StandardCursorTypes #2378
pull/2607/head
Nikita Tsukanov 7 years ago
committed by GitHub
parent
commit
28964f2b62
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      native/Avalonia.Native/inc/avalonia-native.h
  2. 10
      native/Avalonia.Native/src/OSX/cursor.h
  3. 5
      native/Avalonia.Native/src/OSX/cursor.mm
  4. 10
      native/Avalonia.Native/src/OSX/window.mm
  5. 1
      src/Avalonia.Input/Cursors.cs
  6. 24
      src/Avalonia.X11/X11CursorFactory.cs
  7. 3
      src/Avalonia.X11/XLib.cs
  8. 3
      src/Gtk/Avalonia.Gtk3/CursorFactory.cs
  9. 1
      src/Gtk/Avalonia.Gtk3/GdkCursor.cs
  10. 1
      src/Windows/Avalonia.Win32/CursorFactory.cs

1
native/Avalonia.Native/inc/avalonia-native.h

@ -144,6 +144,7 @@ enum AvnStandardCursorType
CursorDragMove, CursorDragMove,
CursorDragCopy, CursorDragCopy,
CursorDragLink, CursorDragLink,
CursorNone
}; };
enum AvnWindowEdge enum AvnWindowEdge

10
native/Avalonia.Native/src/OSX/cursor.h

@ -11,18 +11,24 @@ class Cursor : public ComSingleObject<IAvnCursor, &IID_IAvnCursor>
{ {
private: private:
NSCursor * _native; NSCursor * _native;
bool _isHidden;
public: public:
FORWARD_IUNKNOWN() FORWARD_IUNKNOWN()
Cursor(NSCursor * cursor) Cursor(NSCursor * cursor, bool isHidden = false)
{ {
_native = cursor; _native = cursor;
_isHidden = isHidden;
} }
NSCursor* GetNative() NSCursor* GetNative()
{ {
return _native; return _native;
} }
bool IsHidden ()
{
return _isHidden;
}
}; };
extern std::map<AvnStandardCursorType, Cursor*> s_cursorMap; extern std::map<AvnStandardCursorType, Cursor*> s_cursorMap;

5
native/Avalonia.Native/src/OSX/cursor.mm

@ -21,6 +21,7 @@ class CursorFactory : public ComSingleObject<IAvnCursorFactory, &IID_IAvnCursorF
Cursor* resizeRightCursor = new Cursor([NSCursor resizeRightCursor]); Cursor* resizeRightCursor = new Cursor([NSCursor resizeRightCursor]);
Cursor* resizeWestEastCursor = new Cursor([NSCursor resizeLeftRightCursor]); Cursor* resizeWestEastCursor = new Cursor([NSCursor resizeLeftRightCursor]);
Cursor* operationNotAllowedCursor = new Cursor([NSCursor operationNotAllowedCursor]); Cursor* operationNotAllowedCursor = new Cursor([NSCursor operationNotAllowedCursor]);
Cursor* noCursor = new Cursor([NSCursor arrowCursor], true);
std::map<AvnStandardCursorType, Cursor*> s_cursorMap = std::map<AvnStandardCursorType, Cursor*> s_cursorMap =
{ {
@ -46,11 +47,13 @@ class CursorFactory : public ComSingleObject<IAvnCursorFactory, &IID_IAvnCursorF
{ CursorIbeam, IBeamCursor }, { CursorIbeam, IBeamCursor },
{ CursorLeftSide, resizeLeftCursor }, { CursorLeftSide, resizeLeftCursor },
{ CursorRightSide, resizeRightCursor }, { CursorRightSide, resizeRightCursor },
{ CursorNo, operationNotAllowedCursor } { CursorNo, operationNotAllowedCursor },
{ CursorNone, noCursor }
}; };
public: public:
FORWARD_IUNKNOWN() FORWARD_IUNKNOWN()
virtual HRESULT GetCursor (AvnStandardCursorType cursorType, IAvnCursor** retOut) override virtual HRESULT GetCursor (AvnStandardCursorType cursorType, IAvnCursor** retOut) override
{ {
*retOut = s_cursorMap[cursorType]; *retOut = s_cursorMap[cursorType];

10
native/Avalonia.Native/src/OSX/window.mm

@ -353,6 +353,16 @@ public:
Cursor* avnCursor = dynamic_cast<Cursor*>(cursor); Cursor* avnCursor = dynamic_cast<Cursor*>(cursor);
this->cursor = avnCursor->GetNative(); this->cursor = avnCursor->GetNative();
UpdateCursor(); UpdateCursor();
if(avnCursor->IsHidden())
{
[NSCursor hide];
}
else
{
[NSCursor unhide];
}
return S_OK; return S_OK;
} }
} }

1
src/Avalonia.Input/Cursors.cs

@ -38,6 +38,7 @@ namespace Avalonia.Input
DragMove, DragMove,
DragCopy, DragCopy,
DragLink, DragLink,
None,
// Not available in GTK directly, see http://www.pixelbeat.org/programming/x_cursors/ // Not available in GTK directly, see http://www.pixelbeat.org/programming/x_cursors/
// We might enable them later, preferably, by loading pixmax direclty from theme with fallback image // We might enable them later, preferably, by loading pixmax direclty from theme with fallback image

24
src/Avalonia.X11/X11CursorFactory.cs

@ -8,6 +8,8 @@ namespace Avalonia.X11
{ {
class X11CursorFactory : IStandardCursorFactory class X11CursorFactory : IStandardCursorFactory
{ {
private static IntPtr _nullCursor;
private readonly IntPtr _display; private readonly IntPtr _display;
private Dictionary<CursorFontShape, IntPtr> _cursors; private Dictionary<CursorFontShape, IntPtr> _cursors;
@ -42,16 +44,34 @@ namespace Avalonia.X11
public X11CursorFactory(IntPtr display) public X11CursorFactory(IntPtr display)
{ {
_display = display; _display = display;
_nullCursor = GetNullCursor(display);
_cursors = Enum.GetValues(typeof(CursorFontShape)).Cast<CursorFontShape>() _cursors = Enum.GetValues(typeof(CursorFontShape)).Cast<CursorFontShape>()
.ToDictionary(id => id, id => XLib.XCreateFontCursor(_display, id)); .ToDictionary(id => id, id => XLib.XCreateFontCursor(_display, id));
} }
public IPlatformHandle GetCursor(StandardCursorType cursorType) public IPlatformHandle GetCursor(StandardCursorType cursorType)
{ {
var handle = s_mapping.TryGetValue(cursorType, out var shape) IntPtr handle;
if (cursorType == StandardCursorType.None)
{
handle = _nullCursor;
}
else
{
handle = s_mapping.TryGetValue(cursorType, out var shape)
? _cursors[shape] ? _cursors[shape]
: _cursors[CursorFontShape.XC_top_left_arrow]; : _cursors[CursorFontShape.XC_top_left_arrow];
}
return new PlatformHandle(handle, "XCURSOR"); return new PlatformHandle(handle, "XCURSOR");
} }
private static IntPtr GetNullCursor(IntPtr display)
{
XColor color = new XColor();
byte[] data = new byte[] { 0 };
IntPtr window = XLib.XRootWindow(display, 0);
IntPtr pixmap = XLib.XCreateBitmapFromData(display, window, data, 1, 1);
return XLib.XCreatePixmapCursor(display, pixmap, pixmap, ref color, ref color, 0, 0);
}
} }
} }

3
src/Avalonia.X11/XLib.cs

@ -321,6 +321,9 @@ namespace Avalonia.X11
public static extern IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, public static extern IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask,
ref XColor foreground_color, ref XColor background_color, int x_hot, int y_hot); ref XColor foreground_color, ref XColor background_color, int x_hot, int y_hot);
[DllImport(libX11)]
public static extern IntPtr XCreateBitmapFromData(IntPtr display, IntPtr drawable, byte[] data, int width, int height);
[DllImport(libX11)] [DllImport(libX11)]
public static extern IntPtr XCreatePixmapFromBitmapData(IntPtr display, IntPtr drawable, byte[] data, int width, public static extern IntPtr XCreatePixmapFromBitmapData(IntPtr display, IntPtr drawable, byte[] data, int width,
int height, IntPtr fg, IntPtr bg, int depth); int height, IntPtr fg, IntPtr bg, int depth);

3
src/Gtk/Avalonia.Gtk3/CursorFactory.cs

@ -12,6 +12,7 @@ namespace Avalonia.Gtk3
private static readonly Dictionary<StandardCursorType, object> CursorTypeMapping = new Dictionary private static readonly Dictionary<StandardCursorType, object> CursorTypeMapping = new Dictionary
<StandardCursorType, object> <StandardCursorType, object>
{ {
{StandardCursorType.None, CursorType.Blank},
{StandardCursorType.AppStarting, CursorType.Watch}, {StandardCursorType.AppStarting, CursorType.Watch},
{StandardCursorType.Arrow, CursorType.LeftPtr}, {StandardCursorType.Arrow, CursorType.LeftPtr},
{StandardCursorType.Cross, CursorType.Cross}, {StandardCursorType.Cross, CursorType.Cross},
@ -80,4 +81,4 @@ namespace Avalonia.Gtk3
return rv; return rv;
} }
} }
} }

1
src/Gtk/Avalonia.Gtk3/GdkCursor.cs

@ -2,6 +2,7 @@
{ {
enum GdkCursorType enum GdkCursorType
{ {
Blank = -2,
CursorIsPixmap = -1, CursorIsPixmap = -1,
XCursor = 0, XCursor = 0,
Arrow = 2, Arrow = 2,

1
src/Windows/Avalonia.Win32/CursorFactory.cs

@ -41,6 +41,7 @@ namespace Avalonia.Win32
private static readonly Dictionary<StandardCursorType, int> CursorTypeMapping = new Dictionary private static readonly Dictionary<StandardCursorType, int> CursorTypeMapping = new Dictionary
<StandardCursorType, int> <StandardCursorType, int>
{ {
{StandardCursorType.None, 0},
{StandardCursorType.AppStarting, 32650}, {StandardCursorType.AppStarting, 32650},
{StandardCursorType.Arrow, 32512}, {StandardCursorType.Arrow, 32512},
{StandardCursorType.Cross, 32515}, {StandardCursorType.Cross, 32515},

Loading…
Cancel
Save