Browse Source

code standards and formatting, copyright message

pull/1977/head
Dan Walmsley 8 years ago
parent
commit
716941ec56
  1. 18
      src/Avalonia.Native.OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj
  2. 2
      src/Avalonia.Native.OSX/Avalonia.Native.OSX.xcodeproj/xcshareddata/xcschemes/Avalonia.Native.OSX.xcscheme
  3. 3
      src/Avalonia.Native.OSX/KeyTransform.h
  4. 29
      src/Avalonia.Native.OSX/KeyTransform.mm
  5. 52
      src/Avalonia.Native.OSX/Screens.mm
  6. 3
      src/Avalonia.Native.OSX/SystemDialogs.mm
  7. 15
      src/Avalonia.Native.OSX/clipboard.mm
  8. 4
      src/Avalonia.Native.OSX/common.h
  9. 9
      src/Avalonia.Native.OSX/cursor.h
  10. 8
      src/Avalonia.Native.OSX/cursor.mm
  11. 54
      src/Avalonia.Native.OSX/main.mm
  12. 3
      src/Avalonia.Native.OSX/platformthreading.mm
  13. 21
      src/Avalonia.Native.OSX/window.h
  14. 363
      src/Avalonia.Native.OSX/window.mm
  15. 29
      src/Avalonia.Native/AvaloniaNativePlatform.cs
  16. 29
      src/Avalonia.Native/AvaloniaNativePlatformExtensions.cs
  17. 20
      src/Avalonia.Native/CallbackBase.cs
  18. 20
      src/Avalonia.Native/ClipboardImpl.cs
  19. 5
      src/Avalonia.Native/Cursor.cs
  20. 14
      src/Avalonia.Native/DeferredFramebuffer.cs
  21. 13
      src/Avalonia.Native/DeferredRendererProxy.cs
  22. 10
      src/Avalonia.Native/DynLoader.cs
  23. 9
      src/Avalonia.Native/Helpers.cs
  24. 4
      src/Avalonia.Native/IconLoader.cs
  25. 5
      src/Avalonia.Native/PlatformThreadingInterface.cs
  26. 7
      src/Avalonia.Native/PopupImpl.cs
  27. 5
      src/Avalonia.Native/ScreenImpl.cs
  28. 5
      src/Avalonia.Native/SystemDialogs.cs
  29. 12
      src/Avalonia.Native/WindowImpl.cs
  30. 28
      src/Avalonia.Native/WindowImplBase.cs
  31. 3
      src/headers/avalonia-native-guids.h
  32. 24
      src/headers/avalonia-native.h
  33. 3
      src/headers/com.h
  34. 3
      src/headers/key.h

18
src/Avalonia.Native.OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj

@ -121,7 +121,7 @@
AB7A61E72147C814003C5833 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0830;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = Avalonia;
TargetAttributes = {
AB7A61EE2147C814003C5833 = {
@ -176,15 +176,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@ -224,15 +232,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

2
src/Avalonia.Native.OSX/Avalonia.Native.OSX.xcodeproj/xcshareddata/xcschemes/Avalonia.Native.OSX.xcscheme

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

3
src/Avalonia.Native.OSX/KeyTransform.h

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#ifndef keytransform_h
#define keytransform_h
#include "common.h"

29
src/Avalonia.Native.OSX/KeyTransform.mm

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#include "KeyTransform.h"
const int kVK_ANSI_A = 0x00;
@ -23,7 +26,7 @@ const int kVK_ANSI_3 = 0x14;
const int kVK_ANSI_4 = 0x15;
const int kVK_ANSI_6 = 0x16;
const int kVK_ANSI_5 = 0x17;
const int kVK_ANSI_Equal = 0x18;
//const int kVK_ANSI_Equal = 0x18;
const int kVK_ANSI_9 = 0x19;
const int kVK_ANSI_7 = 0x1A;
const int kVK_ANSI_Minus = 0x1B;
@ -42,11 +45,11 @@ const int kVK_ANSI_K = 0x28;
const int kVK_ANSI_Semicolon = 0x29;
const int kVK_ANSI_Backslash = 0x2A;
const int kVK_ANSI_Comma = 0x2B;
const int kVK_ANSI_Slash = 0x2C;
//const int kVK_ANSI_Slash = 0x2C;
const int kVK_ANSI_N = 0x2D;
const int kVK_ANSI_M = 0x2E;
const int kVK_ANSI_Period = 0x2F;
const int kVK_ANSI_Grave = 0x32;
//const int kVK_ANSI_Grave = 0x32;
const int kVK_ANSI_KeypadDecimal = 0x41;
const int kVK_ANSI_KeypadMultiply = 0x43;
const int kVK_ANSI_KeypadPlus = 0x45;
@ -54,7 +57,7 @@ const int kVK_ANSI_KeypadClear = 0x47;
const int kVK_ANSI_KeypadDivide = 0x4B;
const int kVK_ANSI_KeypadEnter = 0x4C;
const int kVK_ANSI_KeypadMinus = 0x4E;
const int kVK_ANSI_KeypadEquals = 0x51;
//const int kVK_ANSI_KeypadEquals = 0x51;
const int kVK_ANSI_Keypad0 = 0x52;
const int kVK_ANSI_Keypad1 = 0x53;
const int kVK_ANSI_Keypad2 = 0x54;
@ -79,7 +82,7 @@ const int kVK_RightCommand = 0x36;
const int kVK_RightShift = 0x3C;
const int kVK_RightOption = 0x3D;
const int kVK_RightControl = 0x3E;
const int kVK_Function = 0x3F;
//const int kVK_Function = 0x3F;
const int kVK_F17 = 0x40;
const int kVK_VolumeUp = 0x48;
const int kVK_VolumeDown = 0x49;
@ -113,17 +116,17 @@ const int kVK_LeftArrow = 0x7B;
const int kVK_RightArrow = 0x7C;
const int kVK_DownArrow = 0x7D;
const int kVK_UpArrow = 0x7E;
const int kVK_ISO_Section = 0x0A;
const int kVK_JIS_Yen = 0x5D;
const int kVK_JIS_Underscore = 0x5E;
const int kVK_JIS_KeypadComma = 0x5F;
const int kVK_JIS_Eisu = 0x66;
const int kVK_JIS_Kana = 0x68;
//const int kVK_ISO_Section = 0x0A;
//const int kVK_JIS_Yen = 0x5D;
//const int kVK_JIS_Underscore = 0x5E;
//const int kVK_JIS_KeypadComma = 0x5F;
//const int kVK_JIS_Eisu = 0x66;
//const int kVK_JIS_Kana = 0x68;
std::map<int, AvnKey> s_KeyMap =
{
{0, A},
{1, S},
{kVK_ANSI_A, A},
{kVK_ANSI_S, S},
{kVK_ANSI_D, D},
{kVK_ANSI_F, F},
{kVK_ANSI_H, H},

52
src/Avalonia.Native.OSX/Screens.mm

@ -1,38 +1,46 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#include "common.h"
class Screens : public ComSingleObject<IAvnScreens, &IID_IAvnScreens>
{
public:
virtual HRESULT GetScreenCount (int* ret)
{
*ret = (int)[NSScreen screens].count;
return S_OK;
@autoreleasepool
{
*ret = (int)[NSScreen screens].count;
return S_OK;
}
}
virtual HRESULT GetScreen (int index, AvnScreen* ret)
{
if(index < 0 || index >= [NSScreen screens].count)
@autoreleasepool
{
return E_INVALIDARG;
if(index < 0 || index >= [NSScreen screens].count)
{
return E_INVALIDARG;
}
auto screen = [[NSScreen screens] objectAtIndex:index];
ret->Bounds.X = [screen frame].origin.x;
ret->Bounds.Y = [screen frame].origin.y;
ret->Bounds.Height = [screen frame].size.height;
ret->Bounds.Width = [screen frame].size.width;
ret->WorkingArea.X = [screen visibleFrame].origin.x;
ret->WorkingArea.Y = [screen visibleFrame].origin.y;
ret->WorkingArea.Height = [screen visibleFrame].size.height;
ret->WorkingArea.Width = [screen visibleFrame].size.width;
ret->Primary = index == 0;
return S_OK;
}
auto screen = [[NSScreen screens] objectAtIndex:index];
ret->Bounds.X = [screen frame].origin.x;
ret->Bounds.Y = [screen frame].origin.y;
ret->Bounds.Height = [screen frame].size.height;
ret->Bounds.Width = [screen frame].size.width;
ret->WorkingArea.X = [screen visibleFrame].origin.x;
ret->WorkingArea.Y = [screen visibleFrame].origin.y;
ret->WorkingArea.Height = [screen visibleFrame].size.height;
ret->WorkingArea.Width = [screen visibleFrame].size.width;
ret->Primary = index == 0;
return S_OK;
}
};

3
src/Avalonia.Native.OSX/SystemDialogs.mm

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#include "common.h"
#include "window.h"

15
src/Avalonia.Native.OSX/clipboard.mm

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#include "common.h"
class Clipboard : public ComSingleObject<IAvnClipboard, &IID_IAvnClipboard>
@ -5,28 +8,34 @@ class Clipboard : public ComSingleObject<IAvnClipboard, &IID_IAvnClipboard>
public:
virtual HRESULT GetText (void** retOut)
{
@autoreleasepool {
@autoreleasepool
{
NSString *str = [[NSPasteboard generalPasteboard] stringForType:NSPasteboardTypeString];
*retOut = (void *)str.UTF8String;
}
return S_OK;
}
virtual HRESULT SetText (char* text)
{
@autoreleasepool {
@autoreleasepool
{
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
[pasteBoard clearContents];
[pasteBoard setString:@(text) forType:NSPasteboardTypeString];
}
return S_OK;
}
virtual HRESULT Clear()
{
@autoreleasepool {
@autoreleasepool
{
[[NSPasteboard generalPasteboard] clearContents];
}
return S_OK;
}
};

4
src/Avalonia.Native.OSX/common.h

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#ifndef common_h
#define common_h
#include "com.h"
@ -18,4 +21,5 @@ extern IAvnCursorFactory* CreateCursorFactory();
extern NSPoint ToNSPoint (AvnPoint p);
extern AvnPoint ToAvnPoint (NSPoint p);
extern AvnPoint ConvertPointY (AvnPoint p);
extern NSSize ToNSSize (AvnSize s);
#endif

9
src/Avalonia.Native.OSX/cursor.h

@ -1,10 +1,5 @@
//
// cursor.h
// Avalonia.Native.OSX
//
// Created by ElBuda on 10/5/18.
// Copyright © 2018 Avalonia. All rights reserved.
//
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#ifndef cursor_h
#define cursor_h

8
src/Avalonia.Native.OSX/cursor.mm

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#include "common.h"
#include "cursor.h"
#include <map>
@ -53,5 +56,8 @@ public:
extern IAvnCursorFactory* CreateCursorFactory()
{
return new CursorFactory();
@autoreleasepool
{
return new CursorFactory();
}
}

54
src/Avalonia.Native.OSX/main.mm

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
//This file will contain actual IID structures
#define COM_GUIDS_MATERIALIZE
#include "common.h"
@ -125,40 +128,39 @@ extern "C" IAvaloniaNativeFactory* CreateAvaloniaNative()
return new AvaloniaNative();
};
NSSize ToNSSize (AvnSize s)
{
NSSize result;
result.width = s.Width;
result.height = s.Height;
return result;
}
NSPoint ToNSPoint (AvnPoint p)
{
@autoreleasepool
{
NSPoint result;
result.x = p.X;
result.y = p.Y;
return result;
}
NSPoint result;
result.x = p.X;
result.y = p.Y;
return result;
}
AvnPoint ToAvnPoint (NSPoint p)
{
@autoreleasepool
{
AvnPoint result;
result.X = p.x;
result.Y = p.y;
return result;
}
AvnPoint result;
result.X = p.x;
result.Y = p.y;
return result;
}
AvnPoint ConvertPointY (AvnPoint p)
{
@autoreleasepool
{
auto sw = [NSScreen.screens objectAtIndex:0].frame;
auto t = MAX(sw.origin.y, sw.origin.y + sw.size.height);
p.Y = t - p.Y;
return p;
}
auto sw = [NSScreen.screens objectAtIndex:0].frame;
auto t = MAX(sw.origin.y, sw.origin.y + sw.size.height);
p.Y = t - p.Y;
return p;
}

3
src/Avalonia.Native.OSX/platformthreading.mm

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#include "common.h"
class PlatformThreadingInterface;

21
src/Avalonia.Native.OSX/window.h

@ -1,10 +1,5 @@
//
// window.h
// Avalonia.Native.OSX
//
// Created by Dan Walmsley on 23/09/2018.
// Copyright © 2018 Avalonia. All rights reserved.
//
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#ifndef window_h
#define window_h
@ -12,21 +7,21 @@
class WindowBaseImpl;
@interface AvnView : NSView<NSTextInputClient>
-(AvnView*) initWithParent: (WindowBaseImpl*) parent;
-(NSEvent*) lastMouseDownEvent;
-(AvnView* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent;
-(NSEvent* _Nonnull) lastMouseDownEvent;
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
-(void) setSwRenderedFrame: (AvnFramebuffer*) fb dispose: (IUnknown*) dispose;
-(void) setSwRenderedFrame: (AvnFramebuffer* _Nonnull) fb dispose: (IUnknown* _Nonnull) dispose;
@end
@interface AvnWindow : NSWindow <NSWindowDelegate>
-(AvnWindow*) initWithParent: (WindowBaseImpl*) parent;
-(AvnWindow* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent;
-(void) setCanBecomeKeyAndMain;
-(void) pollModalSession: (nonnull NSModalSession) session;
-(void) pollModalSession: (NSModalSession _Nonnull) session;
@end
struct INSWindowHolder
{
virtual AvnWindow* GetNSWindow () = 0;
virtual AvnWindow* _Nonnull GetNSWindow () = 0;
};
struct IWindowStateChanged

363
src/Avalonia.Native.OSX/window.mm

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#include "common.h"
#include "window.h"
#include "KeyTransform.h"
@ -35,26 +38,37 @@ public:
virtual HRESULT Show()
{
SetPosition(lastPositionSet);
UpdateStyle();
[Window makeKeyAndOrderFront:Window];
return S_OK;
@autoreleasepool
{
SetPosition(lastPositionSet);
UpdateStyle();
[Window makeKeyAndOrderFront:Window];
return S_OK;
}
}
virtual HRESULT Hide ()
{
if(Window != nullptr)
@autoreleasepool
{
[Window orderOut:Window];
if(Window != nullptr)
{
[Window orderOut:Window];
}
return S_OK;
}
return S_OK;
}
virtual HRESULT Activate ()
{
if(Window != nullptr)
@autoreleasepool
{
[Window makeKeyWindow];
if(Window != nullptr)
{
[Window makeKeyWindow];
}
}
return S_OK;
@ -62,129 +76,186 @@ public:
virtual HRESULT SetTopMost (bool value)
{
[Window setLevel: value ? NSFloatingWindowLevel : NSNormalWindowLevel];
return S_OK;
@autoreleasepool
{
[Window setLevel: value ? NSFloatingWindowLevel : NSNormalWindowLevel];
return S_OK;
}
}
virtual HRESULT Close()
{
[Window close];
return S_OK;
@autoreleasepool
{
[Window close];
return S_OK;
}
}
virtual HRESULT GetClientSize(AvnSize* ret)
{
if(ret == nullptr)
return E_POINTER;
auto frame = [View frame];
ret->Width = frame.size.width;
ret->Height = frame.size.height;
return S_OK;
@autoreleasepool
{
if(ret == nullptr)
return E_POINTER;
auto frame = [View frame];
ret->Width = frame.size.width;
ret->Height = frame.size.height;
return S_OK;
}
}
virtual HRESULT GetMaxClientSize(AvnSize* ret)
{
if(ret == nullptr)
return E_POINTER;
auto size = [NSScreen.screens objectAtIndex:0].frame.size;
ret->Height = size.height;
ret->Width = size.width;
return S_OK;
@autoreleasepool
{
if(ret == nullptr)
return E_POINTER;
auto size = [NSScreen.screens objectAtIndex:0].frame.size;
ret->Height = size.height;
ret->Width = size.width;
return S_OK;
}
}
virtual HRESULT GetScaling (double* ret)
{
if(ret == nullptr)
return E_POINTER;
if(Window == nullptr)
@autoreleasepool
{
*ret = 1;
if(ret == nullptr)
return E_POINTER;
if(Window == nullptr)
{
*ret = 1;
return S_OK;
}
*ret = [Window backingScaleFactor];
return S_OK;
}
}
virtual HRESULT SetMinMaxSize (AvnSize minSize, AvnSize maxSize)
{
@autoreleasepool
{
[Window setMinSize: ToNSSize(minSize)];
[Window setMaxSize: ToNSSize(maxSize)];
*ret = [Window backingScaleFactor];
return S_OK;
return S_OK;
}
}
virtual HRESULT Resize(double x, double y)
{
[Window setContentSize:NSSize{x, y}];
return S_OK;
@autoreleasepool
{
[Window setContentSize:NSSize{x, y}];
return S_OK;
}
}
virtual void Invalidate (AvnRect rect)
virtual HRESULT Invalidate (AvnRect rect)
{
[View setNeedsDisplayInRect:[View frame]];
@autoreleasepool
{
[View setNeedsDisplayInRect:[View frame]];
return S_OK;
}
}
virtual void BeginMoveDrag ()
virtual HRESULT BeginMoveDrag ()
{
auto lastEvent = [View lastMouseDownEvent];
if(lastEvent == nullptr)
@autoreleasepool
{
return;
auto lastEvent = [View lastMouseDownEvent];
if(lastEvent == nullptr)
{
return S_OK;
}
[Window performWindowDragWithEvent:lastEvent];
return S_OK;
}
[Window performWindowDragWithEvent:lastEvent];
}
virtual HRESULT BeginResizeDrag (AvnWindowEdge edge)
{
return S_OK;
}
virtual HRESULT GetPosition (AvnPoint* ret)
{
if(ret == nullptr)
@autoreleasepool
{
return E_POINTER;
if(ret == nullptr)
{
return E_POINTER;
}
auto frame = [Window frame];
ret->X = frame.origin.x;
ret->Y = frame.origin.y + frame.size.height;
*ret = ConvertPointY(*ret);
return S_OK;
}
auto frame = [Window frame];
ret->X = frame.origin.x;
ret->Y = frame.origin.y + frame.size.height;
*ret = ConvertPointY(*ret);
return S_OK;
}
virtual void SetPosition (AvnPoint point)
virtual HRESULT SetPosition (AvnPoint point)
{
lastPositionSet = point;
[Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(point))];
@autoreleasepool
{
lastPositionSet = point;
[Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(point))];
return S_OK;
}
}
virtual HRESULT PointToClient (AvnPoint point, AvnPoint* ret)
{
if(ret == nullptr)
@autoreleasepool
{
return E_POINTER;
if(ret == nullptr)
{
return E_POINTER;
}
point = ConvertPointY(point);
auto viewPoint = [Window convertScreenToBase:ToNSPoint(point)];
*ret = [View translateLocalPoint:ToAvnPoint(viewPoint)];
return S_OK;
}
point = ConvertPointY(point);
auto viewPoint = [Window convertScreenToBase:ToNSPoint(point)];
*ret = [View translateLocalPoint:ToAvnPoint(viewPoint)];
return S_OK;
}
virtual HRESULT PointToScreen (AvnPoint point, AvnPoint* ret)
{
if(ret == nullptr)
@autoreleasepool
{
return E_POINTER;
if(ret == nullptr)
{
return E_POINTER;
}
auto cocoaViewPoint = ToNSPoint([View translateLocalPoint:point]);
auto cocoaScreenPoint = [Window convertBaseToScreen:cocoaViewPoint];
*ret = ConvertPointY(ToAvnPoint(cocoaScreenPoint));
return S_OK;
}
auto cocoaViewPoint = ToNSPoint([View translateLocalPoint:point]);
auto cocoaScreenPoint = [Window convertBaseToScreen:cocoaViewPoint];
*ret = ConvertPointY(ToAvnPoint(cocoaScreenPoint));
return S_OK;
}
virtual HRESULT ThreadSafeSetSwRenderedFrame(AvnFramebuffer* fb, IUnknown* dispose)
@ -195,10 +266,13 @@ public:
virtual HRESULT SetCursor(IAvnCursor* cursor)
{
Cursor* avnCursor = dynamic_cast<Cursor*>(cursor);
this->cursor = avnCursor->GetNative();
UpdateCursor();
return S_OK;
@autoreleasepool
{
Cursor* avnCursor = dynamic_cast<Cursor*>(cursor);
this->cursor = avnCursor->GetNative();
UpdateCursor();
return S_OK;
}
}
virtual void UpdateCursor()
@ -841,75 +915,87 @@ private:
virtual HRESULT SetCanResize(bool value)
{
_canResize = value;
UpdateStyle();
return S_OK;
@autoreleasepool
{
_canResize = value;
UpdateStyle();
return S_OK;
}
}
virtual HRESULT SetHasDecorations(bool value)
{
_hasDecorations = value;
UpdateStyle();
return S_OK;
@autoreleasepool
{
_hasDecorations = value;
UpdateStyle();
return S_OK;
}
}
virtual HRESULT GetWindowState (AvnWindowState*ret)
{
if(ret == nullptr)
{
return E_POINTER;
}
if([Window isMiniaturized])
{
*ret = Minimized;
return S_OK;
}
if([Window isZoomed])
@autoreleasepool
{
*ret = Maximized;
if(ret == nullptr)
{
return E_POINTER;
}
if([Window isMiniaturized])
{
*ret = Minimized;
return S_OK;
}
if([Window isZoomed])
{
*ret = Maximized;
return S_OK;
}
*ret = Normal;
return S_OK;
}
*ret = Normal;
return S_OK;
}
virtual HRESULT SetWindowState (AvnWindowState state)
{
switch (state) {
case Maximized:
if([Window isMiniaturized])
{
[Window deminiaturize:Window];
}
if(!IsZoomed())
{
DoZoom();
}
break;
case Minimized:
[Window miniaturize:Window];
break;
default:
if([Window isMiniaturized])
{
[Window deminiaturize:Window];
}
if(IsZoomed())
{
DoZoom();
}
break;
@autoreleasepool
{
switch (state) {
case Maximized:
if([Window isMiniaturized])
{
[Window deminiaturize:Window];
}
if(!IsZoomed())
{
DoZoom();
}
break;
case Minimized:
[Window miniaturize:Window];
break;
default:
if([Window isMiniaturized])
{
[Window deminiaturize:Window];
}
if(IsZoomed())
{
DoZoom();
}
break;
}
return S_OK;
}
return S_OK;
}
protected:
@ -939,6 +1025,9 @@ protected:
extern IAvnWindow* CreateAvnWindow(IAvnWindowEvents*events)
{
IAvnWindow* ptr = dynamic_cast<IAvnWindow*>(new WindowImpl(events));
return ptr;
@autoreleasepool
{
IAvnWindow* ptr = dynamic_cast<IAvnWindow*>(new WindowImpl(events));
return ptr;
}
}

29
src/Avalonia.Native/AvaloniaNativePlatform.cs

@ -1,11 +1,12 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using Avalonia.Controls;
using Avalonia.Controls.Platform;
using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.Native;
using Avalonia.Native.Interop;
using Avalonia.Platform;
using Avalonia.Rendering;
@ -73,8 +74,7 @@ namespace Avalonia.Native
.Bind<IClipboard>().ToConstant(new ClipboardImpl(_factory.CreateClipboard()))
.Bind<IRenderLoop>().ToConstant(new RenderLoop())
.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
.Bind<ISystemDialogImpl>().ToConstant(new SystemDialogs(_factory.CreateSystemDialogs()));
.Bind<ISystemDialogImpl>().ToConstant(new SystemDialogs(_factory.CreateSystemDialogs()));
}
public IWindowImpl CreateWindow()
@ -126,22 +126,3 @@ namespace Avalonia.Native
}
}
namespace Avalonia
{
public static class AvaloniaNativePlatformExtensions
{
public static T UseAvaloniaNative<T>(this T builder,
string libraryPath = null,
Action<AvaloniaNativeOptions> configure = null)
where T : AppBuilderBase<T>, new()
{
if (libraryPath == null)
builder.UseWindowingSubsystem(() => AvaloniaNativePlatform.Initialize(configure));
else
builder.UseWindowingSubsystem(() => AvaloniaNativePlatform.Initialize(libraryPath, configure));
return builder;
}
}
}

29
src/Avalonia.Native/AvaloniaNativePlatformExtensions.cs

@ -0,0 +1,29 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Controls;
using Avalonia.Native;
namespace Avalonia
{
public static class AvaloniaNativePlatformExtensions
{
public static T UseAvaloniaNative<T>(this T builder,
string libraryPath = null,
Action<AvaloniaNativeOptions> configure = null)
where T : AppBuilderBase<T>, new()
{
if (libraryPath == null)
{
builder.UseWindowingSubsystem(() => AvaloniaNativePlatform.Initialize(configure));
}
else
{
builder.UseWindowingSubsystem(() => AvaloniaNativePlatform.Initialize(libraryPath, configure));
}
return builder;
}
}
}

20
src/Avalonia.Native/CallbackBase.cs

@ -1,13 +1,16 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using SharpGen.Runtime;
namespace Avalonia.Native
{
public class CallbackBase : SharpGen.Runtime.IUnknown
{
uint _refCount;
bool _disposed;
object _lock = new object();
private uint _refCount;
private bool _disposed;
private readonly object _lock = new object();
private ShadowContainer _shadow;
public CallbackBase()
@ -23,7 +26,10 @@ namespace Avalonia.Native
lock (_lock)
{
if (_disposed && value != null)
{
throw new ObjectDisposedException("CallbackBase");
}
_shadow = value;
}
}
@ -32,17 +38,21 @@ namespace Avalonia.Native
public uint AddRef()
{
lock (_lock)
{
return ++_refCount;
}
}
public void Dispose()
{
lock (_lock)
{
if (!_disposed)
{
_disposed = true;
Release();
}
}
}
public uint Release()
@ -50,12 +60,14 @@ namespace Avalonia.Native
lock (_lock)
{
_refCount--;
if (_refCount == 0)
{
Shadow?.Dispose();
Shadow = null;
Destroyed();
}
return _refCount;
}
}

20
src/Avalonia.Native/ClipboardImpl.cs

@ -1,18 +1,16 @@
using System;
using System.IO;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Avalonia.Controls;
using Avalonia.Controls.Platform;
using Avalonia.Input.Platform;
using Avalonia.Platform;
using Avalonia.Native.Interop;
namespace Avalonia.Native
{
{
class ClipboardImpl : IClipboard
{
IAvnClipboard _native;
private IAvnClipboard _native;
public ClipboardImpl(IAvnClipboard native)
{
@ -22,6 +20,7 @@ namespace Avalonia.Native
public Task ClearAsync()
{
_native.Clear();
return Task.CompletedTask;
}
@ -29,14 +28,19 @@ namespace Avalonia.Native
{
var outPtr = _native.GetText();
var text = Marshal.PtrToStringAnsi(outPtr);
return Task.FromResult(text);
}
public Task SetTextAsync(string text)
{
_native.Clear();
if(text != null)
if (text != null)
{
_native.SetText(text);
}
return Task.CompletedTask;
}
}

5
src/Avalonia.Native/Cursor.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Input;
using Avalonia.Platform;
using Avalonia.Native.Interop;

14
src/Avalonia.Native/DeferredFramebuffer.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
using Avalonia.Native.Interop;
using Avalonia.Platform;
@ -9,6 +12,7 @@ namespace Avalonia.Native
public class DeferredFramebuffer : ILockedFramebuffer
{
private readonly Func<Action<IAvnWindowBase>, bool> _lockWindow;
public DeferredFramebuffer(Func<Action<IAvnWindowBase>, bool> lockWindow,
int width, int height, Vector dpi)
{
@ -28,7 +32,6 @@ namespace Avalonia.Native
public Vector Dpi { get; set; }
public PixelFormat Format { get; set; }
class Disposer : CallbackBase
{
private IntPtr _ptr;
@ -52,6 +55,7 @@ namespace Avalonia.Native
{
if (Address == IntPtr.Zero)
return;
if (!_lockWindow(win =>
{
var fb = new AvnFramebuffer
@ -67,10 +71,16 @@ namespace Avalonia.Native
PixelFormat = (AvnPixelFormat)Format,
Stride = RowBytes
};
using (var d = new Disposer(Address))
{
win.ThreadSafeSetSwRenderedFrame(ref fb, d);
}
}))
{
Marshal.FreeHGlobal(Address);
}
Address = IntPtr.Zero;
}
}

13
src/Avalonia.Native/DeferredRendererProxy.cs

@ -1,6 +1,8 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using Avalonia.Platform;
using Avalonia.Rendering;
using Avalonia.VisualTree;
@ -19,9 +21,9 @@ namespace Avalonia.Native
AvaloniaLocator.Current.GetService<IRenderLoop>().Remove(this);
}
private DeferredRenderer _renderer;
private IRenderLoopTask _rendererTask;
DeferredRenderer _renderer;
IRenderLoopTask _rendererTask;
public DeferredRendererProxy(IRenderRoot root)
{
_renderer = new DeferredRenderer(root, this);
@ -52,7 +54,10 @@ namespace Avalonia.Native
public void Paint(Rect rect)
{
if (NeedsUpdate)
{
Update(TimeSpan.FromMilliseconds(Environment.TickCount));
}
Render();
}

10
src/Avalonia.Native/DynLoader.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
/*
@ -6,7 +9,6 @@ using System.Runtime.InteropServices;
* Source is provided under MIT license for Avalonia project and derived works
*/
namespace Avalonia.Native
{
internal interface IDynLoader
@ -37,10 +39,9 @@ namespace Avalonia.Native
DlError = dlerror;
}
}
static class OsXImports
{
[DllImport("/usr/lib/libSystem.dylib")]
private static extern IntPtr dlopen(string path, int flags);
@ -59,7 +60,6 @@ namespace Avalonia.Native
}
[DllImport("libc")]
static extern int uname(IntPtr buf);

9
src/Avalonia.Native/Helpers.cs

@ -1,4 +1,6 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Native.Interop;
namespace Avalonia.Native
@ -15,6 +17,11 @@ namespace Avalonia.Native
return new AvnPoint { X = pt.X, Y = pt.Y };
}
public static AvnSize ToAvnSize (this Size size)
{
return new AvnSize { Height = size.Height, Width = size.Width };
}
public static Size ToAvaloniaSize (this AvnSize size)
{
return new Size(size.Width, size.Height);

4
src/Avalonia.Native/IconLoader.cs

@ -1,4 +1,6 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.IO;
using Avalonia.Platform;

5
src/Avalonia.Native/PlatformThreadingInterface.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Threading;
using Avalonia.Native.Interop;
using Avalonia.Platform;

7
src/Avalonia.Native/PopupImpl.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Native.Interop;
using Avalonia.Platform;
@ -11,7 +14,9 @@ namespace Avalonia.Native
public PopupImpl(IAvaloniaNativeFactory factory)
{
using (var e = new PopupEvents(this))
{
Init(_native = factory.CreatePopup(e), factory.CreateScreens());
}
}
public override void Dispose()

5
src/Avalonia.Native/ScreenImpl.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Native.Interop;
using Avalonia.Platform;

5
src/Avalonia.Native/SystemDialogs.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

12
src/Avalonia.Native/WindowImpl.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Controls;
using Avalonia.Native.Interop;
using Avalonia.Platform;
@ -11,7 +14,9 @@ namespace Avalonia.Native
public WindowImpl(IAvaloniaNativeFactory factory)
{
using (var e = new WindowEvents(this))
{
Init(_native = factory.CreateWindow(e), factory.CreateScreens());
}
}
class WindowEvents : WindowBaseEvents, IAvnWindowEvents
@ -36,7 +41,6 @@ namespace Avalonia.Native
return _native.ShowDialog();
}
public void CanResize(bool value)
{
_native.CanResize = value;
@ -67,10 +71,14 @@ namespace Avalonia.Native
public void ShowTaskbarIcon(bool value)
{
// NO OP On OSX
}
public void SetIcon(IWindowIconImpl icon)
{
// NO OP on OSX
}
public Func<bool> Closing { get; set; }
}
}

28
src/Avalonia.Native/WindowImplBase.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Controls.Platform.Surfaces;
@ -291,36 +294,35 @@ namespace Avalonia.Native
public Action Deactivated { get; set; }
public Action Activated { get; set; }
#region Stubs
public void SetCursor(IPlatformHandle cursor)
{
var newCursor = cursor as AvaloniaNativeCursor;
newCursor = newCursor ?? (_cursorFactory.GetCursor(StandardCursorType.Arrow) as AvaloniaNativeCursor);
_native.Cursor = newCursor.Cursor;
}
public Action<Point> PositionChanged { get; set; }
public Action<RawInputEventArgs> Input { get; set; }
Action<double> ScalingChanged { get; set; }
public IPlatformHandle Handle => new PlatformHandle(IntPtr.Zero, "NOT SUPPORTED");
Action<double> ITopLevelImpl.ScalingChanged { get; set; }
public IScreenImpl Screen { get; private set; }
Action<double> ITopLevelImpl.ScalingChanged { get; set; }
// TODO
public void SetMinMaxSize(Size minSize, Size maxSize)
{
}
public void SetCursor(IPlatformHandle cursor)
{
var newCursor = cursor as AvaloniaNativeCursor;
newCursor = newCursor ?? (_cursorFactory.GetCursor(StandardCursorType.Arrow) as AvaloniaNativeCursor);
_native.Cursor = newCursor.Cursor;
_native.SetMinMaxSize(minSize.ToAvnSize(), maxSize.ToAvnSize());
}
public void BeginResizeDrag(WindowEdge edge)
{
}
#endregion
public IPlatformHandle Handle => new PlatformHandle(IntPtr.Zero, "NOT SUPPORTED");
}
}

3
src/headers/avalonia-native-guids.h

@ -1,2 +1,5 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#define COM_GUIDS_MATERIALIZE
#include "avalonia-native.h"

24
src/headers/avalonia-native.h

@ -1,7 +1,9 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#include "com.h"
#include "key.h"
#define AVNCOM(name, id) COMINTERFACE(name, 2e2cda0a, 9ae5, 4f1b, 8e, 20, 08, 1a, 04, 27, 9f, id)
struct IAvnWindowEvents;
@ -126,6 +128,18 @@ enum AvnStandardCursorType
CursorDragLink,
};
enum AvnWindowEdge
{
WindowEdgeNorthWest,
WindowEdgeNorth,
WindowEdgeNorthEast,
WindowEdgeWest,
WindowEdgeEast,
WindowEdgeSouthWest,
WindowEdgeSouth,
WindowEdgeSouthEast
};
AVNCOM(IAvaloniaNativeFactory, 01) : virtual IUnknown
{
public:
@ -149,11 +163,13 @@ AVNCOM(IAvnWindowBase, 02) : virtual IUnknown
virtual HRESULT GetClientSize(AvnSize*ret) = 0;
virtual HRESULT GetMaxClientSize(AvnSize* ret) = 0;
virtual HRESULT GetScaling(double*ret)=0;
virtual HRESULT SetMinMaxSize(AvnSize minSize, AvnSize maxSize) = 0;
virtual HRESULT Resize(double width, double height) = 0;
virtual void Invalidate (AvnRect rect) = 0;
virtual void BeginMoveDrag () = 0;
virtual HRESULT Invalidate (AvnRect rect) = 0;
virtual HRESULT BeginMoveDrag () = 0;
virtual HRESULT BeginResizeDrag (AvnWindowEdge edge) = 0;
virtual HRESULT GetPosition (AvnPoint*ret) = 0;
virtual void SetPosition (AvnPoint point) = 0;
virtual HRESULT SetPosition (AvnPoint point) = 0;
virtual HRESULT PointToClient (AvnPoint point, AvnPoint*ret) = 0;
virtual HRESULT PointToScreen (AvnPoint point, AvnPoint*ret) = 0;
virtual HRESULT ThreadSafeSetSwRenderedFrame(AvnFramebuffer* fb, IUnknown* dispose) = 0;

3
src/headers/com.h

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#ifndef COM_H_INCLUDED

3
src/headers/key.h

@ -1,3 +1,6 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
#ifndef _KEY_H_
#define _KEY_H_

Loading…
Cancel
Save