initialize to macro
This commit is contained in:
parent
ce8288f1b1
commit
08e012aa6c
|
@ -15,22 +15,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
|||
DependencyProperty VisualBellLight::_IsTargetProperty{ nullptr };
|
||||
DependencyProperty CursorLight::_IsTargetProperty{ nullptr };
|
||||
|
||||
void VisualBellLight::_InitializeProperties()
|
||||
{
|
||||
// Initialize any dependency properties here.
|
||||
// This performs a lazy load on these properties, instead of
|
||||
// initializing them when the DLL loads.
|
||||
if (!_IsTargetProperty)
|
||||
{
|
||||
_IsTargetProperty =
|
||||
DependencyProperty::RegisterAttached(
|
||||
L"IsTarget",
|
||||
winrt::xaml_typename<bool>(),
|
||||
winrt::xaml_typename<Control::VisualBellLight>(),
|
||||
PropertyMetadata{ winrt::box_value(false), PropertyChangedCallback{ &VisualBellLight::OnIsTargetChanged } });
|
||||
}
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - This function is called when the first target UIElement is shown on the screen,
|
||||
// this enables delaying composition object creation until it's actually necessary.
|
||||
|
@ -46,22 +30,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
|||
}
|
||||
}
|
||||
|
||||
void CursorLight::_InitializeProperties()
|
||||
{
|
||||
// Initialize any dependency properties here.
|
||||
// This performs a lazy load on these properties, instead of
|
||||
// initializing them when the DLL loads.
|
||||
if (!_IsTargetProperty)
|
||||
{
|
||||
_IsTargetProperty =
|
||||
DependencyProperty::RegisterAttached(
|
||||
L"IsTarget",
|
||||
winrt::xaml_typename<bool>(),
|
||||
winrt::xaml_typename<Control::CursorLight>(),
|
||||
PropertyMetadata{ winrt::box_value(false), PropertyChangedCallback{ &CursorLight::OnIsTargetChanged } });
|
||||
}
|
||||
}
|
||||
|
||||
void CursorLight::ChangeLocation(float xCoord, float yCoord)
|
||||
{
|
||||
if (const auto light = CompositionLight())
|
||||
|
|
|
@ -7,107 +7,115 @@
|
|||
#include "VisualBellLight.g.h"
|
||||
#include "CursorLight.g.h"
|
||||
|
||||
#define CREATE_XAML_LIGHT(name) \
|
||||
public: \
|
||||
name() \
|
||||
{ \
|
||||
_InitializeProperties(); \
|
||||
} \
|
||||
\
|
||||
winrt::hstring GetId() \
|
||||
{ \
|
||||
return name::GetIdStatic(); \
|
||||
} \
|
||||
\
|
||||
static Windows::UI::Xaml::DependencyProperty IsTargetProperty() \
|
||||
{ \
|
||||
return _IsTargetProperty; \
|
||||
} \
|
||||
\
|
||||
static bool GetIsTarget(Windows::UI::Xaml::DependencyObject const& target) \
|
||||
{ \
|
||||
return winrt::unbox_value<bool>(target.GetValue(_IsTargetProperty)); \
|
||||
} \
|
||||
\
|
||||
static void SetIsTarget(Windows::UI::Xaml::DependencyObject const& target, bool value) \
|
||||
{ \
|
||||
target.SetValue(_IsTargetProperty, winrt::box_value(value)); \
|
||||
} \
|
||||
\
|
||||
void OnDisconnected(Windows::UI::Xaml::UIElement const& /*oldElement*/) \
|
||||
{ \
|
||||
if (CompositionLight()) \
|
||||
{ \
|
||||
CompositionLight(nullptr); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static void OnIsTargetChanged(Windows::UI::Xaml::DependencyObject const& d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs const& e) \
|
||||
{ \
|
||||
const auto uielem{ d.try_as<Windows::UI::Xaml::UIElement>() }; \
|
||||
const auto brush{ d.try_as<Windows::UI::Xaml::Media::Brush>() }; \
|
||||
\
|
||||
if (!uielem && !brush) \
|
||||
{ \
|
||||
/* terminate early*/ \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
const auto isAdding = winrt::unbox_value<bool>(e.NewValue()); \
|
||||
const auto id = GetIdStatic(); \
|
||||
\
|
||||
if (isAdding) \
|
||||
{ \
|
||||
if (uielem) \
|
||||
{ \
|
||||
Windows::UI::Xaml::Media::XamlLight::AddTargetElement(id, uielem); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
Windows::UI::Xaml::Media::XamlLight::AddTargetBrush(id, brush); \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
if (uielem) \
|
||||
{ \
|
||||
Windows::UI::Xaml::Media::XamlLight::RemoveTargetElement(id, uielem); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
Windows::UI::Xaml::Media::XamlLight::RemoveTargetBrush(id, brush); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
inline static winrt::hstring GetIdStatic() \
|
||||
{ \
|
||||
/* This specifies the unique name of the light. In most cases you should use the type's full name. */ \
|
||||
return winrt::xaml_typename<winrt::Microsoft::Terminal::Control::name>().Name; \
|
||||
#define CREATE_XAML_LIGHT(name) \
|
||||
public: \
|
||||
name() \
|
||||
{ \
|
||||
_InitializeProperties(); \
|
||||
} \
|
||||
\
|
||||
winrt::hstring GetId() \
|
||||
{ \
|
||||
return name::GetIdStatic(); \
|
||||
} \
|
||||
\
|
||||
static Windows::UI::Xaml::DependencyProperty IsTargetProperty() \
|
||||
{ \
|
||||
return _IsTargetProperty; \
|
||||
} \
|
||||
\
|
||||
static bool GetIsTarget(Windows::UI::Xaml::DependencyObject const& target) \
|
||||
{ \
|
||||
return winrt::unbox_value<bool>(target.GetValue(_IsTargetProperty)); \
|
||||
} \
|
||||
\
|
||||
static void SetIsTarget(Windows::UI::Xaml::DependencyObject const& target, bool value) \
|
||||
{ \
|
||||
target.SetValue(_IsTargetProperty, winrt::box_value(value)); \
|
||||
} \
|
||||
\
|
||||
void OnDisconnected(Windows::UI::Xaml::UIElement const& /*oldElement*/) \
|
||||
{ \
|
||||
if (CompositionLight()) \
|
||||
{ \
|
||||
CompositionLight(nullptr); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static void OnIsTargetChanged(Windows::UI::Xaml::DependencyObject const& d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs const& e) \
|
||||
{ \
|
||||
const auto uielem{ d.try_as<Windows::UI::Xaml::UIElement>() }; \
|
||||
const auto brush{ d.try_as<Windows::UI::Xaml::Media::Brush>() }; \
|
||||
\
|
||||
if (!uielem && !brush) \
|
||||
{ \
|
||||
/* terminate early*/ \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
const auto isAdding = winrt::unbox_value<bool>(e.NewValue()); \
|
||||
const auto id = GetIdStatic(); \
|
||||
\
|
||||
if (isAdding) \
|
||||
{ \
|
||||
if (uielem) \
|
||||
{ \
|
||||
Windows::UI::Xaml::Media::XamlLight::AddTargetElement(id, uielem); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
Windows::UI::Xaml::Media::XamlLight::AddTargetBrush(id, brush); \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
if (uielem) \
|
||||
{ \
|
||||
Windows::UI::Xaml::Media::XamlLight::RemoveTargetElement(id, uielem); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
Windows::UI::Xaml::Media::XamlLight::RemoveTargetBrush(id, brush); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
inline static winrt::hstring GetIdStatic() \
|
||||
{ \
|
||||
/* This specifies the unique name of the light. In most cases you should use the type's full name. */ \
|
||||
return winrt::xaml_typename<winrt::Microsoft::Terminal::Control::name>().Name; \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty _IsTargetProperty; \
|
||||
static void _InitializeProperties() \
|
||||
{ \
|
||||
if (!_IsTargetProperty) \
|
||||
{ \
|
||||
_IsTargetProperty = \
|
||||
Windows::UI::Xaml::DependencyProperty::RegisterAttached( \
|
||||
L"IsTarget", \
|
||||
winrt::xaml_typename<bool>(), \
|
||||
winrt::xaml_typename<Control::name>(), \
|
||||
Windows::UI::Xaml::PropertyMetadata{ winrt::box_value(false), Windows::UI::Xaml::PropertyChangedCallback{ &name::OnIsTargetChanged } }); \
|
||||
} \
|
||||
}
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
{
|
||||
struct VisualBellLight : VisualBellLightT<VisualBellLight>
|
||||
{
|
||||
CREATE_XAML_LIGHT(VisualBellLight);
|
||||
void OnConnected(Windows::UI::Xaml::UIElement const& newElement);
|
||||
|
||||
private:
|
||||
static void _InitializeProperties();
|
||||
static Windows::UI::Xaml::DependencyProperty _IsTargetProperty;
|
||||
CREATE_XAML_LIGHT(VisualBellLight);
|
||||
};
|
||||
|
||||
struct CursorLight : CursorLightT<CursorLight>
|
||||
{
|
||||
CREATE_XAML_LIGHT(CursorLight);
|
||||
void ChangeLocation(float xCoord, float yCoord);
|
||||
void OnConnected(Windows::UI::Xaml::UIElement const& newElement);
|
||||
CREATE_XAML_LIGHT(CursorLight);
|
||||
|
||||
private:
|
||||
static void _InitializeProperties();
|
||||
static Windows::UI::Xaml::DependencyProperty _IsTargetProperty;
|
||||
|
||||
void _InitializeHelper(float xCoord, float yCoord);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue