| 20 | } |
| 21 | |
| 22 | HRESULT VisualTreeWatcher::OnVisualTreeChange(ParentChildRelation relation, VisualElement element, VisualMutationType mutationType) try |
| 23 | { |
| 24 | switch (mutationType) |
| 25 | { |
| 26 | case Add: |
| 27 | { |
| 28 | const std::wstring_view type { element.Type, SysStringLen(element.Type) }; |
| 29 | if (type == winrt::name_of<wuxh::DesktopWindowXamlSource>()) |
| 30 | { |
| 31 | // we cannot check if the source contains a taskbar here, |
| 32 | // because when a new taskbar gets added the source gets created |
| 33 | // without containing anything initially. save the source to a set |
| 34 | // of handles so we can later match it against the added TaskbarFrame. |
| 35 | m_NonMatchingXamlSources.insert(element.Handle); |
| 36 | } |
| 37 | else if (type == L"Taskbar.TaskbarFrame") |
| 38 | { |
| 39 | // assume it goes DesktopWindowXamlSource -> RootGrid -> TaskbarFrame. |
| 40 | // we need RootGrid's pointer to find the right source based on its contents. |
| 41 | const auto rootGrid = FromHandle<wux::UIElement>(relation.Parent); |
| 42 | |
| 43 | for (auto it = m_NonMatchingXamlSources.begin(); it != m_NonMatchingXamlSources.end(); ++it) |
| 44 | { |
| 45 | const auto xamlSource = FromHandle<wuxh::DesktopWindowXamlSource>(*it); |
| 46 | wux::UIElement content = nullptr; |
| 47 | try |
| 48 | { |
| 49 | content = xamlSource.Content(); |
| 50 | } |
| 51 | catch (const winrt::hresult_wrong_thread&) |
| 52 | { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | if (content == rootGrid) |
| 57 | { |
| 58 | const auto nativeSource = xamlSource.as<IDesktopWindowXamlSourceNative>(); |
| 59 | |
| 60 | HWND hwnd = nullptr; |
| 61 | winrt::check_hresult(nativeSource->get_WindowHandle(&hwnd)); |
| 62 | |
| 63 | m_AppearanceService->RegisterTaskbar(element.Handle, hwnd); |
| 64 | m_NonMatchingXamlSources.erase(it); |
| 65 | |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | else if (type == winrt::name_of<wux::Shapes::Rectangle>()) |
| 71 | { |
| 72 | const std::wstring_view name { element.Name, SysStringLen(element.Name) }; |
| 73 | const auto backgroundFill = name == L"BackgroundFill"; |
| 74 | const auto backgroundStroke = name == L"BackgroundStroke"; |
| 75 | if (backgroundFill || backgroundStroke) |
| 76 | { |
| 77 | if (const auto frame = FindParent(L"TaskbarFrame", FromHandle<wux::FrameworkElement>(relation.Parent))) |
| 78 | { |
| 79 | InstanceHandle handle = 0; |
nothing calls this directly
no test coverage detected