Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / FromExpression / Framework / PropertyInspector / PropertyContainerPopupHelper.cs
1 // -------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
3 // -------------------------------------------------------------------
4 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework\Properties
5 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector
6 {
7     using System;
8     using System.Collections.Generic;
9     using System.Text;
10     using System.Windows;
11     using System.Windows.Controls.Primitives;
12     using System.Windows.Input;
13     using System.Windows.Media;
14     using System.Activities.Presentation.PropertyEditing;
15     using System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.Controls;
16
17     // <summary>
18     // Acrylic needs a way of knowing when we begin and end extended edit mode,
19     // so this class fires commands when those two events take place.
20     // </summary>
21     internal class PropertyContainerPopup : WorkaroundPopup
22     {
23         // these events allow Acrylic to implement its workaround for Avalon/MFC interop
24         // focus issues (WinOS bug # 1713206)
25         public static readonly RoutedCommand OnBeginExtendedEdit = new RoutedCommand("OnBeginExtendedEdit", typeof(PropertyContainerPopup));
26         public static readonly RoutedCommand OnEndExtendedEdit = new RoutedCommand("OnEndExtendedEdit", typeof(PropertyContainerPopup));
27
28         public static CustomPopupPlacementCallback RightAlignedPopupPlacement
29         {
30             get { return new CustomPopupPlacementCallback(PropertyContainerPopup.RightAlignedPopupPlacementCallback); }
31         }
32
33         protected override void OnOpened(EventArgs e)
34         {
35             // Fire OnBeginExtendedEdit command (for Acrylic)
36             PropertyContainer owningPropertyContainer = (PropertyContainer)this.GetValue(PropertyContainer.OwningPropertyContainerProperty);
37             PropertyContainerPopup.OnBeginExtendedEdit.Execute(this, owningPropertyContainer);
38
39             base.OnOpened(e);
40         }
41
42         protected override void OnClosed(EventArgs e)
43         {
44             base.OnClosed(e);
45
46             PropertyContainer owningPropertyContainer = (PropertyContainer)this.GetValue(PropertyContainer.OwningPropertyContainerProperty);
47
48             // Revert back to Inline when the popup is dismissed and we haven't already switched
49             // to the pinned mode
50             if (owningPropertyContainer != null && owningPropertyContainer.ActiveEditMode == PropertyContainerEditMode.ExtendedPopup)
51             {
52                 DependencyObject potentialDescendant = Mouse.Captured as DependencyObject;
53                 if (potentialDescendant != null && owningPropertyContainer.IsAncestorOf(potentialDescendant))
54                 {
55                     // v1 38479: This is a mitigation for Windows OS Bug 1965872.
56                     // Here we force any control which has capture to lose it, though
57                     // this situation can occur in other cases (e.g. via extensibility) but this covers the most
58                     // common cases and is a safe fix.
59                     Mouse.Capture(null);
60                 }
61
62                 owningPropertyContainer.ActiveEditMode = PropertyContainerEditMode.Inline;
63             }
64
65             // Fire OnEndExtendedEdit command (for Acrylic)
66             OnEndExtendedEdit.Execute(this, owningPropertyContainer);
67         }
68
69         public static CustomPopupPlacement[] RightAlignedPopupPlacementCallback(Size popupSize, Size targetSize, Point offset)
70         {
71             return new CustomPopupPlacement[] { new CustomPopupPlacement(new Point(targetSize.Width - popupSize.Width, targetSize.Height), PopupPrimaryAxis.Horizontal) };
72         }
73     }
74 }