[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / WorkflowElementDialog.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation
5 {
6     using System.Windows;
7     using System.Windows.Controls;
8     using System.Activities.Presentation.Model;
9     using System.Activities.Presentation.Hosting;
10     using System.Runtime;
11
12     [Fx.Tag.XamlVisible(false)]
13     public class WorkflowElementDialog : ContentControl
14     {
15         public static readonly DependencyProperty ModelItemProperty =
16             DependencyProperty.Register("ModelItem",
17             typeof(ModelItem),
18             typeof(WorkflowElementDialog),
19             new PropertyMetadata(OnModelItemChanged));
20
21         public static readonly DependencyProperty TitleProperty =
22             DependencyProperty.Register("Title",
23             typeof(string),
24             typeof(WorkflowElementDialog));
25
26         public static readonly DependencyProperty ContextProperty =
27             DependencyProperty.Register("Context",
28             typeof(EditingContext),
29             typeof(WorkflowElementDialog));
30
31         public static readonly DependencyProperty WindowResizeModeProperty =
32             DependencyProperty.Register("WindowResizeMode", 
33             typeof(ResizeMode), 
34             typeof(WorkflowElementDialog),
35             new UIPropertyMetadata(ResizeMode.CanResize));
36
37         public static readonly DependencyProperty WindowSizeToContentProperty =
38             DependencyProperty.Register("WindowSizeToContent", 
39             typeof(SizeToContent),
40             typeof(WorkflowElementDialog), 
41             new UIPropertyMetadata(SizeToContent.WidthAndHeight));
42
43         protected WorkflowElementDialog()
44         {
45         }
46
47         public ModelItem ModelItem
48         {
49             get { return (ModelItem)GetValue(ModelItemProperty); }
50             set { SetValue(ModelItemProperty, value); }
51         }
52
53         public string Title
54         {
55             get { return (string)GetValue(TitleProperty); }
56             set { SetValue(TitleProperty, value); }
57         }
58
59         public EditingContext Context
60         {
61             get { return (EditingContext)GetValue(ContextProperty); }
62             set { SetValue(ContextProperty, value); }
63         }
64
65         public DependencyObject Owner
66         {
67             get;
68             set;
69         }
70
71         public ResizeMode WindowResizeMode
72         {
73             get { return (ResizeMode)GetValue(WindowResizeModeProperty); }
74             set { SetValue(WindowResizeModeProperty, value); }
75         }
76
77         public SizeToContent WindowSizeToContent
78         {
79             get { return (SizeToContent)GetValue(WindowSizeToContentProperty); }
80             set { SetValue(WindowSizeToContentProperty, value); }
81         }
82
83         public bool EnableMinimizeButton
84         {
85             get;
86             set;
87         }
88
89         public bool EnableMaximizeButton
90         {
91             get;
92             set;
93         }
94
95         public string HelpKeyword
96         {
97             get;
98             set;
99         }
100
101         internal Func<bool> OnOk
102         {
103             get;
104             set;
105         }
106
107         public void Show()
108         {
109             Show(false);
110         }
111
112         public bool ShowOkCancel()
113         {
114             bool? result = Show(true);
115             return result.HasValue && result.Value;
116         }
117
118         internal void CloseDialog(bool commitChanges)
119         {
120             this.Window.DialogResult = commitChanges;
121         }
122
123         internal WorkflowElementDialogWindow Window
124         {
125             get;
126             set;
127         }
128
129         bool? Show(bool okCancel)
130         {
131             WorkflowElementDialogWindow wnd = new WorkflowElementDialogWindow(this, okCancel, this.EnableMinimizeButton, this.EnableMaximizeButton, this.OnOk) 
132             { 
133                 Title = this.Title 
134             };
135             if (null != this.Context)
136             {
137                 WindowHelperService srv = this.Context.Services.GetService<WindowHelperService>();
138                 if (null != srv)
139                 {
140                     srv.TrySetWindowOwner(this.Owner, wnd);
141                 }
142             }
143             wnd.Closed += (s, e) => { this.OnWorkflowElementDialogClosed(((Window)s).DialogResult); };
144             return wnd.ShowDialog();
145         }
146
147         protected override void OnInitialized(EventArgs e)
148         {
149             base.OnInitialized(e);
150             // This is necessary for WPF data bindings to work.
151             // It needs to be done explicitly, probably because
152             // this ContentControl doesn't define its own 
153             // Template.VisualTree (maybe it should).
154             this.DataContext = this;
155         }
156
157         protected void EnableOk(bool enabled)
158         {
159             if (this.Window != null)
160             {
161                 this.Window.okButton.IsEnabled = enabled;
162             }
163         }
164
165         protected virtual void OnModelItemChanged(object newItem)
166         {
167         }
168
169         protected virtual void OnWorkflowElementDialogClosed(bool? dialogResult)
170         {
171         }
172
173         static void OnModelItemChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
174         {
175             WorkflowElementDialog dialog = (WorkflowElementDialog)dependencyObject;
176             dialog.OnModelItemChanged(e.NewValue);
177         }
178     }
179 }