Browse Source

Simplify dependency properties and events (#660)

* Use macros for dependency properties

* Remove extra DP field

* Change name of DP nobox macro

* Use CRTP to simplify events.

* Use Mile event helper

* Use namespace shorthand.

* Remove leftover explicit namespace

* Wrap soruce files in namespace block
pull/668/head
Dongle 1 month ago
committed by GitHub
parent
commit
1fe485b678
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 544
      NanaZip.Modern/AddressBar.cpp
  2. 127
      NanaZip.Modern/AddressBar.h
  3. 88
      NanaZip.Modern/ControlMacros.h
  4. 1
      NanaZip.Modern/NanaZip.Modern.vcxproj
  5. 1
      NanaZip.Modern/NanaZip.Modern.vcxproj.filters
  6. 132
      NanaZip.Modern/StatusBar.cpp
  7. 30
      NanaZip.Modern/StatusBar.h

544
NanaZip.Modern/AddressBar.cpp

@ -6,153 +6,148 @@
#include <winrt/Windows.System.h>
namespace wf = winrt::Windows::Foundation;
namespace wfc = wf::Collections;
using namespace winrt::NanaZip::Modern::implementation;
void AddressBar::OnApplyTemplate()
namespace winrt::NanaZip::Modern::implementation
{
m_textBoxElement =
GetTemplateChild(L"TextBoxElement")
.as<winrt::Windows::UI::Xaml::Controls::TextBox>();
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/5341
winrt::Windows::UI::Xaml::Controls::TextCommandBarFlyout textFlyout;
textFlyout.Placement(
winrt::Windows::UI::Xaml::Controls::Primitives::
FlyoutPlacementMode::
BottomEdgeAlignedLeft);
m_textBoxElement.ContextFlyout(textFlyout);
m_textBoxElement.SelectionFlyout(textFlyout);
m_textBoxElement.GotFocus(
[]
(wf::IInspectable const& sender, auto&&)
{
winrt::Windows::UI::Xaml::Controls::TextBox textBox =
sender.as<winrt::Windows::UI::Xaml::Controls::TextBox>();
textBox.SelectAll();
});
void AddressBar::OnApplyTemplate()
{
m_textBoxElement =
GetTemplateChild(L"TextBoxElement")
.as<winrt::TextBox>();
// Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/5341
winrt::TextCommandBarFlyout textFlyout;
textFlyout.Placement(
winrt::FlyoutPlacementMode::BottomEdgeAlignedLeft);
m_textBoxElement.ContextFlyout(textFlyout);
m_textBoxElement.SelectionFlyout(textFlyout);
m_textBoxElement.GotFocus(
[]
(winrt::IInspectable const& sender, auto&&)
{
winrt::TextBox textBox =
sender.as<winrt::TextBox>();
textBox.SelectAll();
});
m_textBoxElement.PreviewKeyDown({ get_weak(), &AddressBar::OnTextBoxPreviewKeyDown });
m_textBoxElement.PreviewKeyDown({ get_weak(), &AddressBar::OnTextBoxPreviewKeyDown });
m_popup =
GetTemplateChild(L"SuggestionsPopup")
.as<winrt::Windows::UI::Xaml::Controls::Primitives::Popup>();
m_popup =
GetTemplateChild(L"SuggestionsPopup")
.as<winrt::Popup>();
m_popup.Closed(
[weak_this{ get_weak() }]
(auto&&, auto&&)
{
if (auto strong_this{ weak_this.get() })
m_popup.Closed(
[weak_this{ get_weak() }]
(auto&&, auto&&)
{
if (!strong_this->m_textBoxElement)
return;
auto tbCorner = strong_this->m_textBoxElement.CornerRadius();
tbCorner.BottomLeft = tbCorner.TopLeft;
tbCorner.BottomRight = tbCorner.TopRight;
strong_this->m_textBoxElement.CornerRadius(tbCorner);
}
});
m_suggestionsList =
GetTemplateChild(L"SuggestionsList")
.as<winrt::Windows::UI::Xaml::Controls::ListView>();
m_suggestionsList.ItemClick(
[weak_this{ get_weak() }]
(auto&&, winrt::Windows::UI::Xaml::Controls::ItemClickEventArgs const& args)
{
if (auto strong_this{ weak_this.get() })
if (auto strong_this{ weak_this.get() })
{
if (!strong_this->m_textBoxElement)
return;
auto tbCorner = strong_this->m_textBoxElement.CornerRadius();
tbCorner.BottomLeft = tbCorner.TopLeft;
tbCorner.BottomRight = tbCorner.TopRight;
strong_this->m_textBoxElement.CornerRadius(tbCorner);
}
});
m_suggestionsList =
GetTemplateChild(L"SuggestionsList")
.as<winrt::ListView>();
m_suggestionsList.ItemClick(
[weak_this{ get_weak() }]
(auto&&, winrt::ItemClickEventArgs const& args)
{
strong_this->m_popup.IsOpen(false);
auto submitArgs = winrt::make<AddressBarQuerySubmittedEventArgs>(
L"",
args.ClickedItem()
);
strong_this->m_querySubmittedEvent(
*strong_this,
submitArgs
);
if (auto strong_this{ weak_this.get() })
{
strong_this->m_popup.IsOpen(false);
auto submitArgs = winrt::make<AddressBarQuerySubmittedEventArgs>(
L"",
args.ClickedItem()
);
strong_this->QuerySubmitted(
*strong_this,
submitArgs
);
}
}
}
);
);
winrt::Windows::UI::Xaml::Controls::Button m_dropDownButton =
GetTemplateChild(L"DropDownButton")
.as<winrt::Windows::UI::Xaml::Controls::Button>();
winrt::Button m_dropDownButton =
GetTemplateChild(L"DropDownButton")
.as<winrt::Button>();
m_dropDownButton.Click(
[ weak_this{ get_weak() }]
(
auto&&, auto&&
)
{
if (auto strong_this{ weak_this.get() })
m_dropDownButton.Click(
[weak_this{ get_weak() }]
(
auto&&, auto&&
)
{
wfc::IVectorView<wf::IInspectable> source =
strong_this->ItemsSource()
.as<wfc::IVectorView<wf::IInspectable>>();
strong_this->OpenSuggestionsPopup(false);
}
});
m_upButtonElement =
GetTemplateChild(L"UpButton")
.as<winrt::Windows::UI::Xaml::Controls::Button>();
m_upButtonElement.Click(
[weak_this{ get_weak() }]
(
auto&&,
winrt::Windows::UI::Xaml::RoutedEventArgs const&
args
)
{
if (auto strong_this{ weak_this.get() })
if (auto strong_this{ weak_this.get() })
{
winrt::IVectorView<winrt::IInspectable> source =
strong_this->ItemsSource()
.as<winrt::IVectorView<winrt::IInspectable>>();
strong_this->OpenSuggestionsPopup(false);
}
});
this->m_upButtonElement =
GetTemplateChild(L"UpButton")
.as<winrt::Button>();
this->m_upButtonElement.Click(
[weak_this{ get_weak() }]
(
auto&&,
winrt::RoutedEventArgs const&
args
)
{
strong_this->m_upButtonClickedEvent(*strong_this, args);
}
});
if (auto strong_this{ weak_this.get() })
{
strong_this->UpButtonClicked(*strong_this, args);
}
});
__super::OnApplyTemplate();
}
__super::OnApplyTemplate();
}
void AddressBar::OnTextBoxPreviewKeyDown(
wf::IInspectable const&,
winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs const& args)
{
switch (args.Key())
void AddressBar::OnTextBoxPreviewKeyDown(
winrt::IInspectable const&,
winrt::KeyRoutedEventArgs const& args)
{
case winrt::Windows::System::VirtualKey::Enter:
switch (args.Key())
{
case winrt::VirtualKey::Enter:
{
if (m_popup &&
m_suggestionsList &&
m_popup.IsOpen() &&
m_suggestionsList.SelectionMode()
!= winrt::Windows::UI::Xaml::Controls::ListViewSelectionMode::None)
!= winrt::ListViewSelectionMode::None)
{
auto selectedItem = m_suggestionsList.SelectedItem();
auto submitArgs = winrt::make<AddressBarQuerySubmittedEventArgs>(L"", selectedItem);
// The suggestions dropdown is opened via keyboard.
m_querySubmittedEvent(*this, submitArgs);
QuerySubmitted(*this, submitArgs);
}
else
{
auto submitArgs = winrt::make<AddressBarQuerySubmittedEventArgs>(Text(), nullptr);
m_querySubmittedEvent(*this, submitArgs);
QuerySubmitted(*this, submitArgs);
}
args.Handled(true);
break;
}
case winrt::Windows::System::VirtualKey::Down:
case winrt::VirtualKey::Down:
{
if (!m_popup || !m_suggestionsList)
break;
wfc::IVectorView<wf::IInspectable> source =
ItemsSource().as<wfc::IVectorView<wf::IInspectable>>();
winrt::IVectorView<winrt::IInspectable> source =
ItemsSource().as<winrt::IVectorView<winrt::IInspectable>>();
if (!m_popup.IsOpen())
{
@ -173,7 +168,7 @@ void AddressBar::OnTextBoxPreviewKeyDown(
break;
}
case winrt::Windows::System::VirtualKey::Up:
case winrt::VirtualKey::Up:
{
if (!m_popup || !m_suggestionsList || !m_popup.IsOpen())
break;
@ -187,278 +182,103 @@ void AddressBar::OnTextBoxPreviewKeyDown(
args.Handled(true);
break;
}
}
__super::OnKeyUp(args);
}
__super::OnKeyUp(args);
}
winrt::hstring AddressBar::Text()
{
auto value = GetValue(TextProperty());
if (!value)
return L"";
return winrt::unbox_value<winrt::hstring>(
value
DEPENDENCY_PROPERTY_SOURCE_BOX(
Text,
winrt::hstring,
AddressBar,
winrt::NanaZip::Modern::AddressBar
);
}
void AddressBar::Text(winrt::hstring const& string)
{
SetValue(
TextProperty(),
winrt::box_value(string)
DEPENDENCY_PROPERTY_SOURCE_NOBOX(
IconSource,
winrt::ImageSource,
AddressBar,
winrt::NanaZip::Modern::AddressBar
);
}
winrt::Windows::UI::Xaml::DependencyProperty AddressBar::TextProperty()
{
if (!s_textProperty)
{
s_textProperty =
winrt::Windows::UI::Xaml::DependencyProperty::Register(
L"Text",
winrt::xaml_typename<winrt::hstring>(),
winrt::xaml_typename<winrt::NanaZip::Modern::AddressBar>(),
nullptr
);
}
return s_textProperty;
}
winrt::Windows::UI::Xaml::Media::ImageSource AddressBar::IconSource()
{
return GetValue(IconSourceProperty())
.as<winrt::Windows::UI::Xaml::Media::ImageSource>();
}
void AddressBar::IconSource(winrt::Windows::UI::Xaml::Media::ImageSource const& iconSource)
{
SetValue(
IconSourceProperty(),
iconSource
DEPENDENCY_PROPERTY_SOURCE_NOBOX(
ItemsSource,
winrt::IInspectable,
AddressBar,
winrt::NanaZip::Modern::AddressBar
);
}
winrt::Windows::UI::Xaml::DependencyProperty AddressBar::IconSourceProperty()
{
if (!s_iconSourceProperty)
{
s_iconSourceProperty =
winrt::Windows::UI::Xaml::DependencyProperty::Register(
L"IconSource",
winrt::xaml_typename<winrt::Windows::UI::Xaml::Media::ImageSource>(),
winrt::xaml_typename<winrt::NanaZip::Modern::AddressBar>(),
nullptr
);
}
return s_iconSourceProperty;
}
wf::IInspectable AddressBar::ItemsSource()
{
return GetValue(ItemsSourceProperty());
}
void AddressBar::ItemsSource(wf::IInspectable const& itemsSource)
{
SetValue(
ItemsSourceProperty(),
itemsSource
DEPENDENCY_PROPERTY_SOURCE_BOX_WITHDEFAULT(
IsUpButtonEnabled,
bool,
AddressBar,
winrt::NanaZip::Modern::AddressBar,
true
);
}
winrt::Windows::UI::Xaml::DependencyProperty AddressBar::ItemsSourceProperty()
{
if (!s_itemsSourceProperty)
bool AddressBar::OpenSuggestionsPopup(
bool isKeyboard
)
{
s_itemsSourceProperty =
winrt::Windows::UI::Xaml::DependencyProperty::Register(
L"ItemsSource",
winrt::xaml_typename<wf::IInspectable>(),
winrt::xaml_typename<winrt::NanaZip::Modern::AddressBar>(),
nullptr
);
}
return s_itemsSourceProperty;
}
if (!m_popup || !m_textBoxElement || !m_suggestionsList)
return false;
bool AddressBar::IsUpButtonEnabled()
{
return winrt::unbox_value<bool>(
GetValue(IsUpButtonEnabledProperty())
);
}
DropDownOpened(*this, nullptr);
void AddressBar::IsUpButtonEnabled(bool isUpButtonEnabled)
{
SetValue(
IsUpButtonEnabledProperty(),
winrt::box_value(isUpButtonEnabled)
);
}
winrt::IVectorView<winrt::IInspectable> source =
ItemsSource().as<winrt::IVectorView<winrt::IInspectable>>();
if (source.Size() == 0)
return false;
winrt::Windows::UI::Xaml::DependencyProperty AddressBar::IsUpButtonEnabledProperty()
{
if (!s_upButtonEnabledProperty)
{
s_upButtonEnabledProperty =
winrt::Windows::UI::Xaml::DependencyProperty::Register(
L"IsUpButtonEnabled",
winrt::xaml_typename<bool>(),
winrt::xaml_typename<winrt::NanaZip::Modern::AddressBar>(),
winrt::Windows::UI::Xaml::PropertyMetadata(
winrt::box_value(true),
nullptr
)
if (!isKeyboard)
{
m_suggestionsList.SelectionMode(
winrt::ListViewSelectionMode::None
);
}
return s_upButtonEnabledProperty;
}
winrt::event_token
AddressBar::QuerySubmitted(
wf::TypedEventHandler<
winrt::NanaZip::Modern::AddressBar,
winrt::NanaZip::Modern::AddressBarQuerySubmittedEventArgs>
const& handler
)
{
return m_querySubmittedEvent.add(handler);
}
void AddressBar::QuerySubmitted(
winrt::event_token const& token
) noexcept
{
m_querySubmittedEvent.remove(token);
}
winrt::event_token
AddressBar::UpButtonClicked(
winrt::Windows::UI::Xaml::RoutedEventHandler const&
handler
)
{
return m_upButtonClickedEvent.add(handler);
}
void AddressBar::UpButtonClicked(
winrt::event_token const& token
) noexcept
{
m_upButtonClickedEvent.remove(token);
}
}
else {
m_suggestionsList.SelectionMode(
winrt::ListViewSelectionMode::Single
);
}
winrt::event_token
AddressBar::DropDownOpened(
wf::TypedEventHandler<
winrt::NanaZip::Modern::AddressBar,
wf::IInspectable>
const& handler
)
{
return m_dropDownOpenedEvent.add(handler);
}
m_suggestionsList.Width(m_textBoxElement.ActualWidth());
m_popup.VerticalOffset(m_textBoxElement.ActualHeight());
void AddressBar::DropDownOpened(
winrt::event_token const& token
) noexcept
{
m_dropDownOpenedEvent.remove(token);
}
auto tbCorner = m_textBoxElement.CornerRadius();
tbCorner.BottomLeft = tbCorner.BottomRight = 0;
m_textBoxElement.CornerRadius(tbCorner);
bool AddressBar::OpenSuggestionsPopup(
bool isKeyboard
)
{
if (!m_popup || !m_textBoxElement || !m_suggestionsList)
return false;
auto slCorner = m_suggestionsList.CornerRadius();
slCorner.TopLeft = slCorner.TopRight = 0;
m_suggestionsList.CornerRadius(slCorner);
m_dropDownOpenedEvent(*this, nullptr);
m_popup.IsOpen(true);
m_textBoxElement.Focus(winrt::FocusState::Programmatic);
wfc::IVectorView<wf::IInspectable> source =
ItemsSource().as<wfc::IVectorView<wf::IInspectable>>();
if (source.Size() == 0)
return false;
return true;
}
if (!isKeyboard)
AddressBarQuerySubmittedEventArgs::
AddressBarQuerySubmittedEventArgs(
winrt::hstring const& queryText,
winrt::IInspectable const& suggestionChosen
)
{
m_suggestionsList.SelectionMode(
winrt::Windows::UI::Xaml::Controls::ListViewSelectionMode::None
);
m_queryText = queryText;
m_chosenSuggestion = suggestionChosen;
}
else {
m_suggestionsList.SelectionMode(
winrt::Windows::UI::Xaml::Controls::ListViewSelectionMode::Single
);
}
m_suggestionsList.Width(m_textBoxElement.ActualWidth());
m_popup.VerticalOffset(m_textBoxElement.ActualHeight());
auto tbCorner = m_textBoxElement.CornerRadius();
tbCorner.BottomLeft = tbCorner.BottomRight = 0;
m_textBoxElement.CornerRadius(tbCorner);
auto slCorner = m_suggestionsList.CornerRadius();
slCorner.TopLeft = slCorner.TopRight = 0;
m_suggestionsList.CornerRadius(slCorner);
m_popup.IsOpen(true);
m_textBoxElement.Focus(winrt::Windows::UI::Xaml::FocusState::Programmatic);
return true;
}
winrt::hstring AddressBarItem::Text()
{
return m_text;
}
void AddressBarItem::Text(winrt::hstring const& text)
{
m_text = text;
}
winrt::Windows::UI::Xaml::Media::ImageSource AddressBarItem::Icon()
{
return m_icon;
}
void AddressBarItem::Icon(winrt::Windows::UI::Xaml::Media::ImageSource const& icon)
{
m_icon = icon;
}
winrt::Windows::UI::Xaml::Thickness AddressBarItem::Padding()
{
return m_padding;
}
void AddressBarItem::Padding(winrt::Windows::UI::Xaml::Thickness const& padding)
{
m_padding = padding;
}
AddressBarQuerySubmittedEventArgs::
AddressBarQuerySubmittedEventArgs(
winrt::hstring const& queryText,
wf::IInspectable const& suggestionChosen
)
{
m_queryText = queryText;
m_chosenSuggestion = suggestionChosen;
}
winrt::hstring
AddressBarQuerySubmittedEventArgs::
QueryText()
{
return m_queryText;
}
winrt::hstring
AddressBarQuerySubmittedEventArgs::
QueryText()
{
return m_queryText;
}
wf::IInspectable
AddressBarQuerySubmittedEventArgs::
ChosenSuggestion()
{
return m_chosenSuggestion;
winrt::IInspectable
AddressBarQuerySubmittedEventArgs::
ChosenSuggestion()
{
return m_chosenSuggestion;
}
}

127
NanaZip.Modern/AddressBar.h

@ -7,6 +7,21 @@
#include <winrt/Windows.UI.Xaml.Media.h>
#include <winrt/Windows.UI.Xaml.Input.h>
#include <Mile.Helpers.CppWinRT.h>
#include "ControlMacros.h"
namespace winrt
{
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::System;
}
namespace winrt::NanaZip::Modern::implementation
{
struct AddressBar : AddressBarT<AddressBar>
@ -15,101 +30,61 @@ namespace winrt::NanaZip::Modern::implementation
void OnApplyTemplate();
void OnTextBoxPreviewKeyDown(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs const&);
winrt::hstring Text();
void Text(winrt::hstring const&);
static winrt::Windows::UI::Xaml::DependencyProperty TextProperty();
winrt::Windows::UI::Xaml::Media::ImageSource IconSource();
void IconSource(winrt::Windows::UI::Xaml::Media::ImageSource const&);
static winrt::Windows::UI::Xaml::DependencyProperty IconSourceProperty();
winrt::IInspectable const&,
winrt::KeyRoutedEventArgs const&);
winrt::Windows::Foundation::IInspectable ItemsSource();
void ItemsSource(winrt::Windows::Foundation::IInspectable const&);
static winrt::Windows::UI::Xaml::DependencyProperty ItemsSourceProperty();
bool IsUpButtonEnabled();
void IsUpButtonEnabled(bool);
static winrt::Windows::UI::Xaml::DependencyProperty
IsUpButtonEnabledProperty();
DEPENDENCY_PROPERTY_HEADER(Text, winrt::hstring);
DEPENDENCY_PROPERTY_HEADER(
IconSource,
winrt::ImageSource
);
DEPENDENCY_PROPERTY_HEADER(
ItemsSource,
winrt::IInspectable
);
DEPENDENCY_PROPERTY_HEADER(
IsUpButtonEnabled,
bool
);
winrt::event_token QuerySubmitted(
winrt::Windows::Foundation::TypedEventHandler<
Mile::WinRT::Event<
winrt::TypedEventHandler<
winrt::NanaZip::Modern::AddressBar,
winrt::NanaZip::Modern::AddressBarQuerySubmittedEventArgs>
const&
);
void QuerySubmitted(winrt::event_token const& token) noexcept;
winrt::NanaZip::Modern::AddressBarQuerySubmittedEventArgs>>
QuerySubmitted;
winrt::event_token UpButtonClicked(
winrt::Windows::UI::Xaml::RoutedEventHandler const&
);
void UpButtonClicked(winrt::event_token const& token) noexcept;
Mile::WinRT::Event<winrt::Windows::UI::Xaml::RoutedEventHandler>
UpButtonClicked;
winrt::event_token DropDownOpened(
winrt::Windows::Foundation::TypedEventHandler<
Mile::WinRT::Event<
winrt::TypedEventHandler<
winrt::NanaZip::Modern::AddressBar,
winrt::Windows::Foundation::IInspectable>
const&
);
void DropDownOpened(winrt::event_token const& token) noexcept;
winrt::IInspectable>>
DropDownOpened;
private:
bool OpenSuggestionsPopup(bool isKeyboard);
inline static winrt::Windows::UI::Xaml::DependencyProperty s_textProperty{ nullptr };
inline static winrt::Windows::UI::Xaml::DependencyProperty s_iconSourceProperty{ nullptr };
inline static winrt::Windows::UI::Xaml::DependencyProperty s_upButtonEnabledProperty{ nullptr };
inline static winrt::Windows::UI::Xaml::DependencyProperty s_itemsSourceProperty{ nullptr };
winrt::Windows::UI::Xaml::Controls::TextBox m_textBoxElement{ nullptr };
winrt::Windows::UI::Xaml::Controls::Primitives::Popup
winrt::TextBox m_textBoxElement{ nullptr };
winrt::Popup
m_popup{ nullptr };
winrt::Windows::UI::Xaml::Controls::Button m_upButtonElement{ nullptr };
winrt::Windows::UI::Xaml::Controls::ListView m_suggestionsList{ nullptr };
winrt::event<
winrt::Windows::Foundation::TypedEventHandler<
winrt::NanaZip::Modern::AddressBar,
winrt::NanaZip::Modern::AddressBarQuerySubmittedEventArgs>>
m_querySubmittedEvent;
winrt::event<winrt::Windows::UI::Xaml::RoutedEventHandler>
m_upButtonClickedEvent;
winrt::event<
winrt::Windows::Foundation::TypedEventHandler<
winrt::NanaZip::Modern::AddressBar,
winrt::Windows::Foundation::IInspectable>>
m_dropDownOpenedEvent;
winrt::Button m_upButtonElement{ nullptr };
winrt::ListView m_suggestionsList{ nullptr };
};
struct AddressBarItem : AddressBarItemT<AddressBarItem>
{
AddressBarItem() = default;
winrt::hstring Text();
void Text(winrt::hstring const&);
winrt::Windows::UI::Xaml::Media::ImageSource Icon();
void Icon(winrt::Windows::UI::Xaml::Media::ImageSource const&);
winrt::Windows::UI::Xaml::Thickness Padding();
void Padding(winrt::Windows::UI::Xaml::Thickness const&);
private:
winrt::hstring m_text;
winrt::Windows::UI::Xaml::Media::ImageSource m_icon{ nullptr };
winrt::Windows::UI::Xaml::Thickness m_padding = { 0, 0, 0, 0 };
Mile::WinRT::Property<winrt::hstring> Text;
Mile::WinRT::Property<winrt::ImageSource> Icon =
Mile::WinRT::Property<winrt::ImageSource>(nullptr);
Mile::WinRT::Property<winrt::Thickness> Padding;
};
struct AddressBarQuerySubmittedEventArgs : AddressBarQuerySubmittedEventArgsT<AddressBarQuerySubmittedEventArgs>
struct AddressBarQuerySubmittedEventArgs :
AddressBarQuerySubmittedEventArgsT<
AddressBarQuerySubmittedEventArgs>
{
AddressBarQuerySubmittedEventArgs(
winrt::hstring const&,

88
NanaZip.Modern/ControlMacros.h

@ -0,0 +1,88 @@
#pragma once
#define DEPENDENCY_PROPERTY_HEADER(name, type) \
type name() const; \
void name(type const&); \
static ::winrt::Windows::UI::Xaml::DependencyProperty \
name##Property();
#define DEPENDENCY_PROPERTY_SOURCE_NOBOX(name, type, implType, projType) \
::winrt::Windows::UI::Xaml::DependencyProperty s_##name##Property{ nullptr }; \
type implType::name() const \
{ \
return GetValue(name##Property()).as<type>(); \
} \
\
void implType::name(type const& name) \
{ \
SetValue(name##Property(), name); \
} \
::winrt::Windows::UI::Xaml::DependencyProperty \
implType::name##Property() \
{ \
if (!s_##name##Property) \
{ \
s_##name##Property = \
::winrt::Windows::UI::Xaml::DependencyProperty::Register( \
L#name, \
::winrt::xaml_typename<type>(), \
::winrt::xaml_typename<projType>(), \
nullptr); \
} \
return s_##name##Property; \
}
#define DEPENDENCY_PROPERTY_SOURCE_BOX(name, type, implType, projType) \
::winrt::Windows::UI::Xaml::DependencyProperty s_##name##Property{ nullptr }; \
type implType::name() const \
{ \
return ::winrt::unbox_value<type>(GetValue(name##Property())); \
} \
\
void implType::name(type const& name) \
{ \
SetValue(name##Property(), ::winrt::box_value(name)); \
} \
::winrt::Windows::UI::Xaml::DependencyProperty \
implType::name##Property() \
{ \
if (!s_##name##Property) \
{ \
s_##name##Property = \
::winrt::Windows::UI::Xaml::DependencyProperty::Register( \
L#name, \
::winrt::xaml_typename<type>(), \
::winrt::xaml_typename<projType>(), \
nullptr); \
} \
return s_##name##Property; \
}
#define DEPENDENCY_PROPERTY_SOURCE_BOX_WITHDEFAULT(name, type, implType, projType, default) \
::winrt::Windows::UI::Xaml::DependencyProperty s_##name##Property{ nullptr }; \
type implType::name() const \
{ \
return ::winrt::unbox_value<type>(GetValue(name##Property())); \
} \
\
void implType::name(type const& name) \
{ \
SetValue(name##Property(), ::winrt::box_value(name)); \
} \
::winrt::Windows::UI::Xaml::DependencyProperty \
implType::name##Property() \
{ \
if (!s_##name##Property) \
{ \
s_##name##Property = \
::winrt::Windows::UI::Xaml::DependencyProperty::Register( \
L#name, \
::winrt::xaml_typename<type>(), \
::winrt::xaml_typename<projType>(), \
::winrt::Windows::UI::Xaml::PropertyMetadata( \
::winrt::box_value(default), nullptr \
) \
); \
} \
return s_##name##Property; \
}

1
NanaZip.Modern/NanaZip.Modern.vcxproj

@ -107,6 +107,7 @@
<ClInclude Include="AddressBarTemplate.h">
<DependentUpon>AddressBarTemplate.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="ControlMacros.h" />
<ClInclude Include="NanaZip.Modern.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="App.h">

1
NanaZip.Modern/NanaZip.Modern.vcxproj.filters

@ -18,6 +18,7 @@
<ClInclude Include="NanaZip.Modern.h" />
<ClInclude Include="AddressBar.h" />
<ClInclude Include="StatusBar.h" />
<ClInclude Include="ControlMacros.h" />
</ItemGroup>
<ItemGroup>
<None Include="Mile.Xaml.Unstaged.targets" />

132
NanaZip.Modern/StatusBar.cpp

@ -4,108 +4,30 @@
using namespace winrt::NanaZip::Modern::implementation;
winrt::hstring StatusBar::Text1() const&
{
return winrt::unbox_value<winrt::hstring>(
GetValue(Text1Property())
);
}
void StatusBar::Text1(winrt::hstring const& text)
{
SetValue(Text1Property(), winrt::box_value(text));
}
winrt::hstring StatusBar::Text2() const&
{
return winrt::unbox_value<winrt::hstring>(
GetValue(Text2Property())
);
}
void StatusBar::Text2(winrt::hstring const& text)
{
SetValue(Text2Property(), winrt::box_value(text));
}
winrt::hstring StatusBar::Text3() const&
{
return winrt::unbox_value<winrt::hstring>(
GetValue(Text3Property())
);
}
void StatusBar::Text3(winrt::hstring const& text)
{
SetValue(Text3Property(), winrt::box_value(text));
}
winrt::hstring StatusBar::Text4() const&
{
return winrt::unbox_value<winrt::hstring>(
GetValue(Text4Property())
);
}
void StatusBar::Text4(winrt::hstring const& text)
{
SetValue(Text4Property(), winrt::box_value(text));
}
wux::DependencyProperty StatusBar::Text1Property()
{
if (!s_text1Property)
{
s_text1Property = wux::DependencyProperty::Register(
L"Text1",
winrt::xaml_typename<winrt::hstring>(),
winrt::xaml_typename<winrt::NanaZip::Modern::StatusBar>(),
nullptr
);
}
return s_text1Property;
}
wux::DependencyProperty StatusBar::Text2Property()
{
if (!s_text2Property)
{
s_text2Property = wux::DependencyProperty::Register(
L"Text2",
winrt::xaml_typename<winrt::hstring>(),
winrt::xaml_typename<winrt::NanaZip::Modern::StatusBar>(),
nullptr
);
}
return s_text2Property;
}
wux::DependencyProperty StatusBar::Text3Property()
{
if (!s_text3Property)
{
s_text3Property = wux::DependencyProperty::Register(
L"Text3",
winrt::xaml_typename<winrt::hstring>(),
winrt::xaml_typename<winrt::NanaZip::Modern::StatusBar>(),
nullptr
);
}
return s_text3Property;
}
wux::DependencyProperty StatusBar::Text4Property()
{
if (!s_text4Property)
{
s_text4Property = wux::DependencyProperty::Register(
L"Text4",
winrt::xaml_typename<winrt::hstring>(),
winrt::xaml_typename<winrt::NanaZip::Modern::StatusBar>(),
nullptr
);
}
return s_text4Property;
}
DEPENDENCY_PROPERTY_SOURCE_BOX(
Text1,
winrt::hstring,
StatusBar,
winrt::NanaZip::Modern::StatusBar
);
DEPENDENCY_PROPERTY_SOURCE_BOX(
Text2,
winrt::hstring,
StatusBar,
winrt::NanaZip::Modern::StatusBar
);
DEPENDENCY_PROPERTY_SOURCE_BOX(
Text3,
winrt::hstring,
StatusBar,
winrt::NanaZip::Modern::StatusBar
);
DEPENDENCY_PROPERTY_SOURCE_BOX(
Text4,
winrt::hstring,
StatusBar,
winrt::NanaZip::Modern::StatusBar
);

30
NanaZip.Modern/StatusBar.h

@ -1,9 +1,7 @@
#pragma once
#include "StatusBar.g.h"
namespace wux = ::winrt::Windows::UI::Xaml;
namespace wuxc = wux::Controls;
#include "ControlMacros.h"
namespace winrt::NanaZip::Modern::implementation
{
@ -11,28 +9,10 @@ namespace winrt::NanaZip::Modern::implementation
{
StatusBar() = default;
winrt::hstring Text1() const&;
void Text1(winrt::hstring const&);
winrt::hstring Text2() const&;
void Text2(winrt::hstring const&);
winrt::hstring Text3() const&;
void Text3(winrt::hstring const&);
winrt::hstring Text4() const&;
void Text4(winrt::hstring const&);
static wux::DependencyProperty Text1Property();
static wux::DependencyProperty Text2Property();
static wux::DependencyProperty Text3Property();
static wux::DependencyProperty Text4Property();
private:
inline static wux::DependencyProperty s_text1Property{ nullptr };
inline static wux::DependencyProperty s_text2Property{ nullptr };
inline static wux::DependencyProperty s_text3Property{ nullptr };
inline static wux::DependencyProperty s_text4Property{ nullptr };
DEPENDENCY_PROPERTY_HEADER(Text1, winrt::hstring);
DEPENDENCY_PROPERTY_HEADER(Text2, winrt::hstring);
DEPENDENCY_PROPERTY_HEADER(Text3, winrt::hstring);
DEPENDENCY_PROPERTY_HEADER(Text4, winrt::hstring);
};
}

Loading…
Cancel
Save