Skip to content

Commit

Permalink
IComponentConnector2 doesn't exist in WinUI (#1156)
Browse files Browse the repository at this point in the history
* IComponentConnector2 doesn't exist in WinUI

* added new header
  • Loading branch information
Scottj1s authored Jun 7, 2022
1 parent dcea885 commit a54d678
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3272,11 +3272,11 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
}
else if (namespace_name == "Windows.UI.Xaml.Markup")
{
w.write(strings::base_xaml_component_connector, "Windows");
w.write(strings::base_xaml_component_connector);
}
else if (namespace_name == "Microsoft.UI.Xaml.Markup")
{
w.write(strings::base_xaml_component_connector, "Microsoft");
w.write(strings::base_xaml_component_connector_winui);
}
}

Expand Down
1 change: 1 addition & 0 deletions cppwinrt/cppwinrt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<ClInclude Include="..\strings\base_weak_ref.h" />
<ClInclude Include="..\strings\base_windows.h" />
<ClInclude Include="..\strings\base_xaml_component_connector.h" />
<ClInclude Include="..\strings\base_xaml_component_connector_winui.h" />
<ClInclude Include="..\strings\base_xaml_typename.h" />
<ClInclude Include="cmd_reader.h" />
<ClInclude Include="code_writers.h" />
Expand Down
3 changes: 3 additions & 0 deletions cppwinrt/cppwinrt.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@
<ClInclude Include="..\strings\base_coroutine_system_winui.h">
<Filter>strings</Filter>
</ClInclude>
<ClInclude Include="..\strings\base_xaml_component_connector_winui.h">
<Filter>strings</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="$(OutDir)version.rc" />
Expand Down
2 changes: 1 addition & 1 deletion strings/base_xaml_component_connector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

WINRT_EXPORT namespace winrt::%::UI::Xaml::Markup
WINRT_EXPORT namespace winrt::Windows::UI::Xaml::Markup
{
template <typename D>
struct ComponentConnectorT : D
Expand Down
52 changes: 52 additions & 0 deletions strings/base_xaml_component_connector_winui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

WINRT_EXPORT namespace winrt::Microsoft::UI::Xaml::Markup
{
template <typename D>
struct ComponentConnectorT : D
{
using composable_base = typename D::composable_base;

void InitializeComponent()
{
if constexpr (m_has_connectable_base)
{
m_dispatch_base = true;
composable_base::InitializeComponent();
m_dispatch_base = false;
}
D::InitializeComponent();
}

void Connect(int32_t connectionId, Windows::Foundation::IInspectable const& target)
{
if constexpr (m_has_connectable_base)
{
if (m_dispatch_base)
{
composable_base::Connect(connectionId, target);
return;
}
}
D::Connect(connectionId, target);
}

auto GetBindingConnector(int32_t connectionId, Windows::Foundation::IInspectable const& target)
{
if constexpr (m_has_connectable_base)
{
if (m_dispatch_base)
{
return composable_base::GetBindingConnector(connectionId, target);
}
}
return D::GetBindingConnector(connectionId, target);
}

private:
static constexpr bool m_has_connectable_base{
impl::has_initializer<composable_base>::value &&
impl::has_interface<D, IComponentConnector>() };

bool m_dispatch_base{};
};
}

0 comments on commit a54d678

Please sign in to comment.