[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Annotations / FloatingAnnotationView.xaml.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace System.Activities.Presentation.Annotations
8 {
9     using System.Activities.Presentation.Model;
10     using System.ComponentModel;
11     using System.Windows;
12     using System.Windows.Controls;
13     using System.Windows.Data;
14     using System.Windows.Input;
15
16     internal sealed partial class FloatingAnnotationView : UserControl, IFloatingAnnotation
17     {
18         public static readonly DependencyProperty ModelItemProperty = DependencyProperty.Register("ModelItem", typeof(ModelItem), typeof(FloatingAnnotationView));
19
20         public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(FloatingAnnotationView));
21
22         private bool focusOnLoad;
23
24         public FloatingAnnotationView()
25         {
26             this.InitializeComponent();
27             this.Loaded += new RoutedEventHandler(this.OnFloatingAnnotationViewLoaded);
28         }
29
30         public event Action DockButtonClicked;
31
32         public event EventHandler IsMouseOverChanged
33         {
34             add
35             {
36                 DependencyPropertyDescriptor descriptor = DependencyPropertyDescriptor.FromProperty(UIElement.IsMouseOverProperty, typeof(UIElement));
37                 descriptor.AddValueChanged(this, value);
38             }
39
40             remove
41             {
42                 DependencyPropertyDescriptor descriptor = DependencyPropertyDescriptor.FromProperty(UIElement.IsMouseOverProperty, typeof(UIElement));
43                 descriptor.RemoveValueChanged(this, value);
44             }
45         }
46
47         public bool IsReadOnly
48         {
49             get { return (bool)GetValue(IsReadOnlyProperty); }
50             set { SetValue(IsReadOnlyProperty, value); }
51         }
52
53         public ModelItem ModelItem
54         {
55             get { return (ModelItem)GetValue(ModelItemProperty); }
56             set { SetValue(ModelItemProperty, value); }
57         }
58
59         public void FocusOnContent()
60         {
61             if (this.annotationTextBox.Focus() != true)
62             {
63                 this.focusOnLoad = true;
64             }
65         }
66
67         public void UpdateModelItem()
68         {
69             BindingExpression be = this.annotationTextBox.GetBindingExpression(TextBox.TextProperty);
70             be.UpdateSource();
71         }
72
73         protected override void OnContextMenuOpening(ContextMenuEventArgs e)
74         {
75             e.Handled = true;
76         }
77
78         private void OnFloatingAnnotationViewLoaded(object sender, RoutedEventArgs e)
79         {
80             if (this.focusOnLoad)
81             {
82                 Keyboard.Focus(this.annotationTextBox);
83                 this.focusOnLoad = false;
84             }
85         }
86
87         private void OnDockButtonClicked(object sender, RoutedEventArgs e)
88         {
89             if (this.DockButtonClicked != null)
90             {
91                 this.DockButtonClicked();
92             }
93         }
94     }
95 }