246441484527d0aaace3b010d521354b43896569
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Expressions / ExpressionActivityEditor.cs
1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4
5 namespace System.Activities.Presentation.Expressions
6 {
7     using System;
8     using System.Collections.Generic;
9     using System.Linq;
10     using System.Text;
11     using System.Windows.Controls;
12     using System.Activities.Presentation.Model;
13     using System.Windows;
14     using System.Runtime;
15     using System.Windows.Automation.Peers;
16     using System.Diagnostics.CodeAnalysis;
17     using System.Xaml;
18     using System.Globalization;
19
20     public abstract class ExpressionActivityEditor : UserControl
21     {
22         public static readonly DependencyProperty HintTextProperty = DependencyProperty.Register("HintText", typeof(string), typeof(ExpressionActivityEditor));
23
24         public static readonly DependencyProperty ExpressionProperty = DependencyProperty.Register("Expression", typeof(ModelItem), typeof(ExpressionActivityEditor),
25                 new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
26
27         public static readonly DependencyProperty ExpressionTypeProperty = DependencyProperty.Register("ExpressionType", typeof(Type), typeof(ExpressionActivityEditor),
28                 new FrameworkPropertyMetadata(null));
29
30         public static readonly DependencyProperty OwnerActivityProperty = DependencyProperty.Register("OwnerActivity", typeof(ModelItem), typeof(ExpressionActivityEditor),
31                 new FrameworkPropertyMetadata(null));
32
33         public static readonly DependencyProperty UseLocationExpressionProperty = DependencyProperty.Register("UseLocationExpression", typeof(bool), typeof(ExpressionActivityEditor),
34                 new FrameworkPropertyMetadata(false));
35
36         public static readonly DependencyProperty PathToArgumentProperty = DependencyProperty.Register("PathToArgument", typeof(string), typeof(ExpressionActivityEditor),
37                 new FrameworkPropertyMetadata(null));
38
39         public static readonly DependencyProperty IsSupportedExpressionProperty = DependencyProperty.Register("IsSupportedExpression", typeof(bool), typeof(ExpressionActivityEditor),
40                 new FrameworkPropertyMetadata(true));
41
42         public static readonly DependencyProperty VerticalScrollBarVisibilityProperty = DependencyProperty.Register("VerticalScrollBarVisibility", typeof(ScrollBarVisibility), typeof(ExpressionActivityEditor),
43                 new FrameworkPropertyMetadata(ScrollBarVisibility.Hidden));
44
45         public static readonly DependencyProperty HorizontalScrollBarVisibilityProperty = DependencyProperty.Register("HorizontalScrollBarVisibility", typeof(ScrollBarVisibility), typeof(ExpressionActivityEditor),
46                 new FrameworkPropertyMetadata(ScrollBarVisibility.Hidden));
47
48         public static readonly DependencyProperty ExplicitCommitProperty = DependencyProperty.Register("ExplicitCommit", typeof(bool), typeof(ExpressionActivityEditor),
49                 new FrameworkPropertyMetadata(false));
50
51         public static readonly DependencyProperty AcceptsReturnProperty = DependencyProperty.Register("AcceptsReturn", typeof(bool), typeof(ExpressionActivityEditor),
52                 new FrameworkPropertyMetadata(true));
53
54         public static readonly DependencyProperty AcceptsTabProperty = DependencyProperty.Register("AcceptsTab", typeof(bool), typeof(ExpressionActivityEditor),
55                 new FrameworkPropertyMetadata(false));
56
57         public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(ExpressionActivityEditor),
58                 new FrameworkPropertyMetadata(false));
59
60         public static readonly DependencyProperty IsIndependentExpressionProperty = DependencyProperty.Register("IsIndependentExpression", typeof(bool), typeof(ExpressionActivityEditor),
61                 new FrameworkPropertyMetadata(false));
62
63         public string HintText
64         {
65             get { return (string)GetValue(HintTextProperty); }
66             set { SetValue(HintTextProperty, value); }
67         }
68
69         [Fx.Tag.KnownXamlExternal]
70         public ModelItem Expression
71         {
72             get { return (ModelItem)GetValue(ExpressionProperty); }
73             set { SetValue(ExpressionProperty, value); }
74         }
75
76         public Type ExpressionType
77         {
78             get { return (Type)GetValue(ExpressionTypeProperty); }
79             set { SetValue(ExpressionTypeProperty, value); }
80         }
81
82         public bool UseLocationExpression
83         {
84             get { return (bool)GetValue(UseLocationExpressionProperty); }
85             set { SetValue(UseLocationExpressionProperty, value); }
86         }
87
88         public bool IsIndependentExpression
89         {
90             get { return (bool)GetValue(IsIndependentExpressionProperty); }
91             set { SetValue(IsIndependentExpressionProperty, value); }
92         }
93
94         [Fx.Tag.KnownXamlExternal]
95         public ModelItem OwnerActivity
96         {
97             get { return (ModelItem)GetValue(OwnerActivityProperty); }
98             set { SetValue(OwnerActivityProperty, value); }
99         }
100
101         public string PathToArgument
102         {
103             get { return (string)GetValue(PathToArgumentProperty); }
104             set { SetValue(PathToArgumentProperty, value); }
105         }
106
107         public bool IsSupportedExpression
108         {
109             get { return (bool)GetValue(IsSupportedExpressionProperty); }
110             set { SetValue(IsSupportedExpressionProperty, value); }
111         }
112
113         public bool AcceptsReturn
114         {
115             get { return (bool)GetValue(AcceptsReturnProperty); }
116             set { SetValue(AcceptsReturnProperty, value); }
117         }
118
119         public bool AcceptsTab
120         {
121             get { return (bool)GetValue(AcceptsTabProperty); }
122             set { SetValue(AcceptsTabProperty, value); }
123         }
124
125         public bool IsReadOnly
126         {
127             get { return (bool)GetValue(IsReadOnlyProperty); }
128             set { SetValue(IsReadOnlyProperty, value); }
129         }
130
131         public ScrollBarVisibility VerticalScrollBarVisibility
132         {
133             get { return (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty); }
134             set { SetValue(VerticalScrollBarVisibilityProperty, value); }
135         }
136
137         public ScrollBarVisibility HorizontalScrollBarVisibility
138         {
139             get { return (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty); }
140             set { SetValue(HorizontalScrollBarVisibilityProperty, value); }
141         }
142
143         public bool ExplicitCommit
144         {
145             get { return (bool)GetValue(ExplicitCommitProperty); }
146             set { SetValue(ExplicitCommitProperty, value); }
147         }
148
149         static AttachableMemberIdentifier editorPropertyID = new AttachableMemberIdentifier(typeof(ExpressionActivityEditor), "ExpressionActivityEditor");
150
151         public static void SetExpressionActivityEditor(object target, string name)
152         {
153             ValidateExpressionActivityEditorName(name);
154             AttachablePropertyServices.SetProperty(target, editorPropertyID, name);
155         }
156
157         public static string GetExpressionActivityEditor(object target)
158         {
159             string value;
160             return AttachablePropertyServices.TryGetProperty(target, editorPropertyID, out value) ? value : null;
161         }
162
163         internal static void ValidateExpressionActivityEditorName(string name)
164         {
165             if (name != null && name.Trim().Length == 0)
166             {
167                 throw FxTrace.Exception.AsError(new ArgumentException(string.Format(CultureInfo.CurrentUICulture, SR.InvalidExpressionEditorNameToSet,
168                     name)));
169             }
170         }
171
172         internal string ItemStatus
173         {
174             get
175             {
176                 return this.OnCreateAutomationPeer().GetItemStatus();
177             }
178         }
179
180         protected EditingContext Context
181         {
182             get
183             {
184                 if (this.OwnerActivity != null)
185                 {
186                     return this.OwnerActivity.GetEditingContext();
187                 }
188                 else
189                 {
190                     return null;
191                 }
192             }
193         }
194
195         protected ExpressionActivityEditor()
196         { }
197         
198         public virtual void BeginEdit() { }
199         public virtual bool CanCommit() { return true; }
200         public abstract bool Commit(bool isExplicitCommit);
201     }
202 }