From 38a150e62e0e928cfa58bb32a8b5d7f394abe53a Mon Sep 17 00:00:00 2001 From: Simeon Cran Date: Tue, 22 Sep 2020 16:41:48 -0700 Subject: [PATCH 1/3] Get image layer working with cppwinrt. Has some issues if the images are not found, but it works otherwise. Includes some untested cleaning up of the CX code. --- .../Cppwinrt/CppwinrtInstantiatorGenerator.cs | 213 +++++++++++------- .../CodeGen/Cx/CxInstantiatorGenerator.cs | 24 +- .../CodeGen/InstantiatorGeneratorBase.cs | 2 +- 3 files changed, 147 insertions(+), 92 deletions(-) diff --git a/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs b/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs index 47b9d8e9..c7afc388 100644 --- a/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs +++ b/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs @@ -85,6 +85,10 @@ public static CppwinrtCodegenResult CreateFactoryCode(CodegenConfiguration confi IAnimatedVisualSourceInfo SourceInfo => AnimatedVisualSourceInfo; + /// + /// Generates the text for the .IDL file. + /// + /// The text for the .IDL file. string GenerateIdlText() { var builder = new CodeBuilder(); @@ -104,17 +108,41 @@ string GenerateIdlText() builder.WriteLine($"runtimeclass {_sourceClassName}"); builder.Indent(); - builder.WriteLine($": [default] {SourceInfo.InterfaceType.NormalizedQualifiedName}Source"); + if (SourceInfo.IsInterfaceCustom) + { + builder.WriteLine($": [default] {SourceInfo.InterfaceType.NormalizedQualifiedName}Source"); + } + else + { + if (_isIDynamic) + { + builder.WriteLine(": [default] Microsoft.UI.Xaml.Controls.IDynamicAnimatedVisualSource"); + } + else + { + builder.WriteLine(": [default] Microsoft.UI.Xaml.Controls.IAnimatedVisualSource"); + } + } + + if (_isIDynamic) + { + builder.WriteLine(", Windows.UI.Xaml.Data.INotifyPropertyChanged"); + } + builder.UnIndent(); builder.OpenScope(); builder.WriteLine($"{_sourceClassName}();"); if (_isIDynamic) { - // The IDynamicAnimatedVisualSource implementation has events and properties that - // have to be declared in the IDL. + // The IDynamicAnimatedVisualSource implementation has properties that + // have to be declared in the IDL. The AnimatedVisualInvalidated event does + // not need to be declared in IDL because it is implied by the class inheriting + // from IDynamicAnimatedVisualSource. builder.WriteLine(); - builder.WriteLine("// TODO.... events and properties for IDynamicAnimatedVisualSource"); + builder.WriteLine("Boolean IsAnimatedVisualSourceDynamic;"); + builder.WriteLine("Boolean IsImageLoadingCompleted { get; };"); + builder.WriteLine("Double ImageSuccessfulLoadingProgress { get; };"); } builder.CloseCppTypeScope(); @@ -262,7 +290,7 @@ void WriteThemeHeader(HeaderBuilder builder) if (SourceInfo.GenerateDependencyObject) { builder.Class.Private.WriteLine($"static {_winUINamespace}::Xaml::DependencyProperty^ _{prop.BindingName}Property;"); - builder.Class.Private.WriteLine($"static void On{prop.BindingName}Changed({_winUINamespace}::Xaml::DependencyObject^ d, {_winUINamespace}::Xaml::DependencyPropertyChangedEventArgs^ e);"); + builder.Class.Private.WriteLine($"static void On{prop.BindingName}Changed({_winUINamespace}::Xaml::DependencyObject d, {_winUINamespace}::Xaml::DependencyPropertyChangedEventArgs e);"); } else { @@ -362,69 +390,57 @@ void WriteThemePropertyImpls(CodeBuilder builder) void WriteIDynamicAnimatedVisualSourceHeaderText(HeaderBuilder builder) { - builder.Class.Private.WriteLine($"const int c_loadedImageSurfaceCount = {SourceInfo.LoadedImageSurfaces.Distinct().Count()};"); - builder.Class.Private.WriteLine("double m_imageSuccessfulLoadingProgress{};"); - builder.Class.Private.WriteLine("int m_loadCompleteEventCount{};"); - builder.Class.Private.WriteLine("bool m_isAnimatedVisualSourceDynamic{};"); - builder.Class.Private.WriteLine("bool m_isImageLoadingCompleted{};"); - builder.Class.Private.WriteLine("bool m_isTryCreateAnimatedVisualCalled{};"); - builder.Class.Private.WriteLine("bool m_isImageLoadingStarted{};"); - builder.Class.Private.WriteLine("event Windows::Foundation::TypedEventHandler m_InternalHandler{};"); + var pub = builder.Class.Public; + var priv = builder.Class.Private; + + priv.WriteLine($"const int c_loadedImageSurfaceCount = {SourceInfo.LoadedImageSurfaces.Distinct().Count()};"); + priv.WriteLine("double m_imageSuccessfulLoadingProgress{};"); + priv.WriteLine("int m_loadCompleteEventCount{};"); + priv.WriteLine("bool m_isAnimatedVisualSourceDynamic{};"); + priv.WriteLine("bool m_isImageLoadingCompleted{};"); + priv.WriteLine("bool m_isTryCreateAnimatedVisualCalled{};"); + priv.WriteLine("bool m_isImageLoadingStarted{};"); + priv.WriteLine("winrt::event> m_InternalHandler{};"); + priv.WriteLine("winrt::event m_PropertyChanged{};"); foreach (var n in SourceInfo.LoadedImageSurfaces) { - builder.Class.Private.WriteLine($"winrt::Windows::UI::Xaml::Media::{n.TypeName} {n.FieldName}{{ nullptr }};"); + priv.WriteLine($"winrt::Windows::UI::Xaml::Media::{n.TypeName} {n.FieldName}{{ nullptr }};"); } - builder.Class.Private.WriteLine("void EnsureImageLoadingStarted();"); - builder.Class.Private.WriteLine("void HandleLoadCompleted(winrt::Windows::UI::Xaml::Media::LoadedImageSurface sender, winrt::Windows::UI::Xaml::Media::LoadedImageSourceLoadCompletedEventArgs e);"); - builder.Class.Private.WriteLine("void RaiseAnimatedVisualInvalidatedEvent(winrt::Microsoft::UI::Xaml::IDynamicAnimatedVisualSource sender, winrt::Windows::Foundation::IInspectable object)"); - builder.Class.Private.OpenScope(); - builder.Class.Private.OpenScope(); - builder.Class.Private.WriteLine("m_InternalHandler::raise(sender, object);"); - builder.Class.Private.CloseScope(); - builder.Class.Private.CloseScope(); + priv.WriteLine("void EnsureImageLoadingStarted();"); + priv.WriteLine("void HandleLoadCompleted(winrt::Windows::UI::Xaml::Media::LoadedImageSurface sender, winrt::Windows::UI::Xaml::Media::LoadedImageSourceLoadCompletedEventArgs e);"); - builder.Class.Public.WriteLine(); - builder.Class.Public.WriteLine("event Windows::Foundation::TypedEventHandler AnimatedVisualInvalidated"); - builder.Class.Public.OpenScope(); - builder.Class.Public.WriteLine("Windows::Foundation::EventRegistrationToken add(winrt::Windows::Foundation::TypedEventHandler value)"); - builder.Class.Public.OpenScope(); - builder.Class.Public.WriteLine("return m_InternalHandler::add(value);"); - builder.Class.Public.CloseScope(); - builder.Class.Public.WriteLine("void remove(winrt::Windows::Foundation::EventRegistrationToken token)"); - builder.Class.Public.OpenScope(); - builder.Class.Public.WriteLine("m_InternalHandler::remove(token);"); - builder.Class.Public.CloseScope(); - builder.Class.Public.CloseScope(); + // INotifyPropertyChanged implementation. + pub.WriteLine("winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler);"); + pub.WriteLine("void PropertyChanged(winrt::event_token const& token) noexcept;"); - builder.Class.Public.WriteLine(); - builder.Class.Public.WriteLine($"event PropertyChangedEventHandler PropertyChanged;"); - builder.Class.Public.WriteSummaryComment("If this property is set to true, will" + + // IDynamicAnimatedVisualSource implementation. + pub.WriteLine(); + pub.WriteLine("winrt::event_token AnimatedVisualInvalidated(Windows::Foundation::TypedEventHandler const& handler);"); + pub.WriteLine("void AnimatedVisualInvalidated(winrt::event_token const& token) noexcept;"); + + pub.WriteLine(); + pub.WriteSummaryComment("If this property is set to true, will" + " return null until all images have loaded. When all images have loaded, " + " will return the AnimatedVisual. To use, set it when declaring the AnimatedVisualSource. Once" + " is called, changes made to this property will be ignored." + " Default value is true."); - builder.Class.Public.WriteLine("property bool IsAnimatedVisualSourceDynamic"); - builder.Class.Public.OpenScope(); - builder.Class.Public.WriteLine("bool get();"); - builder.Class.Public.WriteLine("void set(bool value);"); - builder.Class.Public.CloseScope(); - builder.Class.Public.WriteSummaryComment("Returns true if all images have loaded. To see if the images succeeded to load," + + pub.WriteLine("bool IsAnimatedVisualSourceDynamic();"); + pub.WriteLine("void IsAnimatedVisualSourceDynamic(bool value);"); + pub.WriteLine(); + + pub.WriteSummaryComment("Returns true if all images have loaded. To see if the images succeeded to load," + " see ."); - builder.Class.Public.WriteLine("property bool IsImageLoadingCompleted"); - builder.Class.Public.OpenScope(); - builder.Class.Public.WriteLine("bool get() { return m_isImageLoadingCompleted; }"); - builder.Class.Public.CloseScope(); - builder.Class.Public.WriteSummaryComment("Represents the progress of successful image loading. Returns a value between" + + pub.WriteLine("bool IsImageLoadingCompleted();"); + pub.WriteLine(); + + pub.WriteSummaryComment("Represents the progress of successful image loading. Returns a value between" + " 0 and 1. 0 means none of the images succeeded to load. 1 means all images succeeded to load."); - builder.Class.Public.WriteLine("property double ImageSuccessfulLoadingProgress"); - builder.Class.Public.OpenScope(); - builder.Class.Public.WriteLine("double get() { return m_imageSuccessfulLoadingProgress; }"); - builder.Class.Public.CloseScope(); - builder.Class.Public.WriteLine(); + pub.WriteLine("double ImageSuccessfulLoadingProgress();"); + pub.WriteLine(); WriteTryCreateAnimatedVisualDeclaration(builder.Class.Public); } @@ -511,6 +527,11 @@ protected override void WriteImplementationFileStart(CodeBuilder builder) builder.WriteLine("#include "); } + if (_isIDynamic) + { + builder.WriteLine("#include "); + } + if (SourceInfo.UsesCanvas || SourceInfo.UsesCanvasEffects || SourceInfo.UsesCanvasGeometry) @@ -673,7 +694,7 @@ protected override string WriteCompositeEffectFactory(CodeBuilder builder, Mgce. builder.WriteLine($"compositeEffect.SetMode({_s.CanvasCompositeMode(compositeEffect.Mode)});"); foreach (var source in compositeEffect.Sources) { - builder.WriteLine($"compositeEffect.AddSource(CompositionEffectSourceParameter({_s.String(source.Name)}));"); + builder.WriteLine($"compositeEffect.AddSource(CompositionEffectSourceParameter(L\"{source.Name}));"); } return "compositeEffect"; @@ -705,7 +726,7 @@ protected override void WriteImplementationFileEnd(CodeBuilder builder) builder.WriteLine("const auto _ = EnsureThemeProperties(compositor);"); } - if (SourceInfo.LoadedImageSurfaces.Count > 0) + if (_isIDynamic) { WriteIDynamicAnimatedVisualSource(builder); } @@ -797,40 +818,75 @@ void WriteIDynamicAnimatedVisualSource(CodeBuilder builder) builder.WriteLine(); // Generate the get() and set() methods of IsAnimatedVisualSourceDynamic property. - WriteIsAnimatedVisualSourceDynamicGetSet(builder); + WriteSimplePropertyGetterImpl(builder, "IsAnimatedVisualSourceDynamic", "m_isAnimatedVisualSourceDynamic", "bool"); + builder.WriteLine($"void {_sourceClassName}::IsAnimatedVisualSourceDynamic(bool isAnimatedVisualSourceDynamic)"); + builder.OpenScope(); + builder.WriteLine("if (!m_isTryCreateAnimatedVisualCalled && m_isAnimatedVisualSourceDynamic != isAnimatedVisualSourceDynamic)"); + builder.OpenScope(); + builder.WriteLine("m_isAnimatedVisualSourceDynamic = isAnimatedVisualSourceDynamic;"); + builder.WriteLine($"m_PropertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs(L\"IsAnimatedVisualSourceDynamic\"));"); + builder.CloseScope(); + builder.CloseScope(); + builder.WriteLine(); + + // Generate the get() method of IsImageLoadingCompleted. + WriteSimplePropertyGetterImpl(builder, "IsImageLoadingCompleted", "m_isImageLoadingCompleted", "bool"); + + // Generate the get() method of ImageSuccessfulLoadingProgress + WriteSimplePropertyGetterImpl(builder, "ImageSuccessfulLoadingProgress", "m_imageSuccessfulLoadingProgress", "double"); // Generate the method that loads all the LoadedImageSurfaces. WriteEnsureImageLoadingStarted(builder); // Generate the method that handles the LoadCompleted event of the LoadedImageSurface objects. WriteHandleLoadCompleted(builder); + + // Generate the PropertyChanged event implementation. + WriteEventImpl( + builder, + "PropertyChanged", + "Windows::UI::Xaml::Data::PropertyChangedEventHandler", + "m_PropertyChanged"); + + // Generate the AnimatedVisualInvalidated event implementation. + WriteEventImpl( + builder, + "AnimatedVisualInvalidated", + "Windows::Foundation::TypedEventHandler", + "m_InternalHandler"); } - void WriteIsAnimatedVisualSourceDynamicGetSet(CodeBuilder builder) + void WriteEventImpl(CodeBuilder builder, string eventName, string handlerTypeName, string backingEventName) { - builder.WriteLine($"bool {_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::IsAnimatedVisualSourceDynamic::get()"); + builder.WriteLine($"winrt::event_token {_sourceClassName}::{eventName}({handlerTypeName} const& handler)"); builder.OpenScope(); - builder.WriteLine("return m_isAnimatedVisualSourceDynamic;"); + builder.WriteLine($"return {backingEventName}.add(handler);"); builder.CloseScope(); builder.WriteLine(); - builder.WriteLine($"void {_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::IsAnimatedVisualSourceDynamic::set(bool isAnimatedVisualSourceDynamic)"); - builder.OpenScope(); - builder.WriteLine("if (!m_isTryCreateAnimatedVisualCalled && m_isAnimatedVisualSourceDynamic != isAnimatedVisualSourceDynamic)"); + + builder.WriteLine($"void {_sourceClassName}::{eventName}(winrt::event_token const& token) noexcept"); builder.OpenScope(); - builder.WriteLine("m_isAnimatedVisualSourceDynamic = isAnimatedVisualSourceDynamic;"); - builder.WriteLine("PropertyChanged(this, ref new PropertyChangedEventArgs(\"IsAnimatedVisualSourceDynamic\"));"); + builder.WriteLine($"{backingEventName}.remove(token);"); builder.CloseScope(); + builder.WriteLine(); + } + + void WriteSimplePropertyGetterImpl(CodeBuilder builder, string methodName, string backingFieldName, string typeName) + { + builder.WriteLine($"{typeName} {_sourceClassName}::{methodName}()"); + builder.OpenScope(); + builder.WriteLine($"return {backingFieldName};"); builder.CloseScope(); builder.WriteLine(); } void WriteEnsureImageLoadingStarted(CodeBuilder builder) { - builder.WriteLine($"void {_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::EnsureImageLoadingStarted()"); + builder.WriteLine($"void {_sourceClassName}::EnsureImageLoadingStarted()"); builder.OpenScope(); builder.WriteLine("if (!m_isImageLoadingStarted)"); builder.OpenScope(); - builder.WriteLine($"auto eventHandler = ref new TypedEventHandler<{_s.ReferenceTypeName("LoadedImageSurface")}, {_s.ReferenceTypeName("LoadedImageSourceLoadCompletedEventArgs")}>(this, &{_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::HandleLoadCompleted);"); + builder.WriteLine($"auto eventHandler = Windows::Foundation::TypedEventHandler(this, &{_sourceClassName}::HandleLoadCompleted);"); foreach (var n in SourceInfo.LoadedImageSurfaces) { @@ -849,13 +905,13 @@ void WriteEnsureImageLoadingStarted(CodeBuilder builder) builder.WriteLine($"{imageMemberName} = {_winUINamespace}::Xaml::Media::LoadedImageSurface::StartLoadFromStream({streamName});"); break; case LoadedImageSurface.LoadedImageSurfaceType.FromUri: - builder.WriteLine($"{imageMemberName} = {_winUINamespace}::Xaml::Media::LoadedImageSurface::StartLoadFromUri(ref new Uri(\"{n.ImageUri}\"));"); + builder.WriteLine($"{imageMemberName} = {_winUINamespace}::Xaml::Media::LoadedImageSurface::StartLoadFromUri(Windows::Foundation::Uri(L\"{n.ImageUri.AbsoluteUri}\"));"); break; default: throw new InvalidOperationException(); } - builder.WriteLine($"{imageMemberName}->LoadCompleted += eventHandler;"); + builder.WriteLine($"{imageMemberName}.LoadCompleted(eventHandler);"); } builder.WriteLine("m_isImageLoadingStarted = true;"); @@ -866,22 +922,22 @@ void WriteEnsureImageLoadingStarted(CodeBuilder builder) void WriteHandleLoadCompleted(CodeBuilder builder) { - builder.WriteLine($"void {_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::HandleLoadCompleted({_s.ReferenceTypeName("LoadedImageSurface")} sender, {_s.ReferenceTypeName("LoadedImageSourceLoadCompletedEventArgs")} e)"); + builder.WriteLine($"void {_sourceClassName}::HandleLoadCompleted(LoadedImageSurface sender, LoadedImageSourceLoadCompletedEventArgs e)"); builder.OpenScope(); builder.WriteLine("m_loadCompleteEventCount++;"); - builder.WriteLine("if (e->Status == LoadedImageSourceLoadStatus::Success)"); + builder.WriteLine("if (e.Status() == LoadedImageSourceLoadStatus::Success)"); builder.OpenScope(); builder.WriteLine("m_imageSuccessfulLoadingProgress = (double)m_loadCompleteEventCount / c_loadedImageSurfaceCount;"); - builder.WriteLine("PropertyChanged(this, ref new PropertyChangedEventArgs(\"ImageSuccessfulLoadingProgress\"));"); + builder.WriteLine("m_PropertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs(L\"ImageSuccessfulLoadingProgress\"));"); builder.CloseScope(); builder.WriteLine(); builder.WriteLine("if (m_loadCompleteEventCount == c_loadedImageSurfaceCount)"); builder.OpenScope(); builder.WriteLine("m_isImageLoadingCompleted = true;"); - builder.WriteLine("PropertyChanged(this, ref new PropertyChangedEventArgs(\"IsImageLoadingCompleted\"));"); + builder.WriteLine("m_PropertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs(L\"IsImageLoadingCompleted\"));"); builder.WriteLine("if (m_isAnimatedVisualSourceDynamic)"); builder.OpenScope(); - builder.WriteLine("RaiseAnimatedVisualInvalidatedEvent(this, nullptr);"); + builder.WriteLine("m_InternalHandler(*this, nullptr);"); builder.CloseScope(); builder.CloseScope(); builder.CloseScope(); @@ -897,7 +953,7 @@ void WriteIsRuntimeCompatibleMethod(CodeBuilder builder, IAnimatedVisualInfo inf // Write the IsRuntimeCompatible static method. builder.WriteLine("static bool IsRuntimeCompatible()"); builder.OpenScope(); - builder.WriteLine($"return winrt::Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent({_s.String("Windows.Foundation.UniversalApiContract")}, {info.RequiredUapVersion});"); + builder.WriteLine($"return winrt::Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent(L\"Windows.Foundation.UniversalApiContract\", {info.RequiredUapVersion});"); builder.CloseScope(); } } @@ -971,21 +1027,21 @@ protected override void WriteAnimatedVisualEnd( { var propertyImplBuilder = new CodeBuilder(); propertyImplBuilder.WriteLine($"return {{ {_s.TimeSpan(SourceInfo.DurationTicksFieldName)} }};"); - WritePropertyImpl(builder, isVirtual: true, "TimeSpan", "Duration", propertyImplBuilder); + WritePropertyImpl(builder, "TimeSpan", "Duration", propertyImplBuilder); } builder.WriteLine(); { var propertyImplBuilder = new CodeBuilder(); propertyImplBuilder.WriteLine("return _root;"); - WritePropertyImpl(builder, isVirtual: true, nameof(Visual), "RootVisual", propertyImplBuilder); + WritePropertyImpl(builder, nameof(Visual), "RootVisual", propertyImplBuilder); } builder.WriteLine(); { var propertyImplBuilder = new CodeBuilder(); propertyImplBuilder.WriteLine($"return {_s.Vector2(SourceInfo.CompositionDeclaredSize)};"); - WritePropertyImpl(builder, isVirtual: true, "float2", "Size", propertyImplBuilder); + WritePropertyImpl(builder, "float2", "Size", propertyImplBuilder); } WriteIsRuntimeCompatibleMethod(builder, info); @@ -996,7 +1052,6 @@ protected override void WriteAnimatedVisualEnd( void WritePropertyImpl( CodeBuilder builder, - bool isVirtual, string returnType, string propertyName, CodeBuilder getImplementation) @@ -1090,7 +1145,7 @@ IEnumerable GetConstructorParameters(IAnimatedVisualInfo info) foreach (var loadedImageSurfaceNode in info.LoadedImageSurfaceNodes) { - yield return $"{_s.ReferenceTypeName(loadedImageSurfaceNode.TypeName)} {_s.CamelCase(loadedImageSurfaceNode.Name)}"; + yield return $"{loadedImageSurfaceNode.TypeName} {_s.CamelCase(loadedImageSurfaceNode.Name)}"; } } diff --git a/source/UIDataCodeGen/CodeGen/Cx/CxInstantiatorGenerator.cs b/source/UIDataCodeGen/CodeGen/Cx/CxInstantiatorGenerator.cs index d39e974f..f8a9f2fb 100644 --- a/source/UIDataCodeGen/CodeGen/Cx/CxInstantiatorGenerator.cs +++ b/source/UIDataCodeGen/CodeGen/Cx/CxInstantiatorGenerator.cs @@ -379,9 +379,9 @@ void WriteIDynamicAnimatedVisualSourceHeaderText(HeaderBuilder builder) } builder.Preamble.WriteLine(); - builder.Preamble.WriteLine($"virtual event {_s.ReferenceTypeName($"Windows::Foundation::TypedEventHandler<{_s.ReferenceTypeName("IDynamicAnimatedVisualSource")}, Object^>")} AnimatedVisualInvalidated"); + builder.Preamble.WriteLine("virtual event Windows::Foundation::TypedEventHandler^ AnimatedVisualInvalidated"); builder.Preamble.OpenScope(); - builder.Preamble.WriteLine($"Windows::Foundation::EventRegistrationToken add({_s.ReferenceTypeName($"Windows::Foundation::TypedEventHandler<{_s.ReferenceTypeName("IDynamicAnimatedVisualSource")}, Object^>")} value)"); + builder.Preamble.WriteLine("Windows::Foundation::EventRegistrationToken add(Windows::Foundation::TypedEventHandler^ value)"); builder.Preamble.OpenScope(); builder.Preamble.WriteLine("return m_InternalHandler::add(value);"); builder.Preamble.CloseScope(); @@ -392,13 +392,13 @@ void WriteIDynamicAnimatedVisualSourceHeaderText(HeaderBuilder builder) builder.Preamble.CloseScope(); builder.Preamble.WriteLine(); - builder.Preamble.WriteLine($"virtual {_s.ReferenceTypeName($"{_animatedVisualTypeName}^")} TryCreateAnimatedVisual("); + builder.Preamble.WriteLine($"virtual {_animatedVisualTypeName}^ TryCreateAnimatedVisual("); builder.Preamble.Indent(); builder.Preamble.WriteLine($"{_wuc}::Compositor^ compositor,"); builder.Preamble.WriteLine($"Object^* diagnostics);"); builder.Preamble.UnIndent(); builder.Preamble.WriteLine(); - builder.Preamble.WriteLine($"virtual event {_s.ReferenceTypeName("PropertyChangedEventHandler")} PropertyChanged;"); + builder.Preamble.WriteLine($"virtual event PropertyChangedEventHandler^ PropertyChanged;"); builder.Preamble.WriteSummaryComment("If this property is set to true, will" + " return null until all images have loaded. When all images have loaded, " + " will return the AnimatedVisual. To use, set it when declaring the AnimatedVisualSource. Once" + @@ -432,16 +432,16 @@ void WriteIDynamicAnimatedVisualSourceHeaderText(HeaderBuilder builder) builder.Private.WriteLine("bool m_isImageLoadingCompleted{}"); builder.Private.WriteLine("bool m_isTryCreateAnimatedVisualCalled{}"); builder.Private.WriteLine("bool m_isImageLoadingStarted{}"); - builder.Private.WriteLine($"event {_s.ReferenceTypeName($"Windows::Foundation::TypedEventHandler<{_s.ReferenceTypeName("IDynamicAnimatedVisualSource")}, Object^>")} m_InternalHandler;"); + builder.Private.WriteLine("event Windows::Foundation::TypedEventHandler^ m_InternalHandler;"); foreach (var n in SourceInfo.LoadedImageSurfaces) { - builder.Private.WriteLine($"{_s.ReferenceTypeName(n.TypeName)} {n.FieldName}{{}};"); + builder.Private.WriteLine($"{n.TypeName}^ {n.FieldName}{{}};"); } builder.Private.WriteLine("void EnsureImageLoadingStarted();"); - builder.Private.WriteLine($"void HandleLoadCompleted({_s.ReferenceTypeName("LoadedImageSurface")} sender, {_s.ReferenceTypeName("LoadedImageSourceLoadCompletedEventArgs")} e);"); - builder.Private.WriteLine($"void RaiseAnimatedVisualInvalidatedEvent({_s.ReferenceTypeName("IDynamicAnimatedVisualSource")} sender, Object^ object)"); + builder.Private.WriteLine("void HandleLoadCompleted(LoadedImageSurface^ sender, LoadedImageSourceLoadCompletedEventArgs^ e);"); + builder.Private.WriteLine("void RaiseAnimatedVisualInvalidatedEvent(IDynamicAnimatedVisualSource^ sender, Object^ object)"); builder.Private.OpenScope(); builder.Private.OpenScope(); builder.Private.WriteLine("m_InternalHandler::raise(sender, object);"); @@ -631,7 +631,7 @@ protected override string WriteCompositeEffectFactory(CodeBuilder builder, Mgce. builder.CloseScope(); } - return $"reinterpret_cast<{_s.ReferenceTypeName("Windows::Graphics::Effects::IGraphicsEffect")}>(compositeEffect.Get())"; + return "reinterpret_cast(compositeEffect.Get())"; } /// @@ -824,7 +824,7 @@ void WriteEnsureImageLoadingStarted(CodeBuilder builder) builder.OpenScope(); builder.WriteLine("if (!m_isImageLoadingStarted)"); builder.OpenScope(); - builder.WriteLine($"auto eventHandler = ref new TypedEventHandler<{_s.ReferenceTypeName("LoadedImageSurface")}, {_s.ReferenceTypeName("LoadedImageSourceLoadCompletedEventArgs")}>(this, &{_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::HandleLoadCompleted);"); + builder.WriteLine($"auto eventHandler = ref new TypedEventHandler(this, &{_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::HandleLoadCompleted);"); foreach (var n in SourceInfo.LoadedImageSurfaces) { @@ -860,7 +860,7 @@ void WriteEnsureImageLoadingStarted(CodeBuilder builder) void WriteHandleLoadCompleted(CodeBuilder builder) { - builder.WriteLine($"void {_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::HandleLoadCompleted({_s.ReferenceTypeName("LoadedImageSurface")} sender, {_s.ReferenceTypeName("LoadedImageSourceLoadCompletedEventArgs")} e)"); + builder.WriteLine($"void {_s.Namespace(SourceInfo.Namespace)}::{_sourceClassName}::HandleLoadCompleted(LoadedImageSurface^ sender, LoadedImageSourceLoadCompletedEventArgs^ e)"); builder.OpenScope(); builder.WriteLine("m_loadCompleteEventCount++;"); builder.WriteLine("if (e->Status == LoadedImageSourceLoadStatus::Success)"); @@ -1165,7 +1165,7 @@ IEnumerable GetConstructorParameters(IAnimatedVisualInfo info) foreach (var loadedImageSurfaceNode in info.LoadedImageSurfaceNodes) { - yield return $"{_s.ReferenceTypeName(loadedImageSurfaceNode.TypeName)} {_s.CamelCase(loadedImageSurfaceNode.Name)}"; + yield return $"{loadedImageSurfaceNode.TypeName}^ {_s.CamelCase(loadedImageSurfaceNode.Name)}"; } } diff --git a/source/UIDataCodeGen/CodeGen/InstantiatorGeneratorBase.cs b/source/UIDataCodeGen/CodeGen/InstantiatorGeneratorBase.cs index 40eb760e..2614f1f7 100644 --- a/source/UIDataCodeGen/CodeGen/InstantiatorGeneratorBase.cs +++ b/source/UIDataCodeGen/CodeGen/InstantiatorGeneratorBase.cs @@ -1275,7 +1275,7 @@ string CallFactoryFromFor_UnCached(ObjectData callerNode, ObjectData calleeNode) // factory, then a dereference of the ".Properties" property on the owner. if (propertySet.Owner != null) { - return $"{CallFactoryFromFor(callerNode, NodeFor(propertySet.Owner))}{Deref}Properties"; + return _s.PropertyGet(CallFactoryFromFor(callerNode, NodeFor(propertySet.Owner)), "Properties"); } } From 404b1af16a8310414ecff89e6dff1ccab0ea4c50 Mon Sep 17 00:00:00 2001 From: Simeon Cran Date: Tue, 22 Sep 2020 17:08:50 -0700 Subject: [PATCH 2/3] Remove "final" from generated cppwinrt classes. In some non-release cases, cppwinrt does not allow classes to be final because it subclasses them.. --- .../CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs b/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs index c7afc388..28ed5b8b 100644 --- a/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs +++ b/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs @@ -175,7 +175,7 @@ string GenerateHeaderText() throw new NotImplementedException(); } - builder.Class.Preamble.WriteLine($"class {_sourceClassName} final"); + builder.Class.Preamble.WriteLine($"class {_sourceClassName}"); builder.Class.Preamble.Indent(); builder.Class.Preamble.WriteLine($": public {_sourceClassName}T<{_sourceClassName}>"); builder.Class.Preamble.UnIndent(); @@ -205,7 +205,7 @@ string GenerateHeaderText() // Write the factory_implementation namespace. This allows the class to be activatable. builder.Postamble.WriteLine("namespace factory_implementation"); builder.Postamble.OpenScope(); - builder.Postamble.WriteLine($"struct {_sourceClassName} final : {_sourceClassName}T<{_sourceClassName}, implementation::{_sourceClassName}>"); + builder.Postamble.WriteLine($"struct {_sourceClassName} : {_sourceClassName}T<{_sourceClassName}, implementation::{_sourceClassName}>"); builder.Postamble.OpenScope(); builder.Postamble.CloseCppTypeScope(); builder.Postamble.CloseScope(); @@ -450,7 +450,7 @@ protected override void WriteAnimatedVisualStart( IAnimatedVisualInfo info) { // Start writing the instantiator. - builder.WriteLine($"class {info.ClassName} final : public winrt::implements<{info.ClassName},"); + builder.WriteLine($"class {info.ClassName} : public winrt::implements<{info.ClassName},"); builder.Indent(); builder.Indent(); builder.WriteLine($"winrt::{_animatedVisualTypeName},"); @@ -1200,7 +1200,7 @@ internal CodeBuilder ToCodeBuilder() } static string CanvasGeometryClass => -@"class CanvasGeometry final : public winrt::implements { @@ -1253,7 +1253,7 @@ enum class CanvasComposite : int // Windows::UI::Composition::CompositionEffectBrush without requiring Win2d. This is // achieved by implementing the interfaces Windows::UI::Composition requires for it // to consume an effect. - class CompositeEffect final : public winrt::implements From 127924aab5b2cd84099e103c1de824efeb992c1f Mon Sep 17 00:00:00 2001 From: Simeon Cran Date: Tue, 22 Sep 2020 17:29:12 -0700 Subject: [PATCH 3/3] Fix string incorrectly terminated. --- .../CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs b/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs index 28ed5b8b..cf723e2c 100644 --- a/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs +++ b/source/UIDataCodeGen/CodeGen/Cppwinrt/CppwinrtInstantiatorGenerator.cs @@ -694,7 +694,7 @@ protected override string WriteCompositeEffectFactory(CodeBuilder builder, Mgce. builder.WriteLine($"compositeEffect.SetMode({_s.CanvasCompositeMode(compositeEffect.Mode)});"); foreach (var source in compositeEffect.Sources) { - builder.WriteLine($"compositeEffect.AddSource(CompositionEffectSourceParameter(L\"{source.Name}));"); + builder.WriteLine($"compositeEffect.AddSource(CompositionEffectSourceParameter(L\"{source.Name}\"));"); } return "compositeEffect";