Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back-porting external changes from the OS repo. #202

Merged
merged 5 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 7 additions & 27 deletions dev/CommandBarFlyout/CommandBarFlyout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,6 @@ CommandBarFlyout::CommandBarFlyout()
{
if (auto commandBar = winrt::get_self<CommandBarFlyoutCommandBar>(m_commandBar.get()))
{
if (SharedHelpers::IsThemeShadowAvailable())
{
#if defined(BUILD_WINDOWS)
if (Feature_CommandBarFlyoutShadow::IsEnabled())
{
// Apply a shadow (only if we have a CommandBar worth shadowing)
winrt::Windows::UI::Xaml::Media::ThemeShadow shadow;
commandBar->Shadow(shadow);
bool havePrimaryCommands = PrimaryCommands().Size() > 0;
auto translation = havePrimaryCommands ? winrt::float3{ 0.0f, 0.0f, 32.0f } : winrt::float3{ 0.0f, 0.0f, 0.0f };
commandBar->Translation(translation);
}
#endif
}

if (commandBar->HasOpenAnimation())
{
commandBar->PlayOpenAnimation();
Expand All @@ -175,6 +160,13 @@ CommandBarFlyout::CommandBarFlyout()
});
commandBar->IsOpen(false);
}

#ifdef USE_INSIDER_SDK
//CommandBarFlyoutCommandBar.Closed will be called when
//clicking the more (...) button, we clear the translations
//here
commandBar->ClearShadow();
#endif
}
}
});
Expand All @@ -186,18 +178,6 @@ CommandBarFlyout::CommandBarFlyout()
{
if (auto commandBar = m_commandBar.get())
{
if (SharedHelpers::IsThemeShadowAvailable())
{
#if defined(BUILD_WINDOWS)
if (Feature_CommandBarFlyoutShadow::IsEnabled())
{
// Clear the shadow
auto translation = winrt::float3{ 0.0f, 0.0f, 0.0f };
commandBar.Translation(translation);
}
#endif
}

if (commandBar.IsOpen())
{
commandBar.IsOpen(false);
Expand Down
60 changes: 59 additions & 1 deletion dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ CommandBarFlyoutCommandBar::CommandBarFlyoutCommandBar()
});

SizeChanged({ [this](auto const&, auto const&) { UpdateUI(); } });
Closed({ [this](auto const&, auto const&) { m_secondaryItemsRootSized = false; } });
Closed({ [this](auto const&, auto const&)
{
m_secondaryItemsRootSized = false;
} });

RegisterPropertyChangedCallback(
winrt::AppBar::IsOpenProperty(),
Expand All @@ -45,6 +48,7 @@ CommandBarFlyoutCommandBar::CommandBarFlyoutCommandBar()
// in fact, if we tried to remove these handlers in our destructor,
// these properties will have already been cleared, and we'll nullref.
PrimaryCommands().VectorChanged({ [this](auto const&, auto const&) { UpdateUI(); } });

SecondaryCommands().VectorChanged({
[this](auto const&, auto const&)
{
Expand Down Expand Up @@ -190,6 +194,10 @@ void CommandBarFlyoutCommandBar::UpdateUI(bool useTransitions)
{
UpdateTemplateSettings();
UpdateVisualState(useTransitions);

#ifdef USE_INSIDER_SDK
UpdateShadow();
#endif
}

void CommandBarFlyoutCommandBar::UpdateVisualState(bool useTransitions)
Expand Down Expand Up @@ -391,3 +399,53 @@ void CommandBarFlyoutCommandBar::UpdateTemplateSettings()
}
}
}

#ifdef USE_INSIDER_SDK
void CommandBarFlyoutCommandBar::UpdateShadow()
{
if (PrimaryCommands().Size() > 0)
{
AddShadow();
}
else if (PrimaryCommands().Size() == 0)
{
ClearShadow();
}
}

void CommandBarFlyoutCommandBar::AddShadow()
{
if (SharedHelpers::IsThemeShadowAvailable())
{
//Apply Shadow on the Grid named "ContentRoot", this is the first element below
//the clip animation of the commandBar. This guarantees that shadow respects the
//animation
winrt::IControlProtected thisAsControlProtected = *this;
auto grid = GetTemplateChildT<winrt::Grid>(L"ContentRoot", thisAsControlProtected);

if (grid != nullptr && grid.Shadow() == nullptr)
{
winrt::Windows::UI::Xaml::Media::ThemeShadow shadow;
grid.Shadow(shadow);
auto translation = winrt::float3{ grid.Translation().x, grid.Translation().y, 32.0f };
grid.Translation(translation);
}
}
}

void CommandBarFlyoutCommandBar::ClearShadow()
{
if (SharedHelpers::IsThemeShadowAvailable())
{
winrt::IControlProtected thisAsControlProtected = *this;
auto grid = GetTemplateChildT<winrt::Grid>(L"ContentRoot", thisAsControlProtected);
if (grid!= nullptr && grid.Shadow() != nullptr)
{
grid.Shadow(nullptr);
//Undo the elevation
auto translation = winrt::float3{ grid.Translation().x, grid.Translation().y, 0.0f };
grid.Translation(translation);
}
}
}
#endif
9 changes: 9 additions & 0 deletions dev/CommandBarFlyout/CommandBarFlyoutCommandBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class CommandBarFlyoutCommandBar :
bool HasCloseAnimation();
void PlayCloseAnimation(std::function<void()> onCompleteFunc);

#ifdef USE_INSIDER_SDK
void ClearShadow();
#endif

private:
void AttachEventHandlers();
void DetachEventHandlers(bool useSafeGet = false);
Expand All @@ -32,6 +36,11 @@ class CommandBarFlyoutCommandBar :
void UpdateVisualState(bool useTransitions);
void UpdateTemplateSettings();

#ifdef USE_INSIDER_SDK
void AddShadow();
void UpdateShadow();
#endif

tracker_ref<winrt::FrameworkElement> m_primaryItemsRoot{ this };
tracker_ref<winrt::FrameworkElement> m_secondaryItemsRoot{ this };
weak_ref<winrt::CommandBarFlyout> m_owningFlyout{ nullptr };
Expand Down
53 changes: 13 additions & 40 deletions dev/CommandBarFlyout/TextCommandBarFlyout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,11 @@ void TextCommandBarFlyout::ExecuteCutCommand()
}
else if (auto richEditBoxTarget = safe_try_cast<winrt::RichEditBox>(target))
{
#ifdef BUILD_WINDOWS
if (auto richEditBoxCutCopyPaste = richEditBoxTarget.try_as<winrt::IRichEditBoxFeature_RichEditBoxCutCopyPasteAPIs>())
{
richEditBoxCutCopyPaste.CutSelectionToClipboard();
}
else
#endif
{
auto selection{ SharedHelpers::GetRichTextSelection(richEditBoxTarget) };
auto selection{ SharedHelpers::GetRichTextSelection(richEditBoxTarget) };

if (selection)
{
selection.Cut();
}
if (selection)
{
selection.Cut();
}
}

Expand Down Expand Up @@ -634,20 +625,11 @@ void TextCommandBarFlyout::ExecuteCopyCommand()
}
else if (auto richEditBoxTarget = safe_try_cast<winrt::RichEditBox>(target))
{
#ifdef BUILD_WINDOWS
if (auto richEditBoxCutCopyPaste = richEditBoxTarget.try_as<winrt::IRichEditBoxFeature_RichEditBoxCutCopyPasteAPIs>())
{
richEditBoxCutCopyPaste.CopySelectionToClipboard();
}
else
#endif
{
auto selection{ SharedHelpers::GetRichTextSelection(richEditBoxTarget) };
auto selection{ SharedHelpers::GetRichTextSelection(richEditBoxTarget) };

if (selection)
{
selection.Copy();
}
if (selection)
{
selection.Copy();
}
}
else if (auto richTextBlockTarget = safe_try_cast<winrt::RichTextBlock>(target))
Expand Down Expand Up @@ -706,20 +688,11 @@ void TextCommandBarFlyout::ExecutePasteCommand()
}
else if (auto richEditBoxTarget = safe_try_cast<winrt::RichEditBox>(target))
{
#ifdef BUILD_WINDOWS
if (auto richEditBoxCutCopyPaste = richEditBoxTarget.try_as<winrt::IRichEditBoxFeature_RichEditBoxCutCopyPasteAPIs>())
{
richEditBoxCutCopyPaste.PasteFromClipboard();
}
else
#endif
{
auto selection{ SharedHelpers::GetRichTextSelection(richEditBoxTarget) };
auto selection{ SharedHelpers::GetRichTextSelection(richEditBoxTarget) };

if (selection)
{
selection.Paste(0);
}
if (selection)
{
selection.Paste(0);
}
}
else if (auto passwordBoxTarget = safe_try_cast<winrt::PasswordBox>(target))
Expand Down Expand Up @@ -1068,4 +1041,4 @@ winrt::ICommandBarElement TextCommandBarFlyout::GetButton(TextControlButtons tex
return nullptr;
}
}
}
}
3 changes: 0 additions & 3 deletions dev/inc/CppWinRTIncludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ namespace winrt
using IPasswordBox5 = ::winrt::Windows::UI::Xaml::Controls::IPasswordBox5;
using IRichEditBox6 = ::winrt::Windows::UI::Xaml::Controls::IRichEditBox6;
using IRichEditBox8 = ::winrt::Windows::UI::Xaml::Controls::IRichEditBox8;
#ifdef BUILD_WINDOWS
using IRichEditBoxFeature_RichEditBoxCutCopyPasteAPIs = ::winrt::Windows::UI::Xaml::Controls::IRichEditBoxFeature_RichEditBoxCutCopyPasteAPIs;
#endif
using IRichTextBlock6 = ::winrt::Windows::UI::Xaml::Controls::IRichTextBlock6;
using ITextBlock7 = ::winrt::Windows::UI::Xaml::Controls::ITextBlock7;
using ITextBox8 = ::winrt::Windows::UI::Xaml::Controls::ITextBox8;
Expand Down