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 3 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
3 changes: 3 additions & 0 deletions dev/CommandBarFlyout/CommandBarFlyout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +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 Down
38 changes: 16 additions & 22 deletions dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ void CommandBarFlyoutCommandBar::UpdateUI(bool useTransitions)
{
UpdateTemplateSettings();
UpdateVisualState(useTransitions);

#ifdef USE_INSIDER_SDK
UpdateShadow();
#endif
}

void CommandBarFlyoutCommandBar::UpdateVisualState(bool useTransitions)
Expand Down Expand Up @@ -473,6 +476,7 @@ void CommandBarFlyoutCommandBar::UpdateTemplateSettings()
}
}

#ifdef USE_INSIDER_SDK
void CommandBarFlyoutCommandBar::UpdateShadow()
{
if (PrimaryCommands().Size() > 0)
Expand All @@ -489,45 +493,35 @@ void CommandBarFlyoutCommandBar::AddShadow()
{
if (SharedHelpers::IsThemeShadowAvailable())
{
#ifdef USE_INSIDER_SDK
//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 (winrt::IUIElement10 grid_uiElement10 = grid)
{
if (!grid_uiElement10.Shadow())
{
winrt::Windows::UI::Xaml::Media::ThemeShadow shadow;
grid_uiElement10.Shadow(shadow);

auto translation = winrt::float3{ grid.Translation().x, grid.Translation().y, 32.0f };
grid.Translation(translation);
}
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);
}
#endif
}
}

void CommandBarFlyoutCommandBar::ClearShadow()
{
if (SharedHelpers::IsThemeShadowAvailable())
{
#ifdef USE_INSIDER_SDK
winrt::IControlProtected thisAsControlProtected = *this;
auto grid = GetTemplateChildT<winrt::Grid>(L"ContentRoot", thisAsControlProtected);
if (winrt::IUIElement10 grid_uiElement10 = grid)
if (grid!= nullptr && grid.Shadow() != nullptr)
{
if (grid_uiElement10.Shadow())
{
grid_uiElement10.Shadow(nullptr);

//Undo the elevation
auto translation = winrt::float3{ grid.Translation().x, grid.Translation().y, 0.0f };
grid.Translation(translation);
}
grid.Shadow(nullptr);
//Undo the elevation
auto translation = winrt::float3{ grid.Translation().x, grid.Translation().y, 0.0f };
grid.Translation(translation);
}
#endif
}
}
#endif
9 changes: 9 additions & 0 deletions dev/CommandBarFlyout/CommandBarFlyoutCommandBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class CommandBarFlyoutCommandBar :
void PlayCloseAnimation(std::function<void()> onCompleteFunc);
void ClearShadow();

#ifdef USE_INSIDER_SDK
void ClearShadow();
#endif

private:
void AttachEventHandlers();
void DetachEventHandlers(bool useSafeGet = false);
Expand All @@ -37,6 +41,11 @@ class CommandBarFlyoutCommandBar :
void UpdateTemplateSettings();
void UpdateShadow();

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

tracker_ref<winrt::FrameworkElement> m_primaryItemsRoot{ this };
tracker_ref<winrt::FrameworkElement> m_secondaryItemsRoot{ this };
tracker_ref<winrt::ButtonBase> m_moreButton{ this };
Expand Down
51 changes: 12 additions & 39 deletions dev/CommandBarFlyout/TextCommandBarFlyout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,20 +565,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 @@ -643,20 +634,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 @@ -715,20 +697,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
3 changes: 0 additions & 3 deletions dev/inc/CppWinRTIncludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,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