[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / CiderStandardCategoryLayout.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing 
5 {
6     using System.Diagnostics.CodeAnalysis;
7     using System.Windows;
8
9     using System.Activities.Presentation.PropertyEditing;
10
11     using Blend = System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector;
12     using System.Activities.Presentation.Internal.PropertyEditing.Selection;
13     using System.Activities.Presentation.Internal.PropertyEditing.State;
14
15     // <summary>
16     // Container for PropertyContainers - fancy wrapper for ItemsControl that eliminates the need
17     // for intermediate ContentControls.
18     //
19     // This class is referenced from XAML
20     // </summary>
21     [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
22     internal class CiderStandardCategoryLayout : Blend.StandardCategoryLayout 
23     {
24
25         protected override void PrepareContainerForItemOverride(DependencyObject element, object item) 
26         {
27             base.PrepareContainerForItemOverride(element, item);
28
29             if (element != null) 
30             {
31                 PropertyEntry property = ((PropertyContainer)element).PropertyEntry;
32
33                 if (property != null) 
34                 {
35                     // Make each PropertyContainer its own selection stop
36                     PropertySelection.SetSelectionStop(element, new PropertySelectionStop(property));
37                 }
38
39                 PropertyContainer container = element as PropertyContainer;
40                 if (container != null)
41                 {
42                     container.Loaded += new RoutedEventHandler(OnPropertyContainerLoaded);
43                 }
44             }
45         }
46
47         private void OnPropertyContainerLoaded(object sender, RoutedEventArgs e) 
48         {
49             PropertyContainer container = sender as PropertyContainer;
50             if (container != null) 
51             {
52
53                 // When each PropertyContainer gets loaded, restore its ActiveEditMode
54                 // based on stored state
55                 //
56                 container.ActiveEditMode = PropertyActiveEditModeStateContainer.Instance.GetActiveEditMode(container.PropertyEntry);
57
58                 // HACK: Here, we would want to hook into the ActiveEditModeChanged
59                 // event to store (and restore) the correct expaded state to each
60                 // value editor across domain reloads.  However, we already shipped
61                 // System.Activities.Presentation.dll which contains the PropertyContainer
62                 // class and it's dangerous to add new events to this assembly at this
63                 // point.  Once we refactor MWD, we need to add this new event and
64                 // simplify this code.  In the meanwhile, we can cheat and accomplish
65                 // the same effect by listening to SizeChanged event, which _will_
66                 // change when the expanded value editor is pinned down.  It will also
67                 // change at other times (user-triggered resize events, etc.), but
68                 // it shouldn't cause any noticeable perf degradation.
69                 //
70                 container.SizeChanged += new SizeChangedEventHandler(OnPropertyContainerSizeChanged);
71                 container.Unloaded += new RoutedEventHandler(OnPropertyContainerUnloaded);
72             }
73         }
74
75         // When the size of each PropertyContainer changes, assume that ActiveEditMode
76         // may have been changed and record its current state
77         //
78         private void OnPropertyContainerSizeChanged(object sender, SizeChangedEventArgs e) 
79         {
80             PropertyContainer container = sender as PropertyContainer;
81             if (container != null && container.IsLoaded)
82             {
83                 PropertyActiveEditModeStateContainer.Instance.StoreActiveEditMode(container.PropertyEntry, container.ActiveEditMode);
84             }
85         }
86
87         // When each PropertyContainer gets unloaded, stop listening to all events so
88         // that it can be garbage collected
89         //
90         private void OnPropertyContainerUnloaded(object sender, RoutedEventArgs e) 
91         {
92             PropertyContainer container = sender as PropertyContainer;
93
94             if (container != null) 
95             {
96                 container.SizeChanged -= new SizeChangedEventHandler(OnPropertyContainerSizeChanged);
97                 container.Loaded -= new RoutedEventHandler(OnPropertyContainerLoaded);
98                 container.Unloaded -= new RoutedEventHandler(OnPropertyContainerUnloaded);
99             }
100         }
101     }
102 }