View | Details | Raw Unified | Return to bug 494034
Collapse All | Expand All

(-)a/UIAutomationWinforms/UIAutomationWinforms/Makefile.am (-1 / +1 lines)
Lines 296-303 FILES = \ Link Here
296
	Mono.UIAutomation.Winforms.Events/DateTimePicker/AutomationNamePropertyEvent.cs \
296
	Mono.UIAutomation.Winforms.Events/DateTimePicker/AutomationNamePropertyEvent.cs \
297
	Mono.UIAutomation.Winforms.Events/DateTimePicker/ButtonInvokePatternInvokedEvent.cs \
297
	Mono.UIAutomation.Winforms.Events/DateTimePicker/ButtonInvokePatternInvokedEvent.cs \
298
	Mono.UIAutomation.Winforms.Events/DateTimePicker/CheckboxAutomationHasKeyboardFocusPropertyEvent.cs \
298
	Mono.UIAutomation.Winforms.Events/DateTimePicker/CheckboxAutomationHasKeyboardFocusPropertyEvent.cs \
299
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartAutomationIsEnabledPropertyEvent.cs \
300
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartAutomationHasKeyboardFocusPropertyEvent.cs \
299
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartAutomationHasKeyboardFocusPropertyEvent.cs \
300
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartAutomationIsEnabledPropertyEvent.cs \
301
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartListItemAutomationHasKeyboardFocusPropertyEvent.cs \
301
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartListItemAutomationHasKeyboardFocusPropertyEvent.cs \
302
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartListItemSelectionItemPatternElementSelectedEvent.cs \
302
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartListItemSelectionItemPatternElementSelectedEvent.cs \
303
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartListItemSelectionItemPatternIsSelectedEvent.cs \
303
	Mono.UIAutomation.Winforms.Events/DateTimePicker/PartListItemSelectionItemPatternIsSelectedEvent.cs \
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/BalloonWindow/EmbeddedImageProviderBehavior.cs (-3 / +5 lines)
Lines 66-76 namespace Mono.UIAutomation.Winforms.Behaviors.BalloonWindow Link Here
66
			get {
66
			get {
67
				// from ThemeWin32Classic.cs
67
				// from ThemeWin32Classic.cs
68
				int borderSize = 8;
68
				int borderSize = 8;
69
				int iconSize = (balloonWindow.Icon == SWF.ToolTipIcon.None) ? 0 : 16;
69
				int iconSize = 0;
70
				if (balloonWindow.InvokeSync (c => !(c.Icon == SWF.ToolTipIcon.None)))
71
					iconSize = 16;
70
				if (iconSize == 0)
72
				if (iconSize == 0)
71
					return Rect.Empty;
73
					return Rect.Empty;
72
				int imageX, imageY, imageWidth, imageHeight;
74
				int imageX, imageY, imageWidth, imageHeight;
73
75
	
74
				Rect balloonRect 
76
				Rect balloonRect 
75
					= (Rect) Provider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
77
					= (Rect) Provider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
76
			
78
			
Lines 78-84 namespace Mono.UIAutomation.Winforms.Behaviors.BalloonWindow Link Here
78
				imageY = (int) balloonRect.Y + borderSize;
80
				imageY = (int) balloonRect.Y + borderSize;
79
				imageWidth = iconSize;
81
				imageWidth = iconSize;
80
				imageHeight = iconSize;
82
				imageHeight = iconSize;
81
83
	
82
				Rect imageRect = new Rect (imageX, imageY, imageWidth, imageHeight);
84
				Rect imageRect = new Rect (imageX, imageY, imageWidth, imageHeight);
83
				balloonRect.Intersect (imageRect);
85
				balloonRect.Intersect (imageRect);
84
				return balloonRect;
86
				return balloonRect;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/BaseColorControl/SmallColorControlInvokeProviderBehavior.cs (-26 / +14 lines)
Lines 71-108 namespace Mono.UIAutomation.Winforms.Behaviors.BaseColorControl Link Here
71
		
71
		
72
		public virtual void Invoke ()
72
		public virtual void Invoke ()
73
		{
73
		{
74
			if (!Provider.Control.Enabled)
74
			if (Provider.Control.InvokeSync (e => !e.Enabled))
75
				throw new ElementNotEnabledException ();
75
				throw new ElementNotEnabledException ();
76
76
77
			PerformClick ();
77
			Provider.Control.InvokeSync (delegate {
78
			// TODO: Use internal property when backport
79
//				ColorDialog.BaseColorControl.SmallColorControl selected =
80
//					((ColorDialog.BaseColorControl) baseColorControl).UIASelectedSmallColorControl;
81
				try {
82
					ColorDialog.BaseColorControl.SmallColorControl selected =
83
						Helper.GetPrivateProperty<ColorDialog.BaseColorControl, ColorDialog.BaseColorControl.SmallColorControl>
84
							((ColorDialog.BaseColorControl) baseColorControl, "UIASelectedSmallColorControl");
85
					if (selected != null)
86
						selected.IsSelected = false;
87
				} catch (NotSupportedException) { }
88
				smallColorControl.IsSelected = true;
89
			});
78
		}
90
		}
79
		
91
		
80
		#endregion	
92
		#endregion	
81
		
93
		
82
		#region Private Methods
83
		
84
		private void PerformClick ()
85
		{
86
			if (Provider.Control.InvokeRequired == true) {
87
				Provider.Control.BeginInvoke (new MethodInvoker (PerformClick));
88
				return;
89
			}
90
91
			// TODO: Use internal property when backport
92
//			ColorDialog.BaseColorControl.SmallColorControl selected =
93
//				((ColorDialog.BaseColorControl) baseColorControl).UIASelectedSmallColorControl;
94
			try {
95
				ColorDialog.BaseColorControl.SmallColorControl selected =
96
					Helper.GetPrivateProperty<ColorDialog.BaseColorControl, ColorDialog.BaseColorControl.SmallColorControl>
97
						((ColorDialog.BaseColorControl) baseColorControl, "UIASelectedSmallColorControl");
98
				if (selected != null)
99
					selected.IsSelected = false;
100
			} catch (NotSupportedException) { }
101
			smallColorControl.IsSelected = true;
102
		}
103
		
104
		#endregion
105
106
		#region Private Field
94
		#region Private Field
107
95
108
		ColorDialog.BaseColorControl.SmallColorControl smallColorControl;
96
		ColorDialog.BaseColorControl.SmallColorControl smallColorControl;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/Button/InvokeProviderBehavior.cs (-15 / +2 lines)
Lines 90-112 namespace Mono.UIAutomation.Winforms.Behaviors.Button Link Here
90
		
90
		
91
		public virtual void Invoke ()
91
		public virtual void Invoke ()
92
		{
92
		{
93
			if (Provider.Control.Enabled == false)
93
			if (button.InvokeSync (c => !c.Enabled))
94
				throw new ElementNotEnabledException ();
94
				throw new ElementNotEnabledException ();
95
95
96
			PerformClick ();
96
			button.InvokeSync (delegate { button.PerformClick (); });
97
		}
98
		
99
		#endregion	
100
		
101
		#region Private Methods
102
		
103
		private void PerformClick ()
104
		{
105
			if (Provider.Control.InvokeRequired == true) {
106
				Provider.Control.BeginInvoke (new SWF.MethodInvoker (PerformClick));
107
				return;
108
			}
109
			button.PerformClick ();
110
		}
97
		}
111
		
98
		
112
		#endregion
99
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/CheckBox/ToggleProviderBehavior.cs (-16 / +12 lines)
Lines 87-112 namespace Mono.UIAutomation.Winforms.Behaviors.CheckBox Link Here
87
	
87
	
88
		public void Toggle ()
88
		public void Toggle ()
89
		{
89
		{
90
			if (checkbox.Enabled == false)
90
			if (checkbox.InvokeSync (c => !c.Enabled))
91
				throw new ElementNotEnabledException ();
91
				throw new ElementNotEnabledException ();
92
92
93
			switch (checkbox.CheckState) {
93
			SWF.CheckState newState = SWF.CheckState.Checked;
94
95
			switch (checkbox.InvokeSync (c => c.CheckState)) {
94
			case SWF.CheckState.Checked:
96
			case SWF.CheckState.Checked:
95
				PerformToggle (checkbox, SWF.CheckState.Unchecked);
97
				newState = SWF.CheckState.Unchecked;
96
				break;
98
				break;
97
			case SWF.CheckState.Unchecked:
99
			case SWF.CheckState.Unchecked:
98
				if (checkbox.ThreeState)
100
				if (checkbox.InvokeSync (c => c.ThreeState))
99
					PerformToggle (checkbox, SWF.CheckState.Indeterminate);
101
					newState = SWF.CheckState.Indeterminate;
100
				else
102
				else
101
					PerformToggle (checkbox, SWF.CheckState.Checked);
103
					newState = SWF.CheckState.Checked;
102
				break;
104
				break;
103
			// Control could still have been set to intermediate
105
			// Control could still have been set to intermediate
104
			// programatically, regardless of ThreeState value.
106
			// programatically, regardless of ThreeState value.
105
			case SWF.CheckState.Indeterminate:
107
			case SWF.CheckState.Indeterminate:
106
			default:
108
			default:
107
				PerformToggle (checkbox, SWF.CheckState.Checked);
109
				newState = SWF.CheckState.Checked;
108
				break;
110
				break;
109
			}
111
			}
112
113
			checkbox.InvokeSync (delegate { PerformToggle (newState); });
110
		}
114
		}
111
115
112
		public ToggleState ToggleState {
116
		public ToggleState ToggleState {
Lines 127-140 namespace Mono.UIAutomation.Winforms.Behaviors.CheckBox Link Here
127
		
131
		
128
		#region Private Methods
132
		#region Private Methods
129
		
133
		
130
		private void PerformToggle (SWF.CheckBox checkbox, SWF.CheckState state)
134
		private void PerformToggle (SWF.CheckState state)
131
		{
135
		{
132
			if (checkbox.InvokeRequired == true) {
133
				checkbox.BeginInvoke (new PerformToggleDelegate (PerformToggle),
134
				                      new object [] { checkbox, state });
135
				return;
136
			}
137
138
			// NOTE: We can count on presence of InvokeOnClick;
136
			// NOTE: We can count on presence of InvokeOnClick;
139
			//       it is a protected member of CheckBox.
137
			//       it is a protected member of CheckBox.
140
			//
138
			//
Lines 151-156 namespace Mono.UIAutomation.Winforms.Behaviors.CheckBox Link Here
151
		}
149
		}
152
		#endregion
150
		#endregion
153
	}
151
	}
154
	
155
	delegate void PerformToggleDelegate (SWF.CheckBox checkbox, SWF.CheckState state);
156
}
152
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ComboBox/ButtonInvokeBehavior.cs (-19 / +6 lines)
Lines 83-110 namespace Mono.UIAutomation.Winforms.Behaviors.ComboBox Link Here
83
		
83
		
84
		public void Invoke ()
84
		public void Invoke ()
85
		{
85
		{
86
			if (Provider.Control.Enabled == false)
86
			if (Provider.Control.InvokeSync (b => !b.Enabled))
87
				throw new ElementNotEnabledException ();
87
				throw new ElementNotEnabledException ();
88
			
89
			PerformComboBoxClick ((SWF.ComboBox) Provider.Control);
90
		}
91
		
92
		#endregion	
93
88
94
		#region Private Methods
89
			SWF.ComboBox combobox = (SWF.ComboBox) Provider.Control;
95
		
90
			combobox.InvokeSync (delegate {
96
		private void PerformComboBoxClick (SWF.ComboBox combobox)
91
				combobox.DroppedDown = !combobox.DroppedDown;
97
		{
92
			});
98
	        if (Provider.Control.InvokeRequired == true) {
99
	            Provider.Control.BeginInvoke (new PerformComboBoxClickDelegate (PerformComboBoxClick),
100
				                              new object [] { combobox });
101
	            return;
102
	        }
103
			combobox.DroppedDown = !combobox.DroppedDown;
104
		}
93
		}
105
		
94
		
106
		#endregion
95
		#endregion	
107
	}
96
	}
108
	
109
	delegate void PerformComboBoxClickDelegate (SWF.ComboBox combobox);
110
}
97
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ComboBox/ExpandCollapseProviderBehavior.cs (-23 / +18 lines)
Lines 79-122 namespace Mono.UIAutomation.Winforms.Behaviors.ComboBox Link Here
79
		
79
		
80
		public ExpandCollapseState ExpandCollapseState {
80
		public ExpandCollapseState ExpandCollapseState {
81
			get {
81
			get {
82
				return ((SWF.ComboBox) Provider.Control).DroppedDown ? ExpandCollapseState.Expanded 
82
				SWF.ComboBox combobox = (SWF.ComboBox) Provider.Control;
83
					: ExpandCollapseState.Collapsed;
83
				if (combobox.InvokeSync (c => c.DroppedDown))
84
					return ExpandCollapseState.Expanded;
85
				else
86
					return ExpandCollapseState.Collapsed;
84
			}
87
			}
85
		}
88
		}
86
89
87
		public void Collapse ()
90
		public void Collapse ()
88
		{
91
		{
89
			if (Provider.Control.Enabled == false)
92
			SWF.ComboBox combobox = (SWF.ComboBox) Provider.Control;
93
			
94
			if (combobox.InvokeSync (c => !c.Enabled))
90
				throw new ElementNotEnabledException ();
95
				throw new ElementNotEnabledException ();
91
			
96
			
92
			PerformExpandOrCollapse ((SWF.ComboBox) Provider.Control, false);
97
			combobox.InvokeSync (delegate {
98
				combobox.DroppedDown = false;
99
			});
93
		}
100
		}
94
101
95
		public void Expand ()
102
		public void Expand ()
96
		{
103
		{
97
			if (Provider.Control.Enabled == false)
104
			SWF.ComboBox combobox = (SWF.ComboBox) Provider.Control;
98
				throw new ElementNotEnabledException ();
99
			
105
			
100
			PerformExpandOrCollapse ((SWF.ComboBox) Provider.Control, true);
106
			if (combobox.InvokeSync (c => !c.Enabled))
101
		}
107
				throw new ElementNotEnabledException ();
102
108
103
		#endregion
109
			combobox.InvokeSync (delegate {
104
		
110
				combobox.DroppedDown = true;
105
		#region Private Methods
111
			});
106
		
107
		private void PerformExpandOrCollapse (SWF.ComboBox combobox, bool droppedDown)
108
		{
109
			if (combobox.InvokeRequired == true) {
110
				combobox.BeginInvoke (new PerformExpandOrCollapseDelegate (PerformExpandOrCollapse),
111
				                      new object [] { combobox, droppedDown } );
112
				return;
113
			}
114
			combobox.DroppedDown = droppedDown;
115
		}
112
		}
116
		
113
117
		#endregion
114
		#endregion
118
		
115
		
119
	}
116
	}
120
	
121
	delegate void PerformExpandOrCollapseDelegate (SWF.ComboBox combobox, bool droppedDown);
122
}
117
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ComboBox/ListBoxSelectionProviderBehavior.cs (-5 / +3 lines)
Lines 70-76 namespace Mono.UIAutomation.Winforms.Behaviors.ComboBox Link Here
70
		#region ISelectionProvider Members
70
		#region ISelectionProvider Members
71
71
72
		public override bool IsSelectionRequired {
72
		public override bool IsSelectionRequired {
73
			get { return ((SWF.ComboBox) provider.Control).SelectedIndex != -1; }
73
			get {
74
				return ((SWF.ComboBox) Provider.Control).InvokeSync (c => c.SelectedIndex != -1);
75
			}
74
		}
76
		}
75
		
77
		
76
		public override IRawElementProviderSimple[] GetSelection ()
78
		public override IRawElementProviderSimple[] GetSelection ()
Lines 79-89 namespace Mono.UIAutomation.Winforms.Behaviors.ComboBox Link Here
79
		}
81
		}
80
82
81
		#endregion
83
		#endregion
82
83
		#region Private Fields
84
		
84
		
85
		private ComboBoxProvider provider;
85
		private ComboBoxProvider provider;
86
		
87
		#endregion
88
	}
86
	}
89
}
87
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ComboBox/SelectionProviderBehavior.cs (-1 / +3 lines)
Lines 95-101 namespace Mono.UIAutomation.Winforms.Behaviors.ComboBox Link Here
95
		}
95
		}
96
96
97
		public virtual bool IsSelectionRequired {
97
		public virtual bool IsSelectionRequired {
98
			get { return ((SWF.ComboBox) Provider.Control).SelectedIndex != -1; }
98
			get {
99
				return ((SWF.ComboBox) Provider.Control).InvokeSync (c => c.SelectedIndex != -1);
100
			}
99
		}
101
		}
100
		
102
		
101
		public virtual IRawElementProviderSimple[] GetSelection ()
103
		public virtual IRawElementProviderSimple[] GetSelection ()
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ComboBox/ValueProviderBehavior.cs (-20 / +6 lines)
Lines 83-93 namespace Mono.UIAutomation.Winforms.Behaviors.ComboBox Link Here
83
		#region IValueProvider Interface
83
		#region IValueProvider Interface
84
		
84
		
85
		public bool IsReadOnly {
85
		public bool IsReadOnly {
86
			get { return Provider.Control.Enabled == false; }
86
			get { return Provider.Control.InvokeSync (c => !c.Enabled); }
87
		}
87
		}
88
88
89
		public string Value {
89
		public string Value {
90
			get { return Provider.Control.Text; }
90
			get { return Provider.Control.InvokeSync (c => c.Text); }
91
		}
91
		}
92
92
93
		public void SetValue (string value)
93
		public void SetValue (string value)
Lines 95-120 namespace Mono.UIAutomation.Winforms.Behaviors.ComboBox Link Here
95
			if (IsReadOnly == true)
95
			if (IsReadOnly == true)
96
				throw new ElementNotEnabledException ();
96
				throw new ElementNotEnabledException ();
97
97
98
			PerformSetValue (value);
98
			Provider.Control.InvokeSync (delegate {
99
				Provider.Control.Text = value;
100
			});
99
		}
101
		}
100
102
101
		#endregion
103
		#endregion
102
		
103
		#region Private Methods
104
		
105
		private void PerformSetValue (string value) 
106
		{
107
			if (Provider.Control.InvokeRequired == true) {
108
				Provider.Control.BeginInvoke (new ComboBoxSetValueDelegate (PerformSetValue),
109
				                              new object [] { value } );
110
				return;
111
			}
112
			
113
			Provider.Control.Text = value;
114
		}
115
		
116
		#endregion
117
	}
104
	}
118
	
105
119
	delegate void ComboBoxSetValueDelegate (string value);
120
}
106
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGrid/CustomInvokeProviderBehavior.cs (-5 / +7 lines)
Lines 67-79 namespace Mono.UIAutomation.Winforms.Behaviors.DataGrid Link Here
67
		
67
		
68
		public void Invoke ()
68
		public void Invoke ()
69
		{
69
		{
70
			if (!customProvider.DataGridProvider.Control.Enabled)
70
			if (customProvider.DataGridProvider.Control.InvokeSync (c => !c.Enabled))
71
				throw new ElementNotEnabledException ();
71
				throw new ElementNotEnabledException ();
72
72
73
			if (customProvider.DataGridProvider.DataGrid.IsExpanded (customProvider.Row))
73
			customProvider.DataGridProvider.DataGrid.InvokeSync (delegate {
74
				customProvider.DataGridProvider.DataGrid.Collapse (customProvider.Row);
74
				if (customProvider.DataGridProvider.DataGrid.IsExpanded (customProvider.Row))
75
			else
75
					customProvider.DataGridProvider.DataGrid.Collapse (customProvider.Row);
76
				customProvider.DataGridProvider.DataGrid.Expand (customProvider.Row);
76
				else
77
					customProvider.DataGridProvider.DataGrid.Expand (customProvider.Row);
78
			});
77
		}
79
		}
78
		
80
		
79
		#endregion	
81
		#endregion	
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGrid/DataItemEditValueProviderBehavior.cs (-25 / +10 lines)
Lines 84-94 namespace Mono.UIAutomation.Winforms.Behaviors.DataGrid Link Here
84
			// words an editable style doesn't necessarily mean that you can 
84
			// words an editable style doesn't necessarily mean that you can 
85
			// set the value. In Vista Wwhen the cell is not editable and you call
85
			// set the value. In Vista Wwhen the cell is not editable and you call
86
			// SetValue it will throw an exception so, we are swallowing all the exceptions.
86
			// SetValue it will throw an exception so, we are swallowing all the exceptions.
87
			PerformSetValue (value);
87
88
			provider.ItemProvider.Control.InvokeSync (delegate {
89
	 			try {
90
					provider.ItemProvider.SetEditValue (provider, value);
91
				} catch (Exception e) {
92
					// DataSource may throw any exception.
93
					Log.Warn ("{0}: Caught exception:\n{1}", this.GetType (), e);
94
				}
95
			});
88
		}
96
		}
89
		
97
		
90
		public bool IsReadOnly {
98
		public bool IsReadOnly {
91
			get { return provider.Column.ReadOnly; }
99
			get { return false; }
92
		}
100
		}
93
		
101
		
94
		public string Value {
102
		public string Value {
Lines 99-127 namespace Mono.UIAutomation.Winforms.Behaviors.DataGrid Link Here
99
107
100
		#region Private Methods
108
		#region Private Methods
101
109
102
		private void PerformSetValue (string value)
103
		{
104
			if (IsReadOnly)
105
				throw new ElementNotEnabledException ();
106
107
			if (provider.ItemProvider.Control.InvokeRequired) {
108
				provider.ItemProvider.Control.BeginInvoke (new DataItemSetValueDelegate (PerformSetValue),
109
				                                           new object [] { value } );
110
				return;
111
			}
112
			
113
		 	try {
114
				provider.ItemProvider.SetEditValue (provider, value);
115
			} catch (Exception e) {
116
				// DataSource may throw any exception.
117
				Log.Warn ("{0}: Caught exception:\n{1}", this.GetType (), e);
118
			}
119
		}
120
121
		#endregion
122
123
		#region Private Methods
124
125
		private DataGridProvider.DataGridDataItemEditProvider provider;
110
		private DataGridProvider.DataGridDataItemEditProvider provider;
126
		
111
		
127
		#endregion
112
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGrid/DataItemValueProviderBehavior.cs (-20 / +8 lines)
Lines 88-94 namespace Mono.UIAutomation.Winforms.Behaviors.DataGrid Link Here
88
			// words an editable style doesn't necessarily mean that you can 
88
			// words an editable style doesn't necessarily mean that you can 
89
			// set the value. In Vista Wwhen the cell is not editable and you call
89
			// set the value. In Vista Wwhen the cell is not editable and you call
90
			// SetValue it will throw an exception so, we are swallowing all the exceptions.
90
			// SetValue it will throw an exception so, we are swallowing all the exceptions.
91
			PerformSetValue (value);
91
			provider.Control.InvokeSync (delegate {
92
			 	try {
93
					provider.Value = value;
94
				} catch (Exception e) {
95
					// DataSource may throw any exception.
96
					Log.Warn ("{0}: Caught exception:\n{1}", this.GetType (), e);
97
				}
98
			});
92
		}
99
		}
93
		
100
		
94
		public bool IsReadOnly {
101
		public bool IsReadOnly {
Lines 103-127 namespace Mono.UIAutomation.Winforms.Behaviors.DataGrid Link Here
103
110
104
		#region Private Methods
111
		#region Private Methods
105
112
106
		private void PerformSetValue (string value)
107
		{
108
			if (provider.Control.InvokeRequired) {
109
				provider.Control.BeginInvoke (new DataItemSetValueDelegate (PerformSetValue),
110
				                              new object [] { value } );
111
				return;
112
			}
113
		 	try {
114
				provider.Value = value;
115
			} catch (Exception e) {
116
				// DataSource may throw any exception.
117
				Log.Warn ("{0}: Caught exception:\n{1}", this.GetType (), e);
118
			}
119
		}
120
121
		#endregion
122
123
		#region Private Methods
124
125
		private DataGridProvider.DataGridDataItemProvider provider;
113
		private DataGridProvider.DataGridDataItemProvider provider;
126
		
114
		
127
		#endregion
115
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGrid/HeaderItemInvokeProviderBehavior.cs (-28 / +16 lines)
Lines 75-97 namespace Mono.UIAutomation.Winforms.Behaviors.DataGrid Link Here
75
		
75
		
76
		public void Invoke ()
76
		public void Invoke ()
77
		{
77
		{
78
			if (!dataGrid.Enabled || !dataGrid.AllowSorting || !dataGrid.ColumnHeadersVisible)
78
			if (dataGrid.InvokeSync (b => !b.Enabled || !b.AllowSorting || !b.ColumnHeadersVisible))
79
				throw new ElementNotEnabledException ();
79
				throw new ElementNotEnabledException ();
80
80
81
			PerformClick ();
82
		}
83
		
84
		#endregion	
85
		
86
		#region Private Members
87
		
88
		private void PerformClick ()
89
		{
90
			if (dataGrid.InvokeRequired) {
91
				dataGrid.BeginInvoke (new SWF.MethodInvoker (PerformClick));
92
				return;
93
			}
94
95
			// FIXME: We need to replace reflection with an internal method in SWF.DataGrid
81
			// FIXME: We need to replace reflection with an internal method in SWF.DataGrid
96
			MethodInfo methodInfo = typeof (SWF.DataGrid).GetMethod ("OnMouseDown",
82
			MethodInfo methodInfo = typeof (SWF.DataGrid).GetMethod ("OnMouseDown",
97
			                                                          BindingFlags.InvokeMethod
83
			                                                          BindingFlags.InvokeMethod
Lines 103-121 namespace Mono.UIAutomation.Winforms.Behaviors.DataGrid Link Here
103
			                                        (int) rect.Y,
89
			                                        (int) rect.Y,
104
			                                        (int) rect.Width, 
90
			                                        (int) rect.Width, 
105
			                                        (int) rect.Height);
91
			                                        (int) rect.Height);
106
			sdRect = dataGrid.RectangleToClient (sdRect);
92
			dataGrid.InvokeSync (delegate {
107
93
				sdRect = dataGrid.RectangleToClient (sdRect);
108
			Action<SWF.DataGrid, SWF.MouseEventArgs> mouseDownMethod
94
	
109
				= (Action<SWF.DataGrid, SWF.MouseEventArgs>) Delegate.CreateDelegate 
95
				Action<SWF.DataGrid, SWF.MouseEventArgs> mouseDownMethod
110
					(typeof (Action<SWF.DataGrid, SWF.MouseEventArgs>), methodInfo);
96
					= (Action<SWF.DataGrid, SWF.MouseEventArgs>) Delegate.CreateDelegate 
111
97
						(typeof (Action<SWF.DataGrid, SWF.MouseEventArgs>), methodInfo);
112
			SWF.MouseEventArgs args 
98
	
113
				= new SWF.MouseEventArgs (SWF.MouseButtons.Left,
99
				SWF.MouseEventArgs args 
114
				                          1,
100
					= new SWF.MouseEventArgs (SWF.MouseButtons.Left,
115
				                          sdRect.X + 2,
101
					                          1,
116
				                          sdRect.Y + 2,
102
					                          sdRect.X + 2,
117
				                          0);
103
					                          sdRect.Y + 2,
118
			mouseDownMethod (dataGrid, args);
104
					                          0);
105
				mouseDownMethod (dataGrid, args);
106
			});
119
		}
107
		}
120
108
121
		private SWF.DataGrid dataGrid;		
109
		private SWF.DataGrid dataGrid;		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGridView/DataItemChildInvokeProviderBehavior.cs (-18 / +6 lines)
Lines 76-99 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
76
			if (provider.Cell.ReadOnly)
76
			if (provider.Cell.ReadOnly)
77
				throw new ElementNotEnabledException ();
77
				throw new ElementNotEnabledException ();
78
78
79
			PerformClick ();
79
			provider.ItemProvider.DataGridView.InvokeSync (delegate {
80
		}
80
				SWF.DataGridViewCellEventArgs args
81
		
81
					= new SWF.DataGridViewCellEventArgs (provider.Cell.ColumnIndex, 
82
		#endregion	
82
					                                     provider.Cell.RowIndex);
83
		
83
				provider.ItemProvider.DataGridView.InternalOnCellContentClick (args);
84
		#region Private Methods
84
			});
85
		
86
		private void PerformClick ()
87
		{
88
			if (provider.ItemProvider.DataGridView.InvokeRequired) {
89
				provider.ItemProvider.DataGridView.BeginInvoke (new SWF.MethodInvoker (PerformClick));
90
				return;
91
			}
92
93
			SWF.DataGridViewCellEventArgs args
94
				= new SWF.DataGridViewCellEventArgs (provider.Cell.ColumnIndex, 
95
				                                     provider.Cell.RowIndex);
96
			provider.ItemProvider.DataGridView.InternalOnCellContentClick (args);
97
		}
85
		}
98
		
86
		
99
		#endregion
87
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGridView/DataItemChildToggleProviderBehavior.cs (-48 / +46 lines)
Lines 105-149 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
105
105
106
		public ToggleState ToggleState {
106
		public ToggleState ToggleState {
107
			get {
107
			get {
108
				// More information: 
108
				return provider.ItemProvider.DataGridView.InvokeSync (d => {
109
				// http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcell.valuetype.aspx
109
					// More information: 
110
					
110
					// http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcell.valuetype.aspx
111
				if (provider.CheckBoxCell.Value == null) {
111
						
112
					if (provider.CheckBoxCell.ThreeState)
112
					if (provider.CheckBoxCell.Value == null) {
113
						return ToggleState.Indeterminate;
113
						if (provider.CheckBoxCell.ThreeState)
114
					else
114
							return ToggleState.Indeterminate;
115
						return ToggleState.Off;
115
						else
116
				} else {
116
							return ToggleState.Off;
117
					SWF.CheckState state = SWF.CheckState.Indeterminate;
117
					} else {
118
					bool tryBoolean = false;
118
						SWF.CheckState state = SWF.CheckState.Indeterminate;
119
					try {
119
						bool tryBoolean = false;
120
						state = (SWF.CheckState) provider.CheckBoxCell.Value;
121
					} catch (InvalidCastException) { tryBoolean = true; }
122
123
					if (tryBoolean) {
124
						try {
120
						try {
125
							bool val = (bool) provider.CheckBoxCell.Value;
121
							state = (SWF.CheckState) provider.CheckBoxCell.Value;
126
							if (val)
122
						} catch (InvalidCastException) { tryBoolean = true; }
127
								state = SWF.CheckState.Checked;
123
	
128
							else
124
						if (tryBoolean) {
129
								state = SWF.CheckState.Unchecked;
125
							try {
130
						} catch (InvalidCastException) {
126
								bool val = (bool) provider.CheckBoxCell.Value;
131
							// We just can't get valid value
127
								if (val)
128
									state = SWF.CheckState.Checked;
129
								else
130
									state = SWF.CheckState.Unchecked;
131
							} catch (InvalidCastException) {
132
								// We just can't get valid value
133
								return ToggleState.Indeterminate;
134
							}
135
						}
136
	
137
						switch (state) {
138
						case SWF.CheckState.Checked:
139
							return ToggleState.On;
140
						case SWF.CheckState.Unchecked:
141
							return ToggleState.Off;
142
						case SWF.CheckState.Indeterminate:
132
							return ToggleState.Indeterminate;
143
							return ToggleState.Indeterminate;
133
						}
144
						}
134
					}
145
						
135
136
					switch (state) {
137
					case SWF.CheckState.Checked:
138
						return ToggleState.On;
139
					case SWF.CheckState.Unchecked:
140
						return ToggleState.Off;
141
					case SWF.CheckState.Indeterminate:
142
					default:
143
						return ToggleState.Indeterminate;
146
						return ToggleState.Indeterminate;
144
					}
147
					}
145
148
				});
146
				}
147
			}
149
			}
148
		}
150
		}
149
151
Lines 153-172 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
153
		
155
		
154
		private void PerformToggle (SWF.CheckState state)
156
		private void PerformToggle (SWF.CheckState state)
155
		{
157
		{
156
			if (provider.ItemProvider.DataGridView.InvokeRequired) {
158
			provider.ItemProvider.DataGridView.InvokeSync (delegate {
157
				provider.ItemProvider.DataGridView.BeginInvoke (new PerformToggleDelegate (PerformToggle),
159
				// FIXME: Validate InvalidCastException ? (thrown usually because of ValueType)
158
				                                                new object [] { state });
160
	
159
				return;
161
				SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell;
160
			}
162
				provider.ItemProvider.DataGridView.CurrentCell = provider.CheckBoxCell;
161
163
	//			provider.ItemProvider.DataGridView.BeginEdit (false);
162
			// FIXME: Validate InvalidCastException ? (thrown usually because of ValueType)
164
				provider.CheckBoxCell.Value = state;
163
165
	//			provider.ItemProvider.DataGridView.EndEdit ();
164
			SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell;
166
				provider.ItemProvider.DataGridView.CurrentCell = oldCell;
165
			provider.ItemProvider.DataGridView.CurrentCell = provider.CheckBoxCell;
167
			});
166
//			provider.ItemProvider.DataGridView.BeginEdit (false);
167
			provider.CheckBoxCell.Value = state;
168
//			provider.ItemProvider.DataGridView.EndEdit ();
169
			provider.ItemProvider.DataGridView.CurrentCell = oldCell;
170
		}
168
		}
171
169
172
		#endregion
170
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGridView/DataItemChildValueProviderBehavior.cs (-27 / +18 lines)
Lines 87-130 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
87
			if (IsReadOnly)
87
			if (IsReadOnly)
88
				throw new ElementNotEnabledException ();
88
				throw new ElementNotEnabledException ();
89
89
90
			PerformSetValue (value);
90
			provider.ItemProvider.DataGridView.InvokeSync (delegate {
91
				// Notice however that this is the weird behavior in .NET, because
92
				// editing an IsNewRow Row *WONT ADD* a new row
93
	
94
				SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell;
95
				provider.ItemProvider.DataGridView.CurrentCell = provider.TextBoxCell;
96
				provider.TextBoxCell.Value = value;
97
				provider.ItemProvider.DataGridView.CurrentCell = oldCell;
98
			});
91
		}
99
		}
92
100
93
		public bool IsReadOnly {
101
		public bool IsReadOnly {
94
			get { return provider.TextBoxCell.ReadOnly; }
102
			get {
103
				return provider.ItemProvider.DataGridView.InvokeSync (c => provider.TextBoxCell.ReadOnly);
104
			}
95
		}
105
		}
96
		
106
		
97
		public string Value {
107
		public string Value {
98
			get { return provider.TextBoxCell.Value as string ?? string.Empty; }
108
			get {
109
				return provider.ItemProvider.DataGridView.InvokeSync (c => provider.TextBoxCell.Value as string ?? string.Empty); 
110
			}
99
		}
111
		}
100
		
112
		
101
		#endregion
113
		#endregion
102
103
		#region Private Members
104
		
114
		
105
		private void PerformSetValue (string value)
115
		#region Private fields
106
		{
116
		
107
			if (provider.ItemProvider.DataGridView.InvokeRequired) {
108
				provider.ItemProvider.DataGridView.BeginInvoke (new SetValueDelegate (PerformSetValue),
109
				                                                new object [] { value });
110
				return;
111
			}
112
113
			// Notice however that this is the weird behavior in .NET, because
114
			// editing an IsNewRow Row *WONT ADD* a new row
115
116
			SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell;
117
			provider.ItemProvider.DataGridView.CurrentCell = provider.TextBoxCell;
118
			provider.TextBoxCell.Value = value;
119
			provider.ItemProvider.DataGridView.CurrentCell = oldCell;
120
		}
121
122
123
		private DataGridViewProvider.DataGridViewDataItemEditProvider provider;
117
		private DataGridViewProvider.DataGridViewDataItemEditProvider provider;
124
118
		
125
		private delegate void SetValueDelegate (string val);
126
127
		#endregion
119
		#endregion
128
129
	}
120
	}
130
}
121
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGridView/DataItemComboBoxButtonInvokeProviderBehavior.cs (-22 / +10 lines)
Lines 71-105 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
71
		
71
		
72
		public void Invoke ()
72
		public void Invoke ()
73
		{
73
		{
74
			if (provider.ComboBoxProvider.ComboBoxCell.ReadOnly)
74
			if (provider.ComboBoxProvider.ItemProvider.DataGridView.InvokeSync (d => provider.ComboBoxProvider.ComboBoxCell.ReadOnly))
75
				throw new ElementNotEnabledException ();
75
				throw new ElementNotEnabledException ();
76
76
77
			PerformClick ();
77
			provider.ComboBoxProvider.ItemProvider.DataGridView.InvokeSync (delegate {
78
				SWF.DataGridViewCellEventArgs args
79
					= new SWF.DataGridViewCellEventArgs (provider.ComboBoxProvider.Cell.ColumnIndex, 
80
					                                     provider.ComboBoxProvider.Cell.RowIndex);
81
				provider.ComboBoxProvider.ItemProvider.DataGridView.InternalOnCellContentClick (args);
82
			});
78
		}
83
		}
79
		
84
		
80
		#endregion	
85
		#endregion
81
		
82
		#region Private Methods
83
		
86
		
84
		private void PerformClick ()
87
		#region Private fields
85
		{
86
			if (provider.ComboBoxProvider.ItemProvider.DataGridView.InvokeRequired) {
87
				provider.ComboBoxProvider.ItemProvider.DataGridView.BeginInvoke (new SWF.MethodInvoker (PerformClick));
88
				return;
89
			}
90
91
			SWF.DataGridViewCellEventArgs args
92
				= new SWF.DataGridViewCellEventArgs (provider.ComboBoxProvider.Cell.ColumnIndex, 
93
				                                     provider.ComboBoxProvider.Cell.RowIndex);
94
			provider.ComboBoxProvider.ItemProvider.DataGridView.InternalOnCellContentClick (args);
95
		}
96
		
88
		
97
		#endregion
98
99
		#region Private Methods
100
101
		private DataGridViewProvider.DataGridViewDataItemComboBoxButtonProvider provider;
89
		private DataGridViewProvider.DataGridViewDataItemComboBoxButtonProvider provider;
102
90
		
103
		#endregion
91
		#endregion
104
		
92
		
105
	}
93
	}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGridView/DataItemComboBoxExpandCollapseProviderBehavior.cs (-28 / +23 lines)
Lines 89-95 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
89
		
89
		
90
		public ExpandCollapseState ExpandCollapseState {
90
		public ExpandCollapseState ExpandCollapseState {
91
			get {
91
			get {
92
				if (lastComboBox == null || !lastComboBox.DroppedDown)
92
				if (lastComboBox == null 
93
				    || lastComboBox.InvokeSync (c => !c.DroppedDown))
93
					return ExpandCollapseState.Collapsed;
94
					return ExpandCollapseState.Collapsed;
94
				else 
95
				else 
95
					return ExpandCollapseState.Expanded;
96
					return ExpandCollapseState.Expanded;
Lines 98-104 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
98
99
99
		public void Collapse ()
100
		public void Collapse ()
100
		{
101
		{
101
			if (provider.ComboBoxCell.ReadOnly)
102
			if (provider.ItemProvider.DataGridView.InvokeSync (c => provider.ComboBoxCell.ReadOnly))
102
				throw new ElementNotEnabledException ();
103
				throw new ElementNotEnabledException ();
103
104
104
			PerformExpandOrCollapse (false);
105
			PerformExpandOrCollapse (false);
Lines 106-112 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
106
107
107
		public void Expand ()
108
		public void Expand ()
108
		{
109
		{
109
			if (provider.ComboBoxCell.ReadOnly)
110
			if (provider.ItemProvider.DataGridView.InvokeSync (c => provider.ComboBoxCell.ReadOnly))
110
				throw new ElementNotEnabledException ();
111
				throw new ElementNotEnabledException ();
111
			
112
			
112
			PerformExpandOrCollapse (true);
113
			PerformExpandOrCollapse (true);
Lines 119-155 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
119
120
120
		private void PerformExpandOrCollapse (bool expand)
121
		private void PerformExpandOrCollapse (bool expand)
121
		{
122
		{
122
			if (provider.ItemProvider.DataGridView.InvokeRequired) {
123
			provider.ItemProvider.DataGridView.InvokeSync (delegate {
123
				provider.ItemProvider.DataGridView.BeginInvoke (new ExpandOrCollapseDelegate (PerformExpandOrCollapse),
124
				SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell;
124
				                                                new object [] { expand });
125
				provider.ItemProvider.DataGridView.CurrentCell = provider.ComboBoxCell;
125
				return;
126
				provider.ItemProvider.DataGridView.BeginEdit (false);
126
			}
127
	
127
128
				SWF.ComboBox combobox = provider.ItemProvider.DataGridView.EditingControl as SWF.ComboBox;
128
			SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell;
129
				if (combobox != null) {
129
			provider.ItemProvider.DataGridView.CurrentCell = provider.ComboBoxCell;
130
					// We we'll basically are keeping a reference to the EditingControl
130
			provider.ItemProvider.DataGridView.BeginEdit (false);
131
					// to listen for DroppedDown event and set it when it changes.
131
132
					if (lastComboBox != combobox)
132
			SWF.ComboBox combobox = provider.ItemProvider.DataGridView.EditingControl as SWF.ComboBox;
133
						expandCollapseEvent.CurrentComboBox = combobox;
133
			if (combobox != null) {
134
					
134
				// We we'll basically are keeping a reference to the EditingControl
135
					lastComboBox = combobox;
135
				// to listen for DroppedDown event and set it when it changes.
136
					lastComboBox.DroppedDown = expand;
136
				if (lastComboBox != combobox)
137
				} else
137
					expandCollapseEvent.CurrentComboBox = combobox;
138
	
138
				
139
				provider.ItemProvider.DataGridView.EndEdit ();
139
				lastComboBox = combobox;
140
				provider.ItemProvider.DataGridView.CurrentCell = oldCell;
140
				lastComboBox.DroppedDown = expand;
141
			});
141
			} else
142
143
			provider.ItemProvider.DataGridView.EndEdit ();
144
			provider.ItemProvider.DataGridView.CurrentCell = oldCell;
145
		}
142
		}
146
143
147
		private DataItemComboBoxExpandCollapsePatternStateEvent expandCollapseEvent;
144
		private DataItemComboBoxExpandCollapsePatternStateEvent expandCollapseEvent;
148
		private SWF.ComboBox lastComboBox;
145
		private SWF.ComboBox lastComboBox;
149
		private DataGridViewProvider.DataGridViewDataItemComboBoxProvider provider;
146
		private DataGridViewProvider.DataGridViewDataItemComboBoxProvider provider;
150
147
151
		private delegate void ExpandOrCollapseDelegate (bool expand);
152
153
		#endregion
148
		#endregion
154
		
149
		
155
	}
150
	}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGridView/GridProviderBehavior.cs (-9 / +10 lines)
Lines 91-101 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
91
		#region IGridProvider implementation
91
		#region IGridProvider implementation
92
92
93
		public int ColumnCount {
93
		public int ColumnCount {
94
			get { return gridviewprovider.DataGridView.Columns.Count; }
94
			get { return gridviewprovider.DataGridView.InvokeSync (v => v.Columns.Count); }
95
		}
95
		}
96
96
97
		public int RowCount {
97
		public int RowCount {
98
			get { return gridviewprovider.DataGridView.Rows.Count; }
98
			get { return gridviewprovider.DataGridView.InvokeSync (v => v.Rows.Count); }
99
		}
99
		}
100
100
101
		public IRawElementProviderSimple GetItem (int row, int column)
101
		public IRawElementProviderSimple GetItem (int row, int column)
Lines 104-116 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
104
			if (row < 0 || column < 0 || row >= RowCount || column >= ColumnCount)
104
			if (row < 0 || column < 0 || row >= RowCount || column >= ColumnCount)
105
			    throw new ArgumentOutOfRangeException ();
105
			    throw new ArgumentOutOfRangeException ();
106
106
107
			DataGridViewProvider.DataGridDataItemProvider item 
107
			return gridviewprovider.DataGridView.InvokeSync (d => {
108
				= (DataGridViewProvider.DataGridDataItemProvider) gridviewprovider.GetItemProviderFrom (gridviewprovider,
108
				DataGridViewProvider.DataGridDataItemProvider item 
109
				                                                                                        gridviewprovider.DataGridView.Rows [row],
109
					= (DataGridViewProvider.DataGridDataItemProvider) gridviewprovider.GetItemProviderFrom (gridviewprovider,
110
				                                                                                        false);
110
					                                                                                        d.Rows [row],
111
			SWF.DataGridViewColumn viewColumn 
111
					                                                                                        false);
112
				= gridviewprovider.DataGridView.Columns [column];
112
				SWF.DataGridViewColumn viewColumn = d.Columns [column];
113
			return item.GetChildItem (viewColumn);
113
				return item.GetChildItem (viewColumn);
114
			});
114
		}
115
		}
115
		
116
		
116
		#endregion
117
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DataGridView/HeaderItemInvokeProviderBehavior.cs (-40 / +28 lines)
Lines 75-121 namespace Mono.UIAutomation.Winforms.Behaviors.DataGridView Link Here
75
		
75
		
76
		public void Invoke ()
76
		public void Invoke ()
77
		{
77
		{
78
			if (!dataGridView.Enabled)
78
			if (dataGridView.InvokeSync (b => !b.Enabled))
79
				throw new ElementNotEnabledException ();
79
				throw new ElementNotEnabledException ();
80
80
			
81
			PerformClick ();
81
			dataGridView.InvokeSync (delegate {
82
		}
82
				// FIXME: We need to replace reflection with an internal method in SWF.DataGridView
83
		
83
				MethodInfo methodInfo = typeof (SWF.DataGridView).GetMethod ("OnMouseClick",
84
		#endregion	
84
				                                                             BindingFlags.InvokeMethod
85
		
85
				                                                             | BindingFlags.NonPublic
86
		#region Private Members
86
				                                                             | BindingFlags.Instance);
87
		
87
				Rect rect = itemProvider.BoundingRectangle;
88
		private void PerformClick ()
88
	
89
		{
89
				SD.Rectangle sdRect = new SD.Rectangle ((int) rect.X, 
90
			if (dataGridView.InvokeRequired) {
90
				                                        (int) rect.Y,
91
				dataGridView.BeginInvoke (new SWF.MethodInvoker (PerformClick));
91
				                                        (int) rect.Width, 
92
				return;
92
				                                        (int) rect.Height);
93
			}
93
				sdRect = dataGridView.RectangleToClient (sdRect);
94
94
	
95
			// FIXME: We need to replace reflection with an internal method in SWF.DataGridView
95
				Action<SWF.DataGridView, SWF.MouseEventArgs> mouseClickMethod
96
			MethodInfo methodInfo = typeof (SWF.DataGridView).GetMethod ("OnMouseClick",
96
					= (Action<SWF.DataGridView, SWF.MouseEventArgs>) Delegate.CreateDelegate 
97
			                                                             BindingFlags.InvokeMethod
97
						(typeof (Action<SWF.DataGridView, SWF.MouseEventArgs>), methodInfo);
98
			                                                             | BindingFlags.NonPublic
98
	
99
			                                                             | BindingFlags.Instance);
99
				SWF.MouseEventArgs args 
100
			Rect rect = itemProvider.BoundingRectangle;
100
					= new SWF.MouseEventArgs (SWF.MouseButtons.Left,
101
101
					                          1,
102
			SD.Rectangle sdRect = new SD.Rectangle ((int) rect.X, 
102
					                          (int) (sdRect.X + sdRect.Width / 2),
103
			                                        (int) rect.Y,
103
					                          (int) (sdRect.Y + sdRect.Height / 2),
104
			                                        (int) rect.Width, 
104
					                          0);
105
			                                        (int) rect.Height);
105
				mouseClickMethod (dataGridView, args);
106
			sdRect = dataGridView.RectangleToClient (sdRect);
106
			});
107
108
			Action<SWF.DataGridView, SWF.MouseEventArgs> mouseClickMethod
109
				= (Action<SWF.DataGridView, SWF.MouseEventArgs>) Delegate.CreateDelegate 
110
					(typeof (Action<SWF.DataGridView, SWF.MouseEventArgs>), methodInfo);
111
112
			SWF.MouseEventArgs args 
113
				= new SWF.MouseEventArgs (SWF.MouseButtons.Left,
114
				                          1,
115
				                          (int) (sdRect.X + sdRect.Width / 2),
116
				                          (int) (sdRect.Y + sdRect.Height / 2),
117
				                          0);
118
			mouseClickMethod (dataGridView, args);
119
		}
107
		}
120
108
121
		private SWF.DataGridView dataGridView;		
109
		private SWF.DataGridView dataGridView;		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DateTimePicker/ButtonInvokeProviderBehavior.cs (-19 / +6 lines)
Lines 69-98 namespace Mono.UIAutomation.Winforms.Behaviors.DateTimePicker Link Here
69
#region IInvokeProvider Members
69
#region IInvokeProvider Members
70
		public virtual void Invoke ()
70
		public virtual void Invoke ()
71
		{
71
		{
72
			if (!Provider.Control.Enabled)
72
			if (Provider.Control.InvokeSync (c => !c.Enabled))
73
				throw new ElementNotEnabledException ();
73
				throw new ElementNotEnabledException ();
74
74
75
			PerformClick ();
75
			Provider.Control.InvokeSync (delegate {
76
		}
76
				((SWF.DateTimePicker) dateTimePicker.Control)
77
#endregion	
77
					.DropDownButtonClicked ();
78
		
78
			});
79
#region Private Methods
80
		private void PerformClick ()
81
		{
82
			if (Provider.Control.InvokeRequired) {
83
				Provider.Control.BeginInvoke (
84
					new SWF.MethodInvoker (PerformClick));
85
				return;
86
			}
87
88
			((SWF.DateTimePicker) dateTimePicker.Control)
89
				.DropDownButtonClicked ();
90
		}
79
		}
91
#endregion
80
#endregion
92
81
		
93
#region Private Fields
94
		private DateTimePickerProvider dateTimePicker;
82
		private DateTimePickerProvider dateTimePicker;
95
#endregion
96
	}
83
	}
97
84
98
}
85
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DateTimePicker/PartRangeValueProviderBehavior.cs (-25 / +9 lines)
Lines 108-123 namespace Mono.UIAutomation.Winforms.Behaviors.DateTimePicker Link Here
108
	
108
	
109
#region IRangeValueProvider Members
109
#region IRangeValueProvider Members
110
		public bool IsReadOnly {
110
		public bool IsReadOnly {
111
			get {
111
			get { return dateTimePicker.InvokeSync (b => b.ShowCheckBox && !b.Checked); }
112
				return (dateTimePicker.ShowCheckBox
113
				        && !dateTimePicker.Checked);
114
			}
115
		}
112
		}
116
		
113
		
117
		public double Minimum {
114
		public double Minimum {
118
			get {
115
			get {
119
				DateTime min = dateTimePicker.MinDate;
116
				DateTime min = dateTimePicker.InvokeSync (v => v.MinDate);
120
				DateTime cur = dateTimePicker.Value;
117
				DateTime cur = dateTimePicker.InvokeSync (v => v.Value);
118
				
121
				switch (partProvider.PartData.date_time_part) {
119
				switch (partProvider.PartData.date_time_part) {
122
				case SWF.DateTimePicker.DateTimePart.Seconds:
120
				case SWF.DateTimePicker.DateTimePart.Seconds:
123
					return IsDateEqual (min, cur) ? min.Second : 0;
121
					return IsDateEqual (min, cur) ? min.Second : 0;
Lines 153-160 namespace Mono.UIAutomation.Winforms.Behaviors.DateTimePicker Link Here
153
		
151
		
154
		public double Maximum {
152
		public double Maximum {
155
			get {
153
			get {
156
				DateTime max = dateTimePicker.MaxDate;
154
				DateTime max = dateTimePicker.InvokeSync (c => c.MaxDate);
157
				DateTime cur = dateTimePicker.Value;
155
				DateTime cur = dateTimePicker.InvokeSync (c => c.Value);
158
				switch (partProvider.PartData.date_time_part) {
156
				switch (partProvider.PartData.date_time_part) {
159
				case SWF.DateTimePicker.DateTimePart.Seconds:
157
				case SWF.DateTimePicker.DateTimePart.Seconds:
160
					return IsDateEqual (max, cur) ? max.Second : 60;
158
					return IsDateEqual (max, cur) ? max.Second : 60;
Lines 205-229 namespace Mono.UIAutomation.Winforms.Behaviors.DateTimePicker Link Here
205
			if (value < Minimum || value > Maximum)
203
			if (value < Minimum || value > Maximum)
206
				throw new ArgumentOutOfRangeException ();
204
				throw new ArgumentOutOfRangeException ();
207
205
208
			PerformSetValue (value);
209
		}
210
#endregion
211
		
212
#region Private Methods
213
		private void PerformSetValue (double value) 
214
		{
215
			if (IsReadOnly)
206
			if (IsReadOnly)
216
				throw new ElementNotEnabledException ();
207
				throw new ElementNotEnabledException ();
217
208
218
			if (dateTimePicker.InvokeRequired) {
209
			dateTimePicker.InvokeSync (delegate {
219
				dateTimePicker.BeginInvoke (
210
				dateTimePicker.SetPart ((int) value, partProvider.PartData.date_time_part);
220
					new DateTimePickerPartSetValueDelegate (PerformSetValue),
211
			});
221
					new object [] { value }
222
				);
223
				return;
224
			}
225
226
			dateTimePicker.SetPart ((int) value, partProvider.PartData.date_time_part);
227
		}
212
		}
228
213
229
		private bool IsDateEqual (DateTime date1, DateTime date2)
214
		private bool IsDateEqual (DateTime date1, DateTime date2)
Lines 238-242 namespace Mono.UIAutomation.Winforms.Behaviors.DateTimePicker Link Here
238
#endregion
223
#endregion
239
	}
224
	}
240
225
241
	public delegate void DateTimePickerPartSetValueDelegate (double value);
242
}
226
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/DateTimePicker/ToggleProviderBehavior.cs (-16 / +5 lines)
Lines 76-105 namespace Mono.UIAutomation.Winforms.Behaviors.DateTimePicker Link Here
76
#region IToggleProvider Members
76
#region IToggleProvider Members
77
		public ToggleState ToggleState {
77
		public ToggleState ToggleState {
78
			get {
78
			get {
79
				return dateTimePicker.Checked ? ToggleState.On
79
				return dateTimePicker.InvokeSync (c => c.Checked) ? ToggleState.On
80
			                                      : ToggleState.Off;
80
			                                      : ToggleState.Off;
81
			}
81
			}
82
		}
82
		}
83
83
84
		public void Toggle ()
84
		public void Toggle ()
85
		{
85
		{
86
			if (!Provider.Control.Enabled)
86
			if (dateTimePicker.InvokeSync (b => !b.Enabled))
87
				throw new ElementNotEnabledException ();
87
				throw new ElementNotEnabledException ();
88
88
89
			PerformToggle ();
89
			dateTimePicker.InvokeSync (delegate {
90
		}
90
				dateTimePicker.Checked = !dateTimePicker.Checked;
91
#endregion	
91
			});
92
		
93
#region Private Methods
94
		private void PerformToggle ()
95
		{
96
			if (Provider.Control.InvokeRequired) {
97
				Provider.Control.BeginInvoke (
98
					new SWF.MethodInvoker (PerformToggle));
99
				return;
100
			}
101
102
			dateTimePicker.Checked = !dateTimePicker.Checked;
103
		}
92
		}
104
#endregion
93
#endregion
105
94
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/Form/TransformProviderBehavior.cs (-20 / +10 lines)
Lines 91-103 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
91
	
91
	
92
		public bool CanMove {
92
		public bool CanMove {
93
			get {
93
			get {
94
				return form.WindowState == SWF.FormWindowState.Normal;
94
				return form.InvokeSync (f => f.WindowState == SWF.FormWindowState.Normal);
95
			}
95
			}
96
		}
96
		}
97
97
98
		public bool CanResize {
98
		public bool CanResize {
99
			get {
99
			get {
100
				switch (form.FormBorderStyle) {
100
				switch (form.InvokeSync (f => f.FormBorderStyle)) {
101
				case SWF.FormBorderStyle.Fixed3D:
101
				case SWF.FormBorderStyle.Fixed3D:
102
				case SWF.FormBorderStyle.FixedDialog:
102
				case SWF.FormBorderStyle.FixedDialog:
103
				case SWF.FormBorderStyle.FixedSingle:
103
				case SWF.FormBorderStyle.FixedSingle:
Lines 119-132 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
119
			//       exceptions are thrown with bad input
119
			//       exceptions are thrown with bad input
120
			if (!CanMove)
120
			if (!CanMove)
121
				throw new InvalidOperationException ("CanMove is false");
121
				throw new InvalidOperationException ("CanMove is false");
122
			
122
123
			if (form.InvokeRequired == true) {
123
			form.InvokeSync (delegate {
124
				form.BeginInvoke (new PerformTransformDelegate (Move),
124
				form.Location = new Point ((int) x, (int) y);
125
				                  new object [] { x, y});
125
			});
126
				return;
127
			}
128
			
129
			form.Location = new Point ((int) x, (int) y);
130
		}
126
		}
131
127
132
		public void Resize (double width, double height)
128
		public void Resize (double width, double height)
Lines 135-148 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
135
			//       exceptions are thrown with bad input
131
			//       exceptions are thrown with bad input
136
			if (!CanResize)
132
			if (!CanResize)
137
				throw new InvalidOperationException ("CanResize is false");
133
				throw new InvalidOperationException ("CanResize is false");
138
			
134
139
			if (form.InvokeRequired == true) {
135
			form.InvokeSync (delegate { 
140
				form.BeginInvoke (new PerformTransformDelegate (Resize),
136
				form.Size = new Size ((int) width, (int) height);
141
				                  new object [] { width, height});
137
			});
142
				return;
143
			}
144
			
145
			form.Size = new Size ((int) width, (int) height);
146
		}
138
		}
147
139
148
		public void Rotate (double degrees)
140
		public void Rotate (double degrees)
Lines 159-165 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
159
		#endregion
151
		#endregion
160
		
152
		
161
	}
153
	}
162
	
163
	delegate void PerformTransformDelegate (double width, double height);
164
154
165
}
155
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/Form/WindowProviderBehavior.cs (-32 / +9 lines)
Lines 141-147 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
141
		
141
		
142
		public void SetVisualState (WindowVisualState state)
142
		public void SetVisualState (WindowVisualState state)
143
		{
143
		{
144
			SWF.FormWindowState newState = form.WindowState;
144
			SWF.FormWindowState newState = form.InvokeSync (f => f.WindowState);
145
			switch (state) {
145
			switch (state) {
146
			case WindowVisualState.Maximized:
146
			case WindowVisualState.Maximized:
147
				newState = SWF.FormWindowState.Maximized;
147
				newState = SWF.FormWindowState.Maximized;
Lines 153-188 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
153
				newState = SWF.FormWindowState.Normal;
153
				newState = SWF.FormWindowState.Normal;
154
				break;
154
				break;
155
			}
155
			}
156
			PerformSetVisualState (form, newState);
156
157
			form.InvokeSync (delegate { form.WindowState = newState; });
157
		}
158
		}
158
		
159
		
159
		public void Close ()
160
		public void Close ()
160
		{
161
		{
161
			form.Close ();
162
			form.InvokeSync (delegate { form.Close (); });
162
		}
163
		}
163
		
164
		
164
		public bool Minimizable {
165
		public bool Minimizable {
165
			get {
166
			get { return form.InvokeSync (f => f.MinimizeBox); }
166
				return form.MinimizeBox;
167
			}
168
		}
167
		}
169
		
168
		
170
		public bool Maximizable {
169
		public bool Maximizable {
171
			get {
170
			get { return form.InvokeSync (f => f.MaximizeBox); }
172
				return form.MaximizeBox;
173
			}
174
		}
171
		}
175
		
172
		
176
		public bool IsTopmost {
173
		public bool IsTopmost {
177
			get {
174
			get { return form.InvokeSync (f => f.TopMost); }
178
				return form.TopMost;
179
			}
180
		}
175
		}
181
		
176
		
182
		public bool IsModal {
177
		public bool IsModal {
183
			get {
178
			get { return form.InvokeSync (f => f.Modal); }
184
				return form.Modal;
185
			}
186
		}
179
		}
187
		
180
		
188
		public WindowInteractionState InteractionState {
181
		public WindowInteractionState InteractionState {
Lines 197-203 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
197
		
190
		
198
		public WindowVisualState VisualState {
191
		public WindowVisualState VisualState {
199
			get {
192
			get {
200
				switch (form.WindowState) {
193
				switch (form.InvokeSync (f => f.WindowState)) {
201
				case SWF.FormWindowState.Maximized:
194
				case SWF.FormWindowState.Maximized:
202
					return WindowVisualState.Maximized;
195
					return WindowVisualState.Maximized;
203
				case SWF.FormWindowState.Minimized:
196
				case SWF.FormWindowState.Minimized:
Lines 225-244 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
225
		
218
		
226
		#endregion
219
		#endregion
227
		
220
		
228
		#region Private Methods
229
		
230
		private void PerformSetVisualState (SWF.Form form, SWF.FormWindowState state)
231
		{
232
			if (form.InvokeRequired == true) {
233
				form.BeginInvoke (new PerformSetVisualStateDelegate (PerformSetVisualState),
234
				                  new object [] { form, state });
235
				return;
236
			}
237
			form.WindowState = state;
238
		}
239
		
240
		#endregion
241
		
242
		#region Private Fields
221
		#region Private Fields
243
222
244
		private bool closing;
223
		private bool closing;
Lines 247-252 namespace Mono.UIAutomation.Winforms.Behaviors.Form Link Here
247
		#endregion
226
		#endregion
248
	}
227
	}
249
	
228
	
250
	delegate void PerformSetVisualStateDelegate (SWF.Form form, SWF.FormWindowState state);
251
	
252
}
229
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/Generic/ScrollProviderBehavior.cs (-32 / +35 lines)
Lines 102-111 namespace Mono.UIAutomation.Winforms.Behaviors.Generic Link Here
102
		//FIXME: This MUST BE locale-specific
102
		//FIXME: This MUST BE locale-specific
103
		public double HorizontalScrollPercent {
103
		public double HorizontalScrollPercent {
104
			get { 
104
			get { 
105
				if (HorizontallyScrollable == false || hscrollbar.Maximum == 0)
105
				if (HorizontallyScrollable == false)
106
					return ScrollPatternIdentifiers.NoScroll;
106
					return ScrollPatternIdentifiers.NoScroll;
107
				else
107
				else {
108
					return (hscrollbar.Value * 100) / hscrollbar.Maximum; 
108
					return hscrollbar.InvokeSync (c => {
109
						if (c.Maximum == 0)
110
							return ScrollPatternIdentifiers.NoScroll;
111
						else
112
							return (double) ((c.Value * 100) / c.Maximum);
113
					});
114
				}
109
			}
115
			}
110
		}
116
		}
111
		
117
		
Lines 128-137 namespace Mono.UIAutomation.Winforms.Behaviors.Generic Link Here
128
		//FIXME: This MUST BE locale-specific
134
		//FIXME: This MUST BE locale-specific
129
		public double VerticalScrollPercent {
135
		public double VerticalScrollPercent {
130
			get { 
136
			get { 
131
				if (VerticallyScrollable == false || vscrollbar.Maximum == 0)
137
				if (VerticallyScrollable == false)
132
					return ScrollPatternIdentifiers.NoScroll;
138
					return ScrollPatternIdentifiers.NoScroll;
133
				else
139
				else {
134
					return (vscrollbar.Value * 100) / vscrollbar.Maximum; 
140
					return vscrollbar.InvokeSync (c => {
141
						if (c.Maximum == 0)
142
							return ScrollPatternIdentifiers.NoScroll;
143
						else
144
							return (double) ((c.Value * 100) / c.Maximum);
145
					});
146
				}
135
			}
147
			}
136
		}
148
		}
137
149
Lines 164-178 namespace Mono.UIAutomation.Winforms.Behaviors.Generic Link Here
164
			if (horizontalPercent != ScrollPatternIdentifiers.NoScroll) {
176
			if (horizontalPercent != ScrollPatternIdentifiers.NoScroll) {
165
				if (horizontalPercent < 0 || horizontalPercent > 100)
177
				if (horizontalPercent < 0 || horizontalPercent > 100)
166
					throw new ArgumentOutOfRangeException ();
178
					throw new ArgumentOutOfRangeException ();
167
				else
179
				else {
168
					PerformScrollByPercent (hscrollbar, (int) ((horizontalPercent * hscrollbar.Maximum) / 100));
180
					double maximum = hscrollbar.InvokeSync (h => h.Maximum);
181
					hscrollbar.InvokeSync (delegate {
182
						hscrollbar.Value = (int) ((horizontalPercent * maximum) / 100);
183
					});
184
				}
169
			}
185
			}
170
			
186
			
171
			if (verticalPercent != ScrollPatternIdentifiers.NoScroll) {
187
			if (verticalPercent != ScrollPatternIdentifiers.NoScroll) {
172
			    if (verticalPercent < 0 || verticalPercent > 100)
188
			    if (verticalPercent < 0 || verticalPercent > 100)
173
					throw new ArgumentOutOfRangeException ();
189
					throw new ArgumentOutOfRangeException ();
174
				else 
190
				else {
175
					PerformScrollByPercent (vscrollbar, (int) ((verticalPercent * vscrollbar.Maximum) / 100));
191
					double maximum = vscrollbar.InvokeSync (v => v.Maximum);
192
					hscrollbar.InvokeSync (delegate {
193
						vscrollbar.Value = (int) ((verticalPercent * maximum) / 100);
194
					});
195
				}
176
			}
196
			}
177
		}
197
		}
178
198
Lines 222-249 namespace Mono.UIAutomation.Winforms.Behaviors.Generic Link Here
222
			invoke
242
			invoke
223
				= (Action<SWF.ScrollBar>) Delegate.CreateDelegate (typeof (Action<SWF.ScrollBar>), 
243
				= (Action<SWF.ScrollBar>) Delegate.CreateDelegate (typeof (Action<SWF.ScrollBar>), 
224
				                                                   methodInfo);
244
				                                                   methodInfo);
225
			PerformScrollByAmount (scrollbar);
245
226
		}
246
			scrollbar.InvokeSync (delegate { 
227
		
247
				invoke (scrollbar);
228
		private void PerformScrollByAmount (SWF.ScrollBar scrollbar)
248
				invoke = null;
229
		{
249
			});
230
			if (scrollbar.InvokeRequired == true) {
231
				scrollbar.BeginInvoke (new ScrollByAmountDelegate (PerformScrollByAmount),
232
				                       new object [] { scrollbar });
233
				return;
234
			}
235
			invoke (scrollbar);
236
			invoke = null;
237
		}
238
		
239
		private void PerformScrollByPercent (SWF.ScrollBar scrollbar, int value)
240
		{
241
			if (scrollbar.InvokeRequired == true) {
242
				scrollbar.BeginInvoke (new ScrollByPercentDelegate (PerformScrollByPercent),
243
				                       new object [] { scrollbar, value });
244
				return;
245
			}
246
			scrollbar.Value = value;
247
		}
250
		}
248
251
249
		#endregion
252
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/Generic/SelectionItemProviderBehavior.cs (-11 / +7 lines)
Lines 122-133 namespace Mono.UIAutomation.Winforms.Behaviors.Generic Link Here
122
		{
122
		{
123
			if (IsSelected)
123
			if (IsSelected)
124
				return;
124
				return;
125
			
125
126
			if (itemProvider.ContainerControl.InvokeRequired) {
126
			itemProvider.ContainerControl.InvokeSync (delegate {
127
				itemProvider.ContainerControl.BeginInvoke (new MethodInvoker (Select));
127
				itemProvider.Select ();
128
				return;
128
			});
129
			}
130
			itemProvider.Select ();
131
		}
129
		}
132
130
133
		public bool IsSelected {
131
		public bool IsSelected {
Lines 165-175 namespace Mono.UIAutomation.Winforms.Behaviors.Generic Link Here
165
163
166
		private void PerformUnselect ()
164
		private void PerformUnselect ()
167
		{
165
		{
168
			if (itemProvider.ContainerControl.InvokeRequired) {
166
			itemProvider.ContainerControl.InvokeSync (delegate {
169
				itemProvider.ContainerControl.BeginInvoke (new MethodInvoker (PerformUnselect));
167
				itemProvider.Unselect ();
170
				return;
168
			});
171
			}
172
			itemProvider.Unselect ();
173
		}
169
		}
174
		
170
		
175
		private T itemProvider;
171
		private T itemProvider;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/LinkLabel/InvokeProviderBehavior.cs (-50 / +43 lines)
Lines 86-124 namespace Mono.UIAutomation.Winforms.Behaviors.LinkLabel Link Here
86
		#region IHypertext Specialization
86
		#region IHypertext Specialization
87
		
87
		
88
		public int NumberOfLinks { 
88
		public int NumberOfLinks { 
89
			get { return linkLabel.Links.Count; }
89
			get { return linkLabel.InvokeSync (c => c.Links.Count); }
90
		}
90
		}
91
		
91
		
92
		public int Start (int index) 
92
		public int Start (int index) 
93
		{
93
		{
94
			if (index >= linkLabel.Links.Count || index < 0)
94
			return linkLabel.InvokeSync (c => {
95
				return -1;
95
				if (index >= c.Links.Count || index < 0)
96
			else
96
					return -1;
97
				return linkLabel.Links [index].Start;
97
				else
98
					return c.Links [index].Start;
99
			});
98
		}
100
		}
99
		
101
		
100
		public int Length (int index)
102
		public int Length (int index)
101
		{
103
		{
102
			if (index >= linkLabel.Links.Count || index < 0)
104
			return linkLabel.InvokeSync (c => {
103
				return -1;
105
				if (index >= c.Links.Count || index < 0)
104
			else
106
					return -1;
105
				return linkLabel.Links [index].Length;
107
				else
108
					return c.Links [index].Length;
109
			});
106
		}
110
		}
107
		
111
		
108
		public string Uri (int index)
112
		public string Uri (int index)
109
		{
113
		{
110
			if (index >= linkLabel.Links.Count || index < 0)
114
			return linkLabel.InvokeSync (c => {
111
				return null;
115
				if (index >= c.Links.Count || index < 0)
112
			else
116
					return null;
113
				return linkLabel.Links [index].LinkData as string;
117
				else
118
					return c.Links [index].LinkData as string;
119
			});
114
		}
120
		}
115
		
121
		
116
		public bool Enabled (int index)
122
		public bool Enabled (int index)
117
		{
123
		{
118
			if (!linkLabel.Enabled || index >= linkLabel.Links.Count || index < 0)
124
			return linkLabel.InvokeSync (c => {
119
				return false;
125
				if (!c.Enabled || index >= c.Links.Count || index < 0)
120
			else
126
					return false;
121
				return linkLabel.Links [index].Enabled;
127
				else
128
					return c.Links [index].Enabled;
129
			});
122
		}
130
		}
123
		
131
		
124
		public void Invoke (int index)
132
		public void Invoke (int index)
Lines 126-166 namespace Mono.UIAutomation.Winforms.Behaviors.LinkLabel Link Here
126
			if (!Enabled (index))
134
			if (!Enabled (index))
127
				throw new ElementNotEnabledException ();
135
				throw new ElementNotEnabledException ();
128
			
136
			
129
			PerformClick (index);
137
			linkLabel.InvokeSync (c => {
130
		}
138
				if (index >= c.Links.Count || index < 0)
131
		
139
					return;
132
		#endregion
140
	
133
		
141
				MethodInfo methodInfo = typeof (SWF.LinkLabel).GetMethod ("OnLinkClicked",
134
		#region Private Methods
142
				                                                          BindingFlags.InvokeMethod
135
		
143
				                                                          | BindingFlags.NonPublic
136
		private void PerformClick (int index)
144
				                                                          | BindingFlags.Instance);
137
		{
145
				Action<SWF.LinkLabel, SWF.LinkLabelLinkClickedEventArgs> invokeMethod
138
			if (index >= linkLabel.Links.Count || index < 0)
146
					= (Action<SWF.LinkLabel, SWF.LinkLabelLinkClickedEventArgs>) Delegate.CreateDelegate 
139
				return;
147
						(typeof (Action<SWF.LinkLabel, SWF.LinkLabelLinkClickedEventArgs>),
140
148
						 methodInfo);
141
			if (linkLabel.InvokeRequired) {
149
	
142
				linkLabel.BeginInvoke (new PerformClickDelegate (PerformClick),
150
				SWF.LinkLabelLinkClickedEventArgs args 
143
				                       new object [] { index });
151
					= new SWF.LinkLabelLinkClickedEventArgs (c.Links [index],
144
				return;
152
					                                         SWF.MouseButtons.Left);
145
			}
153
				invokeMethod (c, args);
146
			
154
			});
147
			MethodInfo methodInfo = typeof (SWF.LinkLabel).GetMethod ("OnLinkClicked",
148
			                                                          BindingFlags.InvokeMethod
149
			                                                          | BindingFlags.NonPublic
150
			                                                          | BindingFlags.Instance);
151
			Action<SWF.LinkLabel, SWF.LinkLabelLinkClickedEventArgs> invokeMethod
152
				= (Action<SWF.LinkLabel, SWF.LinkLabelLinkClickedEventArgs>) Delegate.CreateDelegate 
153
					(typeof (Action<SWF.LinkLabel, SWF.LinkLabelLinkClickedEventArgs>),
154
					 methodInfo);
155
156
			SWF.LinkLabelLinkClickedEventArgs args 
157
				= new SWF.LinkLabelLinkClickedEventArgs (linkLabel.Links [index],
158
				                                         SWF.MouseButtons.Left);
159
			invokeMethod (linkLabel, args);
160
		}
155
		}
161
		
156
		
162
		#endregion
157
		#endregion
163
	}
158
	}
164
	
165
	delegate void PerformClickDelegate (int index);
166
}
159
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListBox/SelectionProviderBehavior.cs (-4 / +4 lines)
Lines 92-102 namespace Mono.UIAutomation.Winforms.Behaviors.ListBox Link Here
92
		#region ISelectionProvider Members
92
		#region ISelectionProvider Members
93
93
94
		public bool CanSelectMultiple {
94
		public bool CanSelectMultiple {
95
			get { 
95
			get {
96
				SWF.ListBox listBoxControl = (SWF.ListBox) Provider.Control;
96
				SWF.ListBox listBoxControl = (SWF.ListBox) Provider.Control;
97
				
97
98
				return listBoxControl.SelectionMode == SWF.SelectionMode.MultiExtended
98
				return listBoxControl.InvokeSync (c => c.SelectionMode == SWF.SelectionMode.MultiExtended
99
					|| listBoxControl.SelectionMode == SWF.SelectionMode.MultiSimple;
99
				                                   || c.SelectionMode == SWF.SelectionMode.MultiSimple);
100
			}
100
			}
101
		}
101
		}
102
102
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListItem/ScrollItemProviderBehavior.cs (-18 / +4 lines)
Lines 69-94 namespace Mono.UIAutomation.Winforms.Behaviors.ListItem Link Here
69
		
69
		
70
		public void ScrollIntoView ()
70
		public void ScrollIntoView ()
71
		{
71
		{
72
			PerformScrollIntoView (((ListItemProvider) Provider).ListProvider);
72
			IListProvider itemProvider = ((ListItemProvider) Provider).ListProvider;
73
			itemProvider.Control.InvokeSync (delegate {
74
				itemProvider.ScrollItemIntoView ((ListItemProvider) Provider);
75
			});
73
		}
76
		}
74
77
75
		#endregion
78
		#endregion
76
		
77
		#region Private Methods
78
		
79
		private void PerformScrollIntoView (IListProvider provider)
80
		{
81
			if (provider.Control.InvokeRequired == true) {
82
				provider.Control.BeginInvoke (new ScrollIntoViewDelegate (PerformScrollIntoView),
83
				                              new object [] { provider });
84
				return;
85
			}
86
87
			provider.ScrollItemIntoView ((ListItemProvider) Provider);
88
		}
89
		
90
		#endregion
91
	}
79
	}
92
	
93
	delegate void ScrollIntoViewDelegate (ListProvider provider);
94
}
80
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListItem/ToggleProviderBehavior.cs (-7 / +4 lines)
Lines 78-90 namespace Mono.UIAutomation.Winforms.Behaviors.ListItem Link Here
78
		public void Toggle ()
78
		public void Toggle ()
79
		{
79
		{
80
			ListItemProvider provider = (ListItemProvider) Provider;
80
			ListItemProvider provider = (ListItemProvider) Provider;
81
			
81
82
			if (provider.ListProvider.Control.InvokeRequired == true) {
82
			provider.ListProvider.Control.InvokeSync (delegate {
83
				provider.ListProvider.Control.BeginInvoke (new SWF.MethodInvoker (Toggle));
83
				provider.ListProvider.ToggleItem (provider);
84
				return;
84
			});
85
			}
86
			
87
			provider.ListProvider.ToggleItem (provider);
88
		}
85
		}
89
86
90
		#endregion
87
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/GridProviderBehavior.cs (-14 / +18 lines)
Lines 89-112 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
89
89
90
		public int ColumnCount {
90
		public int ColumnCount {
91
			get {
91
			get {
92
				if (listView.View == SWF.View.Details)
92
				return listView.InvokeSync (c => {
93
					return listView.Columns.Count;
93
					if (c.View == SWF.View.Details)
94
				else { //Is View.List
94
						return c.Columns.Count;
95
					if (RowCount == 0)
95
					else { //Is View.List
96
						return -1;
96
						if (RowCount == 0)
97
97
							return -1;
98
					bool module = listView.Items.Count % RowCount > 0;
98
	
99
					return (listView.Items.Count / RowCount) + (module ? 1 : 0);
99
						bool module = c.Items.Count % RowCount > 0;
100
				}
100
						return (c.Items.Count / RowCount) + (module ? 1 : 0);
101
					}
102
				});
101
			}
103
			}
102
		}
104
		}
103
105
104
		public int RowCount {
106
		public int RowCount {
105
			get {
107
			get {
106
				if (listView.View == SWF.View.Details)
108
				return listView.InvokeSync (c => {
107
					return listView.Items.Count;
109
					if (c.View == SWF.View.Details)
108
				else //Is View.List
110
						return c.Items.Count;
109
					return listView.UIARows; 
111
					else //Is View.List
112
						return c.UIARows;
113
				});
110
			}
114
			}
111
		}
115
		}
112
116
Lines 121-127 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
121
125
122
			ListViewProvider provider = (ListViewProvider) Provider;
126
			ListViewProvider provider = (ListViewProvider) Provider;
123
127
124
			if (listView.View == SWF.View.Details) {
128
			if (listView.InvokeSync (c => c.View == SWF.View.Details)) {
125
				// FIXME: In Vista when listView.Groups == 0 no Groups are added,
129
				// FIXME: In Vista when listView.Groups == 0 no Groups are added,
126
				// and we should iterate when listView.Groups > 0
130
				// and we should iterate when listView.Groups > 0
127
				SWF.ListViewItem item = listView.Items [row];
131
				SWF.ListViewItem item = listView.Items [row];
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/GroupGridProviderBehavior.cs (-21 / +25 lines)
Lines 97-113 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
97
		
97
		
98
		public int ColumnCount {
98
		public int ColumnCount {
99
			get {
99
			get {
100
				if (viewGroupProvider.ListView.View == SWF.View.Details)
100
				return viewGroupProvider.ListView.InvokeSync (c => {
101
					return viewGroupProvider.ListView.Columns.Count;
101
					if (viewGroupProvider.ListView.View == SWF.View.Details)
102
				else {
102
						return c.Columns.Count;
103
					int maxColums = viewGroupProvider.ListView.UIAColumns;
103
					else {
104
					int itemsInGroup = ItemsInGroupCount ();
104
						int maxColums = c.UIAColumns;
105
	
105
						int itemsInGroup = ItemsInGroupCount ();
106
					if (itemsInGroup < maxColums)
106
		
107
						return itemsInGroup;
107
						if (itemsInGroup < maxColums)
108
					else
108
							return itemsInGroup;
109
						return maxColums;
109
						else
110
				}
110
							return maxColums;
111
					}
112
				});
111
			}
113
			}
112
		}
114
		}
113
		
115
		
Lines 135-151 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
135
137
136
		private int ItemsInGroupCount ()
138
		private int ItemsInGroupCount ()
137
		{
139
		{
138
			ListViewProvider listViewProvider
140
			return viewGroupProvider.ListView.InvokeSync (c => {
139
				= (ListViewProvider) ProviderFactory.FindProvider (viewGroupProvider.ListView);
141
				ListViewProvider listViewProvider
140
			if (listViewProvider.IsDefaultGroup (viewGroupProvider.Group) == true) {
142
					= (ListViewProvider) ProviderFactory.FindProvider (viewGroupProvider.ListView);
141
				int itemsInGroup = 0;
143
				if (listViewProvider.IsDefaultGroup (viewGroupProvider.Group) == true) {
142
				for (int index = 0; index < viewGroupProvider.ListView.Items.Count; index++) {
144
					int itemsInGroup = 0;
143
					if (viewGroupProvider.ListView.Items [index].Group == null)
145
					for (int index = 0; index < c.Items.Count; index++) {
144
						itemsInGroup++;
146
						if (c.Items [index].Group == null)
145
				}
147
							itemsInGroup++;
146
				return itemsInGroup;
148
					}
147
			} else
149
					return itemsInGroup;
150
				} else
148
				return viewGroupProvider.Group.Items.Count;
151
				return viewGroupProvider.Group.Items.Count;
152
			});
149
		}
153
		}
150
154
151
		#endregion
155
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/HeaderItemInvokeProvider.cs (-4 / +2 lines)
Lines 70-79 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
70
		#region IInvokeProvider implementation 
70
		#region IInvokeProvider implementation 
71
		
71
		
72
		public void Invoke ()
72
		public void Invoke ()
73
		{	
73
		{
74
			var clickArgs = new SWF.ColumnClickEventArgs (
74
			Log.Warn ("HeaderItemInvokePatternInvokedEvent: Invoke not implemented");
75
			  itemProvider.ColumnHeader.ListView.Columns.IndexOf (itemProvider.ColumnHeader));
76
			itemProvider.ColumnHeader.ListView.OnColumnClick (clickArgs);
77
		}
75
		}
78
76
79
		#endregion
77
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/ListItemCheckBoxToggleProviderBehavior.cs (-7 / +4 lines)
Lines 84-96 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
84
		public void Toggle ()
84
		public void Toggle ()
85
		{
85
		{
86
			ListItemProvider provider = checkboxProvider.ItemProvider;
86
			ListItemProvider provider = checkboxProvider.ItemProvider;
87
			
87
88
			if (provider.ListProvider.Control.InvokeRequired == true) {
88
			provider.ListProvider.Control.InvokeSync (delegate {
89
				provider.ListProvider.Control.BeginInvoke (new SWF.MethodInvoker (Toggle));
89
				provider.ListProvider.ToggleItem (provider);
90
				return;
90
			});
91
			}
92
			
93
			provider.ListProvider.ToggleItem (provider);
94
		}
91
		}
95
92
96
		#endregion
93
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/ListItemClipboardProviderBehavior.cs (-17 / +3 lines)
Lines 77-102 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
77
			position = (int) System.Math.Min (position, text.Length);
77
			position = (int) System.Math.Min (position, text.Length);
78
78
79
			string newValue = viewItem.Text.Insert (position, SWF.Clipboard.GetText ());
79
			string newValue = viewItem.Text.Insert (position, SWF.Clipboard.GetText ());
80
			PerformSetValue (newValue);
80
			viewItem.ListView.InvokeSync (delegate {
81
				viewItem.Text = newValue;
82
			});
81
		}
83
		}
82
84
83
		#endregion
85
		#endregion
84
86
85
		#region Private Methods
86
87
		private void PerformSetValue (string value)
88
		{
89
			if (viewItem.ListView.InvokeRequired == true) {
90
				viewItem.ListView.BeginInvoke (new ListItemSetValueDelegate (PerformSetValue),
91
				                               new object [] { value } );
92
				return;
93
			}
94
			
95
			viewItem.Text = value;
96
		}
97
98
		#endregion
99
		
100
		#region Private Fields
87
		#region Private Fields
101
		
88
		
102
		private SWF.ListViewItem viewItem;
89
		private SWF.ListViewItem viewItem;
Lines 104-108 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
104
		#endregion
91
		#endregion
105
	}
92
	}
106
93
107
	delegate void ListItemSetValueDelegate (string value);
108
}
94
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/ListItemEditGridItemProviderBehavior.cs (-2 / +2 lines)
Lines 106-119 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
106
		public int Row {
106
		public int Row {
107
			get {
107
			get {
108
				SWF.ListView listView = editProvider.ItemProvider.ListView;
108
				SWF.ListView listView = editProvider.ItemProvider.ListView;
109
				return listView.Items.IndexOf (editProvider.ItemProvider.ListViewItem);
109
				return listView.InvokeSync (c => c.Items.IndexOf (editProvider.ItemProvider.ListViewItem) );
110
			}
110
			}
111
		}
111
		}
112
		
112
		
113
		public int Column {
113
		public int Column {
114
			get {
114
			get {
115
				SWF.ListView listView = editProvider.ItemProvider.ListView;
115
				SWF.ListView listView = editProvider.ItemProvider.ListView;
116
				return listView.Columns.IndexOf (editProvider.ColumnHeader);
116
				return listView.InvokeSync (c => c.Columns.IndexOf (editProvider.ColumnHeader) );
117
			}
117
			}
118
		}
118
		}
119
		
119
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/ListItemEditValueProviderBehavior.cs (-31 / +20 lines)
Lines 87-134 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
87
		
87
		
88
		public void SetValue (string value)
88
		public void SetValue (string value)
89
		{
89
		{
90
			PerformSetValue (value);
90
			int indexOf = listView.InvokeSync (l => l.Columns.IndexOf (columnHeader));
91
92
			if (indexOf < 0 || indexOf >= listViewItem.SubItems.Count)
93
				return;
94
95
			listView.InvokeSync (delegate {
96
				if (indexOf == 0)
97
					listViewItem.Text = value;
98
				else
99
					listViewItem.SubItems [indexOf - 1].Text = value;
100
			});
91
		}
101
		}
92
		
102
		
93
		public bool IsReadOnly {
103
		public bool IsReadOnly {
94
			get { return !listView.LabelEdit; }
104
			get { return listView.InvokeSync (l => !l.LabelEdit); }
95
		}
105
		}
96
		
106
		
97
		public string Value {
107
		public string Value {
98
			get {
108
			get {
99
				int indexOf = listView.Columns.IndexOf (columnHeader);
109
				return listView.InvokeSync (c => {
100
110
					int indexOf = c.Columns.IndexOf (columnHeader);
101
				if (indexOf < 0 || indexOf >= listViewItem.SubItems.Count)
111
	
102
					return string.Empty;
112
					if (indexOf < 0 || indexOf >= listViewItem.SubItems.Count)
103
				else
113
						return string.Empty;
104
					return listViewItem.SubItems [indexOf].Text;
114
					else
115
						return listViewItem.SubItems [indexOf].Text;
116
				});
105
			}
117
			}
106
		}
118
		}
107
		
119
		
108
		#endregion
120
		#endregion
109
110
		#region Private Methods
111
112
		private void PerformSetValue (string value)
113
		{
114
			int indexOf = listView.Columns.IndexOf (columnHeader);
115
116
			if (indexOf < 0 || indexOf >= listViewItem.SubItems.Count)
117
				return;
118
			
119
			if (listView.InvokeRequired == true) {
120
				listView.BeginInvoke (new ListItemSetValueDelegate (PerformSetValue),
121
				                      new object [] { value } );
122
				return;
123
			}
124
125
			if (indexOf == 0)
126
				listViewItem.Text = value;
127
			else
128
				listViewItem.SubItems [indexOf - 1].Text = value;
129
		}
130
131
		#endregion
132
		
121
		
133
		#region Private Fields
122
		#region Private Fields
134
123
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/ListItemEmbeddedImageProviderBehavior.cs (-19 / +24 lines)
Lines 25-31 Link Here
25
25
26
using System;
26
using System;
27
using System.Windows;
27
using System.Windows;
28
using System.Windows.Forms;
28
using SWF = System.Windows.Forms;
29
using Mono.UIAutomation.Bridge;
29
using Mono.UIAutomation.Bridge;
30
using System.Windows.Automation;
30
using System.Windows.Automation;
31
using Mono.UIAutomation.Winforms;
31
using Mono.UIAutomation.Winforms;
Lines 63-90 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
63
			get {
63
			get {
64
				ListViewProvider.ListViewListItemProvider itemProvider 
64
				ListViewProvider.ListViewListItemProvider itemProvider 
65
					= (ListViewProvider.ListViewListItemProvider) Provider;
65
					= (ListViewProvider.ListViewListItemProvider) Provider;
66
				ListViewItem item = itemProvider.ObjectItem as ListViewItem;
66
				SWF.ListViewItem item = itemProvider.ObjectItem as SWF.ListViewItem;
67
				if (item == null || item.ListView == null 
68
				    || (item.ImageIndex == -1 && item.ImageKey == string.Empty))
69
					return System.Windows.Rect.Empty;
70
71
				ImageList imageList = null;
72
				if (item.ListView.View == View.LargeIcon)
73
					imageList = item.ListView.LargeImageList;
74
				else
75
					imageList = item.ListView.SmallImageList;
76
67
77
				if (imageList == null)
68
				if (item == null || item.ListView == null)
78
					return System.Windows.Rect.Empty;
69
					return System.Windows.Rect.Empty;
79
70
80
				Rect rect = itemProvider.BoundingRectangle;
71
				return item.ListView.InvokeSync (c => {
81
				rect.Width = imageList.ImageSize.Width;
72
				    if (item.ImageIndex == -1 && item.ImageKey == string.Empty)
82
				rect.Height = imageList.ImageSize.Height;
73
						return System.Windows.Rect.Empty;
83
84
				if (itemProvider.CheckboxProvider != null) 
85
					rect.X += itemProvider.CheckboxProvider.BoundingRectangle.Width;
86
74
87
				return rect;
75
					SWF.ImageList imageList = null;
76
					if (c.View == SWF.View.LargeIcon)
77
						imageList = c.LargeImageList;
78
					else
79
						imageList = c.SmallImageList;
80
	
81
					if (imageList == null)
82
						return System.Windows.Rect.Empty;
83
	
84
					Rect rect = itemProvider.BoundingRectangle;
85
					rect.Width = imageList.ImageSize.Width;
86
					rect.Height = imageList.ImageSize.Height;
87
	
88
					if (itemProvider.CheckboxProvider != null) 
89
						rect.X += itemProvider.CheckboxProvider.BoundingRectangle.Width;
90
	
91
					return rect;
92
				});
88
			}
93
			}
89
		}
94
		}
90
		
95
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/ListItemGridItemProviderBehavior.cs (-32 / +38 lines)
Lines 107-118 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
107
			get { 
107
			get { 
108
				SWF.ListView view = (SWF.ListView) viewProvider.Control;
108
				SWF.ListView view = (SWF.ListView) viewProvider.Control;
109
109
110
				if (view.View == SWF.View.List) //From Top to Bottom
110
				return view.InvokeSync (c => {
111
					return MaxRows == 0 ? -1 : IndexOf % MaxRows;
111
					if (c.View == SWF.View.List) //From Top to Bottom
112
				else if (view.View == SWF.View.Details)
112
						return MaxRows == 0 ? -1 : IndexOf % MaxRows;
113
					return itemProvider.Index;
113
					else if (c.View == SWF.View.Details)
114
				else //From Left to Right
114
						return itemProvider.Index;
115
					else //From Left to Right
115
					return MaxColumns == 0 ? -1 : IndexOf / MaxColumns;
116
					return MaxColumns == 0 ? -1 : IndexOf / MaxColumns;
117
				});
116
			}
118
			}
117
		}
119
		}
118
		
120
		
Lines 120-131 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
120
			get {
122
			get {
121
				SWF.ListView view = (SWF.ListView) viewProvider.Control;
123
				SWF.ListView view = (SWF.ListView) viewProvider.Control;
122
124
123
				if (view.View == SWF.View.List) //From Top to Bottom
125
				return view.InvokeSync (c => {
124
					return MaxRows == 0 ? -1 : IndexOf / MaxRows;
126
					if (c.View == SWF.View.List) //From Top to Bottom
125
				else if (view.View == SWF.View.Details) // Always 0
127
						return MaxRows == 0 ? -1 : IndexOf / MaxRows;
126
					return 0;
128
					else if (c.View == SWF.View.Details) // Always 0
127
				else //From Left to Right
129
						return 0;
128
					return IndexOf - (Row * MaxColumns); 
130
					else //From Left to Right
131
					return IndexOf - (Row * MaxColumns);
132
				});
129
			}
133
			}
130
		}
134
		}
131
		
135
		
Lines 149-184 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
149
			get {
153
			get {
150
				SWF.ListViewItem item = (SWF.ListViewItem) itemProvider.ObjectItem;
154
				SWF.ListViewItem item = (SWF.ListViewItem) itemProvider.ObjectItem;
151
155
152
				if (view.View == SWF.View.List || view.ShowGroups == false)
156
				return view.InvokeSync (c => {
153
					return view.Items.IndexOf (item);
157
					if (c.View == SWF.View.List || c.ShowGroups == false)
154
158
						return c.Items.IndexOf (item);
155
				if (viewProvider.IsDefaultGroup (group) == true) {					
159
	
156
					int indexOf = 0;
160
					if (viewProvider.IsDefaultGroup (group) == true) {					
157
					bool found = false;					
161
						int indexOf = 0;
158
					
162
						bool found = false;					
159
					//TODO: Is this OK??
163
						
160
					for (int index = 0; index < view.Items.Count; index++) {
164
						//TODO: Is this OK??
161
						if (view.Items [index].Group == null) {
165
						for (int index = 0; index < c.Items.Count; index++) {
162
							if (view.Items [index] == item) {
166
							if (c.Items [index].Group == null) {
163
								found = true;
167
								if (c.Items [index] == item) {
164
								break;
168
									found = true;
169
									break;
170
								}
171
								indexOf++;
165
							}
172
							}
166
							indexOf++;
167
						}
173
						}
168
					}
174
						
169
					
175
						return found == false ? -1 : indexOf;
170
					return found == false ? -1 : indexOf;
176
					} else
171
				} else
177
						return group.Items.IndexOf (item);
172
					return group.Items.IndexOf (item);
178
				});
173
			}
179
			}
174
		}
180
		}
175
		
181
		
176
		private int MaxColumns {
182
		private int MaxColumns {
177
			get { return view.UIAColumns; }
183
			get { return view.InvokeSync (v => v.UIAColumns); }
178
		}
184
		}
179
185
180
		private int MaxRows {
186
		private int MaxRows {
181
			get { return view.UIARows; }
187
			get { return view.InvokeSync (v => v.UIARows); }
182
		}
188
		}
183
		
189
		
184
		#endregion
190
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/ListItemValueProviderBehavior.cs (-17 / +4 lines)
Lines 86-96 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
86
			if (IsReadOnly == true)
86
			if (IsReadOnly == true)
87
				throw new ElementNotEnabledException ();
87
				throw new ElementNotEnabledException ();
88
88
89
			PerformSetValue (value);
89
			viewItem.ListView.InvokeSync (delegate {
90
				viewItem.Text = value;
91
			});
90
		}
92
		}
91
		
93
		
92
		public bool IsReadOnly {
94
		public bool IsReadOnly {
93
			get { return viewItem.ListView.LabelEdit == false; }
95
			get { return viewItem.ListView.InvokeSync (v => !v.LabelEdit); }
94
		}
96
		}
95
		
97
		
96
		public string Value {
98
		public string Value {
Lines 98-118 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
98
		}
100
		}
99
		
101
		
100
		#endregion
102
		#endregion
101
102
		#region Private Methods
103
104
		private void PerformSetValue (string value)
105
		{
106
			if (viewItem.ListView.InvokeRequired == true) {
107
				viewItem.ListView.BeginInvoke (new ListItemSetValueDelegate (PerformSetValue),
108
				                               new object [] { value } );
109
				return;
110
			}
111
			
112
			viewItem.Text = value;
113
		}
114
115
		#endregion
116
		
103
		
117
		#region Private Fields
104
		#region Private Fields
118
		
105
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ListView/SelectionProviderBehavior.cs (-1 / +4 lines)
Lines 93-99 namespace Mono.UIAutomation.Winforms.Behaviors.ListView Link Here
93
		#region ISelectionProvider Members
93
		#region ISelectionProvider Members
94
94
95
		public bool CanSelectMultiple {
95
		public bool CanSelectMultiple {
96
			get { return ((SWF.ListView) Provider.Control).MultiSelect; }
96
			get {
97
				SWF.ListView listview = (SWF.ListView) Provider.Control;
98
				return listview.InvokeSync (c => c.MultiSelect);
99
			}
97
		}
100
		}
98
101
99
		public bool IsSelectionRequired {
102
		public bool IsSelectionRequired {
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/MaskedTextBox/InsertDeleteTextProviderBehavior.cs (-81 / +72 lines)
Lines 64-166 namespace Mono.UIAutomation.Winforms.Behaviors.MaskedTextBox Link Here
64
		// rejected as it contains too many characters.
64
		// rejected as it contains too many characters.
65
		public void InsertText (string str, ref int position)
65
		public void InsertText (string str, ref int position)
66
		{
66
		{
67
			if (maskedTextBox.ReadOnly)
67
			if (maskedTextBox.InvokeSync (m => m.ReadOnly))
68
				throw new ElementNotEnabledException ();
68
				throw new ElementNotEnabledException ();
69
69
			
70
			if (Provider.Control.InvokeRequired) {
70
			int newPosition = position;
71
				object[] args = new object[] { str, position };
71
72
				Provider.Control.BeginInvoke (new InsertTextDelegate (InsertText), args);
72
			maskedTextBox.InvokeSync (delegate {
73
				position = (int) args[1];
73
74
				return;
74
				System.ComponentModel.MaskedTextProvider prov
75
			}
75
					= maskedTextBox.MaskedTextProvider;
76
76
	
77
			System.ComponentModel.MaskedTextProvider prov
77
				string text = prov.ToDisplayString ();
78
				= maskedTextBox.MaskedTextProvider;
78
	
79
79
				int offset = newPosition;
80
			string text = prov.ToDisplayString ();
80
				for (int i = 0; i < str.Length; i++) {
81
81
					int localOffset = offset;
82
			int offset = position;
82
					
83
			for (int i = 0; i < str.Length; i++) {
83
					// skip over an unavailable slot if we see one
84
				int localOffset = offset;
84
					bool reachedBounds = false;
85
				
85
					while (!prov.IsEditPosition (i + localOffset)) {
86
				// skip over an unavailable slot if we see one
86
						localOffset++;
87
				bool reachedBounds = false;
87
						if (i + localOffset >= prov.Length) {
88
				while (!prov.IsEditPosition (i + localOffset)) {
88
							reachedBounds = true;
89
					localOffset++;
89
							break;
90
					if (i + localOffset >= prov.Length) {
90
						}
91
						reachedBounds = true;
91
					}
92
	
93
					if (reachedBounds)
92
						break;
94
						break;
95
	
96
					// There is already a character here, so while
97
					// the GUI will actually move this character
98
					// over, we cannot as there are _many, many_
99
					// edge cases that we cannot handle.
100
					// Instead, we skip over the character.
101
					if (!prov.IsAvailablePosition (i + localOffset)) {
102
						// Make sure offset is correct for the
103
						// next iteration
104
						offset = localOffset;
105
						continue;
93
					}
106
					}
94
				}
107
	
95
108
					// The correct value of position is equal to
96
				if (reachedBounds)
109
					// the localOffset of the first character.
97
					break;
110
					//
98
111
					// This check needs to be done after
99
				// There is already a character here, so while
112
					// IsAvailablePosition in case we are trying to
100
				// the GUI will actually move this character
113
					// insert into a place that already has a
101
				// over, we cannot as there are _many, many_
114
					// character.
102
				// edge cases that we cannot handle.
115
					if (offset != localOffset && i == 0)
103
				// Instead, we skip over the character.
116
						newPosition = localOffset;
104
				if (!prov.IsAvailablePosition (i + localOffset)) {
117
					
105
					// Make sure offset is correct for the
106
					// next iteration
107
					offset = localOffset;
118
					offset = localOffset;
108
					continue;
119
	
120
					text = text.Substring (0, i + offset)
121
						+ str[i] + text.Substring (i + offset + 1);
109
				}
122
				}
110
123
111
				// The correct value of position is equal to
124
				maskedTextBox.Text = text;
112
				// the localOffset of the first character.
125
			});
113
				//
126
			
114
				// This check needs to be done after
127
			position = newPosition;
115
				// IsAvailablePosition in case we are trying to
116
				// insert into a place that already has a
117
				// character.
118
				if (offset != localOffset && i == 0)
119
					position = localOffset;
120
				
121
				offset = localOffset;
122
123
				text = text.Substring (0, i + offset)
124
					+ str[i] + text.Substring (i + offset + 1);
125
			}
126
127
			maskedTextBox.Text = text;
128
		}
128
		}
129
129
130
		public void DeleteText (int start, int end)
130
		public void DeleteText (int start, int end)
131
		{
131
		{
132
			if (maskedTextBox.ReadOnly)
132
			if (maskedTextBox.InvokeSync (m => m.ReadOnly))
133
				throw new ElementNotEnabledException ();
133
				throw new ElementNotEnabledException ();
134
134
135
			if (Provider.Control.InvokeRequired) {
135
			maskedTextBox.InvokeSync (delegate {
136
				Provider.Control.BeginInvoke (new DeleteTextDelegate (DeleteText),
136
				// MaskedTextProvider.RemoveAt does not work for this.
137
				                              new object [] {start, end});
137
				System.ComponentModel.MaskedTextProvider prov
138
				return;
138
					= maskedTextBox.MaskedTextProvider;
139
			}
139
	
140
140
				string text = prov.ToDisplayString ();
141
			// MaskedTextProvider.RemoveAt does not work for this.
141
				for (int i = start; i < end; i++) {
142
			System.ComponentModel.MaskedTextProvider prov
142
					if (!prov.IsEditPosition (i)
143
				= maskedTextBox.MaskedTextProvider;
143
					    || prov.IsAvailablePosition (i))
144
144
						continue;
145
			string text = prov.ToDisplayString ();
145
	
146
			for (int i = start; i < end; i++) {
146
					text = text.Substring (0, i) + prov.PromptChar
147
				if (!prov.IsEditPosition (i)
147
						+ text.Substring (i + 1);
148
				    || prov.IsAvailablePosition (i))
148
				}
149
					continue;
150
151
				text = text.Substring (0, i) + prov.PromptChar
152
					+ text.Substring (i + 1);
153
			}
154
149
155
			maskedTextBox.Text = text;
150
				maskedTextBox.Text = text;
151
			});
156
		}
152
		}
157
#endregion
153
#endregion
158
154
159
#region Private Delegates
160
		private delegate void InsertTextDelegate (string str, ref int position);
161
		private delegate void DeleteTextDelegate (int start, int end);
162
#endregion
163
164
#region Private Fields
155
#region Private Fields
165
		private SWF.MaskedTextBox maskedTextBox;
156
		private SWF.MaskedTextBox maskedTextBox;
166
#endregion
157
#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/MonthCalendar/ButtonInvokeProviderBehavior.cs (-8 / +10 lines)
Lines 72-90 namespace Mono.UIAutomation.Winforms.Behaviors.MonthCalendar Link Here
72
		
72
		
73
		public void Invoke ()
73
		public void Invoke ()
74
		{
74
		{
75
			if (!Provider.Control.Enabled)
75
			if (Provider.Control.InvokeSync (c => !c.Enabled))
76
				throw new ElementNotEnabledException ();
76
				throw new ElementNotEnabledException ();
77
77
78
			SWF.MonthCalendar calendar
78
			SWF.MonthCalendar calendar
79
				= (SWF.MonthCalendar) provider.DataGridProvider.Control;
79
				= (SWF.MonthCalendar) provider.DataGridProvider.Control;
80
80
81
			int offset = 1;
81
			calendar.InvokeSync (delegate {
82
			if (provider.Direction
82
				int offset = 1;
83
				== MonthCalendarButtonProvider.ButtonDirection.Back) {
83
				if (provider.Direction
84
				offset = -1;
84
					== MonthCalendarButtonProvider.ButtonDirection.Back) {
85
			}
85
					offset = -1;
86
86
				}
87
			calendar.CurrentMonth = calendar.CurrentMonth.AddMonths (offset);
87
	
88
				calendar.CurrentMonth = calendar.CurrentMonth.AddMonths (offset);
89
			});
88
		}
90
		}
89
		
91
		
90
#endregion	
92
#endregion	
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/NumericUpDown/EditableRangeProviderBehavior.cs (-21 / +14 lines)
Lines 65-92 namespace Mono.UIAutomation.Winforms.Behaviors.NumericUpDown Link Here
65
		#region IEditableRange Members
65
		#region IEditableRange Members
66
		public void BeginEdit (string text)
66
		public void BeginEdit (string text)
67
		{
67
		{
68
			if (numericUpDown.ReadOnly)
68
			if (numericUpDown.InvokeSync (n => numericUpDown.ReadOnly))
69
				throw new ElementNotEnabledException ();
69
				throw new ElementNotEnabledException ();
70
			if (numericUpDown.InvokeRequired == true) {
70
71
				numericUpDown.BeginInvoke (new NumericUpDownBeginEditDelegate (BeginEdit),
71
			numericUpDown.InvokeSync (delegate {
72
				                           new object [] { text });
72
				numericUpDown.txtView.Text = text;
73
				return;
73
			});
74
			}
75
			numericUpDown.txtView.Text = text;
76
		}
74
		}
77
75
78
		public void CommitEdit ()
76
		public void CommitEdit ()
79
		{
77
		{
80
			if (numericUpDown.InvokeRequired) {
78
			numericUpDown.InvokeSync (delegate {
81
				numericUpDown.BeginInvoke (new NumericUpDownCommitEditDelegate (CommitEdit));
79
				decimal value = decimal.Parse (numericUpDown.Text);
82
				return;
80
				if (value < numericUpDown.Minimum)
83
			}
81
					value = numericUpDown.Minimum;
84
			decimal value = decimal.Parse (numericUpDown.Text);
82
				if (value > numericUpDown.Maximum)
85
			if (value < numericUpDown.Minimum)
83
					value = numericUpDown.Maximum;
86
				value = numericUpDown.Minimum;
84
				numericUpDown.Value = value;
87
			if (value > numericUpDown.Maximum)
85
			});
88
				value = numericUpDown.Maximum;
89
			numericUpDown.Value = value;
90
		}
86
		}
91
		#endregion
87
		#endregion
92
88
Lines 95-102 namespace Mono.UIAutomation.Winforms.Behaviors.NumericUpDown Link Here
95
		private SWF.NumericUpDown numericUpDown;
91
		private SWF.NumericUpDown numericUpDown;
96
		
92
		
97
		#endregion
93
		#endregion
98
	}
94
	}		
99
100
	delegate void NumericUpDownBeginEditDelegate (string value);
101
	delegate void NumericUpDownCommitEditDelegate ();		
102
}
95
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/NumericUpDown/RangeValueProviderBehavior.cs (-23 / +6 lines)
Lines 107-132 namespace Mono.UIAutomation.Winforms.Behaviors.NumericUpDown Link Here
107
		#region IRangeValueProvider Members
107
		#region IRangeValueProvider Members
108
	
108
	
109
		public bool IsReadOnly {
109
		public bool IsReadOnly {
110
			get { return numericUpDown.ReadOnly; }
110
			get { return numericUpDown.InvokeSync (c => c.ReadOnly); }
111
		}
111
		}
112
		
112
		
113
		public double Minimum {
113
		public double Minimum {
114
			get { return (double) numericUpDown.Minimum; }
114
			get { return numericUpDown.InvokeSync (c => (double) c.Minimum); }
115
		}
115
		}
116
		
116
		
117
		public double Maximum {
117
		public double Maximum {
118
			get { return (double) numericUpDown.Maximum; }
118
			get { return numericUpDown.InvokeSync (c => (double) c.Maximum); }
119
		}
119
		}
120
		
120
		
121
		public double LargeChange {
121
		public double LargeChange {
122
			get { return double.NaN; }
122
			get { return double.NaN; }
123
		}
123
		}
124
		public double SmallChange {
124
		public double SmallChange {
125
			get { return (double) numericUpDown.Increment; }
125
			get { return numericUpDown.InvokeSync (c => (double) c.Increment); }
126
		}
126
		}
127
127
128
		public double Value {
128
		public double Value {
129
			get { return (double) numericUpDown.Value; }
129
			get { return numericUpDown.InvokeSync (c => (double) c.Value); }
130
		}
130
		}
131
		
131
		
132
		public void SetValue (double value)
132
		public void SetValue (double value)
Lines 134-155 namespace Mono.UIAutomation.Winforms.Behaviors.NumericUpDown Link Here
134
			if (value < Minimum || value > Maximum)
134
			if (value < Minimum || value > Maximum)
135
				throw new ArgumentOutOfRangeException ();
135
				throw new ArgumentOutOfRangeException ();
136
136
137
			PerformSetValue ((decimal) value);
137
			numericUpDown.InvokeSync (delegate { numericUpDown.Value = (decimal) value; });
138
		}
139
140
		#endregion
141
		
142
143
		#region Private Methods
144
		
145
		private void PerformSetValue (decimal value) 
146
		{
147
			if (numericUpDown.InvokeRequired == true) {
148
				numericUpDown.BeginInvoke (new NumericUpDownSetValueDelegate (PerformSetValue),
149
				                           new object [] { value });
150
				return;
151
			}
152
			numericUpDown.Value = value;
153
		}
138
		}
154
			
139
			
155
		#endregion
140
		#endregion
Lines 160-165 namespace Mono.UIAutomation.Winforms.Behaviors.NumericUpDown Link Here
160
		
145
		
161
		#endregion
146
		#endregion
162
	}
147
	}
163
	
164
	delegate void NumericUpDownSetValueDelegate (decimal value);
165
}
148
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/PictureBox/EmbeddedImageProviderBehavior.cs (-14 / +19 lines)
Lines 63-83 namespace Mono.UIAutomation.Winforms.Behaviors.PictureBox Link Here
63
#region IEmbeddedImageProvider Interface
63
#region IEmbeddedImageProvider Interface
64
		public Rect Bounds {
64
		public Rect Bounds {
65
			get {
65
			get {
66
				if (control.Image == null)
66
				return control.InvokeSync (c => {
67
					return Rect.Empty;
67
						if (c.Image == null)
68
				GraphicsUnit unit = GraphicsUnit.Pixel;
68
							return Rect.Empty;
69
				RectangleF rectF = control.Image.GetBounds (ref unit);
70
				if (unit != GraphicsUnit.Pixel)
71
					return Rect.Empty;
72
69
73
				System.Windows.Rect ret
70
						GraphicsUnit unit = GraphicsUnit.Pixel;
74
					= (System.Windows.Rect) Provider.GetPropertyValue (
71
						RectangleF rectF = c.Image.GetBounds (ref unit);
75
						AutomationElementIdentifiers.BoundingRectangleProperty.Id);
72
76
				ret.X += rectF.X;
73
						if (unit != GraphicsUnit.Pixel)
77
				ret.Y += rectF.Y;
74
							return Rect.Empty;
78
				ret.Width = rectF.Width;
75
79
				ret.Height = rectF.Height;
76
						System.Windows.Rect ret
80
				return ret;
77
							= (System.Windows.Rect) Provider.GetPropertyValue (
78
								AutomationElementIdentifiers.BoundingRectangleProperty.Id);
79
						ret.X += rectF.X;
80
						ret.Y += rectF.Y;
81
						ret.Width = rectF.Width;
82
						ret.Height = rectF.Height;
83
						return ret;
84
					}
85
				);
81
			}
86
			}
82
		}
87
		}
83
88
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/PopupButtonPanel/InvokeProviderBehavior.cs (-17 / +3 lines)
Lines 80-106 namespace Mono.UIAutomation.Winforms.Behaviors.PopupButtonPanel Link Here
80
		
80
		
81
		public virtual void Invoke ()
81
		public virtual void Invoke ()
82
		{
82
		{
83
			if (Provider.Control.Enabled == false)
83
			if (Provider.Control.InvokeSync (c => !c.Enabled))
84
				throw new ElementNotEnabledException ();
84
				throw new ElementNotEnabledException ();
85
85
86
			PerformClick ();
86
			Provider.Control.InvokeSync (delegate { button.PerformClick (); });
87
		}
87
		}
88
		
88
	
89
		#endregion	
89
		#endregion	
90
		
91
		#region Private Methods
92
		
93
		private void PerformClick ()
94
		{
95
			if (Provider.Control.InvokeRequired == true) {
96
				Provider.Control.BeginInvoke (new SWF.MethodInvoker (PerformClick));
97
				return;
98
			}
99
			button.PerformClick ();
100
		}
101
		
102
		#endregion
103
		
104
	}
90
	}
105
91
106
}
92
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ProgressBar/RangeValueProviderBehavior.cs (-8 / +4 lines)
Lines 101-107 namespace Mono.UIAutomation.Winforms.Behaviors.ProgressBar Link Here
101
		#region IRangeValueProvider Members
101
		#region IRangeValueProvider Members
102
		
102
		
103
		public double Value {
103
		public double Value {
104
			get { return (double) progressBar.Value; }
104
			get { return progressBar.InvokeSync (p => p.Value); }
105
		}
105
		}
106
		
106
		
107
		public bool IsReadOnly {
107
		public bool IsReadOnly {
Lines 129-141 namespace Mono.UIAutomation.Winforms.Behaviors.ProgressBar Link Here
129
			if (value < Minimum || value > Maximum)
129
			if (value < Minimum || value > Maximum)
130
				throw new ArgumentOutOfRangeException ();
130
				throw new ArgumentOutOfRangeException ();
131
			
131
			
132
			if (progressBar.InvokeRequired == true) {
132
			progressBar.InvokeSync (delegate {
133
				progressBar.BeginInvoke (new PerformSetValueDelegate (SetValue),
133
				progressBar.Value = (int) value;
134
				                         new object [] { value });
134
			});
135
				return;
136
			}
137
			
138
			progressBar.Value = (int) value;
139
		}
135
		}
140
		
136
		
141
		#endregion
137
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/PropertyGrid/ListItemChildValueProviderBeahvior.cs (-16 / +2 lines)
Lines 83-89 namespace Mono.UIAutomation.Winforms.Behaviors.PropertyGrid Link Here
83
			if (IsReadOnly)
83
			if (IsReadOnly)
84
				throw new ElementNotEnabledException ();
84
				throw new ElementNotEnabledException ();
85
85
86
			PerformSetValue (value);
86
			provider.ListItemProvider.Value = value;
87
		}
87
		}
88
88
89
		public bool IsReadOnly {
89
		public bool IsReadOnly {
Lines 95-116 namespace Mono.UIAutomation.Winforms.Behaviors.PropertyGrid Link Here
95
		}
95
		}
96
#endregion
96
#endregion
97
97
98
#region Private Members
98
#region Private Fields
99
		private void PerformSetValue (string value)
100
		{
101
			if (provider.ListItemProvider.PropertyGridView.InvokeRequired) {
102
				provider.ListItemProvider.PropertyGridView.BeginInvoke (
103
					new SetValueDelegate (PerformSetValue),
104
					new object [] { value });
105
				return;
106
			}
107
108
			provider.ListItemProvider.Value = value;
109
		}
110
111
		private PropertyGridListItemValueProvider provider;
99
		private PropertyGridListItemValueProvider provider;
112
113
		private delegate void SetValueDelegate (string val);
114
#endregion
100
#endregion
115
	}
101
	}
116
}
102
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/RadioButton/SelectionItemProviderBehavior.cs (-17 / +3 lines)
Lines 120-126 namespace Mono.UIAutomation.Winforms.Behaviors.RadioButton Link Here
120
120
121
		public void Select ()
121
		public void Select ()
122
		{
122
		{
123
			PerformSelectDelegate (radioButton);
123
			radioButton.InvokeSync (delegate {
124
				radioButton.Checked = true;
125
			});
124
		}
126
		}
125
127
126
		public IRawElementProviderSimple SelectionContainer {
128
		public IRawElementProviderSimple SelectionContainer {
Lines 134-154 namespace Mono.UIAutomation.Winforms.Behaviors.RadioButton Link Here
134
		}
136
		}
135
137
136
#endregion
138
#endregion
137
		
138
		#region Private Methods
139
		
140
		private void PerformSelectDelegate (SWF.RadioButton radioButton)
141
		{
142
			if (radioButton.InvokeRequired == true) {
143
				radioButton.BeginInvoke (new PerformSelectDelegate (PerformSelectDelegate),
144
				                         new object [] { radioButton });
145
				return;
146
			}
147
			radioButton.Checked = true;
148
		}
149
		
150
		#endregion 
151
	}
139
	}
152
	
153
	delegate void PerformSelectDelegate (SWF.RadioButton radioButton);
154
}
140
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ScrollBar/ButtonInvokeProviderBehavior.cs (-19 / +5 lines)
Lines 84-90 namespace Mono.UIAutomation.Winforms.Behaviors.ScrollBar Link Here
84
		
84
		
85
		public void Invoke ()
85
		public void Invoke ()
86
		{
86
		{
87
			if (!Provider.Control.Enabled)
87
			if (!Provider.Control.InvokeSync (c => c.Enabled))
88
				throw new ElementNotEnabledException ();
88
				throw new ElementNotEnabledException ();
89
89
90
			string methodName = string.Empty;
90
			string methodName = string.Empty;
Lines 103-135 namespace Mono.UIAutomation.Winforms.Behaviors.ScrollBar Link Here
103
			                                                          | BindingFlags.NonPublic
103
			                                                          | BindingFlags.NonPublic
104
			                                                          | BindingFlags.Instance);
104
			                                                          | BindingFlags.Instance);
105
			if (methodInfo != null) {
105
			if (methodInfo != null) {
106
				invokeMethod
106
				Action<SWF.ScrollBar> invokeMethod
107
					= (Action<SWF.ScrollBar>) Delegate.CreateDelegate (typeof (Action<SWF.ScrollBar>), 
107
					= (Action<SWF.ScrollBar>) Delegate.CreateDelegate (typeof (Action<SWF.ScrollBar>), 
108
					                                                   methodInfo);
108
					                                                   methodInfo);
109
				PerformScrollBarButtonClick ();
109
				provider.ScrollBarContainer.InvokeSync (delegate {
110
					invokeMethod (provider.ScrollBarContainer);
111
				});
110
			}
112
			}
111
		}
113
		}
112
		
114
		
113
		#endregion	
115
		#endregion	
114
		
116
		
115
		#region Private Methods
116
		
117
		private void PerformScrollBarButtonClick ()
118
		{
119
	        if (provider.ScrollBarContainer.InvokeRequired == true) {
120
	            provider.ScrollBarContainer.BeginInvoke (new SWF.MethodInvoker (PerformScrollBarButtonClick));
121
	            return;
122
	        }
123
			
124
			invokeMethod (provider.ScrollBarContainer);
125
			invokeMethod = null;
126
		}
127
		
128
		#endregion
129
		
130
		#region Private Fields
117
		#region Private Fields
131
		
118
		
132
		private Action<SWF.ScrollBar> invokeMethod;
133
		private ScrollBarProvider.ScrollBarButtonProvider provider;
119
		private ScrollBarProvider.ScrollBarButtonProvider provider;
134
120
135
		#endregion
121
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ScrollBar/RangeValueProviderBehavior.cs (-23 / +11 lines)
Lines 112-159 namespace Mono.UIAutomation.Winforms.Behaviors.ScrollBar Link Here
112
			if (value < Minimum || value > Maximum)
112
			if (value < Minimum || value > Maximum)
113
				throw new ArgumentOutOfRangeException ();
113
				throw new ArgumentOutOfRangeException ();
114
			
114
			
115
			PerformSetValue ((int) value);
115
			scrollbar.InvokeSync (delegate {
116
				scrollbar.Value = (int) value;
117
			});
116
		}
118
		}
117
		
119
		
118
		public bool IsReadOnly {
120
		public bool IsReadOnly {
119
			get { return scrollbar.Enabled == false || scrollbar.Visible == false; }
121
			get {
122
				return scrollbar.InvokeSync (s => !s.Enabled || !s.Visible);
123
			}
120
		}
124
		}
121
		
125
		
122
		public double LargeChange {
126
		public double LargeChange {
123
			get { return scrollbar.LargeChange; }
127
			get { return scrollbar.InvokeSync (s => s.LargeChange); }
124
		}
128
		}
125
		
129
		
126
		public double Maximum {
130
		public double Maximum {
127
			get { return scrollbar.Maximum; }
131
			get { return scrollbar.InvokeSync (s => s.Maximum); }
128
		}
132
		}
129
		
133
		
130
		public double Minimum {
134
		public double Minimum {
131
			get { return scrollbar.Minimum; }
135
			get { return scrollbar.InvokeSync (s => s.Minimum); }
132
		}
136
		}
133
		
137
		
134
		public double SmallChange {
138
		public double SmallChange {
135
			get { return scrollbar.SmallChange; }
139
			get { return scrollbar.InvokeSync (s => s.SmallChange); }
136
		}
140
		}
137
		
141
		
138
		public double Value {
142
		public double Value {
139
			get { return scrollbar.Value; }
143
			get { return scrollbar.InvokeSync (s => s.Value); }
140
		}
144
		}
141
		
145
		
142
		#endregion 
146
		#endregion 
143
		
144
		#region Private Methods
145
		
146
		private void PerformSetValue (int value)
147
		{
148
			if (scrollbar.InvokeRequired == true) {
149
				scrollbar.BeginInvoke (new PerformSetValueDelegate (PerformSetValue),
150
				                       new object [] { value });
151
				return;
152
			}
153
			scrollbar.Value = value;
154
		}
155
		
156
		#endregion
157
147
158
		#region Private Fields
148
		#region Private Fields
159
149
Lines 161-166 namespace Mono.UIAutomation.Winforms.Behaviors.ScrollBar Link Here
161
151
162
		#endregion
152
		#endregion
163
	}
153
	}
164
	
165
	delegate void PerformSetValueDelegate (int value);
166
}
154
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/SplitContainer/DockProviderBehavior.cs (-10 / +4 lines)
Lines 76-95 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
76
		#region IDockProvider Members
76
		#region IDockProvider Members
77
		
77
		
78
		public DockPosition DockPosition {
78
		public DockPosition DockPosition {
79
			get { return Helper.GetDockPosition (splitContainer.Dock); }
79
			get { return splitContainer.InvokeSync (s => Helper.GetDockPosition (s.Dock)); }
80
		}
80
		}
81
		
81
		
82
		public void SetDockPosition (DockPosition dockPosition)
82
		public void SetDockPosition (DockPosition dockPosition)
83
		{
83
		{
84
			//throw new InvalidOperationException ();
84
			//throw new InvalidOperationException ();
85
			
85
			
86
			if (splitContainer.InvokeRequired == true) {
86
			splitContainer.InvokeSync (delegate {
87
				splitContainer.BeginInvoke (new PerformSetDockPositionDelegate (SetDockPosition),
87
				splitContainer.Dock = Helper.GetDockStyle (dockPosition);
88
				                            new object [] { dockPosition });
88
			});
89
				return;
90
			}
91
			
92
			splitContainer.Dock = Helper.GetDockStyle (dockPosition);
93
		}
89
		}
94
		
90
		
95
		#endregion
91
		#endregion
Lines 100-105 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
100
		
96
		
101
		#endregion
97
		#endregion
102
	}
98
	}
103
	
104
	delegate void PerformSetDockPositionDelegate (DockPosition dockPosition);
105
}
99
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/SplitContainer/RangeValueProviderBehavior.cs (-21 / +7 lines)
Lines 92-102 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
92
			if (value < Minimum || value > Maximum)
92
			if (value < Minimum || value > Maximum)
93
				throw new ArgumentOutOfRangeException ();
93
				throw new ArgumentOutOfRangeException ();
94
			
94
			
95
			PerformSetValue ((int) value);
95
			splitcontainer.InvokeSync (delegate {
96
				splitcontainer.SplitterDistance = (int) value;
97
			});
96
		}
98
		}
97
		
99
		
98
		public bool IsReadOnly {
100
		public bool IsReadOnly {
99
			get { return splitcontainer.Enabled == false || splitcontainer.Visible == false; }
101
			get { return splitcontainer.InvokeSync (s => !s.Enabled || !s.Visible); }
100
		}
102
		}
101
		
103
		
102
		public double LargeChange {
104
		public double LargeChange {
Lines 104-114 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
104
		}
106
		}
105
		
107
		
106
		public double Maximum {
108
		public double Maximum {
107
			get { return splitcontainer.Width - (splitcontainer.SplitterWidth + splitcontainer.Panel2MinSize); }
109
			get { return splitcontainer.InvokeSync (s => s.Width - (s.SplitterWidth + s.Panel2MinSize)); }
108
		}
110
		}
109
		
111
		
110
		public double Minimum {
112
		public double Minimum {
111
			get { return splitcontainer.Panel1MinSize; }
113
			get { return splitcontainer.InvokeSync (s => s.Panel1MinSize); }
112
		}
114
		}
113
		
115
		
114
		public double SmallChange {
116
		public double SmallChange {
Lines 116-139 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
116
		}
118
		}
117
		
119
		
118
		public double Value {
120
		public double Value {
119
			get { return splitcontainer.SplitterDistance; }
121
			get { return splitcontainer.InvokeSync (s => s.SplitterDistance); }
120
		}
122
		}
121
		
123
		
122
		#endregion 
124
		#endregion 
123
		
124
		#region Private Methods
125
		
126
		private void PerformSetValue (int value)
127
		{
128
			if (splitcontainer.InvokeRequired == true) {
129
				splitcontainer.BeginInvoke (new PerformSetValueDelegate (PerformSetValue),
130
				                       new object [] { value });
131
				return;
132
			}
133
			splitcontainer.SplitterDistance = value;
134
		}
135
		
136
		#endregion
137
125
138
		#region Private Fields
126
		#region Private Fields
139
127
Lines 141-146 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
141
129
142
		#endregion
130
		#endregion
143
	}
131
	}
144
	
145
	delegate void PerformSetValueDelegate (int value);
146
}
132
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/SplitContainer/SplitterPanelTransformProviderBehavior.cs (-19 / +8 lines)
Lines 87-98 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
87
		}
87
		}
88
		
88
		
89
		public bool CanResize {
89
		public bool CanResize {
90
			get {
90
			get { return splitContainer.InvokeSync (s => !(s.Panel1Collapsed || s.Panel2Collapsed)); }
91
				if (splitContainer.Panel1Collapsed || splitContainer.Panel2Collapsed)
92
					return false;
93
				else
94
					return true;
95
			}
96
		}
91
		}
97
		
92
		
98
		public bool CanRotate {
93
		public bool CanRotate {
Lines 108-124 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
108
		{
103
		{
109
			if (!CanResize)
104
			if (!CanResize)
110
				throw new InvalidOperationException ();
105
				throw new InvalidOperationException ();
111
			
106
112
			if (splitContainer.InvokeRequired == true) {
107
			splitContainer.InvokeSync (delegate {
113
				splitContainer.BeginInvoke (new PerformResizeDelegate (Resize),
108
				if (splitContainer.Orientation == SWF.Orientation.Horizontal)
114
				                            new object [] { width, height });
109
					splitContainer.Panel1.Width = (int) width;
115
				return;
110
				else
116
			}
111
					splitContainer.Panel1.Width = (int) height;
117
			
112
			});
118
			if (splitContainer.Orientation == SWF.Orientation.Horizontal)
119
				splitContainer.Panel1.Width = (int) width;
120
			else
121
				splitContainer.Panel1.Width = (int) height;
122
		}
113
		}
123
		
114
		
124
		public void Rotate (double degrees)
115
		public void Rotate (double degrees)
Lines 134-139 namespace Mono.UIAutomation.Winforms.Behaviors.SplitContainer Link Here
134
		
125
		
135
		#endregion
126
		#endregion
136
	}
127
	}
137
	
138
	delegate void PerformResizeDelegate (double width, double height);
139
}
128
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/Splitter/DockProviderBehavior.cs (-10 / +4 lines)
Lines 76-82 namespace Mono.UIAutomation.Winforms.Behaviors.Splitter Link Here
76
		#region IDockProvider Members
76
		#region IDockProvider Members
77
		
77
		
78
		public DockPosition DockPosition {
78
		public DockPosition DockPosition {
79
			get { return Helper.GetDockPosition (splitter.Dock); }
79
			get { return splitter.InvokeSync (s => Helper.GetDockPosition (s.Dock)); }
80
		}
80
		}
81
		
81
		
82
		public void SetDockPosition (DockPosition dockPosition)
82
		public void SetDockPosition (DockPosition dockPosition)
Lines 85-97 namespace Mono.UIAutomation.Winforms.Behaviors.Splitter Link Here
85
			    dockPosition == DockPosition.None)
85
			    dockPosition == DockPosition.None)
86
				throw new InvalidOperationException ();
86
				throw new InvalidOperationException ();
87
			
87
			
88
			if (splitter.InvokeRequired == true) {
88
			splitter.InvokeSync (delegate {
89
				splitter.BeginInvoke (new PerformSetDockPositionDelegate (SetDockPosition),
89
				splitter.Dock = Helper.GetDockStyle (dockPosition);
90
				                      new object [] { dockPosition });
90
			});
91
				return;
92
			}
93
			
94
			splitter.Dock = Helper.GetDockStyle (dockPosition);
95
		}
91
		}
96
		
92
		
97
		#endregion
93
		#endregion
Lines 102-107 namespace Mono.UIAutomation.Winforms.Behaviors.Splitter Link Here
102
		
98
		
103
		#endregion
99
		#endregion
104
	}
100
	}
105
	
106
	delegate void PerformSetDockPositionDelegate (DockPosition dockPosition);
107
}
101
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/Splitter/RangeValueProviderBehavior.cs (-21 / +7 lines)
Lines 92-102 namespace Mono.UIAutomation.Winforms.Behaviors.Splitter Link Here
92
			if (value < Minimum || value > Maximum)
92
			if (value < Minimum || value > Maximum)
93
				throw new ArgumentOutOfRangeException ();
93
				throw new ArgumentOutOfRangeException ();
94
			
94
			
95
			PerformSetValue ((int) value);
95
			splitter.InvokeSync (delegate {
96
				splitter.SplitPosition = (int) value;
97
			});
96
		}
98
		}
97
		
99
		
98
		public bool IsReadOnly {
100
		public bool IsReadOnly {
99
			get { return splitter.Enabled == false || splitter.Visible == false; }
101
			get { return splitter.InvokeSync (s => !s.Enabled || !s.Visible); }
100
		}
102
		}
101
		
103
		
102
		public double LargeChange {
104
		public double LargeChange {
Lines 104-114 namespace Mono.UIAutomation.Winforms.Behaviors.Splitter Link Here
104
		}
106
		}
105
		
107
		
106
		public double Maximum {
108
		public double Maximum {
107
			get { return splitter.MaxSize; }
109
			get { return splitter.InvokeSync (s => s.MaxSize); }
108
		}
110
		}
109
		
111
		
110
		public double Minimum {
112
		public double Minimum {
111
			get { return splitter.MinSize; }
113
			get { return splitter.InvokeSync (s => s.MinSize); }
112
		}
114
		}
113
		
115
		
114
		public double SmallChange {
116
		public double SmallChange {
Lines 116-146 namespace Mono.UIAutomation.Winforms.Behaviors.Splitter Link Here
116
		}
118
		}
117
		
119
		
118
		public double Value {
120
		public double Value {
119
			get { return splitter.SplitPosition; }
121
			get { return splitter.InvokeSync (s => s.SplitPosition); }
120
		}
122
		}
121
		
123
		
122
		#endregion 
124
		#endregion 
123
		
125
		
124
		#region Private Methods
125
		
126
		private void PerformSetValue (int value)
127
		{
128
			if (splitter.InvokeRequired == true) {
129
				splitter.BeginInvoke (new PerformSetValueDelegate (PerformSetValue),
130
				                       new object [] { value });
131
				return;
132
			}
133
			splitter.SplitPosition = value;
134
		}
135
		
136
		#endregion
137
138
		#region Private Fields
126
		#region Private Fields
139
127
140
		private SWF.Splitter splitter;
128
		private SWF.Splitter splitter;
141
129
142
		#endregion
130
		#endregion
143
	}
131
	}
144
	
145
	delegate void PerformSetValueDelegate (int value);
146
}
132
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/Splitter/TransformProviderBehavior.cs (-10 / +6 lines)
Lines 98-113 namespace Mono.UIAutomation.Winforms.Behaviors.Splitter Link Here
98
		
98
		
99
		public void Move (double x, double y)
99
		public void Move (double x, double y)
100
		{
100
		{
101
			if (splitter.InvokeRequired == true) {
101
			splitter.InvokeSync (delegate {
102
				splitter.BeginInvoke (new PerformMoveDelegate (Move),
102
				if (splitter.Dock == SWF.DockStyle.Left || splitter.Dock == SWF.DockStyle.Right)
103
				                      new object [] { x, y });
103
					splitter.SplitPosition = (int) x;
104
				return;
104
				else
105
			}
105
					splitter.SplitPosition = (int) y;
106
			
106
			});
107
			if (splitter.Dock == SWF.DockStyle.Left || splitter.Dock == SWF.DockStyle.Right)
108
				splitter.SplitPosition = (int) x;
109
			else
110
				splitter.SplitPosition = (int) y;
111
		}
107
		}
112
		
108
		
113
		public void Resize (double width, double height)
109
		public void Resize (double width, double height)
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/StatusBar/GridProviderBehavior.cs (-1 / +1 lines)
Lines 86-92 namespace Mono.UIAutomation.Winforms.Behaviors.StatusBar Link Here
86
		}
86
		}
87
		
87
		
88
		public int ColumnCount {
88
		public int ColumnCount {
89
			get { return statusBar.Panels.Count; }
89
			get { return statusBar.InvokeSync (s => s.Panels.Count); }
90
		}
90
		}
91
		
91
		
92
		public IRawElementProviderSimple GetItem (int row, int column)
92
		public IRawElementProviderSimple GetItem (int row, int column)
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/StatusBar/StatusBarPanelGridItemProviderBehavior.cs (-1 / +3 lines)
Lines 100-106 namespace Mono.UIAutomation.Winforms.Behaviors.StatusBar Link Here
100
		}
100
		}
101
		
101
		
102
		public int Column {
102
		public int Column {
103
			get { return statusBarPanel.Parent.Panels.IndexOf (statusBarPanel); }
103
			get {
104
				return statusBarPanel.Parent.InvokeSync (s => s.Panels.IndexOf (statusBarPanel));
105
			}
104
		}
106
		}
105
		
107
		
106
		public int RowSpan {
108
		public int RowSpan {
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/StatusStrip/GridProviderBehavior.cs (-1 / +1 lines)
Lines 86-92 namespace Mono.UIAutomation.Winforms.Behaviors.StatusStrip Link Here
86
		}
86
		}
87
		
87
		
88
		public int ColumnCount {
88
		public int ColumnCount {
89
			get { return statusStrip.Items.Count; }
89
			get { return statusStrip.InvokeSync (s => s.Items.Count); }
90
		}
90
		}
91
		
91
		
92
		public IRawElementProviderSimple GetItem (int row, int column)
92
		public IRawElementProviderSimple GetItem (int row, int column)
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TabControl/ScrollProviderBehavior.cs (-29 / +35 lines)
Lines 105-136 namespace Mono.UIAutomation.Winforms.Behaviors.TabControl Link Here
105
105
106
		public double HorizontalScrollPercent {
106
		public double HorizontalScrollPercent {
107
			get {
107
			get {
108
				if (!tabControl.ShowSlider)
108
				return tabControl.InvokeSync (t => {
109
					return ScrollPatternIdentifiers.NoScroll;
109
					if (!t.ShowSlider)
110
				else
110
						return ScrollPatternIdentifiers.NoScroll;
111
					return 100 / tabControl.TabCount;
111
					else
112
						return (double) (100 / t.TabCount);
113
				});
112
			}
114
			}
113
		}
115
		}
114
116
115
		public double HorizontalViewSize {
117
		public double HorizontalViewSize {
116
			get {
118
			get {
117
				if (!tabControl.ShowSlider)
119
				return tabControl.InvokeSync (t => {
118
					return 100;
120
					if (!t.ShowSlider)
119
				else {
121
						return 100;
120
					// FIXME: remove this when we can depend on MWF > 2.4
122
					else {
121
					try {
123
						// FIXME: remove this when we can depend on MWF > 2.4
122
						return Helper.GetPrivateProperty<SWF.TabControl, double> (tabControl,
124
						try {
123
						                                                          "UIAHorizontalViewSize");
125
							return Helper.GetPrivateProperty<SWF.TabControl, double> (t, "UIAHorizontalViewSize");
124
					} catch (NotSupportedException) { }
126
						} catch (NotSupportedException) { }
125
					try {
127
						try {
126
						int leftArea =
128
							int leftArea =
127
							Helper.GetPrivateProperty<SWF.TabControl, int> (tabControl,
129
								Helper.GetPrivateProperty<SWF.TabControl, int> (t, "LeftScrollButtonArea.Left");
128
							                                                "LeftScrollButtonArea.Left");
130
							return (double) leftArea * 100 / t.TabPages [t.TabCount - 1].TabBounds.Right;
129
						return (double) leftArea * 100 / tabControl.TabPages [tabControl.TabCount - 1].TabBounds.Right;
131
						} catch (NotSupportedException) { }
130
					} catch (NotSupportedException) { }
132
						return Double.NaN;
131
					return Double.NaN;
133
132
				}
134
//						return tabControl.UIAHorizontalViewSize;
133
//					return tabControl.UIAHorizontalViewSize;
135
					}
136
				});
134
			}
137
			}
135
		}
138
		}
136
139
Lines 143-149 namespace Mono.UIAutomation.Winforms.Behaviors.TabControl Link Here
143
		}
146
		}
144
147
145
		public bool HorizontallyScrollable {
148
		public bool HorizontallyScrollable {
146
			get { return tabControl.ShowSlider; }
149
			get { return tabControl.InvokeSync (t => t.ShowSlider); }
147
		}
150
		}
148
151
149
		public bool VerticallyScrollable {
152
		public bool VerticallyScrollable {
Lines 167-179 namespace Mono.UIAutomation.Winforms.Behaviors.TabControl Link Here
167
			    horizontalAmount == ScrollAmount.SmallIncrement)
170
			    horizontalAmount == ScrollAmount.SmallIncrement)
168
				throw new ArgumentException ();
171
				throw new ArgumentException ();
169
172
170
			// TODO:
173
/* TODO:
171
//			if (horizontalAmount == ScrollAmount.SmallIncrement)
174
			Helper.SynchronizedSet (tabControl, delegate {
172
//				tabControl.SliderPos += 1;
175
				if (horizontalAmount == ScrollAmount.SmallIncrement)
173
//			else if (horizontalAmount == ScrollAmount.SmallDecrement)
176
					tabControl.SliderPos += 1;
174
//				tabControl.SliderPos -= 1;
177
				else if (horizontalAmount == ScrollAmount.SmallDecrement)
175
//			else
178
					tabControl.SliderPos -= 1;
176
//				return;
179
				else
180
					return;
181
			});
182
*/
177
		}
183
		}
178
184
179
		public void SetScrollPercent (double horizontalPercent, double verticalPercent)
185
		public void SetScrollPercent (double horizontalPercent, double verticalPercent)
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TabPage/SelectionItemProviderBehavior.cs (-6 / +3 lines)
Lines 111-123 namespace Mono.UIAutomation.Winforms.Behaviors.TabPage Link Here
111
			if (IsSelected) {
111
			if (IsSelected) {
112
				return;
112
				return;
113
			}
113
			}
114
			
115
			if (pageProvider.TabControlProvider.Control.InvokeRequired) {
116
				pageProvider.TabControlProvider.Control.BeginInvoke (new MethodInvoker (Select));
117
				return;
118
			}
119
114
120
			pageProvider.TabControlProvider.SelectItem (pageProvider);
115
			pageProvider.TabControlProvider.Control.InvokeSync (delegate {
116
				pageProvider.TabControlProvider.SelectItem (pageProvider);
117
			});
121
		}
118
		}
122
119
123
		public bool IsSelected {
120
		public bool IsSelected {
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TextBox/CaretProviderBehavior.cs (-28 / +41 lines)
Lines 70-100 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
70
			get {
70
			get {
71
				// TODO: This won't scale; we really should
71
				// TODO: This won't scale; we really should
72
				// find a better way of doing it
72
				// find a better way of doing it
73
				SWF.Document document = Document;
73
				return Provider.Control.InvokeSync (c => {
74
				if (document.caret.line.line_no > document.Lines)
74
						SWF.Document document = Document;
75
					return Text.Length;
75
						if (document.caret.line.line_no > document.Lines)
76
				return Document.LineTagToCharIndex
76
							return Text.Length;
77
					(document.caret.line, document.CaretPosition);
77
						return Document.LineTagToCharIndex
78
							(document.caret.line, document.CaretPosition);
79
					}
80
				);
78
			}
81
			}
79
		}
82
		}
80
83
81
		public bool SetCaretOffset (int offset)
84
		public bool SetCaretOffset (int offset)
82
		{
85
		{
83
			if (offset < 0)
86
			return Provider.Control.InvokeSync (c => {
84
				return false;
87
				if (offset < 0)
85
			SWF.Document document = Document;
88
					return false;
86
			int curPos = 0;
89
				SWF.Document document = Document;
87
			SWF.Line line = null;
90
				int curPos = 0;
88
			for (int i = 1;i <= document.Lines;i++) {
91
				SWF.Line line = null;
89
				line = document.GetLine (i);
92
				for (int i = 1;i <= document.Lines;i++) {
90
				int length = line.Text.ToString().Length;
93
					line = document.GetLine (i);
91
				if (curPos + length >= offset) {
94
					int length = line.Text.ToString().Length;
92
					document.PositionCaret (line, offset - curPos);
95
					if (curPos + length >= offset) {
93
					return true;
96
						document.PositionCaret (line, offset - curPos);
97
						return true;
98
					}
99
					curPos += length;
94
				}
100
				}
95
				curPos += length;
101
				return false;
96
			}
102
			});
97
			return false;
98
		}
103
		}
99
104
100
		public string GetSelection (int selectionNum, out int startOffset, out int endOffset)
105
		public string GetSelection (int selectionNum, out int startOffset, out int endOffset)
Lines 104-112 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
104
				return null;
109
				return null;
105
			SWF.TextBoxBase textBoxBase = TextBoxBase;
110
			SWF.TextBoxBase textBoxBase = TextBoxBase;
106
			if (TextBoxBase.Document.SelectionVisible) {
111
			if (TextBoxBase.Document.SelectionVisible) {
107
				startOffset = textBoxBase.SelectionStart;
112
				int sel_start = textBoxBase.InvokeSync (t => t.SelectionStart);
108
				endOffset = startOffset + textBoxBase.SelectionLength;
113
				int sel_len = textBoxBase.InvokeSync (t => t.SelectionLength);
109
				return textBoxBase.Text.Substring (startOffset, endOffset - startOffset);
114
				string text = Text;
115
116
				startOffset = sel_start;
117
				endOffset = startOffset + sel_len;
118
				return text.Substring (startOffset, endOffset - startOffset);
110
			}
119
			}
111
			return null;
120
			return null;
112
		}
121
		}
Lines 124-130 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
124
				if (Provider.Control is SWF.TextBoxBase)
133
				if (Provider.Control is SWF.TextBoxBase)
125
					return (SWF.TextBoxBase)Provider.Control;
134
					return (SWF.TextBoxBase)Provider.Control;
126
				else if (Provider.Control is SWF.UpDownBase)
135
				else if (Provider.Control is SWF.UpDownBase)
127
					return ((SWF.UpDownBase)Provider.Control).txtView;
136
					return ((SWF.UpDownBase)Provider.Control).InvokeSync (c => c.txtView);
128
				else
137
				else
129
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
138
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
130
			}
139
			}
Lines 132-143 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
132
141
133
		private string Text {
142
		private string Text {
134
			get {
143
			get {
135
				if (TextBoxBase is SWF.MaskedTextBox)
144
				if (TextBoxBase is SWF.MaskedTextBox) {
136
					return ((SWF.MaskedTextBox) TextBoxBase).MaskedTextProvider.ToDisplayString ();
145
					return ((SWF.MaskedTextBox) TextBoxBase).InvokeSync (t => t.MaskedTextProvider.ToDisplayString ());
137
				else
146
				} else {
138
					return TextBoxBase.Text;
147
					return TextBoxBase.InvokeSync (t => t.Text);
148
				}
149
			}
150
			set {
151
				SWF.TextBoxBase textBoxBase = TextBoxBase;
152
				textBoxBase.InvokeSync (delegate { textBoxBase.Text = value; });
139
			}
153
			}
140
			set { TextBoxBase.Text = value; }
141
		}
154
		}
142
155
143
		#endregion
156
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TextBox/ClipboardProviderBehavior.cs (-27 / +34 lines)
Lines 62-97 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
62
62
63
		public void Copy (int start, int end)
63
		public void Copy (int start, int end)
64
		{
64
		{
65
			string text = Text;
65
			TextBoxBase.InvokeSync (delegate {
66
			start = (int) System.Math.Max (start, 0);
66
				string text = Text;
67
			end = (int) System.Math.Min (end, text.Length);
67
				start = (int) System.Math.Max (start, 0);
68
			SWF.Clipboard.SetText (text.Substring (start, end - start));
68
				end = (int) System.Math.Min (end, text.Length);
69
				SWF.Clipboard.SetText (text.Substring (start, end - start));
70
			});
69
		}
71
		}
70
		
72
		
71
		public void Paste (int position)
73
		public void Paste (int position)
72
		{
74
		{
73
			string text = Text;
75
			TextBoxBase.InvokeSync (delegate {
74
			position = (int) System.Math.Max (position, 0);
76
				string text = Text;
75
			position = (int) System.Math.Min (position, text.Length);
77
				position = (int) System.Math.Max (position, 0);
78
				position = (int) System.Math.Min (position, text.Length);
76
79
77
			// If you were to paste using the GUI, it would only
80
				// If you were to paste using the GUI, it would only
78
			// paste enough until the control was full, so emulate
81
				// paste enough until the control was full, so emulate
79
			// that behavior.
82
				// that behavior.
80
			int maxLength = 0;
83
				int maxLength = 0;
81
			if (Provider is TextBoxProvider)
84
				if (Provider is TextBoxProvider)
82
				maxLength = ((TextBoxProvider) Provider).MaxLength;
85
					maxLength = ((TextBoxProvider) Provider).MaxLength;
83
86
84
			string clipboardText = SWF.Clipboard.GetText ();
87
				string clipboardText = SWF.Clipboard.GetText ();
85
			if (maxLength > 0 && clipboardText.Length > (maxLength - position))
88
				if (maxLength > 0 && clipboardText.Length > (maxLength - position))
86
				clipboardText = clipboardText.Substring (0, maxLength - position);
89
					clipboardText = clipboardText.Substring (0, maxLength - position);
87
90
88
			IInsertDeleteTextProvider insertDeleteProv
91
				IInsertDeleteTextProvider insertDeleteProv
89
				= Provider.GetPatternProvider (InsertDeleteTextPatternIdentifiers.Pattern.Id)
92
					= Provider.GetPatternProvider (InsertDeleteTextPatternIdentifiers.Pattern.Id)
90
					as IInsertDeleteTextProvider;
93
						as IInsertDeleteTextProvider;
91
			if (insertDeleteProv != null)
94
				if (insertDeleteProv != null)
92
				insertDeleteProv.InsertText (clipboardText, ref position);
95
					insertDeleteProv.InsertText (clipboardText, ref position);
93
			else
96
				else
94
				TextBoxBase.Text = text.Insert (position, clipboardText);
97
					TextBoxBase.Text = text.Insert (position, clipboardText);
98
			});
95
		}
99
		}
96
100
97
		#endregion
101
		#endregion
Lines 101-107 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
101
				if (Provider.Control is SWF.TextBoxBase)
105
				if (Provider.Control is SWF.TextBoxBase)
102
					return (SWF.TextBoxBase)Provider.Control;
106
					return (SWF.TextBoxBase)Provider.Control;
103
				else if (Provider.Control is SWF.UpDownBase)
107
				else if (Provider.Control is SWF.UpDownBase)
104
					return ((SWF.UpDownBase)Provider.Control).txtView;
108
					return ((SWF.UpDownBase)Provider.Control).InvokeSync (c => c.txtView);
105
				else
109
				else
106
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
110
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
107
			}
111
			}
Lines 110-120 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
110
		private string Text {
114
		private string Text {
111
			get {
115
			get {
112
				if (TextBoxBase is SWF.MaskedTextBox)
116
				if (TextBoxBase is SWF.MaskedTextBox)
113
					return ((SWF.MaskedTextBox) TextBoxBase).MaskedTextProvider.ToDisplayString ();
117
					return ((SWF.MaskedTextBox) TextBoxBase).InvokeSync (c => c.MaskedTextProvider.ToDisplayString ());
114
				else
118
				else
115
					return TextBoxBase.Text;
119
					return TextBoxBase.InvokeSync (c => c.Text);
120
			}
121
			set {
122
				SWF.TextBoxBase textBoxBase = TextBoxBase;
123
				textBoxBase.InvokeSync (delegate { textBoxBase.Text = value; }); 
116
			}
124
			}
117
			set { TextBoxBase.Text = value; }
118
		}
125
		}
119
126
120
	}
127
	}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TextBox/TextProviderBehavior.cs (-11 / +16 lines)
Lines 72-78 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
72
			if (propertyId == AutomationElementIdentifiers.IsPasswordProperty.Id) {
72
			if (propertyId == AutomationElementIdentifiers.IsPasswordProperty.Id) {
73
				if (Provider.Control is SWF.TextBox) {
73
				if (Provider.Control is SWF.TextBox) {
74
					SWF.TextBox textbox = TextBox;
74
					SWF.TextBox textbox = TextBox;
75
					return (textbox.UseSystemPasswordChar || (int) textbox.PasswordChar != 0);
75
					return textbox.InvokeSync (c => c.UseSystemPasswordChar || (int) c.PasswordChar != 0);
76
				} else if (Provider.Control is SWF.RichTextBox) {
76
				} else if (Provider.Control is SWF.RichTextBox) {
77
					return false;
77
					return false;
78
				}
78
				}
Lines 102-118 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
102
				
102
				
103
			//TODO: Return null when system cursor is not present, how to?
103
			//TODO: Return null when system cursor is not present, how to?
104
104
105
			if (!TextBoxBase.Document.SelectionVisible)
105
			return TextBoxBase.InvokeSync (c => {
106
				return new ITextRangeProvider [0];
106
				if (!c.Document.SelectionVisible)
107
107
					return new ITextRangeProvider [0];
108
			return new ITextRangeProvider [] { 
108
	
109
				new TextRangeProvider (this, TextBoxBase, TextBoxBase.SelectionStart, TextBoxBase.SelectionStart + TextBoxBase.SelectionLength) };
109
				int sel_len = c.SelectionLength;
110
				int sel_start = c.SelectionStart;
111
	
112
				return new ITextRangeProvider [] { 
113
					new TextRangeProvider (this, TextBoxBase, sel_start, sel_start + sel_len)
114
				};
115
			});
110
		}
116
		}
111
		
117
		
112
		public ITextRangeProvider[] GetVisibleRanges ()
118
		public ITextRangeProvider[] GetVisibleRanges ()
113
		{
119
		{
114
			int start_line = -1, end_line = -1;
120
			int start_line = -1, end_line = -1;
115
			Document.GetVisibleLineIndexes (TextBoxBase.Bounds, out start_line, out end_line);
121
			System.Drawing.Rectangle bounds = TextBoxBase.InvokeSync (c => c.Bounds);
122
			Document.GetVisibleLineIndexes (bounds, out start_line, out end_line);
116
123
117
			ITextRangeProvider range = DocumentRange.Clone ();
124
			ITextRangeProvider range = DocumentRange.Clone ();
118
			range.MoveEndpointByUnit (TextPatternRangeEndpoint.Start, TextUnit.Line, start_line);
125
			range.MoveEndpointByUnit (TextPatternRangeEndpoint.Start, TextUnit.Line, start_line);
Lines 154-160 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
154
				if (Provider.Control is SWF.TextBoxBase)
161
				if (Provider.Control is SWF.TextBoxBase)
155
					return (SWF.TextBoxBase)Provider.Control;
162
					return (SWF.TextBoxBase)Provider.Control;
156
				else if (Provider.Control is SWF.UpDownBase)
163
				else if (Provider.Control is SWF.UpDownBase)
157
					return ((SWF.UpDownBase)Provider.Control).txtView;
164
					return ((SWF.UpDownBase)Provider.Control).InvokeSync (c => c.txtView);
158
				else
165
				else
159
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
166
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
160
			}
167
			}
Lines 167-175 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
167
		}
174
		}
168
175
169
		private SWF.Document Document { 
176
		private SWF.Document Document { 
170
			get { return TextBoxBase.Document; }
177
			get { return TextBoxBase.InvokeSync (c => c.Document); }
171
		}
178
		}
172
173
174
	}
179
	}
175
}
180
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TextBox/ValueProviderBehavior.cs (-28 / +18 lines)
Lines 83-101 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
83
		#region IValueProvider: Specialization
83
		#region IValueProvider: Specialization
84
		
84
		
85
		public bool IsReadOnly {
85
		public bool IsReadOnly {
86
			get { return ((SWF.TextBoxBase) Provider.Control).ReadOnly || !Provider.Control.Enabled; }
86
			get {
87
				return ((SWF.TextBoxBase) Provider.Control).InvokeSync (c => c.ReadOnly 
88
				                                                         || !c.Enabled);
89
			}
87
		}
90
		}
88
		
91
		
89
		public string Value {
92
		public string Value {
90
			get {
93
			get {
91
				if (Provider.Control is SWF.MaskedTextBox) {
94
				if (Provider.Control is SWF.MaskedTextBox) {
92
					System.ComponentModel.MaskedTextProvider mtp
95
					System.ComponentModel.MaskedTextProvider mtp
93
						= ((SWF.MaskedTextBox) Provider.Control).MaskedTextProvider;
96
						= ((SWF.MaskedTextBox) Provider.Control).InvokeSync (c => c.MaskedTextProvider);
94
					if (mtp != null)
97
					if (mtp != null) {
95
						return mtp.ToDisplayString ();
98
						return mtp.ToDisplayString ();
99
					}
96
				}
100
				}
97
101
98
				return Provider.Control.Text;
102
				return Provider.Control.InvokeSync (c => c.Text);
99
			}
103
			}
100
		}
104
		}
101
105
Lines 104-134 namespace Mono.UIAutomation.Winforms.Behaviors.TextBox Link Here
104
			if (IsReadOnly)
108
			if (IsReadOnly)
105
				throw new ElementNotEnabledException ();
109
				throw new ElementNotEnabledException ();
106
110
107
			PerformSetValue (value);
111
			Provider.Control.InvokeSync (delegate {
108
		}
112
					int maxLength = ((TextBoxProvider) Provider).MaxLength;
109
		
113
					if (maxLength > 0
110
		#endregion
114
					    && value.Length > maxLength) {
111
115
						value = value.Substring (0, maxLength);
112
		#region Private Members
116
					}
113
		
117
					
114
		private void PerformSetValue (string value)
118
					Provider.Control.Text = value;
115
		{
119
				}
116
			if (Provider.Control.InvokeRequired) {
120
			);
117
				Provider.Control.BeginInvoke (new SetValueDelegate (PerformSetValue),
118
				                              new object [] {value});
119
				return;
120
			}
121
122
			int maxLength = ((TextBoxProvider) Provider).MaxLength;
123
			if (maxLength > 0
124
			    && value.Length > maxLength) {
125
				value = value.Substring (0, maxLength);
126
			}
127
			
128
			Provider.Control.Text = value;
129
		}
121
		}
130
131
		private delegate void SetValueDelegate (string val);
132
		
122
		
133
		#endregion
123
		#endregion
134
	}
124
	}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ToolBar/ToolBarButtonExpandCollapseProviderBehavior.cs (-14 / +11 lines)
Lines 77-91 namespace Mono.UIAutomation.Winforms.Behaviors.ToolBar Link Here
77
		
77
		
78
		#region IExpandCollapseProvider Members
78
		#region IExpandCollapseProvider Members
79
		
79
		
80
		public ExpandCollapseState ExpandCollapseState
80
		public ExpandCollapseState ExpandCollapseState {
81
		{
82
			get {
81
			get {
83
				SWF.Menu menu = toolBarButton.DropDownMenu;
82
				SWF.Menu menu = toolBarButton.DropDownMenu;
84
				if (menu == null)
83
				if (menu == null)
85
					return ExpandCollapseState.Collapsed;
84
					return ExpandCollapseState.Collapsed;
86
85
87
				return toolBarButton.Pushed ? ExpandCollapseState.Expanded
86
				return toolBar.InvokeSync (t => toolBarButton.Pushed ? ExpandCollapseState.Expanded
88
					: ExpandCollapseState.Collapsed;
87
					                                   : ExpandCollapseState.Collapsed
88
				);
89
			}
89
			}
90
		}
90
		}
91
91
Lines 111-126 namespace Mono.UIAutomation.Winforms.Behaviors.ToolBar Link Here
111
111
112
		private void PerformExpandCollapse ()
112
		private void PerformExpandCollapse ()
113
		{
113
		{
114
			if (toolBar.InvokeRequired == true) {
114
			toolBar.InvokeSync (delegate {
115
				toolBar.BeginInvoke (new SWF.MethodInvoker (PerformExpandCollapse));
115
				SWF.ContextMenu menu = toolBarButton.DropDownMenu as SWF.ContextMenu;
116
				return;
116
				if (menu == null)
117
			}
117
					return;
118
118
				menu.Show (toolBar,
119
			SWF.ContextMenu menu = toolBarButton.DropDownMenu as SWF.ContextMenu;
119
					   new Point (toolBarButton.Rectangle.X, toolBar.Height));
120
			if (menu == null)
120
			});
121
				return;
122
			menu.Show (toolBar,
123
			           new Point (toolBarButton.Rectangle.X, toolBar.Height));
124
		}
121
		}
125
		
122
		
126
		#endregion
123
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ToolBar/ToolBarButtonInvokeProviderBehavior.cs (-15 / +6 lines)
Lines 71-97 namespace Mono.UIAutomation.Winforms.Behaviors.ToolBar Link Here
71
		
71
		
72
		public void Invoke ()
72
		public void Invoke ()
73
		{
73
		{
74
			if (toolBar.Enabled == false || toolBarButton.Enabled == false)
74
			bool notEnabled = toolBar.InvokeSync (t => !t.Enabled || !toolBarButton.Enabled);
75
				
76
			if (notEnabled)
75
				throw new ElementNotEnabledException ();
77
				throw new ElementNotEnabledException ();
76
78
77
			PerformClick ();
79
			toolBar.InvokeSync (delegate {
80
				toolBar.UIAPerformClick (toolBarButton);
81
			});
78
		}
82
		}
79
		
83
		
80
		#endregion
84
		#endregion
81
85
82
		#region Private Methods
83
84
		private void PerformClick ()
85
		{
86
			if (toolBar.InvokeRequired == true) {
87
				toolBar.BeginInvoke (new SWF.MethodInvoker (PerformClick));
88
				return;
89
			}
90
91
			toolBarButton.Parent.UIAPerformClick (toolBarButton);
92
		}
93
		#endregion
94
95
		#region Private Fields
86
		#region Private Fields
96
87
97
		private SWF.ToolBarButton toolBarButton;
88
		private SWF.ToolBarButton toolBarButton;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ToolBar/ToolBarButtonToggleProviderBehavior.cs (-16 / +4 lines)
Lines 79-85 namespace Mono.UIAutomation.Winforms.Behaviors.ToolBar Link Here
79
		public ToggleState ToggleState
79
		public ToggleState ToggleState
80
		{
80
		{
81
			get {
81
			get {
82
				if (toolBarButton.Pushed)
82
				if (toolBar.InvokeSync (t => toolBarButton.Pushed))
83
					return ToggleState.On;
83
					return ToggleState.On;
84
				else
84
				else
85
					return ToggleState.Off;
85
					return ToggleState.Off;
Lines 91-111 namespace Mono.UIAutomation.Winforms.Behaviors.ToolBar Link Here
91
			if (!toolBarButton.Enabled)
91
			if (!toolBarButton.Enabled)
92
				throw new ElementNotEnabledException ();
92
				throw new ElementNotEnabledException ();
93
93
94
			PerformToggle ();
94
			toolBar.InvokeSync (delegate {
95
		}
95
				toolBar.UIAPerformClick (toolBarButton);
96
		
96
			});
97
		#endregion
98
99
		#region Private Methods
100
101
		private void PerformToggle ()
102
		{
103
			if (toolBar.InvokeRequired == true) {
104
				toolBar.BeginInvoke (new SWF.MethodInvoker (PerformToggle));
105
				return;
106
			}
107
108
			toolBar.UIAPerformClick (toolBarButton);
109
		}
97
		}
110
		
98
		
111
		#endregion
99
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ToolStripButton/InvokeProviderBehavior.cs (-11 / +4 lines)
Lines 71-87 namespace Mono.UIAutomation.Winforms.Behaviors.ToolStripButton Link Here
71
			if (button.Enabled == false)
71
			if (button.Enabled == false)
72
				throw new ElementNotEnabledException ();
72
				throw new ElementNotEnabledException ();
73
73
74
			PerformClick ();
74
			SWF.ToolStrip toolstrip = ((SWF.ToolStripButton) Provider.Component).Owner;
75
		}
75
			toolstrip.InvokeSync (delegate {
76
76
				button.PerformClick ();
77
		private void PerformClick ()
77
			});
78
		{
79
			SWF.ToolStrip toolstrip = ((SWF.ToolStripButton)Provider.Component).Owner;
80
			if (toolstrip.InvokeRequired == true) {
81
				toolstrip.BeginInvoke (new SWF.MethodInvoker (PerformClick));
82
				return;
83
			}
84
			button.PerformClick ();
85
		}
78
		}
86
#endregion	
79
#endregion	
87
80
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ToolStripButton/ToggleProviderBehavior.cs (-11 / +16 lines)
Lines 74-80 namespace Mono.UIAutomation.Winforms.Behaviors.ToolStripButton Link Here
74
#region IToggleProvider Members
74
#region IToggleProvider Members
75
		public ToggleState ToggleState {
75
		public ToggleState ToggleState {
76
			get {
76
			get {
77
				switch (button.CheckState) {
77
				SWF.CheckState state =
78
					Owner.InvokeSync (delegate { return button.CheckState; });
79
80
				switch (state) {
78
				case SWF.CheckState.Checked:
81
				case SWF.CheckState.Checked:
79
					return ToggleState.On;
82
					return ToggleState.On;
80
				case SWF.CheckState.Unchecked:
83
				case SWF.CheckState.Unchecked:
Lines 91-97 namespace Mono.UIAutomation.Winforms.Behaviors.ToolStripButton Link Here
91
			if (!button.Enabled)
94
			if (!button.Enabled)
92
				throw new ElementNotEnabledException ();
95
				throw new ElementNotEnabledException ();
93
96
94
			switch (button.CheckState) {
97
			SWF.CheckState state =
98
				Owner.InvokeSync (delegate { return button.CheckState; });
99
100
			switch (state) {
95
			case SWF.CheckState.Checked:
101
			case SWF.CheckState.Checked:
96
				PerformToggle (button, SWF.CheckState.Unchecked);
102
				PerformToggle (button, SWF.CheckState.Unchecked);
97
				break;
103
				break;
Lines 109-122 namespace Mono.UIAutomation.Winforms.Behaviors.ToolStripButton Link Here
109
#region Private Methods
115
#region Private Methods
110
		private void PerformToggle (SWF.ToolStripButton button, SWF.CheckState state)
116
		private void PerformToggle (SWF.ToolStripButton button, SWF.CheckState state)
111
		{
117
		{
112
			SWF.ToolStrip toolstrip = ((SWF.ToolStripButton) Provider.Component).Owner;
118
			Owner.InvokeSync (delegate {
113
			if (toolstrip.InvokeRequired) {
119
				button.CheckState = state;
114
				toolstrip.BeginInvoke (new PerformToggleDelegate (PerformToggle),
120
			});
115
				                       new object [] { button, state });
121
		}
116
				return;
122
#endregion
117
			}
118
123
119
			button.CheckState = state;
124
#region Private Properties
125
		private SWF.ToolStrip Owner {
126
			get { return ((SWF.ToolStripButton) Provider.Component).Owner; }
120
		}
127
		}
121
#endregion
128
#endregion
122
129
Lines 124-129 namespace Mono.UIAutomation.Winforms.Behaviors.ToolStripButton Link Here
124
		private SWF.ToolStripButton button;
131
		private SWF.ToolStripButton button;
125
#endregion
132
#endregion
126
	}
133
	}
127
128
	delegate void PerformToggleDelegate (SWF.ToolStripButton button, SWF.CheckState state);
129
}
134
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ToolStripItem/InvokeProviderBehavior.cs (-22 / +31 lines)
Lines 44-50 namespace Mono.UIAutomation.Winforms.Behaviors.ToolStripItem Link Here
44
		ToolStripItemProvider itemProvider;
44
		ToolStripItemProvider itemProvider;
45
45
46
		#endregion
46
		#endregion
47
47
		
48
		#region Constructor
48
		#region Constructor
49
		
49
		
50
		public InvokeProviderBehavior (ToolStripItemProvider provider)
50
		public InvokeProviderBehavior (ToolStripItemProvider provider)
Lines 82-130 namespace Mono.UIAutomation.Winforms.Behaviors.ToolStripItem Link Here
82
			if (((SWF.ToolStripItem)Provider.Component).Enabled == false)
82
			if (((SWF.ToolStripItem)Provider.Component).Enabled == false)
83
				throw new ElementNotEnabledException ();
83
				throw new ElementNotEnabledException ();
84
84
85
			PerformClick ();
85
			SynchronizedPerformClick ();
86
		}
86
		}
87
		
87
		
88
		#endregion	
88
		#endregion	
89
		
89
		
90
		#region Private Methods
90
		#region Private Methods
91
		
91
		
92
		private void PerformClick ()
92
		private void SynchronizedPerformClick ()
93
		{
93
		{
94
			SWF.ToolStripItem item = (SWF.ToolStripItem) Provider.Component;
94
			SWF.ToolStripItem item = (SWF.ToolStripItem) Provider.Component;
95
			if (item.Owner != null && item.Owner.InvokeRequired) {
95
			if (item.Owner != null)
96
				item.Owner.BeginInvoke (new SWF.MethodInvoker (PerformClick));
96
				item.Owner.InvokeSync (delegate { 
97
				return;
97
					PerformClick (item); 
98
			}
98
				});
99
			else // Hopefully we shouldn't have any issue
100
				PerformClick (item);
101
		}
99
102
100
			var currentParent = item.OwnerItem as SWF.ToolStripMenuItem;
103
		private void PerformClick (SWF.ToolStripItem item)
104
		{
105
			SWF.ToolStrip currentParent = item.GetCurrentParent ();
101
106
102
			// Invoking without a visible parent results in exceptions
107
			// Invoking without a visible parent results in exceptions
103
			if (currentParent != null && !currentParent.DropDown.Visible)
108
			if (currentParent == null || !currentParent.Visible)
104
				return;
109
				return;
105
110
106
			var dropdown = item as SWF.ToolStripDropDownItem;
107
			bool hide = false;
108
			if (dropdown != null)
109
				hide = dropdown.Pressed;
110
111
			// Make sure selection changes, or else another item's
111
			// Make sure selection changes, or else another item's
112
			// dropdown menu might still appear.
112
			// dropdown menu might still appear.
113
			if (item.Owner != null)
113
			if (item.Owner != null)
114
				item.Select ();
114
				item.Select ();
115
115
			
116
			item.PerformClick ();
117
118
			// PerformClick does _not_ show/hide the DropDown, so
116
			// PerformClick does _not_ show/hide the DropDown, so
119
			// we must do this manually.  On Vista, clicking the
117
			// we must do this manually.  On Vista, clicking the
120
			// button appears to both Show the drop down and
118
			// button appears to both Show the drop down and
121
			// Perform a click, so we emulate that behavior.
119
			// Perform a click, so we emulate that behavior.
122
			if (dropdown != null && !(item is SWF.ToolStripSplitButton)) {
120
			if (item is SWF.ToolStripDropDownButton) {
123
				if (hide)
121
				SWF.ToolStripDropDownButton dropDown = (SWF.ToolStripDropDownButton) item;
124
					dropdown.HideDropDown ();
122
				if (!dropDown.Pressed) {
125
				else
123
					dropDown.ShowDropDown ();
126
					dropdown.ShowDropDown ();
124
				} else {
125
					dropDown.HideDropDown ();
126
				}
127
			} else if (item is SWF.ToolStripMenuItem) {
128
				SWF.ToolStripMenuItem menuItem = (SWF.ToolStripMenuItem) item;
129
				if (!menuItem.Pressed) {
130
					menuItem.ShowDropDown ();
131
				} else {
132
					menuItem.HideDropDown ();
133
				}
127
			}
134
			}
135
136
			item.PerformClick ();
128
		}
137
		}
129
		
138
		
130
		#endregion
139
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ToolStripSplitButton/ExpandCollapseProviderBehavior.cs (-4 / +15 lines)
Lines 77-95 namespace Mono.UIAutomation.Winforms.Behaviors.ToolStripSplitButton Link Here
77
				if (dropdown == null)
77
				if (dropdown == null)
78
					return ExpandCollapseState.Collapsed;
78
					return ExpandCollapseState.Collapsed;
79
79
80
				return dropdown.Visible ? ExpandCollapseState.Expanded
80
				return Owner.InvokeSync (o => dropdown.Visible ? ExpandCollapseState.Expanded
81
				                        : ExpandCollapseState.Collapsed;
81
				                                     : ExpandCollapseState.Collapsed
82
				);
82
			}
83
			}
83
		}
84
		}
84
85
85
		public void Collapse ()
86
		public void Collapse ()
86
		{
87
		{
87
			((SWF.ToolStripSplitButton) Provider.Component).HideDropDown ();
88
			Owner.InvokeSync (delegate {
89
				((SWF.ToolStripSplitButton) Provider.Component).HideDropDown ();
90
			});
88
		}
91
		}
89
92
90
		public void Expand ()
93
		public void Expand ()
91
		{
94
		{
92
			((SWF.ToolStripSplitButton) Provider.Component).ShowDropDown ();
95
			Owner.InvokeSync (delegate {
96
				((SWF.ToolStripSplitButton) Provider.Component).ShowDropDown ();
97
			});
98
		}
99
#endregion
100
101
#region Private Properties
102
		private SWF.ToolStrip Owner {
103
			get { return ((SWF.ToolStripItem) Provider.Component).Owner; }
93
		}
104
		}
94
#endregion
105
#endregion
95
	}
106
	}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TrackBar/ButtonInvokeProviderBehavior.cs (-10 / +7 lines)
Lines 84-101 namespace Mono.UIAutomation.Winforms.Behaviors.TrackBar Link Here
84
		
84
		
85
		public void Invoke ()
85
		public void Invoke ()
86
		{
86
		{
87
			if (!Provider.Control.Enabled)
87
			if (Provider.Control.InvokeSync (c => !c.Enabled))
88
				throw new ElementNotEnabledException ();
88
				throw new ElementNotEnabledException ();
89
89
90
	        if (provider.Control.InvokeRequired == true) {
90
			Provider.Control.InvokeSync (delegate {
91
	            provider.Control.BeginInvoke (new SWF.MethodInvoker (Invoke));
91
				if (provider.Orientation == TrackBarProvider.TrackBarButtonOrientation.LargeBack)
92
	            return;
92
					((SWF.TrackBar)Provider.Control).LargeDecrement ();
93
	        }
93
				else if (provider.Orientation == TrackBarProvider.TrackBarButtonOrientation.LargeForward)
94
94
					((SWF.TrackBar)Provider.Control).LargeIncrement ();
95
 			if (provider.Orientation == TrackBarProvider.TrackBarButtonOrientation.LargeBack)
95
			});
96
				((SWF.TrackBar)Provider.Control).LargeDecrement ();
97
			else if (provider.Orientation == TrackBarProvider.TrackBarButtonOrientation.LargeForward)
98
				((SWF.TrackBar)Provider.Control).LargeIncrement ();
99
		}
96
		}
100
		
97
		
101
		#endregion	
98
		#endregion	
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TrackBar/RangeValueProviderBehavior.cs (-23 / +9 lines)
Lines 112-159 namespace Mono.UIAutomation.Winforms.Behaviors.TrackBar Link Here
112
			if (value < Minimum || value > Maximum)
112
			if (value < Minimum || value > Maximum)
113
				throw new ArgumentOutOfRangeException ();
113
				throw new ArgumentOutOfRangeException ();
114
			
114
			
115
			PerformSetValue ((int) value);
115
			trackbar.InvokeSync (delegate {
116
				trackbar.Value = (int) value;
117
			});
116
		}
118
		}
117
		
119
		
118
		public bool IsReadOnly {
120
		public bool IsReadOnly {
119
			get { return trackbar.Enabled == false || trackbar.Visible == false; }
121
			get { return trackbar.InvokeSync (t => !t.Enabled || !t.Visible); }
120
		}
122
		}
121
		
123
		
122
		public double LargeChange {
124
		public double LargeChange {
123
			get { return trackbar.LargeChange; }
125
			get { return trackbar.InvokeSync (t => t.LargeChange); }
124
		}
126
		}
125
		
127
		
126
		public double Maximum {
128
		public double Maximum {
127
			get { return trackbar.Maximum; }
129
			get { return trackbar.InvokeSync (t => t.Maximum); }
128
		}
130
		}
129
		
131
		
130
		public double Minimum {
132
		public double Minimum {
131
			get { return trackbar.Minimum; }
133
			get { return trackbar.InvokeSync (t => t.Minimum); }
132
		}
134
		}
133
		
135
		
134
		public double SmallChange {
136
		public double SmallChange {
135
			get { return trackbar.SmallChange; }
137
			get { return trackbar.InvokeSync (t => t.SmallChange); }
136
		}
138
		}
137
		
139
		
138
		public double Value {
140
		public double Value {
139
			get { return trackbar.Value; }
141
			get { return trackbar.InvokeSync (t => t.Value); }
140
		}
142
		}
141
		
143
		
142
		#endregion 
144
		#endregion 
143
		
144
		#region Private Methods
145
		
146
		private void PerformSetValue (int value)
147
		{
148
			if (trackbar.InvokeRequired == true) {
149
				trackbar.BeginInvoke (new PerformSetValueDelegate (PerformSetValue),
150
				                       new object [] { value });
151
				return;
152
			}
153
			trackbar.Value = value;
154
		}
155
		
156
		#endregion
157
145
158
		#region Private Fields
146
		#region Private Fields
159
147
Lines 161-166 namespace Mono.UIAutomation.Winforms.Behaviors.TrackBar Link Here
161
149
162
		#endregion
150
		#endregion
163
	}
151
	}
164
	
165
	delegate void PerformSetValueDelegate (int value);
166
}
152
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TreeView/ExpandCollapeProviderBehavior.cs (-26 / +6 lines)
Lines 93-104 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
93
			if (!treeView.Enabled)
93
			if (!treeView.Enabled)
94
				throw new ElementNotEnabledException ();
94
				throw new ElementNotEnabledException ();
95
			
95
			
96
			if (treeView != null && treeView.InvokeRequired) {
96
			treeView.InvokeSync (delegate {
97
				treeView.BeginInvoke (new SWF.MethodInvoker (PerformCollapse));
97
				nodeProvider.TreeNode.Collapse ();
98
				return;
98
			});
99
			}
100
101
			PerformCollapse ();
102
		}
99
		}
103
		
100
		
104
		public void Expand ()
101
		public void Expand ()
Lines 110-122 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
110
107
111
			if (!treeView.Enabled)
108
			if (!treeView.Enabled)
112
				throw new ElementNotEnabledException ();
109
				throw new ElementNotEnabledException ();
113
			
114
			if (treeView != null && treeView.InvokeRequired) {
115
				treeView.BeginInvoke (new SWF.MethodInvoker (PerformExpand));
116
				return;
117
			}
118
110
119
			PerformExpand ();
111
			treeView.InvokeSync (delegate {
112
				nodeProvider.TreeNode.Expand ();
113
			});
120
		}
114
		}
121
		
115
		
122
		public ExpandCollapseState ExpandCollapseState {
116
		public ExpandCollapseState ExpandCollapseState {
Lines 131-149 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
131
		}
125
		}
132
		
126
		
133
		#endregion
127
		#endregion
134
135
		#region Private Methods
136
137
		private void PerformCollapse ()
138
		{
139
			nodeProvider.TreeNode.Collapse ();
140
		}
141
142
		private void PerformExpand ()
143
		{
144
			nodeProvider.TreeNode.Expand ();
145
		}
146
147
		#endregion
148
	}
128
	}
149
}
129
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TreeView/ScrollItemProviderBehavior.cs (-3 / +3 lines)
Lines 82-91 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
82
				Log.Error ("TreeView.ScrollItem.ScrollIntoView: Parent TreeView is not set");
82
				Log.Error ("TreeView.ScrollItem.ScrollIntoView: Parent TreeView is not set");
83
				return;
83
				return;
84
			}
84
			}
85
			if (treeView.InvokeRequired)
86
				treeView.BeginInvoke (new SWF.MethodInvoker (ScrollIntoView));
87
85
88
			nodeProvider.TreeNode.EnsureVisible ();
86
			treeView.InvokeSync (delegate {
87
				nodeProvider.TreeNode.EnsureVisible ();
88
			});
89
		}
89
		}
90
90
91
		#endregion
91
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TreeView/SelectionItemProviderBehavior.cs (-6 / +8 lines)
Lines 93-110 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
93
				Log.Error ("TreeView.SelectionItem.Select: Parent TreeView is not set");
93
				Log.Error ("TreeView.SelectionItem.Select: Parent TreeView is not set");
94
				return;
94
				return;
95
			}
95
			}
96
96
			if (!treeView.Enabled)
97
			if (!treeView.Enabled)
97
				throw new ElementNotEnabledException ();
98
				throw new ElementNotEnabledException ();
98
			if (treeView.InvokeRequired) {
99
99
				treeView.BeginInvoke (new SWF.MethodInvoker (Select));
100
			treeView.InvokeSync (delegate {
100
				return;
101
				treeView.SelectedNode = nodeProvider.TreeNode;
101
			}
102
			});
102
			treeView.SelectedNode = nodeProvider.TreeNode;
103
		}
103
		}
104
		
104
		
105
		public bool IsSelected {
105
		public bool IsSelected {
106
			get {
106
			get {
107
				return nodeProvider.TreeNode.IsSelected;
107
				return nodeProvider.TreeNode.TreeView.InvokeSync (
108
					t => nodeProvider.TreeNode.IsSelected
109
				);
108
			}
110
			}
109
		}
111
		}
110
		
112
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TreeView/SelectionProviderBehavior.cs (-5 / +3 lines)
Lines 92-98 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
92
		
92
		
93
		public IRawElementProviderSimple [] GetSelection ()
93
		public IRawElementProviderSimple [] GetSelection ()
94
		{
94
		{
95
			SWF.TreeNode selectedNode = treeView.SelectedNode;
95
			SWF.TreeNode selectedNode = treeView.InvokeSync (c => c.SelectedNode);
96
			TreeNodeProvider selectedNodeProvider = null;
96
			TreeNodeProvider selectedNodeProvider = null;
97
			
97
			
98
			if (selectedNode != null)
98
			if (selectedNode != null)
Lines 105-118 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
105
		}
105
		}
106
		
106
		
107
		public bool CanSelectMultiple {
107
		public bool CanSelectMultiple {
108
			get {
108
			get { return false; }
109
				return false;
110
			}
111
		}
109
		}
112
		
110
		
113
		public bool IsSelectionRequired {
111
		public bool IsSelectionRequired {
114
			get {
112
			get {
115
				return treeView.SelectedNode != null;
113
				return treeView.InvokeSync (t => t.SelectedNode != null);
116
			}
114
			}
117
		}
115
		}
118
		
116
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TreeView/ToggleProviderBehavior.cs (-3 / +4 lines)
Lines 62-73 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
62
				Log.Error ("TreeView.Toggle.Invoke: Parent TreeView is not set");
62
				Log.Error ("TreeView.Toggle.Invoke: Parent TreeView is not set");
63
				return;
63
				return;
64
			}
64
			}
65
65
			if (!treeView.Enabled)
66
			if (!treeView.Enabled)
66
				throw new ElementNotEnabledException ();
67
				throw new ElementNotEnabledException ();
67
			if (treeView.InvokeRequired)
68
				treeView.BeginInvoke (new SWF.MethodInvoker (Toggle));
69
			
68
			
70
			nodeProvider.TreeNode.Checked = !nodeProvider.TreeNode.Checked;
69
			treeView.InvokeSync (delegate {
70
				nodeProvider.TreeNode.Checked = !nodeProvider.TreeNode.Checked;
71
			});
71
		}
72
		}
72
		
73
		
73
		public ToggleState ToggleState {
74
		public ToggleState ToggleState {
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/TreeView/ValueProviderBehavior.cs (-21 / +9 lines)
Lines 93-131 namespace Mono.UIAutomation.Winforms.Behaviors.TreeView Link Here
93
				Log.Error ("TreeView.Value.SetValue: Parent TreeView is not set");
93
				Log.Error ("TreeView.Value.SetValue: Parent TreeView is not set");
94
				return;
94
				return;
95
			}
95
			}
96
96
			if (!treeView.Enabled)
97
			if (!treeView.Enabled)
97
				throw new ElementNotEnabledException ();
98
				throw new ElementNotEnabledException ();
98
			if (treeView.InvokeRequired) {
99
99
				treeView.BeginInvoke (new SetValueDelegate (PerformSetValue),
100
			treeView.InvokeSync (delegate {
100
				                      new object [] {val});
101
				nodeProvider.TreeNode.Text = val;
101
				return;
102
			});
102
			}
103
			PerformSetValue (val);
104
		}
103
		}
105
		
104
		
106
		public bool IsReadOnly {
105
		public bool IsReadOnly {
107
			get {
106
			get { return false; }
108
				return false;
109
			}
110
		}
107
		}
111
		
108
		
112
		public string Value {
109
		public string Value {
113
			get {
110
			get {
114
				return nodeProvider.TreeNode.Text;
111
				return nodeProvider.TreeNode.TreeView.InvokeSync (
112
					t => nodeProvider.TreeNode.Text
113
				);
115
			}
114
			}
116
		}
115
		}
117
		
116
		
118
		#endregion
117
		#endregion
119
120
		#region Private Methods
121
122
		private void PerformSetValue (string val)
123
		{
124
			nodeProvider.TreeNode.Text = val;
125
		}
126
127
		private delegate void SetValueDelegate (string val);
128
129
		#endregion
130
	}
118
	}
131
}
119
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/UpDownBase/ButtonInvokeProviderBehavior.cs (-15 / +7 lines)
Lines 69-88 namespace Mono.UIAutomation.Winforms.Behaviors.UpDownBase Link Here
69
		
69
		
70
		public void Invoke ()
70
		public void Invoke ()
71
		{
71
		{
72
			if (provider.UpDownBase.InvokeRequired) {
72
			provider.UpDownBase.InvokeSync (delegate {
73
				provider.UpDownBase.BeginInvoke (new SWF.MethodInvoker (PerformInvoke));
73
				if (provider.Orientation == UpDownBaseProvider.UpDownBaseButtonOrientation.Forward)
74
				return;
74
					provider.UpDownBase.UpButton ();
75
			}
75
				else if (provider.Orientation == UpDownBaseProvider.UpDownBaseButtonOrientation.Backward)
76
76
					provider.UpDownBase.DownButton ();
77
			PerformInvoke ();
77
			});
78
		}
79
80
		private void PerformInvoke ()
81
		{
82
			if (provider.Orientation == UpDownBaseProvider.UpDownBaseButtonOrientation.Forward)
83
				provider.UpDownBase.UpButton ();
84
			else if (provider.Orientation == UpDownBaseProvider.UpDownBaseButtonOrientation.Backward)
85
				provider.UpDownBase.DownButton ();
86
		}
78
		}
87
		
79
		
88
		#endregion
80
		#endregion
Lines 93-96 namespace Mono.UIAutomation.Winforms.Behaviors.UpDownBase Link Here
93
		
85
		
94
		#endregion
86
		#endregion
95
	}
87
	}
96
}
88
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/UpDownBase/ValueProviderBehavior.cs (-22 / +5 lines)
Lines 82-115 namespace Mono.UIAutomation.Winforms.Behaviors.UpDownBase Link Here
82
		#region IValueProvider Members
82
		#region IValueProvider Members
83
		
83
		
84
		public bool IsReadOnly {
84
		public bool IsReadOnly {
85
			get { return upDownBase.ReadOnly; }
85
			get { return upDownBase.InvokeSync (c => c.ReadOnly); }
86
		}
86
		}
87
		
87
		
88
		public string Value {
88
		public string Value {
89
			get { return upDownBase.Text; }
89
			get { return upDownBase.InvokeSync (c => c.Text); }
90
		}
90
		}
91
		
91
		
92
		public void SetValue (string value)
92
		public void SetValue (string value)
93
		{
93
		{
94
			if (!upDownBase.Enabled || upDownBase.ReadOnly)
94
			if (upDownBase.InvokeSync (c => !c.Enabled || c.ReadOnly))
95
				throw new ElementNotEnabledException ();
95
				throw new ElementNotEnabledException ();
96
			
96
97
			PerformSetValue (value);
97
			upDownBase.InvokeSync (delegate { upDownBase.Text = value; });
98
		}
99
		
100
		#endregion
101
		
102
		#region Private Methods
103
		
104
		private void PerformSetValue (string value) 
105
		{
106
			if (upDownBase.InvokeRequired == true) {
107
				upDownBase.BeginInvoke (new UpDownBaseSetValueDelegate (PerformSetValue),
108
				                          new object [] { value } );
109
				return;
110
			}
111
			
112
			upDownBase.Text = value;
113
		}
98
		}
114
		
99
		
115
		#endregion
100
		#endregion
Lines 120-125 namespace Mono.UIAutomation.Winforms.Behaviors.UpDownBase Link Here
120
		
105
		
121
		#endregion
106
		#endregion
122
	}
107
	}
123
	
124
	delegate void UpDownBaseSetValueDelegate (string value);
125
}
108
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/AutomationIsOffscreenPropertyEvent.cs (-10 / +14 lines)
Lines 48-69 namespace Mono.UIAutomation.Winforms.Events Link Here
48
		
48
		
49
		public override void Connect ()
49
		public override void Connect ()
50
		{
50
		{
51
			Provider.Control.Resize += new EventHandler (OnIsOffScreen);
51
			Provider.Control.InvokeSync (delegate {
52
			Provider.Control.LocationChanged += new EventHandler (OnIsOffScreen);
52
				Provider.Control.Resize += new EventHandler (OnIsOffScreen);
53
			if (Provider.Control.Parent != null)
53
				Provider.Control.LocationChanged += new EventHandler (OnIsOffScreen);
54
				Provider.Control.Parent.LocationChanged += new EventHandler (OnIsOffScreen);
54
				if (Provider.Control.Parent != null)
55
			if (Provider.Control.FindForm () != null)
55
					Provider.Control.Parent.LocationChanged += new EventHandler (OnIsOffScreen);
56
				if (Provider.Control.FindForm () != null)
56
				Provider.Control.FindForm ().Resize += new EventHandler (OnIsOffScreen);
57
				Provider.Control.FindForm ().Resize += new EventHandler (OnIsOffScreen);
58
			});
57
		}
59
		}
58
60
59
		public override void Disconnect ()
61
		public override void Disconnect ()
60
		{
62
		{
61
			Provider.Control.Resize -= new EventHandler (OnIsOffScreen);
63
			Provider.Control.InvokeSync (delegate {
62
			Provider.Control.LocationChanged -= new EventHandler (OnIsOffScreen);
64
				Provider.Control.Resize -= new EventHandler (OnIsOffScreen);
63
			if (Provider.Control.Parent != null)
65
				Provider.Control.LocationChanged -= new EventHandler (OnIsOffScreen);
64
				Provider.Control.Parent.LocationChanged -= new EventHandler (OnIsOffScreen);
66
				if (Provider.Control.Parent != null)
65
			if (Provider.Control.FindForm () != null)
67
					Provider.Control.Parent.LocationChanged -= new EventHandler (OnIsOffScreen);
68
				if (Provider.Control.FindForm () != null)
66
				Provider.Control.FindForm ().Resize -= new EventHandler (OnIsOffScreen);
69
				Provider.Control.FindForm ().Resize -= new EventHandler (OnIsOffScreen);
70
			});
67
		}
71
		}
68
		
72
		
69
		#endregion
73
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/AutomationIsPatternAvailablePropertyEvent.cs (-1 lines)
Lines 116-122 namespace Mono.UIAutomation.Winforms.Events Link Here
116
					return;
116
					return;
117
				
117
				
118
				bool newValue = val ?? false;
118
				bool newValue = val ?? false;
119
				
120
				AutomationPropertyChangedEventArgs args 
119
				AutomationPropertyChangedEventArgs args 
121
					= new AutomationPropertyChangedEventArgs (property,
120
					= new AutomationPropertyChangedEventArgs (property,
122
					                                          !newValue,
121
					                                          !newValue,
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/BaseAutomationEvent.cs (-5 / +8 lines)
Lines 55-65 namespace Mono.UIAutomation.Winforms.Events Link Here
55
		protected void RaiseAutomationEvent ()
55
		protected void RaiseAutomationEvent ()
56
		{
56
		{
57
			if (AutomationInteropProvider.ClientsAreListening == true) {
57
			if (AutomationInteropProvider.ClientsAreListening == true) {
58
				AutomationEventArgs args = 
58
//				Helper.DelegateQueue.Get ().Enqueue (delegate {
59
					new AutomationEventArgs (Event);
59
//				System.Threading.ThreadPool.QueueUserWorkItem (v => {
60
				AutomationInteropProvider.RaiseAutomationEvent (Event, 
60
					AutomationEventArgs args = 
61
				                                                Provider, 
61
						new AutomationEventArgs (Event);
62
				                                                args);
62
					AutomationInteropProvider.RaiseAutomationEvent (Event, 
63
					                                                Provider, 
64
					                                                args);
65
//				});
63
			}
66
			}
64
		}
67
		}
65
		
68
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ComboBox/ListItemSelectionItemPatternElementSelectedEvent.cs (-7 / +1 lines)
Lines 50-65 namespace Mono.UIAutomation.Winforms.Events.ComboBox Link Here
50
		{
50
		{
51
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
51
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
52
				+= new EventHandler (OnElementSelectedEvent);
52
				+= new EventHandler (OnElementSelectedEvent);
53
			if (Provider.Control is SWF.DirComboBox)
54
				((SWF.ComboBox) Provider.Control).SelectedValueChanged 
55
					+= new EventHandler (OnElementSelectedEvent);
56
		}
53
		}
57
54
58
		public override void Disconnect ()
55
		public override void Disconnect ()
59
		{
56
		{
60
			if (Provider.Control is SWF.DirComboBox)
61
				((SWF.ComboBox) Provider.Control).SelectedValueChanged 
62
					-= new EventHandler (OnElementSelectedEvent);
63
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
57
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
64
				-= new EventHandler (OnElementSelectedEvent);
58
				-= new EventHandler (OnElementSelectedEvent);
65
		}
59
		}
Lines 72-78 namespace Mono.UIAutomation.Winforms.Events.ComboBox Link Here
72
		{
66
		{
73
			ListItemProvider provider = (ListItemProvider) Provider;
67
			ListItemProvider provider = (ListItemProvider) Provider;
74
			
68
			
75
			if (provider.Index == ((SWF.ComboBox) provider.Control).SelectedIndex)
69
			if (provider.Index == ((SWF.ComboBox) provider.Control).InvokeSync (c => c.SelectedIndex))
76
				RaiseAutomationEvent ();
70
				RaiseAutomationEvent ();
77
		}
71
		}
78
		
72
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ComboBox/ListItemSelectionItemPatternIsSelectedEvent.cs (-6 lines)
Lines 50-65 namespace Mono.UIAutomation.Winforms.Events.ComboBox Link Here
50
		{
50
		{
51
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
51
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
52
				+= new EventHandler (OnElementSelectedEvent);
52
				+= new EventHandler (OnElementSelectedEvent);
53
			if (Provider.Control is SWF.DirComboBox)
54
				((SWF.ComboBox) Provider.Control).SelectedValueChanged 
55
					+= new EventHandler (OnElementSelectedEvent);
56
		}
53
		}
57
54
58
		public override void Disconnect ()
55
		public override void Disconnect ()
59
		{
56
		{
60
			if (Provider.Control is SWF.DirComboBox)
61
				((SWF.ComboBox) Provider.Control).SelectedValueChanged 
62
					-= new EventHandler (OnElementSelectedEvent);
63
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
57
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
64
				-= new EventHandler (OnElementSelectedEvent);
58
				-= new EventHandler (OnElementSelectedEvent);
65
		}
59
		}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ComboBox/SelectionPatternIsSelectionRequiredEvent.cs (-6 lines)
Lines 52-67 namespace Mono.UIAutomation.Winforms.Events.ComboBox Link Here
52
		{
52
		{
53
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
53
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
54
				+= new EventHandler (OnSelectedIndexChanged);
54
				+= new EventHandler (OnSelectedIndexChanged);
55
			if (Provider.Control is SWF.DirComboBox)
56
				((SWF.ComboBox) Provider.Control).SelectedValueChanged 
57
					+= new EventHandler (OnSelectedIndexChanged);
58
		}
55
		}
59
56
60
		public override void Disconnect ()
57
		public override void Disconnect ()
61
		{
58
		{
62
			if (Provider.Control is SWF.DirComboBox)
63
				((SWF.ComboBox) Provider.Control).SelectedValueChanged 
64
					-= new EventHandler (OnSelectedIndexChanged);
65
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
59
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
66
				-= new EventHandler (OnSelectedIndexChanged);
60
				-= new EventHandler (OnSelectedIndexChanged);
67
		}
61
		}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ComboBox/SelectionPatternSelectionEvent.cs (-6 lines)
Lines 53-68 namespace Mono.UIAutomation.Winforms.Events.ComboBox Link Here
53
		{
53
		{
54
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
54
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
55
				+= new EventHandler (OnSelectedIndexChanged);
55
				+= new EventHandler (OnSelectedIndexChanged);
56
			if (Provider.Control is SWF.DirComboBox)
57
				((SWF.ComboBox) Provider.Control).SelectedValueChanged 
58
					+= new EventHandler (OnSelectedIndexChanged);
59
		}
56
		}
60
57
61
		public override void Disconnect ()
58
		public override void Disconnect ()
62
		{
59
		{
63
			if (Provider.Control is SWF.DirComboBox)
64
				((SWF.ComboBox) Provider.Control).SelectedValueChanged 
65
					-= new EventHandler (OnSelectedIndexChanged);
66
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
60
			((SWF.ComboBox) Provider.Control).SelectedIndexChanged 
67
				-= new EventHandler (OnSelectedIndexChanged);
61
				-= new EventHandler (OnSelectedIndexChanged);
68
		}
62
		}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGrid/DataItemAutomationFocusChangedEvent.cs (-6 / +8 lines)
Lines 70-81 namespace Mono.UIAutomation.Winforms.Events.DataGrid Link Here
70
		
70
		
71
		private void OnFocusChangedEvent (object sender, EventArgs args)
71
		private void OnFocusChangedEvent (object sender, EventArgs args)
72
		{
72
		{
73
			SWF.DataGridCell currentCell = itemProvider.DataGridProvider.DataGrid.CurrentCell;
73
			itemProvider.DataGridProvider.DataGrid.InvokeSync (delegate {
74
			if (currentCell.ColumnNumber == 0 && currentCell.RowNumber == itemProvider.Index) {
74
				SWF.DataGridCell currentCell = itemProvider.DataGridProvider.DataGrid.CurrentCell;
75
				if (focused)
75
				if (currentCell.ColumnNumber == 0 && currentCell.RowNumber == itemProvider.Index) {
76
					RaiseAutomationEvent ();
76
					if (focused)
77
				focused = !focused;
77
						RaiseAutomationEvent ();
78
			}
78
					focused = !focused;
79
				}
80
			});
79
		}
81
		}
80
		
82
		
81
		#endregion
83
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGrid/DataItemAutomationHasKeyboardFocusPropertyEvent.cs (-3 / +5 lines)
Lines 63-71 namespace Mono.UIAutomation.Winforms.Events.DataGrid Link Here
63
		
63
		
64
		private void OnCurrentCellChanged (object sender, EventArgs args)
64
		private void OnCurrentCellChanged (object sender, EventArgs args)
65
		{
65
		{
66
			SWF.DataGridCell currentCell = itemProvider.DataGridProvider.DataGrid.CurrentCell;
66
			itemProvider.DataGridProvider.DataGrid.InvokeSync (delegate {
67
			if (currentCell.ColumnNumber == 0 && currentCell.RowNumber == itemProvider.Index)
67
				SWF.DataGridCell currentCell = itemProvider.DataGridProvider.DataGrid.CurrentCell;
68
				RaiseAutomationPropertyChangedEvent ();
68
				if (currentCell.ColumnNumber == 0 && currentCell.RowNumber == itemProvider.Index)
69
					RaiseAutomationPropertyChangedEvent ();
70
			});
69
		}
71
		}
70
		
72
		
71
		#endregion
73
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGrid/DataItemSelectionItemPatternElementAddedEvent.cs (-7 / +9 lines)
Lines 71-83 namespace Mono.UIAutomation.Winforms.Events.DataGrid Link Here
71
71
72
			ListItemProvider provider = (ListItemProvider) Provider;
72
			ListItemProvider provider = (ListItemProvider) Provider;
73
			SWF.DataGrid datagrid = (SWF.DataGrid) sender;
73
			SWF.DataGrid datagrid = (SWF.DataGrid) sender;
74
			
74
75
			if (!selected
75
			datagrid.InvokeSync (delegate {
76
			    && datagrid.UIASelectedRows > 1
76
				if (!selected
77
			    && datagrid.IsSelected (provider.Index))
77
				    && datagrid.UIASelectedRows > 1
78
				RaiseAutomationEvent ();
78
				    && datagrid.IsSelected (provider.Index))
79
			
79
					RaiseAutomationEvent ();
80
			selected = datagrid.IsSelected (provider.Index);
80
				
81
				selected = datagrid.IsSelected (provider.Index);
82
			});
81
		}
83
		}
82
84
83
		#endregion
85
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGridView/DataItemChildSelectionItemPatternElementAddedEvent.cs (-1 / +1 lines)
Lines 71-77 namespace Mono.UIAutomation.Winforms.Events.DataGridView Link Here
71
			if (args.Cell.RowIndex == provider.Cell.RowIndex) {
71
			if (args.Cell.RowIndex == provider.Cell.RowIndex) {
72
				if (wasSelected != isSelected
72
				if (wasSelected != isSelected
73
				    && isSelected
73
				    && isSelected
74
				    && provider.DataGridViewProvider.DataGridView.SelectedCells.Count > 1) {
74
				    && provider.DataGridViewProvider.DataGridView.InvokeSync (d => d.SelectedCells.Count) > 1) {
75
					RaiseAutomationEvent ();
75
					RaiseAutomationEvent ();
76
				}
76
				}
77
77
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGridView/DataItemChildSelectionItemPatternElementRemovedEvent.cs (-1 / +1 lines)
Lines 71-77 namespace Mono.UIAutomation.Winforms.Events.DataGridView Link Here
71
			if (args.Cell.RowIndex == provider.Cell.RowIndex
71
			if (args.Cell.RowIndex == provider.Cell.RowIndex
72
			    && wasSelected
72
			    && wasSelected
73
			    && !selectionStatus
73
			    && !selectionStatus
74
			    && provider.DataGridViewProvider.DataGridView.SelectedCells.Count > 1)
74
			    && provider.DataGridViewProvider.DataGridView.InvokeSync (d => d.SelectedCells.Count) > 1)
75
				RaiseAutomationEvent ();
75
				RaiseAutomationEvent ();
76
76
77
			wasSelected = selectionStatus;
77
			wasSelected = selectionStatus;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGridView/DataItemChildSelectionItemPatternElementSelectedEvent.cs (-5 / +7 lines)
Lines 62-72 namespace Mono.UIAutomation.Winforms.Events.DataGridView Link Here
62
		private void OnCellStateChanged (object sender, 
62
		private void OnCellStateChanged (object sender, 
63
		                                 SWF.DataGridViewCellStateChangedEventArgs args)
63
		                                 SWF.DataGridViewCellStateChangedEventArgs args)
64
		{
64
		{
65
			if (provider.DataGridViewProvider.DataGridView.SelectedCells.Count == 1
65
			provider.DataGridViewProvider.DataGridView.InvokeSync (delegate {
66
			    && args.Cell.RowIndex == provider.Cell.RowIndex
66
				if (provider.DataGridViewProvider.DataGridView.SelectedCells.Count == 1
67
			    && args.Cell.ColumnIndex == provider.Cell.ColumnIndex
67
				    && args.Cell.RowIndex == provider.Cell.RowIndex
68
			    && provider.Cell.Selected)
68
				    && args.Cell.ColumnIndex == provider.Cell.ColumnIndex
69
			    RaiseAutomationEvent ();
69
				    && provider.Cell.Selected)
70
				    RaiseAutomationEvent ();
71
			});
70
		}
72
		}
71
73
72
		private DataGridViewProvider.DataGridViewDataItemChildProvider provider;
74
		private DataGridViewProvider.DataGridViewDataItemChildProvider provider;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGridView/DataItemSelectionItemPatternElementAddedEvent.cs (-1 / +1 lines)
Lines 68-74 namespace Mono.UIAutomation.Winforms.Events.DataGridView Link Here
68
			if (args.Cell.RowIndex == provider.Row.Index) {
68
			if (args.Cell.RowIndex == provider.Row.Index) {
69
				if (wasSelected != isSelected
69
				if (wasSelected != isSelected
70
				    && isSelected
70
				    && isSelected
71
				    && provider.DataGridView.SelectedCells.Count > 1) {
71
				    && provider.DataGridView.InvokeSync (d => d.SelectedCells.Count) > 1) {
72
					RaiseAutomationEvent ();
72
					RaiseAutomationEvent ();
73
				}
73
				}
74
74
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGridView/DataItemSelectionItemPatternElementRemovedEvent.cs (-1 / +1 lines)
Lines 71-77 namespace Mono.UIAutomation.Winforms.Events.DataGridView Link Here
71
			if (args.Cell.RowIndex == provider.Row.Index
71
			if (args.Cell.RowIndex == provider.Row.Index
72
			    && selected
72
			    && selected
73
			    && !selectionStatus
73
			    && !selectionStatus
74
			    && provider.DataGridView.SelectedCells.Count > 1)
74
			    && provider.DataGridView.InvokeSync (d => d.SelectedCells.Count) > 1)
75
				RaiseAutomationEvent ();
75
				RaiseAutomationEvent ();
76
76
77
			selected = selectionStatus;
77
			selected = selectionStatus;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/DataGridView/DataItemSelectionItemPatternElementSelectedEvent.cs (-5 / +7 lines)
Lines 62-72 namespace Mono.UIAutomation.Winforms.Events.DataGridView Link Here
62
		private void OnCellStateChagned (object sender, 
62
		private void OnCellStateChagned (object sender, 
63
		                                 SWF.DataGridViewCellStateChangedEventArgs args)
63
		                                 SWF.DataGridViewCellStateChangedEventArgs args)
64
		{
64
		{
65
			if (args.Cell.ColumnIndex == 0
65
			provider.DataGridView.InvokeSync (delegate {
66
			    && args.Cell.RowIndex == provider.Row.Index
66
				if (args.Cell.ColumnIndex == 0
67
			    && provider.DataGridView.SelectedCells.Count == 1
67
				    && args.Cell.RowIndex == provider.Row.Index
68
			    && provider.DataGridViewProvider.IsItemSelected ((ListItemProvider) provider))
68
				    && provider.DataGridView.SelectedCells.Count == 1
69
			    RaiseAutomationEvent ();
69
				    && provider.DataGridViewProvider.IsItemSelected ((ListItemProvider) provider))
70
				    RaiseAutomationEvent ();
71
			});
70
		}
72
		}
71
73
72
		private DataGridViewProvider.DataGridDataItemProvider provider;
74
		private DataGridViewProvider.DataGridDataItemProvider provider;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListBox/ListItemSelectionItemPatternElementSelectedEvent.cs (-3 / +5 lines)
Lines 68-76 namespace Mono.UIAutomation.Winforms.Events.ListBox Link Here
68
		{
68
		{
69
			ListItemProvider provider = (ListItemProvider) Provider;
69
			ListItemProvider provider = (ListItemProvider) Provider;
70
			
70
			
71
			if (((SWF.ListBox) provider.Control).SelectedIndex == provider.Index
71
			((SWF.ListBox) provider.Control).InvokeSync (c => {
72
			    && provider.ListProvider.SelectedItemsCount == 1)
72
				if (c.SelectedIndex == provider.Index
73
				RaiseAutomationEvent ();
73
				    && provider.ListProvider.SelectedItemsCount == 1)
74
					RaiseAutomationEvent ();
75
			});
74
		}
76
		}
75
77
76
		#endregion
78
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListView/HeaderItemAutomationBoundingRectanglePropertyEvent.cs (-3 / +5 lines)
Lines 60-68 namespace Mono.UIAutomation.Winforms.Events.ListView Link Here
60
60
61
		private void OnColumnWidthChanged (object sender, ColumnWidthChangedEventArgs args)
61
		private void OnColumnWidthChanged (object sender, ColumnWidthChangedEventArgs args)
62
		{
62
		{
63
			if (args.ColumnIndex
63
			itemProvider.HeaderProvider.ListView.InvokeSync (delegate {
64
			    == itemProvider.HeaderProvider.ListView.Columns.IndexOf (itemProvider.ColumnHeader))
64
				if (args.ColumnIndex
65
			    RaiseAutomationPropertyChangedEvent ();
65
				    == itemProvider.HeaderProvider.ListView.Columns.IndexOf (itemProvider.ColumnHeader))
66
				    RaiseAutomationPropertyChangedEvent ();
67
			});
66
		}
68
		}
67
69
68
		#endregion
70
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListView/HeaderItemAutomationIsOffScreenPropertyEvent.cs (-3 / +5 lines)
Lines 60-68 namespace Mono.UIAutomation.Winforms.Events.ListView Link Here
60
60
61
		private void OnColumnWidthChanged (object sender, ColumnWidthChangedEventArgs args)
61
		private void OnColumnWidthChanged (object sender, ColumnWidthChangedEventArgs args)
62
		{
62
		{
63
			if (args.ColumnIndex
63
			itemProvider.HeaderProvider.ListView.InvokeSync (delegate {
64
			    == itemProvider.HeaderProvider.ListView.Columns.IndexOf (itemProvider.ColumnHeader))
64
				if (args.ColumnIndex
65
			    RaiseAutomationPropertyChangedEvent ();
65
				    == itemProvider.HeaderProvider.ListView.Columns.IndexOf (itemProvider.ColumnHeader))
66
				    RaiseAutomationPropertyChangedEvent ();
67
			});
66
		}
68
		}
67
69
68
		#endregion
70
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListView/ListItemEditValuePatternValueEvent.cs (-9 / +13 lines)
Lines 61-79 namespace Mono.UIAutomation.Winforms.Events.ListView Link Here
61
61
62
		private void OnUIATextChanged (object sender, SWF.LabelEditEventArgs args)
62
		private void OnUIATextChanged (object sender, SWF.LabelEditEventArgs args)
63
		{
63
		{
64
			if (args.Item == editProvider.ItemProvider.ListView.Columns.IndexOf (editProvider.ColumnHeader)) {
64
			editProvider.ItemProvider.ListView.InvokeSync (delegate {
65
				newText = (string) editProvider.GetPropertyValue (ValuePatternIdentifiers.ValueProperty.Id);
65
				if (args.Item == editProvider.ItemProvider.ListView.Columns.IndexOf (editProvider.ColumnHeader)) {
66
				RaiseAutomationPropertyChangedEvent ();
66
					newText = (string) editProvider.GetPropertyValue (ValuePatternIdentifiers.ValueProperty.Id);
67
			}
67
					RaiseAutomationPropertyChangedEvent ();
68
				}
69
			});
68
		}
70
		}
69
71
70
		private void OnAfterLabelEdit (object sender, SWF.LabelEditEventArgs args)
72
		private void OnAfterLabelEdit (object sender, SWF.LabelEditEventArgs args)
71
		{
73
		{
72
			if (editProvider.ItemProvider.ListView.Items.IndexOf (editProvider.ItemProvider.ListViewItem) 
74
			editProvider.ItemProvider.ListView.InvokeSync (delegate {
73
			    == args.Item) {
75
				if (editProvider.ItemProvider.ListView.Items.IndexOf (editProvider.ItemProvider.ListViewItem) 
74
				newText = args.Label;
76
				    == args.Item) {
75
				RaiseAutomationPropertyChangedEvent ();
77
					newText = args.Label;
76
			}
78
					RaiseAutomationPropertyChangedEvent ();
79
				}
80
			});
77
		}
81
		}
78
82
79
		//We are doing this because AfterLabelEdit event is generated before commiting the text
83
		//We are doing this because AfterLabelEdit event is generated before commiting the text
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListView/ListItemSelectionItemPatternElementAddedEvent.cs (-7 / +9 lines)
Lines 66-78 namespace Mono.UIAutomation.Winforms.Events.ListView Link Here
66
		{
66
		{
67
			ListItemProvider provider = (ListItemProvider) Provider;
67
			ListItemProvider provider = (ListItemProvider) Provider;
68
			SWF.ListView listView = (SWF.ListView) sender;
68
			SWF.ListView listView = (SWF.ListView) sender;
69
			
69
70
			if (selected == false
70
			listView.InvokeSync (delegate {
71
			    && listView.SelectedIndices.Count > 1
71
				if (selected == false
72
			    && listView.SelectedIndices.Contains (provider.Index) == true)
72
				    && listView.SelectedIndices.Count > 1
73
				RaiseAutomationEvent ();
73
				    && listView.SelectedIndices.Contains (provider.Index) == true)
74
			
74
					RaiseAutomationEvent ();
75
			selected = listView.SelectedIndices.Contains (provider.Index);
75
				
76
				selected = listView.SelectedIndices.Contains (provider.Index);
77
			});
76
		}
78
		}
77
79
78
		#endregion
80
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListView/ListItemSelectionItemPatternElementRemovedEvent.cs (-7 / +9 lines)
Lines 68-80 namespace Mono.UIAutomation.Winforms.Events.ListView Link Here
68
		{
68
		{
69
			ListItemProvider provider = (ListItemProvider) Provider;
69
			ListItemProvider provider = (ListItemProvider) Provider;
70
			SWF.ListView listView = (SWF.ListView) sender;
70
			SWF.ListView listView = (SWF.ListView) sender;
71
			
71
72
			if (selected == true
72
			listView.InvokeSync (delegate {
73
			    && listView.SelectedIndices.Count > 1
73
				if (selected == true
74
			    && listView.SelectedIndices.Contains (provider.Index) == false)
74
				    && listView.SelectedIndices.Count > 1
75
				RaiseAutomationEvent ();
75
				    && listView.SelectedIndices.Contains (provider.Index) == false)
76
			
76
					RaiseAutomationEvent ();
77
			selected = listView.SelectedIndices.Contains (provider.Index);
77
				
78
				selected = listView.SelectedIndices.Contains (provider.Index);
79
			});
78
		}
80
		}
79
81
80
		#endregion
82
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListView/ListItemSelectionItemPatternElementSelectedEvent.cs (-4 / +6 lines)
Lines 65-74 namespace Mono.UIAutomation.Winforms.Events.ListView Link Here
65
		{
65
		{
66
			ListItemProvider provider = (ListItemProvider) Provider;
66
			ListItemProvider provider = (ListItemProvider) Provider;
67
			SWF.ListView listView = (SWF.ListView) sender;
67
			SWF.ListView listView = (SWF.ListView) sender;
68
			
68
69
			if (listView.SelectedIndices.Count == 1
69
			listView.InvokeSync (delegate {
70
			    && listView.SelectedIndices.Contains (provider.Index) == true)
70
				if (listView.SelectedIndices.Count == 1
71
				RaiseAutomationEvent ();
71
				    && listView.SelectedIndices.Contains (provider.Index) == true)
72
					RaiseAutomationEvent ();
73
			});
72
		}
74
		}
73
75
74
		#endregion
76
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListView/ListItemSelectionItemPatternIsSelectedEvent.cs (-7 / +9 lines)
Lines 67-79 namespace Mono.UIAutomation.Winforms.Events.ListView Link Here
67
		{
67
		{
68
			SWF.ListView listView = (SWF.ListView) sender;
68
			SWF.ListView listView = (SWF.ListView) sender;
69
			ListItemProvider provider = (ListItemProvider) Provider;
69
			ListItemProvider provider = (ListItemProvider) Provider;
70
			
70
71
			bool selectedChanged = listView.SelectedIndices.Contains (provider.Index);
71
			listView.InvokeSync (delegate {
72
			
72
				bool selectedChanged = listView.SelectedIndices.Contains (provider.Index);
73
			if (selectedChanged != selected) {
73
				
74
			    RaiseAutomationPropertyChangedEvent ();
74
				if (selectedChanged != selected) {
75
				selected = selectedChanged;
75
				    RaiseAutomationPropertyChangedEvent ();
76
			}
76
					selected = selectedChanged;
77
				}
78
			});
77
		}
79
		}
78
80
79
		#endregion
81
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/RadioButton/SelectionItemPatternElementSelectedEvent.cs (-1 / +1 lines)
Lines 59-65 namespace Mono.UIAutomation.Winforms.Events.RadioButton Link Here
59
		
59
		
60
		private void OnElementSelectedEvent (object sender, System.EventArgs e)
60
		private void OnElementSelectedEvent (object sender, System.EventArgs e)
61
		{
61
		{
62
			if (((SWF.RadioButton) Provider.Control).Checked)
62
			if (((SWF.RadioButton) Provider.Control).InvokeSync (c => c.Checked))
63
				RaiseAutomationEvent ();
63
				RaiseAutomationEvent ();
64
		}
64
		}
65
		
65
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/TextBox/TextPatternCaretMovedEvent.cs (-1 / +1 lines)
Lines 63-69 namespace Mono.UIAutomation.Winforms.Events.TextBox Link Here
63
				if (Provider.Control is SWF.TextBoxBase)
63
				if (Provider.Control is SWF.TextBoxBase)
64
					return (SWF.TextBoxBase)Provider.Control;
64
					return (SWF.TextBoxBase)Provider.Control;
65
				else if (Provider.Control is SWF.UpDownBase)
65
				else if (Provider.Control is SWF.UpDownBase)
66
					return ((SWF.UpDownBase)Provider.Control).txtView;
66
					return ((SWF.UpDownBase)Provider.Control).InvokeSync (c => c.txtView);
67
				else
67
				else
68
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
68
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
69
			}
69
			}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/TextBox/TextPatternTextSelectionChangedEvent.cs (-2 / +2 lines)
Lines 73-79 namespace Mono.UIAutomation.Winforms.Events.TextBox Link Here
73
		private void OnSelectionChangedEvent (object sender, 
73
		private void OnSelectionChangedEvent (object sender, 
74
		                                    EventArgs args)
74
		                                    EventArgs args)
75
		{
75
		{
76
			SWF.Document document = TextBoxBase.Document;
76
			SWF.Document document = TextBoxBase.InvokeSync (c => c.Document);
77
			if (!selectionVisible && !document.selection_visible)
77
			if (!selectionVisible && !document.selection_visible)
78
				return;
78
				return;
79
			if (document.selection_visible != selectionVisible || document.selection_start != selectionStart || document.selection_end != selectionEnd) {
79
			if (document.selection_visible != selectionVisible || document.selection_start != selectionStart || document.selection_end != selectionEnd) {
Lines 89-95 namespace Mono.UIAutomation.Winforms.Events.TextBox Link Here
89
				if (Provider.Control is SWF.TextBoxBase)
89
				if (Provider.Control is SWF.TextBoxBase)
90
					return (SWF.TextBoxBase)Provider.Control;
90
					return (SWF.TextBoxBase)Provider.Control;
91
				else if (Provider.Control is SWF.UpDownBase)
91
				else if (Provider.Control is SWF.UpDownBase)
92
					return ((SWF.UpDownBase)Provider.Control).txtView;
92
					return ((SWF.UpDownBase)Provider.Control).InvokeSync (c => c.txtView);
93
				else
93
				else
94
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
94
					throw new Exception ("TextBoxBase: Unknown type: " + Provider.Control);
95
			}
95
			}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Navigation/ParentNavigation.cs (-1 / +8 lines)
Lines 160-190 namespace Mono.UIAutomation.Winforms.Navigation Link Here
160
				} else {
160
				} else {
161
					AddElementAt (args.Index, args.ChildProvider.Navigation);
161
					AddElementAt (args.Index, args.ChildProvider.Navigation);
162
				}
162
				}
163
		
163
164
				
164
				if (args.RaiseEvent == true) {
165
				if (args.RaiseEvent == true) {
166
//					Helper.DelegateQueue.Get ().Enqueue (delegate {
165
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildAdded, 
167
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildAdded, 
166
					                                   args.ChildProvider);
168
					                                   args.ChildProvider);
167
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildrenInvalidated,
169
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildrenInvalidated,
168
					                                   (FragmentControlProvider) sender);
170
					                                   (FragmentControlProvider) sender);
171
//					});
169
				}
172
				}
170
			} else if (args.ChangeType == StructureChangeType.ChildRemoved) {
173
			} else if (args.ChangeType == StructureChangeType.ChildRemoved) {
171
				Remove (args.ChildProvider.Navigation);
174
				Remove (args.ChildProvider.Navigation);
172
	
175
	
173
				if (args.RaiseEvent == true) {
176
				if (args.RaiseEvent == true) {
177
//					Helper.DelegateQueue.Get ().Enqueue (delegate {
174
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildRemoved, 
178
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildRemoved, 
175
					                                   args.ChildProvider);
179
					                                   args.ChildProvider);
176
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildrenInvalidated,
180
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildrenInvalidated,
177
					                                   (FragmentControlProvider) sender);
181
					                                   (FragmentControlProvider) sender);
182
//					});
178
				}
183
				}
179
			} else if (args.ChangeType == StructureChangeType.ChildrenReordered) {
184
			} else if (args.ChangeType == StructureChangeType.ChildrenReordered) {
180
				chain.Clear ();
185
				chain.Clear ();
181
				
186
				
182
				//TODO: Is this the event to generate?
187
				//TODO: Is this the event to generate?
183
				if (args.RaiseEvent == true) {
188
				if (args.RaiseEvent == true) {
189
//					Helper.DelegateQueue.Get ().Enqueue (delegate {
184
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildrenBulkRemoved, 
190
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildrenBulkRemoved, 
185
					                                   (FragmentControlProvider) sender);
191
					                                   (FragmentControlProvider) sender);
186
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildrenInvalidated,
192
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildrenInvalidated,
187
					                                   (FragmentControlProvider) sender);
193
					                                   (FragmentControlProvider) sender);
194
//					});
188
				}
195
				}
189
			}
196
			}
190
		}
197
		}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.mdp (-3 / +10 lines)
Lines 1-4 Link Here
1
<Project name="Mono.UIAutomation.Winforms" fileversion="2.0" language="C#" UseParentDirectoryAsNamespace="True" DefaultNamespace="Mono.UIAutomation.Winforms" clr-version="Net_2_0" targetFramework="3.5" ctype="DotNetProject">
1
<Project name="Mono.UIAutomation.Winforms" fileversion="2.0" language="C#" DefaultNamespace="Mono.UIAutomation.Winforms" UseParentDirectoryAsNamespace="True" clr-version="Net_2_0" targetFramework="3.5" ctype="DotNetProject">
2
  <Configurations active="Debug">
2
  <Configurations active="Debug">
3
    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
3
    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
4
      <Output directory="bin/Debug" signAssembly="True" assemblyKeyFile="../mono-uia.snk" assembly="UIAutomationWinforms" />
4
      <Output directory="bin/Debug" signAssembly="True" assemblyKeyFile="../mono-uia.snk" assembly="UIAutomationWinforms" />
Lines 23-29 Link Here
23
    <File name="Mono.UIAutomation.Winforms/RadioButtonProvider.cs" subtype="Code" buildaction="Compile" />
23
    <File name="Mono.UIAutomation.Winforms/RadioButtonProvider.cs" subtype="Code" buildaction="Compile" />
24
    <File name="Mono.UIAutomation.Winforms/LabelProvider.cs" subtype="Code" buildaction="Compile" />
24
    <File name="Mono.UIAutomation.Winforms/LabelProvider.cs" subtype="Code" buildaction="Compile" />
25
    <File name="Mono.UIAutomation.Winforms/TextBoxProvider.cs" subtype="Code" buildaction="Compile" />
25
    <File name="Mono.UIAutomation.Winforms/TextBoxProvider.cs" subtype="Code" buildaction="Compile" />
26
    <File name="Mono.UIAutomation.Winforms/Helper.cs" subtype="Code" buildaction="Compile" />
27
    <File name="Mono.UIAutomation.Winforms/LinkLabelProvider.cs" subtype="Code" buildaction="Compile" />
26
    <File name="Mono.UIAutomation.Winforms/LinkLabelProvider.cs" subtype="Code" buildaction="Compile" />
28
    <File name="Mono.UIAutomation.Winforms.Events/AutomationHasKeyboardFocusPropertyEvent.cs" subtype="Code" buildaction="Compile" />
27
    <File name="Mono.UIAutomation.Winforms.Events/AutomationHasKeyboardFocusPropertyEvent.cs" subtype="Code" buildaction="Compile" />
29
    <File name="Mono.UIAutomation.Winforms.Events/AutomationBoundingRectanglePropertyEvent.cs" subtype="Code" buildaction="Compile" />
28
    <File name="Mono.UIAutomation.Winforms.Events/AutomationBoundingRectanglePropertyEvent.cs" subtype="Code" buildaction="Compile" />
Lines 567-572 Link Here
567
    <File name="Mono.UIAutomation.Winforms.Events/DataGridView/DataItemChildHasKeyboardFocusPropertyEvent.cs" subtype="Code" buildaction="Compile" />
566
    <File name="Mono.UIAutomation.Winforms.Events/DataGridView/DataItemChildHasKeyboardFocusPropertyEvent.cs" subtype="Code" buildaction="Compile" />
568
    <File name="Mono.UIAutomation.Winforms.Behaviors/DataGrid/DataItemEditSelectionItemProviderBehavior.cs" subtype="Code" buildaction="Compile" />
567
    <File name="Mono.UIAutomation.Winforms.Behaviors/DataGrid/DataItemEditSelectionItemProviderBehavior.cs" subtype="Code" buildaction="Compile" />
569
    <File name="Mono.UIAutomation.Winforms.Events/DataGrid/DataItemEditSelectionItemPatternIsSelectedEvent.cs" subtype="Code" buildaction="Compile" />
568
    <File name="Mono.UIAutomation.Winforms.Events/DataGrid/DataItemEditSelectionItemPatternIsSelectedEvent.cs" subtype="Code" buildaction="Compile" />
569
    <File name="Mono.UIAutomation.Winforms.Behaviors/ListView/ListItemInvokeProviderBehavior.cs" subtype="Code" buildaction="Compile" />
570
    <File name="Mono.UIAutomation.Winforms.Behaviors/ToolStripButton/ToggleProviderBehavior.cs" subtype="Code" buildaction="Compile" />
571
    <File name="Mono.UIAutomation.Winforms.Events/DateTimePicker/CheckboxAutomationHasKeyboardFocusPropertyEvent.cs" subtype="Code" buildaction="Compile" />
572
    <File name="Mono.UIAutomation.Winforms.Events/DateTimePicker/PartAutomationHasKeyboardFocusPropertyEvent.cs" subtype="Code" buildaction="Compile" />
573
    <File name="Mono.UIAutomation.Winforms.Events/MonthCalendar/AutomationNamePropertyEvent.cs" subtype="Code" buildaction="Compile" />
574
    <File name="Mono.UIAutomation.Winforms.Events/PopupButton/AutomationHasKeyboardFocusPropertyEvent.cs" subtype="Code" buildaction="Compile" />
575
    <File name="Mono.UIAutomation.Winforms.Events/ToolStripButton/TogglePatternToggleStateEvent.cs" subtype="Code" buildaction="Compile" />
576
    <File name="Mono.UIAutomation.Winforms/Helper.cs" subtype="Code" buildaction="Compile" />
570
  </Contents>
577
  </Contents>
571
  <References>
578
  <References>
572
    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
579
    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Lines 578-587 Link Here
578
    <ProjectReference type="Gac" localcopy="True" refto="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
585
    <ProjectReference type="Gac" localcopy="True" refto="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
579
    <ProjectReference type="Gac" localcopy="True" refto="UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
586
    <ProjectReference type="Gac" localcopy="True" refto="UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
580
    <ProjectReference type="Gac" localcopy="True" refto="UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
587
    <ProjectReference type="Gac" localcopy="True" refto="UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
588
    <ProjectReference type="Gac" localcopy="True" refto="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
581
    <ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.14.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
589
    <ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.14.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
582
    <ProjectReference type="Gac" localcopy="True" refto="atk-sharp, Version=2.14.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
590
    <ProjectReference type="Gac" localcopy="True" refto="atk-sharp, Version=2.14.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
583
    <ProjectReference type="Gac" localcopy="True" refto="Mono.WebBrowser, Version=0.5.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
591
    <ProjectReference type="Gac" localcopy="True" refto="Mono.WebBrowser, Version=0.5.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
584
    <ProjectReference type="Gac" localcopy="True" refto="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
585
  </References>
592
  </References>
586
  <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am" IsAutotoolsProject="True" RelativeConfigureInPath="..">
593
  <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am" IsAutotoolsProject="True" RelativeConfigureInPath="..">
587
    <BuildFilesVar Sync="True" Name="FILES" />
594
    <BuildFilesVar Sync="True" Name="FILES" />
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/BalloonWindowProvider.cs (-1 / +1 lines)
Lines 75-81 namespace Mono.UIAutomation.Winforms Link Here
75
		protected override object GetProviderPropertyValue (int propertyId)
75
		protected override object GetProviderPropertyValue (int propertyId)
76
		{
76
		{
77
			if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id)
77
			if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id)
78
				return balloon.AccessibleDescription?? balloon.Title;
78
				return balloon.InvokeSync (c => c.AccessibleDescription ?? c.Title);
79
			else if (propertyId == AutomationElementIdentifiers.IsNotifyIconProperty.Id)
79
			else if (propertyId == AutomationElementIdentifiers.IsNotifyIconProperty.Id)
80
				return true;
80
				return true;
81
			else
81
			else
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/CheckedListBoxProvider.cs (-3 / +6 lines)
Lines 52-59 namespace Mono.UIAutomation.Winforms Link Here
52
		{
52
		{
53
			if (ContainsItem (item) == true) {
53
			if (ContainsItem (item) == true) {
54
				SWF.CheckedListBox checkedListBox = (SWF.CheckedListBox) Control;
54
				SWF.CheckedListBox checkedListBox = (SWF.CheckedListBox) Control;
55
				bool chcked = checkedListBox.GetItemChecked (item.Index);
55
				checkedListBox.InvokeSync (delegate {
56
				checkedListBox.SetItemChecked (item.Index, !chcked);
56
					bool chcked = checkedListBox.GetItemChecked (item.Index);
57
					checkedListBox.SetItemChecked (item.Index, !chcked);
58
				});
57
			}
59
			}
58
		}
60
		}
59
		
61
		
Lines 62-68 namespace Mono.UIAutomation.Winforms Link Here
62
			if (ContainsItem (item) == true) {
64
			if (ContainsItem (item) == true) {
63
				SWF.CheckedListBox checkedListBox = (SWF.CheckedListBox) Control;	
65
				SWF.CheckedListBox checkedListBox = (SWF.CheckedListBox) Control;	
64
				
66
				
65
				SWF.CheckState state = checkedListBox.GetItemCheckState (item.Index);
67
				SWF.CheckState state 
68
					= checkedListBox.InvokeSync (c => c.GetItemCheckState (item.Index));
66
				switch (state) {
69
				switch (state) {
67
					case SWF.CheckState.Checked:
70
					case SWF.CheckState.Checked:
68
						return ToggleState.On;
71
						return ToggleState.On;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ComboBoxProvider.cs (-54 / +73 lines)
Lines 79-85 namespace Mono.UIAutomation.Winforms Link Here
79
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
79
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
80
				return Catalog.GetString ("combo box");
80
				return Catalog.GetString ("combo box");
81
			else if (propertyId == AEIds.HasKeyboardFocusProperty.Id
81
			else if (propertyId == AEIds.HasKeyboardFocusProperty.Id
82
				 && comboboxControl.DropDownStyle == SWF.ComboBoxStyle.DropDown)
82
			         && comboboxControl.InvokeSync (b => b.DropDownStyle == SWF.ComboBoxStyle.DropDown))
83
				return false;
83
				return false;
84
			else
84
			else
85
				return base.GetProviderPropertyValue (propertyId);
85
				return base.GetProviderPropertyValue (propertyId);
Lines 107-114 namespace Mono.UIAutomation.Winforms Link Here
107
		
107
		
108
		public override IRawElementProviderFragment GetFocus ()
108
		public override IRawElementProviderFragment GetFocus ()
109
		{
109
		{
110
			return listboxProvider.GetItemProviderFrom (listboxProvider, 
110
			return comboboxControl.InvokeSync (c => listboxProvider.GetItemProviderFrom (listboxProvider, c.SelectedItem));
111
			                                            comboboxControl.SelectedItem);
112
		}		
111
		}		
113
		
112
		
114
		public override IRawElementProviderFragment ElementProviderFromPoint (double x, double y)
113
		public override IRawElementProviderFragment ElementProviderFromPoint (double x, double y)
Lines 159-165 namespace Mono.UIAutomation.Winforms Link Here
159
		
158
		
160
		private void UpdateBehaviors (bool updateAssociatedChildren) 
159
		private void UpdateBehaviors (bool updateAssociatedChildren) 
161
		{
160
		{
162
			if (comboboxControl.DropDownStyle == SWF.ComboBoxStyle.Simple) {
161
			SWF.ComboBoxStyle style 
162
				= comboboxControl.InvokeSync (c => c.DropDownStyle);
163
			
164
			if (style == SWF.ComboBoxStyle.Simple) {
163
				SetBehavior (ExpandCollapsePatternIdentifiers.Pattern, 
165
				SetBehavior (ExpandCollapsePatternIdentifiers.Pattern, 
164
				             null);
166
				             null);
165
				if (!IsBehaviorEnabled (ValuePatternIdentifiers.Pattern))
167
				if (!IsBehaviorEnabled (ValuePatternIdentifiers.Pattern))
Lines 173-179 namespace Mono.UIAutomation.Winforms Link Here
173
					TerminateButtonProvider ();
175
					TerminateButtonProvider ();
174
					InitializeEditProvider ();
176
					InitializeEditProvider ();
175
				}
177
				}
176
			} else if (comboboxControl.DropDownStyle == SWF.ComboBoxStyle.DropDown) {
178
			} else if (style == SWF.ComboBoxStyle.DropDown) {
177
				if (!IsBehaviorEnabled (ExpandCollapsePatternIdentifiers.Pattern))
179
				if (!IsBehaviorEnabled (ExpandCollapsePatternIdentifiers.Pattern))
178
					SetBehavior (ExpandCollapsePatternIdentifiers.Pattern,
180
					SetBehavior (ExpandCollapsePatternIdentifiers.Pattern,
179
					             new ExpandCollapseProviderBehavior (this));
181
					             new ExpandCollapseProviderBehavior (this));
Lines 188-194 namespace Mono.UIAutomation.Winforms Link Here
188
					InitializeButtonProvider ();
190
					InitializeButtonProvider ();
189
					InitializeEditProvider ();
191
					InitializeEditProvider ();
190
				}
192
				}
191
			} else if (comboboxControl.DropDownStyle == SWF.ComboBoxStyle.DropDownList) {
193
			} else if (style == SWF.ComboBoxStyle.DropDownList) {
192
				if (!IsBehaviorEnabled (ExpandCollapsePatternIdentifiers.Pattern))
194
				if (!IsBehaviorEnabled (ExpandCollapsePatternIdentifiers.Pattern))
193
					SetBehavior (ExpandCollapsePatternIdentifiers.Pattern,
195
					SetBehavior (ExpandCollapsePatternIdentifiers.Pattern,
194
					             new ExpandCollapseProviderBehavior (this));
196
					             new ExpandCollapseProviderBehavior (this));
Lines 299-305 namespace Mono.UIAutomation.Winforms Link Here
299
					else
301
					else
300
						return Helper.GetControlScreenBounds (listboxControl.Bounds, listboxControl);
302
						return Helper.GetControlScreenBounds (listboxControl.Bounds, listboxControl);
301
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
303
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
302
					if (comboboxControl.DropDownStyle == SWF.ComboBoxStyle.Simple)
304
					if (comboboxControl.InvokeSync (s => s.DropDownStyle)
305
					    == SWF.ComboBoxStyle.Simple)
303
						return false;
306
						return false;
304
					
307
					
305
					IExpandCollapseProvider pattern 
308
					IExpandCollapseProvider pattern 
Lines 310-369 namespace Mono.UIAutomation.Winforms Link Here
310
			}
313
			}
311
314
312
			public override int SelectedItemsCount {
315
			public override int SelectedItemsCount {
313
				get { return comboboxControl.SelectedIndex == -1 ? 0 : 1; }
316
				get {
317
					return comboboxControl.InvokeSync (c => c.SelectedIndex == -1 ? 0 : 1);
318
				}
314
			}
319
			}
315
			
320
			
316
			public override int ItemsCount {
321
			public override int ItemsCount {
317
				get { return comboboxControl.Items.Count; }
322
				get {
323
					return comboboxControl.InvokeSync (c => c.Items.Count);
324
				}
318
			}
325
			}
319
326
320
			public override int IndexOfObjectItem (object objectItem)
327
			public override int IndexOfObjectItem (object objectItem)
321
			{
328
			{
322
				return comboboxControl.Items.IndexOf (objectItem);
329
				return comboboxControl.InvokeSync (c => c.Items.IndexOf (objectItem));
323
			}	
330
			}	
324
331
325
			public override IRawElementProviderSimple[] GetSelectedItems ()
332
			public override IRawElementProviderSimple[] GetSelectedItems ()
326
			{
333
			{
327
				if (comboboxControl == null || comboboxControl.SelectedIndex == -1)
334
				if (comboboxControl == null)
328
					return new IRawElementProviderSimple [0];
335
					return new IRawElementProviderSimple [0];
329
				else
336
				return comboboxControl.InvokeSync (c => {
330
					return new IRawElementProviderSimple [] { GetItemProviderFrom (this,
337
					if (c.SelectedIndex == -1)
331
					                                                               comboboxControl.SelectedItem) };
338
						return new IRawElementProviderSimple [0];
339
					else
340
						return new IRawElementProviderSimple [] { GetItemProviderFrom (this,
341
						                                                               c.SelectedItem) };
342
				});
332
			}
343
			}
333
344
334
			public override void SelectItem (ListItemProvider item)
345
			public override void SelectItem (ListItemProvider item)
335
			{
346
			{
336
				if (ContainsItem (item) == true) {
347
				if (ContainsItem (item) == true) {
337
					comboboxControl.SelectedIndex = item.Index;
348
					comboboxControl.InvokeSync (delegate {
338
349
						comboboxControl.SelectedIndex = item.Index;
339
					// Raise SelectionChangeCommitted event
350
						// Raise SelectionChangeCommitted event
340
					// on the ComboBox. Since we are simulating
351
						// on the ComboBox. Since we are simulating
341
					// a user interacting with the control,
352
						// a user interacting with the control,
342
					// this event is expected.
353
						// this event is expected.
343
					//
354
						//
344
					// NOTE: This is a protected method that
355
						// NOTE: This is a protected method that
345
					//       is a part of the documented
356
						//       is a part of the documented
346
					//       API for SWF.ComboBox.
357
						//       API for SWF.ComboBox.
347
					MethodInfo onSelectionChangeCommitted =
358
						MethodInfo onSelectionChangeCommitted =
348
						comboboxControl.GetType ().GetMethod ("OnSelectionChangeCommitted",
359
							comboboxControl.GetType ().GetMethod ("OnSelectionChangeCommitted",
349
						                                      BindingFlags.NonPublic | BindingFlags.Instance);
360
							                                      BindingFlags.NonPublic | BindingFlags.Instance);
350
					if (onSelectionChangeCommitted != null) {
361
						if (onSelectionChangeCommitted != null) {
351
						onSelectionChangeCommitted.Invoke (comboboxControl,
362
							onSelectionChangeCommitted.Invoke (comboboxControl,
352
							                                   new object [] {EventArgs.Empty});
363
								                                   new object [] {EventArgs.Empty});
353
					}
364
						}
365
					});
354
				}
366
				}
355
			}
367
			}
356
	
368
	
357
			public override void UnselectItem (ListItemProvider item)
369
			public override void UnselectItem (ListItemProvider item)
358
			{
370
			{
359
				if (ContainsItem (item) == true)
371
				if (ContainsItem (item) == true)
360
					comboboxControl.SelectedIndex = -1;
372
					comboboxControl.InvokeSync (delegate {
373
						comboboxControl.SelectedIndex = -1;
374
					});
361
			}
375
			}
362
			
376
			
363
			public override bool IsItemSelected (ListItemProvider item)
377
			public override bool IsItemSelected (ListItemProvider item)
364
			{
378
			{
365
				return ContainsItem (item) == false 
379
				if (!ContainsItem (item))
366
					? false : item.Index == comboboxControl.SelectedIndex;
380
					return false;
381
				else
382
					return comboboxControl.InvokeSync (c => {
383
						return item.Index == c.SelectedIndex; });
367
			}
384
			}
368
385
369
			public override void InitializeChildControlStructure ()
386
			public override void InitializeChildControlStructure ()
Lines 372-378 namespace Mono.UIAutomation.Winforms Link Here
372
389
373
				comboboxControl.Items.UIACollectionChanged += OnCollectionChanged;
390
				comboboxControl.Items.UIACollectionChanged += OnCollectionChanged;
374
391
375
				foreach (object objectItem in comboboxControl.Items) {
392
				foreach (object objectItem 
393
				         in comboboxControl.InvokeSync (c => c.Items)) {
376
					ListItemProvider item = GetItemProviderFrom (this, objectItem);
394
					ListItemProvider item = GetItemProviderFrom (this, objectItem);
377
					AddChildProvider (item);
395
					AddChildProvider (item);
378
				}
396
				}
Lines 395-402 namespace Mono.UIAutomation.Winforms Link Here
395
			                                             int propertyId)
413
			                                             int propertyId)
396
			{
414
			{
397
				if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
415
				if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
398
					return comboboxControl.GetItemText (item.ObjectItem);
416
					return comboboxControl.InvokeSync (c => c.GetItemText (item.ObjectItem));
399
400
				int topItem = -1;
417
				int topItem = -1;
401
				if (ListBoxControl != null)
418
				if (ListBoxControl != null)
402
					topItem = ListBoxControl.UIATopItem;
419
					topItem = ListBoxControl.UIATopItem;
Lines 404-410 namespace Mono.UIAutomation.Winforms Link Here
404
				if (ContainsItem (item) == false)
421
				if (ContainsItem (item) == false)
405
					return null;
422
					return null;
406
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
423
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
407
					return comboboxControl.Focused && item.Index == comboboxControl.SelectedIndex;
424
					return comboboxControl.InvokeSync (b => b.Focused && item.Index == b.SelectedIndex);
408
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
425
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
409
					//FIXME: We need to improve this
426
					//FIXME: We need to improve this
410
					int index = item.Index;
427
					int index = item.Index;
Lines 412-423 namespace Mono.UIAutomation.Winforms Link Here
412
					System.Drawing.Rectangle bounds = System.Drawing.Rectangle.Empty;
429
					System.Drawing.Rectangle bounds = System.Drawing.Rectangle.Empty;
413
430
414
					if (ListBoxControl == null)
431
					if (ListBoxControl == null)
415
						bounds = comboboxControl.Bounds;
432
						bounds = comboboxControl.InvokeSync (c => c.Bounds);
416
					else
433
					else
417
						bounds = ListBoxControl.Bounds;
434
						bounds = ListBoxControl.InvokeSync (c => c.Bounds);
418
435
419
					int itemHeight = comboboxControl.GetItemHeight (0);// TODO: always true?
436
					int itemHeight = comboboxControl.InvokeSync (c => c.GetItemHeight (0));// TODO: always true?
420
					rectangle.Height = comboboxControl.GetItemHeight (index);
437
					rectangle.Height = comboboxControl.InvokeSync (c => c.GetItemHeight (index));
421
					rectangle.Width = bounds.Width;
438
					rectangle.Width = bounds.Width;
422
					rectangle.X = bounds.X;
439
					rectangle.X = bounds.X;
423
					rectangle.Y = bounds.Y + (index * itemHeight) - (topItem * itemHeight);// decreaseY;
440
					rectangle.Y = bounds.Y + (index * itemHeight) - (topItem * itemHeight);// decreaseY;
Lines 427-444 namespace Mono.UIAutomation.Winforms Link Here
427
					else
444
					else
428
						return Helper.GetControlScreenBounds (rectangle, ListBoxControl);
445
						return Helper.GetControlScreenBounds (rectangle, ListBoxControl);
429
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
446
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
430
					if (comboboxControl.SelectedIndex == item.Index)
447
					return comboboxControl.InvokeSync (c => {
431
						return false;
448
						if (c.SelectedIndex == item.Index)
432
					
449
							return false;
433
					if (topItem == -1 || !ListBoxControl.Visible)
450
						
434
						return !(comboboxControl.SelectedIndex == item.Index);
451
						if (topItem == -1 || !ListBoxControl.Visible)
435
452
							return !(c.SelectedIndex == item.Index);
436
					int lastItem = ListBoxControl.UIALastItem;				
453
	
437
					if ((item.Index >= topItem && item.Index < lastItem) 
454
						int lastItem = ListBoxControl.UIALastItem;				
438
					    || (item.Index == lastItem && comboboxControl.Items.Count == lastItem + 1))
455
						if ((item.Index >= topItem && item.Index < lastItem) 
439
						return false;
456
						    || (item.Index == lastItem && c.Items.Count == lastItem + 1))
440
					else
457
							return false;
458
						else
441
						return true;
459
						return true;
460
					});
442
				} else
461
				} else
443
					return null;
462
					return null;
444
			}
463
			}
Lines 594-600 namespace Mono.UIAutomation.Winforms Link Here
594
					// This control cannot be selected, but
613
					// This control cannot be selected, but
595
					// it can still be keyboard focused, so
614
					// it can still be keyboard focused, so
596
					// we override it manually.
615
					// we override it manually.
597
					return Control.CanFocus;
616
					return Control.InvokeSync (c => c.CanFocus);
598
				}
617
				}
599
618
600
				return base.GetProviderPropertyValue (propertyId);
619
				return base.GetProviderPropertyValue (propertyId);
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ContextMenuProvider.cs (+5 lines)
Lines 70-87 namespace Mono.UIAutomation.Winforms Link Here
70
		{
70
		{
71
			base.Initialize ();
71
			base.Initialize ();
72
72
73
//			System.Threading.ThreadPool.QueueUserWorkItem (v => {
74
73
			AutomationEventArgs args = new AutomationEventArgs (AEIds.MenuOpenedEvent);
75
			AutomationEventArgs args = new AutomationEventArgs (AEIds.MenuOpenedEvent);
74
			AutomationInteropProvider.RaiseAutomationEvent (AEIds.MenuOpenedEvent,
76
			AutomationInteropProvider.RaiseAutomationEvent (AEIds.MenuOpenedEvent,
75
			                                                this,
77
			                                                this,
76
			                                                args);
78
			                                                args);
79
//			});
77
		}
80
		}
78
81
79
		public override void Terminate ()
82
		public override void Terminate ()
80
		{
83
		{
84
//			System.Threading.ThreadPool.QueueUserWorkItem (v => {
81
			AutomationEventArgs args = new AutomationEventArgs (AEIds.MenuClosedEvent);
85
			AutomationEventArgs args = new AutomationEventArgs (AEIds.MenuClosedEvent);
82
			AutomationInteropProvider.RaiseAutomationEvent (AEIds.MenuClosedEvent,
86
			AutomationInteropProvider.RaiseAutomationEvent (AEIds.MenuClosedEvent,
83
			                                                this,
87
			                                                this,
84
			                                                args);
88
			                                                args);
89
//			});
85
			base.Terminate ();
90
			base.Terminate ();
86
		}
91
		}
87
		
92
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ContextMenuStripProvider.cs (+4 lines)
Lines 47-65 namespace Mono.UIAutomation.Winforms Link Here
47
		public override void Initialize ()
47
		public override void Initialize ()
48
		{
48
		{
49
			base.Initialize ();
49
			base.Initialize ();
50
//			System.Threading.ThreadPool.QueueUserWorkItem (v => {
50
51
51
			AutomationEventArgs args = new AutomationEventArgs (AEIds.MenuOpenedEvent);
52
			AutomationEventArgs args = new AutomationEventArgs (AEIds.MenuOpenedEvent);
52
			AutomationInteropProvider.RaiseAutomationEvent (AEIds.MenuOpenedEvent,
53
			AutomationInteropProvider.RaiseAutomationEvent (AEIds.MenuOpenedEvent,
53
			                                                this,
54
			                                                this,
54
			                                                args);
55
			                                                args);
56
//			});
55
		}
57
		}
56
58
57
		public override void Terminate ()
59
		public override void Terminate ()
58
		{
60
		{
61
//			System.Threading.ThreadPool.QueueUserWorkItem (v => {
59
			AutomationEventArgs args = new AutomationEventArgs (AEIds.MenuClosedEvent);
62
			AutomationEventArgs args = new AutomationEventArgs (AEIds.MenuClosedEvent);
60
			AutomationInteropProvider.RaiseAutomationEvent (AEIds.MenuClosedEvent,
63
			AutomationInteropProvider.RaiseAutomationEvent (AEIds.MenuClosedEvent,
61
			                                                this,
64
			                                                this,
62
			                                                args);
65
			                                                args);
66
//			});
63
			base.Terminate ();
67
			base.Terminate ();
64
		}
68
		}
65
69
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/DataGridProvider.cs (-86 / +113 lines)
Lines 57-63 namespace Mono.UIAutomation.Winforms Link Here
57
		#region Public Properties
57
		#region Public Properties
58
58
59
		public SWF.DataGridTableStyle CurrentTableStyle {
59
		public SWF.DataGridTableStyle CurrentTableStyle {
60
			get { return datagrid.UIACurrentTableStyle; }
60
			get { return datagrid.InvokeSync (v => v.UIACurrentTableStyle); }
61
		}
61
		}
62
62
63
		public SWF.CurrencyManager CurrencyManager {
63
		public SWF.CurrencyManager CurrencyManager {
Lines 137-147 namespace Mono.UIAutomation.Winforms Link Here
137
			             new SelectionProviderBehavior (this));
137
			             new SelectionProviderBehavior (this));
138
			SetBehavior (GridPatternIdentifiers.Pattern,
138
			SetBehavior (GridPatternIdentifiers.Pattern,
139
			             new GridProviderBehavior (this));
139
			             new GridProviderBehavior (this));
140
			
140
141
			// Table Pattern is *only* supported when Header exists
141
			datagrid.InvokeSync (delegate {
142
			if (datagrid.CurrentTableStyle.GridColumnStyles.Count > 0
142
				// Table Pattern is *only* supported when Header exists
143
			    && datagrid.ColumnHeadersVisible)
143
				if (datagrid.CurrentTableStyle.GridColumnStyles.Count > 0
144
				CreateHeader (datagrid.CurrentTableStyle);
144
				    && datagrid.ColumnHeadersVisible)
145
					CreateHeader (datagrid.CurrentTableStyle);
146
			});
145
		}
147
		}
146
148
147
		public override void Terminate ()
149
		public override void Terminate ()
Lines 213-220 namespace Mono.UIAutomation.Winforms Link Here
213
		public void FocusItem (object objectItem)
215
		public void FocusItem (object objectItem)
214
		{
216
		{
215
			int row = (int) objectItem;
217
			int row = (int) objectItem;
216
			datagrid.Focus ();
218
			datagrid.InvokeSync (delegate {
217
			datagrid.CurrentCell = new SWF.DataGridCell (row, 0);
219
				datagrid.Focus ();
220
				datagrid.CurrentCell = new SWF.DataGridCell (row, 0);
221
			});
218
		}
222
		}
219
223
220
		public int SelectedItemsCount {
224
		public int SelectedItemsCount {
Lines 231-260 namespace Mono.UIAutomation.Winforms Link Here
231
			if (!items.Contains (item))
235
			if (!items.Contains (item))
232
				return false;
236
				return false;
233
			
237
			
234
			return datagrid.IsSelected (item.Index);
238
			return datagrid.InvokeSync (v => v.IsSelected (item.Index));
235
		}
239
		}
236
240
237
		public void SelectItem (ListItemProvider item)
241
		public void SelectItem (ListItemProvider item)
238
		{
242
		{
239
			if (items.Contains (item))
243
			if (items.Contains (item))
240
				datagrid.Select (item.Index);
244
				datagrid.InvokeSync (delegate { datagrid.Select (item.Index); });
241
		}
245
		}
242
246
243
		public void UnselectItem (ListItemProvider item)
247
		public void UnselectItem (ListItemProvider item)
244
		{
248
		{
245
			if (items.Contains (item))
249
			if (items.Contains (item))
246
				datagrid.UnSelect (item.Index);
250
				datagrid.InvokeSync (delegate { datagrid.UnSelect (item.Index); });
247
		}
251
		}
248
252
249
		public object GetItemPropertyValue (ListItemProvider item,
253
		public object GetItemPropertyValue (ListItemProvider item,
250
		                                    int propertyId)
254
		                                    int propertyId)
251
		{
255
		{
252
			if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
256
			if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
253
				int index = item.Index;
257
				return datagrid.InvokeSync (d => {
254
				// We need to union last column and first column
258
					int index = item.Index;
255
				SD.Rectangle rect0 = datagrid.GetCellBounds (index, 0);
259
					// We need to union last column and first column
256
				SD.Rectangle rectN = datagrid.GetCellBounds (index, header.ChildrenCount);
260
					SD.Rectangle rect0 = d.GetCellBounds (index, 0);
257
				return Helper.GetControlScreenBounds (SD.Rectangle.Union (rect0, rectN), datagrid);
261
					SD.Rectangle rectN = d.GetCellBounds (index, header.ChildrenCount);
262
					return Helper.GetControlScreenBounds (SD.Rectangle.Union (rect0, rectN), d);
263
				});
258
			} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
264
			} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
259
				Rect bounds 
265
				Rect bounds 
260
					= (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
266
					= (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
Lines 264-272 namespace Mono.UIAutomation.Winforms Link Here
264
			else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
270
			else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
265
				return true;
271
				return true;
266
			else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id) {
272
			else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id) {
267
				SWF.DataGridCell currentCell = datagrid.CurrentCell;
273
				return datagrid.InvokeSync (d => {
268
				return currentCell.ColumnNumber == 0 && currentCell.RowNumber == item.Index
274
					SWF.DataGridCell currentCell = d.CurrentCell;
269
					&& datagrid.Focused;
275
					return currentCell.ColumnNumber == 0 && currentCell.RowNumber == item.Index
276
						&& d.Focused;
277
				});
270
			} else
278
			} else
271
				return null;
279
				return null;
272
		}
280
		}
Lines 275-281 namespace Mono.UIAutomation.Winforms Link Here
275
		{
283
		{
276
			if (items.Contains (item)) {
284
			if (items.Contains (item)) {
277
				try {
285
				try {
278
					if ((bool) datagrid [item.Index, 0])
286
					if (datagrid.InvokeSync (d => (bool) d [item.Index, 0]))
279
						return ToggleState.On;
287
						return ToggleState.On;
280
					else
288
					else
281
						return ToggleState.Off;
289
						return ToggleState.Off;
Lines 289-298 namespace Mono.UIAutomation.Winforms Link Here
289
		public void ToggleItem (ListItemProvider item)
297
		public void ToggleItem (ListItemProvider item)
290
		{
298
		{
291
			if (items.Contains (item)) {
299
			if (items.Contains (item)) {
292
				try {
300
				datagrid.InvokeSync (delegate {
293
					bool value = (bool) datagrid [item.Index, 0];
301
					try {
294
					datagrid [item.Index, 0] = !value;
302
						bool value = (bool) datagrid [item.Index, 0];
295
				} catch (InvalidCastException) {}
303
						datagrid [item.Index, 0] = !value;
304
					} catch (InvalidCastException) {}
305
				});
296
			}
306
			}
297
		}
307
		}
298
308
Lines 380-400 namespace Mono.UIAutomation.Winforms Link Here
380
					return;
390
					return;
381
			}
391
			}
382
392
383
			// Is showing "+" to expand, this usually happens when DataSource is
393
			datagrid.InvokeSync (delegate {
384
			// DataSet and has more than one DataTable.
394
				// Is showing "+" to expand, this usually happens when DataSource is
385
			if (datagrid.CurrentTableStyle.GridColumnStyles.Count == 0) {
395
				// DataSet and has more than one DataTable.
386
				DataGridCustomProvider customProvider 
396
				if (datagrid.CurrentTableStyle.GridColumnStyles.Count == 0) {
387
					= new DataGridCustomProvider (this, 0, string.Empty);
397
					DataGridCustomProvider customProvider 
388
				customProvider.Initialize ();
398
						= new DataGridCustomProvider (this, 0, string.Empty);
389
				AddChildProvider (customProvider);
399
					customProvider.Initialize ();
390
			} else {
400
					AddChildProvider (customProvider);
391
				CreateHeader (datagrid.CurrentTableStyle);
401
				} else {
392
402
					CreateHeader (datagrid.CurrentTableStyle);
393
				for (int row = 0; row < lastCurrencyManager.Count; row++)
403
	
394
					CreateListItem (row, datagrid.CurrentTableStyle);
404
					for (int row = 0; row < lastCurrencyManager.Count; row++)
395
			}
405
						CreateListItem (row, datagrid.CurrentTableStyle);
406
				}
396
407
397
			lastDataSource = datagrid.DataSource;
408
				lastDataSource = datagrid.DataSource;
409
			});
398
		}
410
		}
399
		
411
		
400
		private void OnDataSourceChanged (object sender, EventArgs args)
412
		private void OnDataSourceChanged (object sender, EventArgs args)
Lines 403-409 namespace Mono.UIAutomation.Winforms Link Here
403
			SWF.CurrencyManager manager = null;
415
			SWF.CurrencyManager manager = null;
404
416
405
			// Happens when Navigating DataGrid
417
			// Happens when Navigating DataGrid
406
			if (lastDataSource == datagrid.DataSource) {
418
			if (lastDataSource == datagrid.InvokeSync (d => d.DataSource)) {
407
				manager = RequestCurrencyManager ();
419
				manager = RequestCurrencyManager ();
408
				// Only when rendering something different we refresh children
420
				// Only when rendering something different we refresh children
409
				if (manager != null && manager != lastCurrencyManager)
421
				if (manager != null && manager != lastCurrencyManager)
Lines 421-436 namespace Mono.UIAutomation.Winforms Link Here
421
433
422
		private SWF.CurrencyManager RequestCurrencyManager () 
434
		private SWF.CurrencyManager RequestCurrencyManager () 
423
		{
435
		{
424
			if (datagrid.DataSource == null)
436
			return datagrid.InvokeSync (d => {
425
			    return null;
437
				if (d.DataSource == null)
426
			
438
				    return null;
427
			return (SWF.CurrencyManager) datagrid.BindingContext [datagrid.DataSource,
439
				
428
			                                                      datagrid.DataMember];
440
				return (SWF.CurrencyManager) d.BindingContext [d.DataSource, d.DataMember];
441
			});
429
		}
442
		}
430
443
431
		private void CreateHeader (SWF.DataGridTableStyle tableStyle)
444
		private void CreateHeader (SWF.DataGridTableStyle tableStyle)
432
		{
445
		{
433
			if (!datagrid.ColumnHeadersVisible || header != null)
446
			if (datagrid.InvokeSync (d => !d.ColumnHeadersVisible)
447
			    || header != null)
434
				return;
448
				return;
435
	
449
	
436
			header = new DataGridHeaderProvider (this, tableStyle.GridColumnStyles);
450
			header = new DataGridHeaderProvider (this, tableStyle.GridColumnStyles);
Lines 513-523 namespace Mono.UIAutomation.Winforms Link Here
513
				else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
527
				else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
514
					return true;
528
					return true;
515
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
529
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
516
					SD.Rectangle rectangle = provider.DataGrid.UIAColumnHeadersArea;
530
					return provider.DataGrid.InvokeSync (d => {
517
					rectangle.X += provider.DataGrid.Bounds.X;
531
						SD.Rectangle rectangle = d.UIAColumnHeadersArea;
518
					rectangle.Y += provider.DataGrid.Bounds.Y;
532
						rectangle.X += d.Bounds.X;
519
533
						rectangle.Y += d.Bounds.Y;
520
					return Helper.GetControlScreenBounds (rectangle, provider.DataGrid);
534
	
535
						return Helper.GetControlScreenBounds (rectangle, d);
536
					});
521
				} else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
537
				} else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
522
					return Helper.GetClickablePoint (this);
538
					return Helper.GetClickablePoint (this);
523
				else
539
				else
Lines 720-727 namespace Mono.UIAutomation.Winforms Link Here
720
			}
736
			}
721
737
722
			public object Value {
738
			public object Value {
723
				get { return provider.DataGrid [Index, 0]; }
739
				get { 
724
				set { provider.DataGrid [Index, 0] = value; }
740
					return provider.DataGrid.InvokeSync (o => o [Index, 0]); 
741
				}
742
				set { provider.DataGrid.InvokeSync (delegate { provider.DataGrid [Index, 0] = value; }); }
725
			}
743
			}
726
744
727
			public void SetEditValue (DataGridDataItemEditProvider edit, object value)
745
			public void SetEditValue (DataGridDataItemEditProvider edit, object value)
Lines 731-737 namespace Mono.UIAutomation.Winforms Link Here
731
				if (column == -1 || row == -1)
749
				if (column == -1 || row == -1)
732
					return;
750
					return;
733
751
734
				provider.DataGrid [row, column] = value;
752
				provider.DataGrid.InvokeSync (delegate { provider.DataGrid [row, column] = value; });
735
			}
753
			}
736
754
737
			public override void InitializeChildControlStructure ()
755
			public override void InitializeChildControlStructure ()
Lines 763-770 namespace Mono.UIAutomation.Winforms Link Here
763
781
764
			public override void SetFocus ()
782
			public override void SetFocus ()
765
			{
783
			{
766
				DataGridProvider.DataGrid.Focus ();
784
				DataGridProvider.DataGrid.InvokeSync (delegate {
767
				DataGridProvider.DataGrid.CurrentCell = new SWF.DataGridCell (Index, 0);
785
					DataGridProvider.DataGrid.Focus ();
786
					DataGridProvider.DataGrid.CurrentCell = new SWF.DataGridCell (Index, 0);
787
				});
768
			}
788
			}
769
789
770
			protected override object GetProviderPropertyValue (int propertyId)
790
			protected override object GetProviderPropertyValue (int propertyId)
Lines 778-789 namespace Mono.UIAutomation.Winforms Link Here
778
					return ControlType.DataItem.Id;
798
					return ControlType.DataItem.Id;
779
				else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
799
				else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
780
					return Catalog.GetString ("data item");
800
					return Catalog.GetString ("data item");
781
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) 
801
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
782
					return Helper.GetControlScreenBounds (DataGridProvider.DataGrid.GetCellBounds (Index, 0),
802
					return DataGridProvider.DataGrid.InvokeSync (v => Helper.GetControlScreenBounds (v.GetCellBounds (Index, 0),
783
					                                      DataGridProvider.DataGrid);
803
					                                                                                  v));
784
				else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
804
				else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
785
					return IsOffScreen (DataGridProvider.DataGrid,
805
					return DataGridProvider.DataGrid.InvokeSync (v => IsOffScreen (v,
786
					                    (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id));
806
					                                                               (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id)));;
787
				} else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
807
				} else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
788
					return Helper.GetClickablePoint (this);
808
					return Helper.GetClickablePoint (this);
789
				else
809
				else
Lines 792-815 namespace Mono.UIAutomation.Winforms Link Here
792
812
793
			public bool IsOffScreen (SWF.DataGrid datagrid, Rect bounds)
813
			public bool IsOffScreen (SWF.DataGrid datagrid, Rect bounds)
794
			{
814
			{
795
				SD.Rectangle rectangle = datagrid.Bounds;
815
				return datagrid.InvokeSync (d => {
796
				rectangle.Height -= datagrid.UIACellsArea.Y - rectangle.Y - datagrid.UIARowHeight;
816
					SD.Rectangle rectangle = d.Bounds;
797
				rectangle.Y = datagrid.UIACellsArea.Y;
817
					rectangle.Height -= d.UIACellsArea.Y - rectangle.Y - d.UIARowHeight;
798
				if (datagrid.ColumnHeadersVisible) {
818
					rectangle.Y = d.UIACellsArea.Y;
799
					rectangle.X += datagrid.RowHeaderWidth;
819
					if (d.ColumnHeadersVisible) {
800
					rectangle.Y += datagrid.UIAColumnHeadersArea.Height;
820
						rectangle.X += d.RowHeaderWidth;
801
					rectangle.Height -= datagrid.UIACaptionArea.Height;
821
						rectangle.Y += d.UIAColumnHeadersArea.Height;
802
				}
822
						rectangle.Height -= d.UIACaptionArea.Height;
803
				if (datagrid.CaptionVisible)
823
					}
804
					rectangle.X += datagrid.UIACaptionArea.Height;
824
					if (d.CaptionVisible)
805
825
						rectangle.X += d.UIACaptionArea.Height;
806
				if (rectangle.Width < 0)
826
	
807
					rectangle.Width = 0;
827
					if (rectangle.Width < 0)
808
				if (rectangle.Height < 0)
828
						rectangle.Width = 0;
809
					rectangle.Height = 0;
829
					if (rectangle.Height < 0)
810
830
						rectangle.Height = 0;
811
				Rect screen = Helper.RectangleToRect (datagrid.Parent.RectangleToScreen (rectangle));
831
	
812
				return !bounds.IntersectsWith (screen);
832
					Rect screen = Helper.RectangleToRect (d.Parent.RectangleToScreen (rectangle));
833
						
834
					return !bounds.IntersectsWith (screen);
835
				});
813
			}
836
			}
814
837
815
			private void OnColumnsCollectionChanged (object sender, CollectionChangeEventArgs args)
838
			private void OnColumnsCollectionChanged (object sender, CollectionChangeEventArgs args)
Lines 892-900 namespace Mono.UIAutomation.Winforms Link Here
892
915
893
			public override void SetFocus ()
916
			public override void SetFocus ()
894
			{
917
			{
895
				ItemProvider.DataGridProvider.DataGrid.Focus ();
918
				ItemProvider.DataGridProvider.DataGrid.InvokeSync (delegate {
896
				ItemProvider.DataGridProvider.DataGrid.CurrentCell = new SWF.DataGridCell (ItemProvider.Index, 
919
					ItemProvider.DataGridProvider.DataGrid.Focus ();
897
				                                                                           ItemProvider.GetColumnIndexOf (this));
920
					ItemProvider.DataGridProvider.DataGrid.CurrentCell = new SWF.DataGridCell (ItemProvider.Index, 
921
					                                                                           ItemProvider.GetColumnIndexOf (this));
922
				});
898
			}
923
			}
899
924
900
			public SWF.Control ContainerControl { 
925
			public SWF.Control ContainerControl { 
Lines 931-945 namespace Mono.UIAutomation.Winforms Link Here
931
					return Catalog.GetString ("edit");
956
					return Catalog.GetString ("edit");
932
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
957
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
933
					// ItemProvider.DataGridProvider.DataGrid.Focused should be used here, but seems SWF.DataGrid loses this state randomly
958
					// ItemProvider.DataGridProvider.DataGrid.Focused should be used here, but seems SWF.DataGrid loses this state randomly
934
					return ItemProvider.DataGridProvider.DataGrid.CurrentCell.RowNumber == ItemProvider.Index
959
					return ItemProvider.DataGridProvider.DataGrid.InvokeSync (d => {
935
						&& ItemProvider.DataGridProvider.DataGrid.CurrentCell.ColumnNumber == ItemProvider.GetColumnIndexOf (this);
960
						return d.CurrentCell.RowNumber == ItemProvider.Index
961
							&& d.CurrentCell.ColumnNumber == ItemProvider.GetColumnIndexOf (this);
962
					});
936
				else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
963
				else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
937
					return ItemProvider.DataGridProvider.DataGrid.Enabled;
964
					return ItemProvider.DataGridProvider.DataGrid.InvokeSync (d => d.Enabled);
938
				else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
965
				else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
939
					return provider.GetName (this);
966
					return provider.GetName (this);
940
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
967
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
941
					SD.Rectangle rectangle = provider.DataGridProvider.DataGrid.GetCellBounds (provider.Index,
968
					SD.Rectangle rectangle = provider.DataGridProvider.DataGrid.InvokeSync (d => d.GetCellBounds (provider.Index,
942
					                                                                           provider.GetColumnIndexOf (this));
969
					                                                                                              provider.GetColumnIndexOf (this)));
943
					Rect rect = Helper.GetControlScreenBounds (rectangle,
970
					Rect rect = Helper.GetControlScreenBounds (rectangle,
944
					                                           provider.DataGridProvider.DataGrid,
971
					                                           provider.DataGridProvider.DataGrid,
945
					                                           true);
972
					                                           true);
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/DataGridViewProvider.cs (-71 / +93 lines)
Lines 108-124 namespace Mono.UIAutomation.Winforms Link Here
108
				return;
108
				return;
109
109
110
			DataGridDataItemProvider dataItem = (DataGridDataItemProvider) item;
110
			DataGridDataItemProvider dataItem = (DataGridDataItemProvider) item;
111
			datagridview.FirstDisplayedCell = dataItem.Row.Cells [0];
111
			datagridview.InvokeSync (delegate {
112
				datagridview.FirstDisplayedCell = dataItem.Row.Cells [0];
113
			});
112
		}
114
		}
113
115
114
		public override IRawElementProviderSimple[] GetSelectedItems ()
116
		public override IRawElementProviderSimple[] GetSelectedItems ()
115
		{
117
		{
116
			List<DataGridViewDataItemChildProvider> items = new List<DataGridViewDataItemChildProvider> ();
118
			List<DataGridViewDataItemChildProvider> items = new List<DataGridViewDataItemChildProvider> ();
117
			
119
			
118
			foreach (SWF.DataGridViewCell cell in datagridview.SelectedCells) {
120
			foreach (SWF.DataGridViewCell cell 
121
			         in datagridview.InvokeSync (d => d.SelectedCells)) {
119
				DataGridDataItemProvider itemProvider
122
				DataGridDataItemProvider itemProvider
120
					= (DataGridDataItemProvider) GetItemProviderFrom (this,
123
					= (DataGridDataItemProvider) GetItemProviderFrom (this,
121
					                                                  datagridview.Rows [cell.RowIndex],
124
					                                                  datagridview.InvokeSync (d => d.Rows [cell.RowIndex]),
122
					                                                  false);
125
					                                                  false);
123
				if (itemProvider == null) //Not yet initialized
126
				if (itemProvider == null) //Not yet initialized
124
					break;
127
					break;
Lines 129-135 namespace Mono.UIAutomation.Winforms Link Here
129
		}
132
		}
130
		
133
		
131
		public override int SelectedItemsCount {
134
		public override int SelectedItemsCount {
132
			get { return datagridview.SelectedRows.Count; }
135
			get { return datagridview.InvokeSync (d => d.SelectedRows.Count); }
133
		}
136
		}
134
137
135
		public override bool IsItemSelected (ListItemProvider item)
138
		public override bool IsItemSelected (ListItemProvider item)
Lines 141-147 namespace Mono.UIAutomation.Winforms Link Here
141
		}
144
		}
142
		
145
		
143
		public override int ItemsCount {
146
		public override int ItemsCount {
144
			get { return datagridview.Rows.Count; }
147
			get { return datagridview.InvokeSync (c => c.Rows.Count); }
145
		}
148
		}
146
149
147
		public override int IndexOfObjectItem (object objectItem)
150
		public override int IndexOfObjectItem (object objectItem)
Lines 150-165 namespace Mono.UIAutomation.Winforms Link Here
150
			if (row == null)
153
			if (row == null)
151
				return -1;
154
				return -1;
152
155
153
			return datagridview.Rows.IndexOf (row);
156
			return datagridview.InvokeSync (c => c.Rows.IndexOf (row));
154
		}
157
		}
155
158
156
		public override void FocusItem (object objectItem)
159
		public override void FocusItem (object objectItem)
157
		{
160
		{
158
			SWF.DataGridViewRow row = objectItem as SWF.DataGridViewRow;
161
			SWF.DataGridViewRow row = objectItem as SWF.DataGridViewRow;
159
			if (row == null || !datagridview.Rows.Contains (row))
162
			if (row == null || datagridview.InvokeSync (c => !c.Rows.Contains (row)))
160
				return;
163
				return;
161
164
162
			datagridview.CurrentCell = row.Cells [0];
165
			datagridview.InvokeSync (delegate { datagridview.CurrentCell = row.Cells [0]; });
163
		}
166
		}
164
167
165
		public override object GetItemPropertyValue (ListItemProvider item, int propertyId)
168
		public override object GetItemPropertyValue (ListItemProvider item, int propertyId)
Lines 169-187 namespace Mono.UIAutomation.Winforms Link Here
169
			if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
172
			if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
170
				return provider.Row.Cells [0].Value as string;
173
				return provider.Row.Cells [0].Value as string;
171
			else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
174
			else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
172
				return datagridview.CurrentCell == provider.Row.Cells [0] && datagridview.Focused;
175
				return datagridview.InvokeSync (c => c.CurrentCell == provider.Row.Cells [0] 
176
				                                && c.Focused);
173
			else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
177
			else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
174
				SD.Rectangle rectangle = datagridview.GetRowDisplayRectangle (provider.Row.Index, false);
178
				return datagridview.InvokeSync (c => {
175
				if (datagridview.RowHeadersVisible)
179
					SD.Rectangle rectangle = c.GetRowDisplayRectangle (provider.Row.Index, false);
176
					rectangle.X += datagridview.RowHeadersWidth;
180
					if (c.RowHeadersVisible)
177
181
						rectangle.X += c.RowHeadersWidth;
178
				return Helper.GetControlScreenBounds (rectangle, 
182
	
179
				                                      datagridview,
183
					return Helper.GetControlScreenBounds (rectangle, 
180
				                                      true);
184
					                                      c,
185
					                                      true);					
186
				});
181
			} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
187
			} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
182
				return Helper.IsListItemOffScreen (item.BoundingRectangle,
188
				return Helper.IsListItemOffScreen (item.BoundingRectangle,
183
				                                   datagridview, 
189
				                                   datagridview, 
184
				                                   datagridview.ColumnHeadersVisible,
190
				                                   datagridview.InvokeSync (d => d.ColumnHeadersVisible),
185
				                                   header.Size,
191
				                                   header.Size,
186
				                                   ScrollBehaviorObserver);
192
				                                   ScrollBehaviorObserver);
187
			else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
193
			else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
Lines 226-232 namespace Mono.UIAutomation.Winforms Link Here
226
			AddChildProvider (header);
232
			AddChildProvider (header);
227
233
228
			datagridview.Rows.CollectionChanged += OnCollectionChanged;
234
			datagridview.Rows.CollectionChanged += OnCollectionChanged;
229
			foreach (SWF.DataGridViewRow row in datagridview.Rows) {
235
			foreach (SWF.DataGridViewRow row 
236
			         in datagridview.InvokeSync (d => d.Rows)) {
230
				ListItemProvider itemProvider = GetItemProviderFrom (this, row);
237
				ListItemProvider itemProvider = GetItemProviderFrom (this, row);
231
				AddChildProvider (itemProvider);
238
				AddChildProvider (itemProvider);
232
			}
239
			}
Lines 290-306 namespace Mono.UIAutomation.Winforms Link Here
290
297
291
			public SD.Rectangle Size {
298
			public SD.Rectangle Size {
292
				get {
299
				get {
293
					if (!DataGridView.ColumnHeadersVisible)
300
					return DataGridView.InvokeSync (d => {
294
						return new SD.Rectangle (0, 0, 0, 0);
301
						if (!d.ColumnHeadersVisible)
295
					else {
302
							return new SD.Rectangle (0, 0, 0, 0);
296
						SD.Rectangle bounds = SD.Rectangle.Empty;
303
						else {
297
						bounds.Height = DataGridView.ColumnHeadersHeight;
304
							SD.Rectangle bounds = SD.Rectangle.Empty;
298
						bounds.Width = DataGridView.RowHeadersWidth;
305
							bounds.Height = d.ColumnHeadersHeight;
299
						for (int index = 0; index < DataGridView.Columns.Count; index++)
306
							bounds.Width = d.RowHeadersWidth;
300
							bounds.Width += DataGridView.Columns [index].Width;
307
							for (int index = 0; index < d.Columns.Count; index++)
301
						
308
								bounds.Width += d.Columns [index].Width;
302
						return bounds;
309
							
303
					}
310
							return bounds;
311
						}
312
					});
304
				}
313
				}
305
			}
314
			}
306
315
Lines 347-353 namespace Mono.UIAutomation.Winforms Link Here
347
			{
356
			{
348
				DataGridView.Columns.CollectionChanged += OnColumnsCollectionChanged;
357
				DataGridView.Columns.CollectionChanged += OnColumnsCollectionChanged;
349
				
358
				
350
				foreach (SWF.DataGridViewColumn column in DataGridView.Columns)
359
				foreach (SWF.DataGridViewColumn column 
360
				         in DataGridView.InvokeSync (d => d.Columns))
351
					UpdateCollection (column, CollectionChangeAction.Add);
361
					UpdateCollection (column, CollectionChangeAction.Add);
352
			}
362
			}
353
363
Lines 447-462 namespace Mono.UIAutomation.Winforms Link Here
447
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
457
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
448
					if (column == null || column.Index < 0)
458
					if (column == null || column.Index < 0)
449
						return Rect.Empty;
459
						return Rect.Empty;
450
451
					Rect headerBounds
452
						= (Rect) headerProvider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
453
					for (int index = 0; index < column.Index; index++)
454
						headerBounds.X += headerProvider.DataGridView.Columns [index].Width;
455
456
					headerBounds.X += headerProvider.DataGridView.RowHeadersWidth;
457
					headerBounds.Width = headerProvider.DataGridView.Columns [column.Index].Width;
458
					
460
					
459
					return headerBounds;
461
					return headerProvider.DataGridView.InvokeSync (d => {
462
						Rect headerBounds
463
							= (Rect) headerProvider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
464
						for (int index = 0; index < column.Index; index++)
465
							headerBounds.X += d.Columns [index].Width;
466
	
467
						headerBounds.X += d.RowHeadersWidth;
468
						headerBounds.Width = d.Columns [column.Index].Width;
469
						
470
						return headerBounds;
471
					});
460
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
472
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
461
					Rect bounds 
473
					Rect bounds 
462
						= (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
474
						= (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
Lines 503-521 namespace Mono.UIAutomation.Winforms Link Here
503
515
504
			public override IRawElementProviderFragment GetFocus ()
516
			public override IRawElementProviderFragment GetFocus ()
505
			{
517
			{
506
				if (DataGridView.CurrentCell == null 
518
				return DataGridView.InvokeSync (d => {
507
				    || DataGridView.CurrentCell.RowIndex != Row.Index)
519
					if (d.CurrentCell == null 
508
					return null;
520
					    || d.CurrentCell.RowIndex != Row.Index)
509
				else {
510
					if (DataGridView.CurrentCell.ColumnIndex < 0 
511
					    || DataGridView.CurrentCell.ColumnIndex >= DataGridView.Columns.Count)
512
						return null;
521
						return null;
513
522
					else {
514
					DataGridViewDataItemChildProvider provider = null;
523
						if (d.CurrentCell.ColumnIndex < 0 
515
					columns.TryGetValue (DataGridView.Columns [DataGridView.CurrentCell.ColumnIndex], 
524
						    || d.CurrentCell.ColumnIndex >= d.Columns.Count)
516
					                     out provider);
525
							return null;
517
					return provider;
526
	
527
						DataGridViewDataItemChildProvider provider = null;
528
						columns.TryGetValue (d.Columns [d.CurrentCell.ColumnIndex], 
529
						                     out provider);
530
						return provider;
518
				}
531
				}
532
				});
519
			}
533
			}
520
534
521
			public DataGridViewDataItemChildProvider GetChildItem (SWF.DataGridViewColumn column)
535
			public DataGridViewDataItemChildProvider GetChildItem (SWF.DataGridViewColumn column)
Lines 531-537 namespace Mono.UIAutomation.Winforms Link Here
531
				if (columnIndex < 0 || columnIndex >= columns.Count)
545
				if (columnIndex < 0 || columnIndex >= columns.Count)
532
					return null;
546
					return null;
533
547
534
				return GetChildItem (datagridview.Columns [columnIndex]);
548
				return GetChildItem (datagridview.InvokeSync (d => d.Columns [columnIndex]));
535
			}
549
			}
536
550
537
			protected override object GetProviderPropertyValue (int propertyId)
551
			protected override object GetProviderPropertyValue (int propertyId)
Lines 641-648 namespace Mono.UIAutomation.Winforms Link Here
641
655
642
			public override void SetFocus ()
656
			public override void SetFocus ()
643
			{
657
			{
644
				itemProvider.DataGridView.Focus ();
658
				itemProvider.DataGridView.InvokeSync (delegate {
645
				itemProvider.DataGridView.CurrentCell = cell;
659
					itemProvider.DataGridView.Focus ();
660
					itemProvider.DataGridView.CurrentCell = cell;
661
				});
646
			}
662
			}
647
663
648
			public override void Initialize ()
664
			public override void Initialize ()
Lines 692-700 namespace Mono.UIAutomation.Winforms Link Here
692
				if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
708
				if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
693
					return cell.Value as string;
709
					return cell.Value as string;
694
				else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
710
				else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
695
					return gridProvider.DataGridView.Enabled;
711
					return gridProvider.DataGridView.InvokeSync (d => d.Enabled);
696
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
712
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
697
					return gridProvider.DataGridView.CurrentCell == cell && gridProvider.DataGridView.Focused;
713
					return gridProvider.DataGridView.InvokeSync (d => d.CurrentCell == cell && d.Focused);
698
				else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
714
				else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
699
					return !Cell.ReadOnly;
715
					return !Cell.ReadOnly;
700
				else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
716
				else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
Lines 702-715 namespace Mono.UIAutomation.Winforms Link Here
702
				else if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id)
718
				else if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id)
703
					return cell.ToolTipText;
719
					return cell.ToolTipText;
704
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
720
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
705
					Rect itemBounds = itemProvider.BoundingRectangle;
721
					return itemProvider.DataGridView.InvokeSync (d => {
706
722
						Rect itemBounds = itemProvider.BoundingRectangle;
707
					for (int index = 0; index < cell.ColumnIndex; index++)
723
	
708
						itemBounds.X += itemProvider.DataGridView.Columns [index].Width;
724
						for (int index = 0; index < cell.ColumnIndex; index++)
709
725
							itemBounds.X += d.Columns [index].Width;
710
					itemBounds.Width = itemProvider.DataGridView.Columns [cell.ColumnIndex].Width;
726
	
711
727
						itemBounds.Width = d.Columns [cell.ColumnIndex].Width;
712
					return itemBounds;
728
	
729
						return itemBounds;
730
					});
713
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
731
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
714
					return cell.Displayed;
732
					return cell.Displayed;
715
				else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
733
				else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
Lines 1148-1163 namespace Mono.UIAutomation.Winforms Link Here
1148
			{
1166
			{
1149
				if (!ContainsItem (item))
1167
				if (!ContainsItem (item))
1150
					return;
1168
					return;
1151
1169
				
1152
				SWF.DataGridViewCell oldCell = comboboxProvider.ComboBoxCell.DataGridView.CurrentCell;
1170
				comboboxProvider.ComboBoxCell.DataGridView.InvokeSync (delegate {
1153
				comboboxProvider.ComboBoxCell.DataGridView.CurrentCell = comboboxProvider.ComboBoxCell;
1171
					SWF.DataGridViewCell oldCell = comboboxProvider.ComboBoxCell.DataGridView.CurrentCell;
1154
				comboboxProvider.ComboBoxCell.Value = GetValueMemberFromValue (item.ObjectItem);
1172
					comboboxProvider.ComboBoxCell.DataGridView.CurrentCell = comboboxProvider.ComboBoxCell;
1155
				comboboxProvider.ComboBoxCell.DataGridView.CurrentCell = oldCell;
1173
					comboboxProvider.ComboBoxCell.Value = GetValueMemberFromValue (item.ObjectItem);
1174
					comboboxProvider.ComboBoxCell.DataGridView.CurrentCell = oldCell;
1175
				});
1156
			}
1176
			}
1157
			
1177
			
1158
			public override void UnselectItem (ListItemProvider item)
1178
			public override void UnselectItem (ListItemProvider item)
1159
			{
1179
			{
1160
				comboboxProvider.ComboBoxCell.Value = null;
1180
				comboboxProvider.ComboBoxCell.DataGridView.InvokeSync (delegate {
1181
					comboboxProvider.ComboBoxCell.Value = null;
1182
				});
1161
			}
1183
			}
1162
1184
1163
			public override int IndexOfObjectItem (object objectItem)
1185
			public override int IndexOfObjectItem (object objectItem)
Lines 1185-1192 namespace Mono.UIAutomation.Winforms Link Here
1185
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
1207
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
1186
					return comboboxProvider.GetPropertyValue (propertyId);
1208
					return comboboxProvider.GetPropertyValue (propertyId);
1187
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
1209
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
1188
					return comboboxProvider.ComboBoxCell.DataGridView.Focused
1210
					return comboboxProvider.ComboBoxCell.DataGridView.InvokeSync (d => d.Focused
1189
						&& comboboxProvider.ComboBoxCell.DataGridView.CurrentCell == comboboxProvider.ComboBoxCell;
1211
					                                                              && d.CurrentCell == comboboxProvider.ComboBoxCell);
1190
				else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
1212
				else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
1191
					// What when combobox is visible and scroll is hiden cell?
1213
					// What when combobox is visible and scroll is hiden cell?
1192
					return IsItemSelected (item);
1214
					return IsItemSelected (item);
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/DateTimePickerProvider.cs (-38 / +36 lines)
Lines 101-107 namespace Mono.UIAutomation.Winforms Link Here
101
#region Private Methods
101
#region Private Methods
102
		private void UpdateChildren ()
102
		private void UpdateChildren ()
103
		{
103
		{
104
			if (control.ShowCheckBox) {
104
			if (control.InvokeSync (b => b.ShowCheckBox)) {
105
				if (checkBox == null) {
105
				if (checkBox == null) {
106
					checkBox = new DateTimePickerCheckBoxProvider (this);
106
					checkBox = new DateTimePickerCheckBoxProvider (this);
107
					InsertChildProvider (checkBox, 0);
107
					InsertChildProvider (checkBox, 0);
Lines 114-120 namespace Mono.UIAutomation.Winforms Link Here
114
				}
114
				}
115
			}
115
			}
116
116
117
			if (control.ShowUpDown) {
117
			if (control.InvokeSync (b => b.ShowUpDown)) {
118
				if (dropDownButton != null) {
118
				if (dropDownButton != null) {
119
					RemoveChildProvider (dropDownButton);
119
					RemoveChildProvider (dropDownButton);
120
					dropDownButton.Terminate ();
120
					dropDownButton.Terminate ();
Lines 131-138 namespace Mono.UIAutomation.Winforms Link Here
131
131
132
		private void AddSegmentItems ()
132
		private void AddSegmentItems ()
133
		{
133
		{
134
			for (int i = 0; i < control.part_data.Length; i++) {
134
			DateTimePicker.PartData []array 
135
				DateTimePicker.PartData part_data = control.part_data [i];
135
				= control.InvokeSync (p => p.part_data);
136
			
137
			for (int i = 0; i < array.Length; i++) {
138
				DateTimePicker.PartData part_data = array [i];
136
				FragmentControlProvider prov = null;
139
				FragmentControlProvider prov = null;
137
140
138
				switch (part_data.date_time_part) {
141
				switch (part_data.date_time_part) {
Lines 205-213 namespace Mono.UIAutomation.Winforms Link Here
205
208
206
				SetBehavior (TogglePatternIdentifiers.Pattern,
209
				SetBehavior (TogglePatternIdentifiers.Pattern,
207
				             new ToggleProviderBehavior (this));
210
				             new ToggleProviderBehavior (this));
208
209
				SetEvent (ProviderEventType.AutomationElementHasKeyboardFocusProperty,
210
					  new CheckboxAutomationHasKeyboardFocusPropertyEvent (this));
211
			}
211
			}
212
212
213
			public override IRawElementProviderFragmentRoot FragmentRoot {
213
			public override IRawElementProviderFragmentRoot FragmentRoot {
Lines 221-230 namespace Mono.UIAutomation.Winforms Link Here
221
				else if (propertyId == AEIds.IsContentElementProperty.Id)
221
				else if (propertyId == AEIds.IsContentElementProperty.Id)
222
					return false;
222
					return false;
223
				else if (propertyId == AEIds.IsKeyboardFocusableProperty.Id)
223
				else if (propertyId == AEIds.IsKeyboardFocusableProperty.Id)
224
					return true;
224
					return false;
225
				else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
226
					return (bool) rootProvider.GetPropertyValue (AEIds.HasKeyboardFocusProperty.Id)
227
					       && ((DateTimePicker) rootProvider.Control).UIAIsCheckBoxSelected;
228
				else if (propertyId == AEIds.ControlTypeProperty.Id)
225
				else if (propertyId == AEIds.ControlTypeProperty.Id)
229
					return ControlType.CheckBox.Id;
226
					return ControlType.CheckBox.Id;
230
				else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
227
				else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
Lines 294-300 namespace Mono.UIAutomation.Winforms Link Here
294
			}
291
			}
295
292
296
			public string Text {
293
			public string Text {
297
				get { return PartData.GetText (((DateTimePicker) rootProvider.Control).Value); }
294
				get {
295
					DateTime time = ((DateTimePicker) rootProvider.Control).InvokeSync (c => c.Value);
296
					return PartData.GetText (time); 
297
				}
298
			}
298
			}
299
299
300
			public override void Initialize ()
300
			public override void Initialize ()
Lines 305-315 namespace Mono.UIAutomation.Winforms Link Here
305
					  new Events.DateTimePicker.AutomationNamePropertyEvent (
305
					  new Events.DateTimePicker.AutomationNamePropertyEvent (
306
						this, rootProvider));
306
						this, rootProvider));
307
307
308
				SetEvent (ProviderEventType.AutomationElementIsEnabledProperty,
308
				SetEvent (ProviderEventType.AutomationElementNameProperty,
309
					  new PartAutomationIsEnabledPropertyEvent (this));
309
					  new PartAutomationIsEnabledPropertyEvent (this));
310
311
				SetEvent (ProviderEventType.AutomationElementHasKeyboardFocusProperty,
312
					  new PartAutomationHasKeyboardFocusPropertyEvent (this));
313
			}
310
			}
314
311
315
			protected override object GetProviderPropertyValue (int propertyId)
312
			protected override object GetProviderPropertyValue (int propertyId)
Lines 328-335 namespace Mono.UIAutomation.Winforms Link Here
328
					return Catalog.GetString ("text");
325
					return Catalog.GetString ("text");
329
				else if (propertyId == AEIds.IsEnabledProperty.Id) {
326
				else if (propertyId == AEIds.IsEnabledProperty.Id) {
330
					DateTimePicker picker = (DateTimePicker) Control;
327
					DateTimePicker picker = (DateTimePicker) Control;
331
					return Control.Enabled
328
					return picker.InvokeSync (c => c.Enabled
332
					       && !(picker.ShowCheckBox && !picker.Checked);
329
					                          && !(c.ShowCheckBox && !c.Checked));
333
				}
330
				}
334
				return base.GetProviderPropertyValue (propertyId);
331
				return base.GetProviderPropertyValue (propertyId);
335
			}
332
			}
Lines 362-371 namespace Mono.UIAutomation.Winforms Link Here
362
359
363
			public override void SetFocus ()
360
			public override void SetFocus ()
364
			{
361
			{
365
				if (dateTimePicker.ShowCheckBox && !dateTimePicker.Checked)
362
				dateTimePicker.InvokeSync (delegate {
366
					return;
363
					if (dateTimePicker.ShowCheckBox && !dateTimePicker.Checked)
367
364
						return;
368
				dateTimePicker.SelectPart (part_index);
365
	
366
					dateTimePicker.SelectPart (part_index);
367
				});
369
			}
368
			}
370
369
371
			protected override object GetProviderPropertyValue (int propertyId)
370
			protected override object GetProviderPropertyValue (int propertyId)
Lines 373-380 namespace Mono.UIAutomation.Winforms Link Here
373
				if (propertyId == AEIds.IsKeyboardFocusableProperty.Id)
372
				if (propertyId == AEIds.IsKeyboardFocusableProperty.Id)
374
					return true;
373
					return true;
375
				else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
374
				else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
376
					return (bool) rootProvider.GetPropertyValue (AEIds.HasKeyboardFocusProperty.Id)
375
					return part_data.Selected;
377
					       && part_data.Selected;
378
				else if (propertyId == AEIds.ControlTypeProperty.Id)
376
				else if (propertyId == AEIds.ControlTypeProperty.Id)
379
					return ControlType.Spinner.Id;
377
					return ControlType.Spinner.Id;
380
				else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
378
				else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
Lines 404-413 namespace Mono.UIAutomation.Winforms Link Here
404
402
405
			public override void SetFocus ()
403
			public override void SetFocus ()
406
			{
404
			{
407
				if (dateTimePicker.ShowCheckBox && !dateTimePicker.Checked)
405
				dateTimePicker.InvokeSync (delegate {
408
					return;
406
					if (dateTimePicker.ShowCheckBox && !dateTimePicker.Checked)
409
407
						return;
410
				((DateTimePicker) rootProvider.Control).SelectPart (part_index);
408
	
409
					((DateTimePicker) rootProvider.Control).SelectPart (part_index);
410
				});
411
			}
411
			}
412
412
413
			public override void InitializeChildControlStructure ()
413
			public override void InitializeChildControlStructure ()
Lines 415-421 namespace Mono.UIAutomation.Winforms Link Here
415
				base.InitializeChildControlStructure ();
415
				base.InitializeChildControlStructure ();
416
416
417
				Calendar cal = Thread.CurrentThread.CurrentCulture.Calendar;
417
				Calendar cal = Thread.CurrentThread.CurrentCulture.Calendar;
418
				DateTime cur = dateTimePicker.Value;
418
				DateTime cur = dateTimePicker.InvokeSync (d => d.Value);
419
419
420
				switch (part_data.date_time_part) {
420
				switch (part_data.date_time_part) {
421
				case DateTimePicker.DateTimePart.Month:
421
				case DateTimePicker.DateTimePart.Month:
Lines 483-490 namespace Mono.UIAutomation.Winforms Link Here
483
				if (propertyId == AEIds.NameProperty.Id)
483
				if (propertyId == AEIds.NameProperty.Id)
484
					return itemProv.Text;
484
					return itemProv.Text;
485
				else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
485
				else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
486
					return (bool) rootProvider.GetPropertyValue (AEIds.HasKeyboardFocusProperty.Id)
486
					return IsItemSelected (prov);
487
					       && IsItemSelected (prov);
488
				else if (propertyId == AEIds.BoundingRectangleProperty.Id)
487
				else if (propertyId == AEIds.BoundingRectangleProperty.Id)
489
					return GetProviderPropertyValue (AEIds.BoundingRectangleProperty.Id);
488
					return GetProviderPropertyValue (AEIds.BoundingRectangleProperty.Id);
490
				return null;
489
				return null;
Lines 503-509 namespace Mono.UIAutomation.Winforms Link Here
503
			public bool IsItemSelected (ListItemProvider prov)
502
			public bool IsItemSelected (ListItemProvider prov)
504
			{
503
			{
505
				Calendar cal = Thread.CurrentThread.CurrentCulture.Calendar;
504
				Calendar cal = Thread.CurrentThread.CurrentCulture.Calendar;
506
				DateTime cur = dateTimePicker.Value;
505
				DateTime cur = dateTimePicker.InvokeSync (d => d.Value);
507
				DateTime date = (DateTime) prov.ObjectItem;
506
				DateTime date = (DateTime) prov.ObjectItem;
508
507
509
				switch (part_data.date_time_part) {
508
				switch (part_data.date_time_part) {
Lines 525-534 namespace Mono.UIAutomation.Winforms Link Here
525
			
524
			
526
			public void SelectItem (ListItemProvider prov)
525
			public void SelectItem (ListItemProvider prov)
527
			{
526
			{
528
				if (dateTimePicker.ShowCheckBox && !dateTimePicker.Checked)
527
				if (dateTimePicker.InvokeSync (d => d.ShowCheckBox && !d.Checked))
529
					return;
528
					return;
530
529
531
				DateTime cur = dateTimePicker.Value;
530
				DateTime cur = dateTimePicker.InvokeSync (d => d.Value);
532
				Calendar cal = Thread.CurrentThread.CurrentCulture.Calendar;
531
				Calendar cal = Thread.CurrentThread.CurrentCulture.Calendar;
533
				DateTime date = (DateTime) prov.ObjectItem;
532
				DateTime date = (DateTime) prov.ObjectItem;
534
533
Lines 538-544 namespace Mono.UIAutomation.Winforms Link Here
538
					break;
537
					break;
539
				case DateTimePicker.DateTimePart.DayName:
538
				case DateTimePicker.DateTimePart.DayName:
540
					cur = cur.AddDays (cal.GetDayOfWeek (date)
539
					cur = cur.AddDays (cal.GetDayOfWeek (date)
541
					                   - cal.GetDayOfWeek (dateTimePicker.Value));
540
					                   - cal.GetDayOfWeek (cur));
542
					break;
541
					break;
543
				case DateTimePicker.DateTimePart.AMPMSpecifier:
542
				case DateTimePicker.DateTimePart.AMPMSpecifier:
544
					if (date == amDate && IsTimePM (cur)) {
543
					if (date == amDate && IsTimePM (cur)) {
Lines 563-569 namespace Mono.UIAutomation.Winforms Link Here
563
562
564
			public ListItemProvider GetSelectedItem ()
563
			public ListItemProvider GetSelectedItem ()
565
			{
564
			{
566
				DateTime cur = dateTimePicker.Value;
565
				DateTime cur = dateTimePicker.InvokeSync (d => d.Value);
567
				Calendar cal = Thread.CurrentThread.CurrentCulture.Calendar;
566
				Calendar cal = Thread.CurrentThread.CurrentCulture.Calendar;
568
				DateTime searchDate = DateTime.MinValue;
567
				DateTime searchDate = DateTime.MinValue;
569
568
Lines 591-598 namespace Mono.UIAutomation.Winforms Link Here
591
				if (propertyId == AEIds.IsKeyboardFocusableProperty.Id)
590
				if (propertyId == AEIds.IsKeyboardFocusableProperty.Id)
592
					return true;
591
					return true;
593
				else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
592
				else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
594
					return (bool) rootProvider.GetPropertyValue (AEIds.HasKeyboardFocusProperty.Id)
593
					return part_data.Selected;
595
					       && part_data.Selected;
596
				else if (propertyId == AEIds.NameProperty.Id)
594
				else if (propertyId == AEIds.NameProperty.Id)
597
					return Text;
595
					return Text;
598
				else if (propertyId == AEIds.ControlTypeProperty.Id)
596
				else if (propertyId == AEIds.ControlTypeProperty.Id)
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/DomainUpDownProvider.cs (-5 / +9 lines)
Lines 76-82 namespace Mono.UIAutomation.Winforms Link Here
76
76
77
		public void FocusItem (object objectItem)
77
		public void FocusItem (object objectItem)
78
		{
78
		{
79
			control.SelectedItem = objectItem;
79
			control.InvokeSync (delegate {
80
				control.SelectedItem = objectItem;
81
			});
80
		}
82
		}
81
#endregion
83
#endregion
82
84
Lines 106-112 namespace Mono.UIAutomation.Winforms Link Here
106
#region IListProvider Implementation
108
#region IListProvider Implementation
107
		public int IndexOfObjectItem (object obj)
109
		public int IndexOfObjectItem (object obj)
108
		{
110
		{
109
			return control.Items.IndexOf (obj);
111
			return control.InvokeSync (c => c.Items.IndexOf (obj));
110
		}
112
		}
111
113
112
		public IProviderBehavior GetListItemBehaviorRealization (AutomationPattern pattern,
114
		public IProviderBehavior GetListItemBehaviorRealization (AutomationPattern pattern,
Lines 135-141 namespace Mono.UIAutomation.Winforms Link Here
135
			if (propertyId == AEIds.NameProperty.Id) {
137
			if (propertyId == AEIds.NameProperty.Id) {
136
				return (string)prov.ObjectItem;
138
				return (string)prov.ObjectItem;
137
			} else if (propertyId == AEIds.HasKeyboardFocusProperty.Id) {
139
			} else if (propertyId == AEIds.HasKeyboardFocusProperty.Id) {
138
				return IsItemSelected (prov) && (string)prov.ObjectItem == Control.Text;
140
				return IsItemSelected (prov) 
141
					&& control.InvokeSync (c => (string) prov.ObjectItem == c.Text);
139
			} else if (propertyId == AEIds.BoundingRectangleProperty.Id) {
142
			} else if (propertyId == AEIds.BoundingRectangleProperty.Id) {
140
				return GetProviderPropertyValue (AEIds.BoundingRectangleProperty.Id);
143
				return GetProviderPropertyValue (AEIds.BoundingRectangleProperty.Id);
141
			}
144
			}
Lines 154-165 namespace Mono.UIAutomation.Winforms Link Here
154
157
155
		public bool IsItemSelected (ListItemProvider prov)
158
		public bool IsItemSelected (ListItemProvider prov)
156
		{
159
		{
157
			int index = control.Items.IndexOf (prov.ObjectItem);
160
			int index 
161
				= control.InvokeSync (c => c.Items.IndexOf (prov.ObjectItem));
158
			if (index < 0) {
162
			if (index < 0) {
159
				return false;
163
				return false;
160
			}
164
			}
161
165
162
			return (index == control.SelectedIndex);
166
			return control.InvokeSync (c => index == c.SelectedIndex);
163
		}
167
		}
164
168
165
		public int SelectedItemsCount {
169
		public int SelectedItemsCount {
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/FormListener.cs (-1 / +3 lines)
Lines 71-76 namespace Mono.UIAutomation.Winforms Link Here
71
			Application.FormAdded += new EventHandler (OnFormAdded);
71
			Application.FormAdded += new EventHandler (OnFormAdded);
72
72
73
			initialized = true;
73
			initialized = true;
74
75
			System.Threading.Thread.CurrentThread.Name = "UIA-Winforms";
74
		}
76
		}
75
		
77
		
76
#endregion
78
#endregion
Lines 101-107 namespace Mono.UIAutomation.Winforms Link Here
101
				//Initialize navigation to let children use it
103
				//Initialize navigation to let children use it
102
				provider.Navigation = NavigationFactory.CreateNavigation (provider);
104
				provider.Navigation = NavigationFactory.CreateNavigation (provider);
103
				provider.Navigation.Initialize ();
105
				provider.Navigation.Initialize ();
104
				
106
105
				// TODO: Fill in rest of eventargs
107
				// TODO: Fill in rest of eventargs
106
				Helper.RaiseStructureChangedEvent (StructureChangeType.ChildAdded,
108
				Helper.RaiseStructureChangedEvent (StructureChangeType.ChildAdded,
107
				                                   provider);
109
				                                   provider);
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/FormProvider.cs (-9 / +12 lines)
Lines 59-65 namespace Mono.UIAutomation.Winforms Link Here
59
			
59
			
60
			// We keep a copy because we can't reference "form" after 
60
			// We keep a copy because we can't reference "form" after 
61
			// Disposed (used in Close()) called by WindowPatternWindowClosedEvent.
61
			// Disposed (used in Close()) called by WindowPatternWindowClosedEvent.
62
			owner = form.Owner;
62
			owner = form.InvokeSync (c => c.Owner);
63
			alreadyClosed = false;
63
			alreadyClosed = false;
64
		}
64
		}
65
		
65
		
Lines 153-162 namespace Mono.UIAutomation.Winforms Link Here
153
		
153
		
154
		public override IRawElementProviderFragment ElementProviderFromPoint (double x, double y)
154
		public override IRawElementProviderFragment ElementProviderFromPoint (double x, double y)
155
		{
155
		{
156
			if (x > form.Width || y > form.Height)
156
			if (form.InvokeSync (c => x > c.Width || y > c.Height))
157
				return null;
157
				return null;
158
			
158
			
159
			Control child = form.GetChildAtPoint (new Point ((int)x, (int)y));
159
			Control child 
160
				= form.InvokeSync (c => c.GetChildAtPoint (new Point ((int) x, (int) y)));
160
			
161
			
161
			if (child != null) {
162
			if (child != null) {
162
				Log.Debug (child.ToString ());
163
				Log.Debug (child.ToString ());
Lines 177-184 namespace Mono.UIAutomation.Winforms Link Here
177
		
178
		
178
		public override IRawElementProviderFragment GetFocus ()
179
		public override IRawElementProviderFragment GetFocus ()
179
		{
180
		{
180
			foreach (Control control in form.Controls) {
181
			foreach (Control control in form.InvokeSync (f => f.Controls)) {
181
				if (control.Focused) {
182
				if (control.InvokeSync (c => c.Focused)) {
182
					// TODO: Necessary to delve into child control
183
					// TODO: Necessary to delve into child control
183
					// for focused element?
184
					// for focused element?
184
					
185
					
Lines 205-214 namespace Mono.UIAutomation.Winforms Link Here
205
			if (AutomationInteropProvider.ClientsAreListening && !AlreadyClosed) {
206
			if (AutomationInteropProvider.ClientsAreListening && !AlreadyClosed) {
206
				alreadyClosed = true;
207
				alreadyClosed = true;
207
208
208
				if (owner == null)
209
				if (owner == null) {
209
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildRemoved,
210
					Helper.RaiseStructureChangedEvent (StructureChangeType.ChildRemoved,
210
					                                   this);
211
					                                   this);
211
				else {
212
				} else {
212
					FormProvider ownerProvider 
213
					FormProvider ownerProvider 
213
						= ProviderFactory.FindProvider (owner) as FormProvider;
214
						= ProviderFactory.FindProvider (owner) as FormProvider;
214
					if (ownerProvider != null)
215
					if (ownerProvider != null)
Lines 219-227 namespace Mono.UIAutomation.Winforms Link Here
219
220
220
		private void SetupMainMenuProvider ()
221
		private void SetupMainMenuProvider ()
221
		{
222
		{
222
			if (form.Menu != null) {
223
			MainMenu mainMenu = form.InvokeSync (f => f.Menu);
224
			
225
			if (mainMenu != null) {
223
				mainMenuProvider = (MainMenuProvider)
226
				mainMenuProvider = (MainMenuProvider)
224
					ProviderFactory.GetProvider (form.Menu);
227
					ProviderFactory.GetProvider (mainMenu);
225
				if (mainMenuProvider != null)
228
				if (mainMenuProvider != null)
226
					AddChildProvider (mainMenuProvider);
229
					AddChildProvider (mainMenuProvider);
227
			}
230
			}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/FragmentControlProvider.cs (-9 / +26 lines)
Lines 73-79 namespace Mono.UIAutomation.Winforms Link Here
73
				HandleContextMenuChanged (null, EventArgs.Empty);
73
				HandleContextMenuChanged (null, EventArgs.Empty);
74
				HandleContextMenuStripChanged (null, EventArgs.Empty);
74
				HandleContextMenuStripChanged (null, EventArgs.Empty);
75
75
76
				visible = Control.Visible;
76
				visible = Control.InvokeSync (c => c.Visible);
77
			}
77
			}
78
		}
78
		}
79
79
Lines 83-89 namespace Mono.UIAutomation.Winforms Link Here
83
				contextMenuStrip.Opened -= HandleContextMenuStripOpened;
83
				contextMenuStrip.Opened -= HandleContextMenuStripOpened;
84
				contextMenuStrip.Closed -= HandleContextMenuStripClosed;
84
				contextMenuStrip.Closed -= HandleContextMenuStripClosed;
85
			}
85
			}
86
			contextMenuStrip = Control.ContextMenuStrip;
86
			contextMenuStrip = Control.InvokeSync (c => c.ContextMenuStrip);
87
87
88
			if (contextMenuStrip != null) {
88
			if (contextMenuStrip != null) {
89
				contextMenuStrip.Opened += HandleContextMenuStripOpened;
89
				contextMenuStrip.Opened += HandleContextMenuStripOpened;
Lines 116-122 namespace Mono.UIAutomation.Winforms Link Here
116
				contextMenu.Popup -= HandleContextMenuPopup;
116
				contextMenu.Popup -= HandleContextMenuPopup;
117
				contextMenu.Collapse -= HandleContextMenuCollapse;
117
				contextMenu.Collapse -= HandleContextMenuCollapse;
118
			}
118
			}
119
			contextMenu = Control.ContextMenu;
119
			contextMenu = Control.InvokeSync (c => c.ContextMenu);
120
120
121
			if (contextMenu != null) {
121
			if (contextMenu != null) {
122
				contextMenu.Popup += HandleContextMenuPopup;
122
				contextMenu.Popup += HandleContextMenuPopup;
Lines 260-265 namespace Mono.UIAutomation.Winforms Link Here
260
			RemoveChildProvider (true, childProvider);
260
			RemoveChildProvider (true, childProvider);
261
		}
261
		}
262
262
263
		public override void Initialize ()
264
		{
265
			base.Initialize ();
266
267
			if (Control != null) {
268
				Control.ContextMenuChanged += HandleContextMenuChanged;
269
				Control.ContextMenuStripChanged += HandleContextMenuStripChanged;
270
271
				HandleContextMenuChanged (null, EventArgs.Empty);
272
				HandleContextMenuStripChanged (null, EventArgs.Empty);
273
274
				visible = Control.InvokeSync (c => c.Visible);
275
			}
276
		}
277
263
		public override void Terminate ()
278
		public override void Terminate ()
264
		{
279
		{
265
			base.Terminate ();
280
			base.Terminate ();
Lines 276-282 namespace Mono.UIAutomation.Winforms Link Here
276
				Control.ControlAdded += OnControlAdded;
291
				Control.ControlAdded += OnControlAdded;
277
				Control.ControlRemoved += OnControlRemoved;
292
				Control.ControlRemoved += OnControlRemoved;
278
				
293
				
279
				foreach (SWF.Control childControl in Control.Controls)
294
				foreach (SWF.Control childControl in Control.InvokeSync (c => c.Controls))
280
					HandleComponentAdded (childControl);
295
					HandleComponentAdded (childControl);
281
296
282
				Control.VisibleChanged += OnControlVisibleChanged;
297
				Control.VisibleChanged += OnControlVisibleChanged;
Lines 334-348 namespace Mono.UIAutomation.Winforms Link Here
334
		
349
		
335
		private void OnControlVisibleChanged (object sender, EventArgs args)
350
		private void OnControlVisibleChanged (object sender, EventArgs args)
336
		{
351
		{
337
			if (visible == Control.Visible)
352
			bool isVisible = Control.InvokeSync (c => c.Visible);
353
			
354
			if (visible == isVisible)
338
				return;
355
				return;
339
356
340
			if (Control.Visible)
357
			if (isVisible)
341
				InitializeChildControlStructure ();
358
				InitializeChildControlStructure ();
342
			else
359
			else
343
				FinalizeChildControlStructure ();
360
				FinalizeChildControlStructure ();
344
361
345
			visible = Control.Visible;
362
			visible = isVisible;
346
		}
363
		}
347
364
348
		private void OnChildControlVisibleChanged (object sender, EventArgs args)
365
		private void OnChildControlVisibleChanged (object sender, EventArgs args)
Lines 462-468 namespace Mono.UIAutomation.Winforms Link Here
462
		{
479
		{
463
			SWF.Control control = null;
480
			SWF.Control control = null;
464
			if ((control = component as SWF.Control) != null)
481
			if ((control = component as SWF.Control) != null)
465
				return control.Visible;
482
				return control.InvokeSync (c => c.Visible);
466
			else // Component based providers will need to override this method
483
			else // Component based providers will need to override this method
467
				return false;
484
				return false;
468
		}
485
		}
Lines 522-528 namespace Mono.UIAutomation.Winforms Link Here
522
		public virtual void SetFocus ()
539
		public virtual void SetFocus ()
523
		{
540
		{
524
			if (Control != null)
541
			if (Control != null)
525
				Control.Focus ();
542
				Control.InvokeSync (delegate { Control.Focus (); });
526
		}
543
		}
527
544
528
		#endregion
545
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/Helper.cs (-29 / +90 lines)
Lines 17-23 Link Here
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
19
// 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
20
// Copyright (c) 2008,2009 Novell, Inc. (http://www.novell.com) 
21
// 
21
// 
22
// Authors: 
22
// Authors: 
23
//	Mario Carrion <mcarrion@novell.com>
23
//	Mario Carrion <mcarrion@novell.com>
Lines 27-36 using System; Link Here
27
using System.Drawing;
27
using System.Drawing;
28
using System.Reflection;
28
using System.Reflection;
29
using System.Windows;
29
using System.Windows;
30
using System.ComponentModel;
30
using SWF = System.Windows.Forms;
31
using SWF = System.Windows.Forms;
31
using System.Windows.Automation;
32
using System.Windows.Automation;
32
using System.Windows.Automation.Provider;
33
using System.Windows.Automation.Provider;
33
34
35
using System.Threading;
36
34
namespace Mono.UIAutomation.Winforms
37
namespace Mono.UIAutomation.Winforms
35
{
38
{
36
39
Lines 68-85 namespace Mono.UIAutomation.Winforms Link Here
68
71
69
		internal static Rect GetControlScreenBounds (Rectangle bounds, SWF.Control control, bool controlIsParent)
72
		internal static Rect GetControlScreenBounds (Rectangle bounds, SWF.Control control, bool controlIsParent)
70
		{
73
		{
71
			if (control == null || !control.Visible)
74
			if (control == null)
72
				return Rect.Empty;
75
				return Rect.Empty;
73
			else if (controlIsParent)
74
				return Helper.RectangleToRect (control.RectangleToScreen (bounds));
75
			else if (control.Parent == null || control.TopLevelControl == null)
76
				return Helper.RectangleToRect (bounds);
77
			else {
76
			else {
78
77
				return control.InvokeSync (c => {
79
				if (control.FindForm () == control.Parent)
78
					if (!c.Visible)
80
					return Helper.RectangleToRect (control.TopLevelControl.RectangleToScreen (bounds));
79
						return Rect.Empty;
81
				else
80
					else if (controlIsParent)
82
					return Helper.RectangleToRect (control.Parent.RectangleToScreen (bounds));
81
						return Helper.RectangleToRect (c.RectangleToScreen (bounds));
82
					else if (c.Parent == null || c.TopLevelControl == null)
83
						return Helper.RectangleToRect (bounds);
84
					else {
85
						if (c.FindForm () == c.Parent)
86
							return Helper.RectangleToRect (c.TopLevelControl.RectangleToScreen (bounds));
87
						else
88
							return Helper.RectangleToRect (c.Parent.RectangleToScreen (bounds));
89
					}
90
				});
83
			}
91
			}
84
		}
92
		}
85
93
Lines 93-99 namespace Mono.UIAutomation.Winforms Link Here
93
			if (item.Owner == null)
101
			if (item.Owner == null)
94
				return item.Bounds;
102
				return item.Bounds;
95
			else
103
			else
96
				return item.Owner.RectangleToScreen (item.Bounds);
104
				return item.Owner.InvokeSync (c => c.RectangleToScreen (item.Bounds));
97
		}
105
		}
98
106
99
		internal static object GetClickablePoint (SimpleControlProvider provider)
107
		internal static object GetClickablePoint (SimpleControlProvider provider)
Lines 131-141 namespace Mono.UIAutomation.Winforms Link Here
131
			else
139
			else
132
				screen = Helper.RectangleToRect (SWF.Screen.GetWorkingArea (referenceControl));
140
				screen = Helper.RectangleToRect (SWF.Screen.GetWorkingArea (referenceControl));
133
141
134
			IRawElementProviderFragment formProvider = null;
142
//			SWF.Form form = Helper.SynchronizedGet<SWF.Control, SWF.Form> (referenceControl, v => referenceControl.FindForm ());
135
			if ((formProvider = ProviderFactory.FindProvider (referenceControl.FindForm ())) != null)
143
136
				return !formProvider.BoundingRectangle.IntersectsWith (bounds) || !bounds.IntersectsWith (screen);
144
//			return Helper.SynchronizedGet<SWF.Control, bool> (referenceControl, v => {
137
145
				IRawElementProviderFragment formProvider = null;
138
			return !bounds.IntersectsWith (screen);
146
//				Console.WriteLine (">>referenceControl: {0}", referenceControl == null);
147
//				if ((formProvider = ProviderFactory.FindProvider (form)) != null)
148
				if ((formProvider = ProviderFactory.FindProvider (referenceControl.FindForm ())) != null)
149
					return !formProvider.BoundingRectangle.IntersectsWith (bounds) || !bounds.IntersectsWith (screen);
150
	
151
				return !bounds.IntersectsWith (screen);
152
//			});
139
		}
153
		}
140
154
141
		internal static bool IsListItemOffScreen (Rect itemBounds,
155
		internal static bool IsListItemOffScreen (Rect itemBounds,
Lines 144-150 namespace Mono.UIAutomation.Winforms Link Here
144
		                                          Rectangle headerBounds,
158
		                                          Rectangle headerBounds,
145
		                                          IScrollBehaviorObserver observer)
159
		                                          IScrollBehaviorObserver observer)
146
		{
160
		{
147
			Rectangle listViewRectangle = containerControl.Bounds;
161
			Rectangle listViewRectangle = containerControl.InvokeSync (c => c.Bounds);
148
			if (visibleHeader) {
162
			if (visibleHeader) {
149
				listViewRectangle.Y += headerBounds.Height;
163
				listViewRectangle.Y += headerBounds.Height;
150
				listViewRectangle.Height -= headerBounds.Height;
164
				listViewRectangle.Height -= headerBounds.Height;
Lines 153-161 namespace Mono.UIAutomation.Winforms Link Here
153
				listViewRectangle.Height -= observer.HorizontalScrollBar.Height;
167
				listViewRectangle.Height -= observer.HorizontalScrollBar.Height;
154
			if (observer.VerticalScrollBar.Visible)
168
			if (observer.VerticalScrollBar.Visible)
155
				listViewRectangle.Width -= observer.VerticalScrollBar.Width;
169
				listViewRectangle.Width -= observer.VerticalScrollBar.Width;
156
170
			
157
			Rect screen 
171
			SWF.Control parent = containerControl.InvokeSync (c => c.Parent);
158
				= Helper.RectangleToRect (containerControl.Parent.RectangleToScreen (listViewRectangle));
172
			Rect screen
173
				= parent.InvokeSync (c => Helper.RectangleToRect (c.RectangleToScreen (listViewRectangle)));
159
			return !itemBounds.IntersectsWith (screen);
174
			return !itemBounds.IntersectsWith (screen);
160
		}
175
		}
161
176
Lines 179-191 namespace Mono.UIAutomation.Winforms Link Here
179
			int imageY;
194
			int imageY;
180
			int imageWidth;
195
			int imageWidth;
181
			int imageHeight;
196
			int imageHeight;
182
			int width = buttonBase.Width;
197
			int width = buttonBase.InvokeSync (c => c.Width);
183
			int height = buttonBase.Height;
198
			int height = buttonBase.InvokeSync (c => c.Height);
184
199
185
			if (buttonBase.ImageIndex != -1)
200
			image = buttonBase.InvokeSync (c => {
186
				image = buttonBase.ImageList.Images [buttonBase.ImageIndex];
201
				if (c.ImageIndex != -1)
187
			else
202
					return c.ImageList.Images [c.ImageIndex];
188
				image = buttonBase.Image;
203
				else
204
					return c.Image;
205
			});
189
			
206
			
190
			if (image == null)
207
			if (image == null)
191
				return Rect.Empty;
208
				return Rect.Empty;
Lines 193-199 namespace Mono.UIAutomation.Winforms Link Here
193
			imageWidth = image.Width;
210
			imageWidth = image.Width;
194
			imageHeight = image.Height;
211
			imageHeight = image.Height;
195
		
212
		
196
			switch (buttonBase.ImageAlign) {
213
			switch (buttonBase.InvokeSync (c => c.ImageAlign)) {
197
				case ContentAlignment.TopLeft: {
214
				case ContentAlignment.TopLeft: {
198
					imageX = 5;
215
					imageX = 5;
199
					imageY = 5;
216
					imageY = 5;
Lines 379-385 namespace Mono.UIAutomation.Winforms Link Here
379
					runtimeId = new int[] {0};
396
					runtimeId = new int[] {0};
380
				else
397
				else
381
					runtimeId = provider.GetRuntimeId ();
398
					runtimeId = provider.GetRuntimeId ();
382
				
399
383
				StructureChangedEventArgs invalidatedArgs 
400
				StructureChangedEventArgs invalidatedArgs 
384
					= new StructureChangedEventArgs (type, runtimeId);
401
					= new StructureChangedEventArgs (type, runtimeId);
385
				AutomationInteropProvider.RaiseStructureChangedEvent (provider, 
402
				AutomationInteropProvider.RaiseStructureChangedEvent (provider, 
Lines 445-450 namespace Mono.UIAutomation.Winforms Link Here
445
					s = s.Remove (i, 1);
462
					s = s.Remove (i, 1);
446
			return s;
463
			return s;
447
		}
464
		}
465
466
		internal static int Counter = 0;
467
		
448
		#endregion
468
		#endregion
449
		
469
		
450
		#region Private Static Methods
470
		#region Private Static Methods
Lines 491-494 namespace Mono.UIAutomation.Winforms Link Here
491
511
492
		#endregion
512
		#endregion
493
	}
513
	}
514
515
	internal static class InvokeRequiredExtensionControl
516
	{	
517
		public static TResult InvokeSync<TControl, TResult> (this TControl control,
518
		                                                       Func<TControl, TResult> func)
519
			where TControl : SWF.Control
520
		{
521
			// This happens when a Winforms event raises an AutomationEvent
522
			// that raises an Atk event that needs to request Winforms data :-)
523
			if (AlreadyInvoked)
524
				return (TResult) func (control);
525
			
526
			if (control.InvokeRequired && control.IsHandleCreated) {
527
				if (Interlocked.CompareExchange (ref alreadyInvoked, 1, 0) == 0) {
528
					TResult result = (TResult) control.Invoke (func, control);
529
					Interlocked.CompareExchange (ref alreadyInvoked, 0, 1);
530
					return result;
531
				} else
532
					return (TResult) func (control);
533
			} else
534
				return (TResult) func (control);
535
		}
536
		
537
		public static void InvokeSync<TControl> (this TControl control, 
538
		                                            Action<TControl> action)
539
			where TControl : SWF.Control
540
		{
541
			// We don't care about AlreadyInvoked since we are not 
542
			// returning a value.
543
			if (control.InvokeRequired && control.IsHandleCreated)
544
				control.BeginInvoke (action, control);
545
			else
546
				action (control);
547
		}
548
549
		private static bool AlreadyInvoked {
550
			get { return Interlocked.CompareExchange (ref alreadyInvoked, 0, 0) == 1; }
551
		}
552
		
553
		private static int alreadyInvoked = 0;
554
	}
494
}
555
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ListBoxProvider.cs (-45 / +69 lines)
Lines 56-66 namespace Mono.UIAutomation.Winforms Link Here
56
		#region Scroll Methods and Properties
56
		#region Scroll Methods and Properties
57
57
58
		protected override ScrollBar HorizontalScrollBar { 
58
		protected override ScrollBar HorizontalScrollBar { 
59
			get { return listboxControl.UIAHScrollBar; }
59
			get { 
60
				return listboxControl.InvokeSync (c => c.UIAHScrollBar); 
61
			}
60
		}
62
		}
61
63
62
		protected override ScrollBar VerticalScrollBar { 
64
		protected override ScrollBar VerticalScrollBar { 
63
			get { return listboxControl.UIAVScrollBar; }
65
			get { 
66
				return listboxControl.InvokeSync (c => c.UIAVScrollBar); 
67
			}
64
		}
68
		}
65
69
66
		#endregion 
70
		#endregion 
Lines 88-97 namespace Mono.UIAutomation.Winforms Link Here
88
			else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
92
			else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
89
				return Catalog.GetString ("list");
93
				return Catalog.GetString ("list");
90
			else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) {
94
			else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) {
91
				if (string.IsNullOrEmpty (listboxControl.AccessibleName))
95
				return listboxControl.InvokeSync (c => {
92
					return Helper.StripAmpersands (listboxControl.Text);
96
					if (string.IsNullOrEmpty (c.AccessibleName))
93
				else
97
						return Helper.StripAmpersands (c.Text);
94
					return listboxControl.AccessibleName;
98
					else
99
						return c.AccessibleName;
100
				});
95
			} else
101
			} else
96
				return base.GetProviderPropertyValue (propertyId);
102
				return base.GetProviderPropertyValue (propertyId);
97
		}
103
		}
Lines 113-143 namespace Mono.UIAutomation.Winforms Link Here
113
		
119
		
114
		public override IRawElementProviderFragment GetFocus ()
120
		public override IRawElementProviderFragment GetFocus ()
115
		{
121
		{
116
			return GetItemProviderFrom (this, listboxControl.Items [listboxControl.FocusedItem]);
122
			return listboxControl.InvokeSync (c => GetItemProviderFrom (this, c.Items [c.FocusedItem]));
117
		}
123
		}
118
		
124
		
119
		public override void FocusItem (object objectItem)
125
		public override void FocusItem (object objectItem)
120
		{
126
		{
121
			listboxControl.FocusedItem = listboxControl.Items.IndexOf (objectItem);
127
			listboxControl.InvokeSync (delegate {
128
				listboxControl.FocusedItem = listboxControl.Items.IndexOf (objectItem);
129
			});
122
		}
130
		}
123
131
124
		public override void InitializeChildControlStructure ()
132
		public override void InitializeChildControlStructure ()
125
		{
133
		{
126
			base.InitializeChildControlStructure ();
134
			base.InitializeChildControlStructure ();
127
			
135
128
			listboxControl.Items.UIACollectionChanged += OnCollectionChanged;
136
			listboxControl.InvokeSync (delegate {
129
			
137
				listboxControl.Items.UIACollectionChanged += OnCollectionChanged;
130
			foreach (object objectItem in listboxControl.Items) {
138
				
131
				ListItemProvider item = GetItemProviderFrom (this, objectItem);
139
				foreach (object objectItem in listboxControl.Items) {
132
				AddChildProvider (item);
140
					ListItemProvider item = GetItemProviderFrom (this, objectItem);
133
			}
141
					AddChildProvider (item);
142
				}
143
			});
134
		}
144
		}
135
		
145
		
136
		public override void FinalizeChildControlStructure ()
146
		public override void FinalizeChildControlStructure ()
137
		{
147
		{
138
			base.FinalizeChildControlStructure ();
148
			base.FinalizeChildControlStructure ();
139
149
140
			listboxControl.Items.UIACollectionChanged -= OnCollectionChanged;
150
			listboxControl.InvokeSync (delegate {
151
				listboxControl.Items.UIACollectionChanged -= OnCollectionChanged;
152
			});
141
		}
153
		}
142
		
154
		
143
		#endregion
155
		#endregion
Lines 148-174 namespace Mono.UIAutomation.Winforms Link Here
148
		                                             int propertyId)
160
		                                             int propertyId)
149
		{
161
		{
150
			if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
162
			if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
151
				return listboxControl.GetItemText (item.ObjectItem);
163
				return listboxControl.InvokeSync (s => s.GetItemText (item.ObjectItem));
152
			
164
			
153
			if (ContainsItem (item) == false)
165
			if (ContainsItem (item) == false)
154
				return null;
166
				return null;
155
167
156
			if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
168
			if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
157
				return listboxControl.Focused && item.Index == listboxControl.FocusedItem;
169
				return listboxControl.InvokeSync (s => s.Focused 
170
				                                  && item.Index == s.FocusedItem);
158
			else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
171
			else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
159
				System.Drawing.Rectangle itemRec = System.Drawing.Rectangle.Empty;
172
				return listboxControl.InvokeSync (c => {
160
				System.Drawing.Rectangle rectangle = listboxControl.Bounds;
173
					System.Drawing.Rectangle itemRec = System.Drawing.Rectangle.Empty;
161
174
					System.Drawing.Rectangle rectangle = c.Bounds;
162
				itemRec = listboxControl.GetItemRectangle (item.Index);
163
				itemRec.X += rectangle.X;
164
				itemRec.Y += rectangle.Y;
165
				
166
				if (listboxControl.FindForm () == listboxControl.Parent)
167
					itemRec = listboxControl.TopLevelControl.RectangleToScreen (itemRec);
168
				else
169
					itemRec = listboxControl.Parent.RectangleToScreen (itemRec);
170
	
175
	
171
				return Helper.RectangleToRect (itemRec);
176
					itemRec = c.GetItemRectangle (item.Index);
177
					itemRec.X += rectangle.X;
178
					itemRec.Y += rectangle.Y;
179
					
180
					if (c.FindForm () == c.Parent)
181
						itemRec = c.TopLevelControl.RectangleToScreen (itemRec);
182
					else
183
						itemRec = c.Parent.RectangleToScreen (itemRec);
184
		
185
					return Helper.RectangleToRect (itemRec);
186
				});
172
			} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
187
			} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
173
				return Helper.IsListItemOffScreen ((Rect) item.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id),
188
				return Helper.IsListItemOffScreen ((Rect) item.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id),
174
				                                   listboxControl,
189
				                                   listboxControl,
Lines 183-228 namespace Mono.UIAutomation.Winforms Link Here
183
		
198
		
184
		#region ListProvider: Specializations
199
		#region ListProvider: Specializations
185
		
200
		
186
		public override int SelectedItemsCount { 
201
		public override int SelectedItemsCount {
187
			get { return listboxControl.SelectedItems.Count; }
202
			get { return listboxControl.InvokeSync (c => c.SelectedItems.Count); }
188
		}
203
		}
189
		
204
		
190
		public override int ItemsCount {
205
		public override int ItemsCount {
191
			get { return listboxControl.Items.Count; }
206
			get { return listboxControl.InvokeSync (c => c.Items.Count); }
192
		}
207
		}
193
208
194
		public override int IndexOfObjectItem (object objectItem)
209
		public override int IndexOfObjectItem (object objectItem)
195
		{
210
		{
196
			return listboxControl.Items.IndexOf (objectItem);
211
			return listboxControl.InvokeSync (c => c.Items.IndexOf (objectItem));
197
		}
212
		}
198
		
213
		
199
		public override IRawElementProviderSimple[] GetSelectedItems ()
214
		public override IRawElementProviderSimple[] GetSelectedItems ()
200
		{
215
		{
201
			ListItemProvider []items;
216
			ListItemProvider []items;
202
217
203
			if (listboxControl == null || listboxControl.SelectedIndices.Count == 0)
218
			if (listboxControl == null 
219
			    || listboxControl.InvokeSync (c => c.SelectedIndices.Count == 0))
204
				return new ListItemProvider [0];
220
				return new ListItemProvider [0];
205
			
221
206
			items = new ListItemProvider [listboxControl.SelectedIndices.Count];		
222
			return listboxControl.InvokeSync (c => {
207
			for (int index = 0; index < items.Length; index++) 
223
				items = new ListItemProvider [c.SelectedIndices.Count];		
208
				items [index] = GetItemProviderFrom (this, listboxControl.Items [listboxControl.SelectedIndices [index]]);
224
				for (int index = 0; index < items.Length; index++) 
209
			
225
					items [index] = GetItemProviderFrom (this, c.Items [c.SelectedIndices [index]]);
210
			return items;
226
				
227
				return items;
228
			});
211
		}
229
		}
212
		
230
		
213
		public override void SelectItem (ListItemProvider item)
231
		public override void SelectItem (ListItemProvider item)
214
		{
232
		{
215
			listboxControl.SetSelected (item.Index, true);
233
			listboxControl.InvokeSync (delegate {
234
				listboxControl.SetSelected (item.Index, true);
235
			});
216
		}
236
		}
217
237
218
		public override void UnselectItem (ListItemProvider item)
238
		public override void UnselectItem (ListItemProvider item)
219
		{
239
		{
220
			listboxControl.SetSelected (item.Index, false);
240
			listboxControl.InvokeSync (delegate {
241
				listboxControl.SetSelected (item.Index, false);
242
			});
221
		}
243
		}
222
		
244
		
223
		public override bool IsItemSelected (ListItemProvider item)
245
		public override bool IsItemSelected (ListItemProvider item)
224
		{
246
		{
225
			return listboxControl.SelectedIndices.Contains (item.Index);
247
			return listboxControl.InvokeSync (b => b.SelectedIndices.Contains (item.Index));
226
		}
248
		}
227
249
228
		public override IConnectable GetListItemEventRealization (ProviderEventType eventType, 
250
		public override IConnectable GetListItemEventRealization (ProviderEventType eventType, 
Lines 241-247 namespace Mono.UIAutomation.Winforms Link Here
241
		public override void ScrollItemIntoView (ListItemProvider item)
263
		public override void ScrollItemIntoView (ListItemProvider item)
242
		{
264
		{
243
			if (ContainsItem (item) == true)
265
			if (ContainsItem (item) == true)
244
				listboxControl.TopIndex = item.Index;
266
				listboxControl.InvokeSync (delegate {
267
					listboxControl.TopIndex = item.Index;
268
				});
245
		}
269
		}
246
		
270
		
247
		#endregion
271
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ListViewProvider.cs (-119 / +159 lines)
Lines 17-23 Link Here
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
19
// 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
20
// Copyright (c) 2008,2009 Novell, Inc. (http://www.novell.com) 
21
// 
21
// 
22
// Authors: 
22
// Authors: 
23
//	Mario Carrion <mcarrion@novell.com>
23
//	Mario Carrion <mcarrion@novell.com>
Lines 48-56 namespace Mono.UIAutomation.Winforms Link Here
48
		public ListViewProvider (SWF.ListView listView) : base (listView)
48
		public ListViewProvider (SWF.ListView listView) : base (listView)
49
		{
49
		{
50
			this.listView = listView;
50
			this.listView = listView;
51
51
			
52
			lastView = listView.View;
52
			lastView = listView.InvokeSync (c => c.View);
53
			showGroups = listView.ShowGroups;
53
			showGroups = listView.InvokeSync (c => c.ShowGroups);
54
			groups = new Dictionary<SWF.ListViewGroup, ListViewGroupProvider> ();
54
			groups = new Dictionary<SWF.ListViewGroup, ListViewGroupProvider> ();
55
		}
55
		}
56
		
56
		
Lines 70-81 namespace Mono.UIAutomation.Winforms Link Here
70
		protected override object GetProviderPropertyValue (int propertyId)
70
		protected override object GetProviderPropertyValue (int propertyId)
71
		{
71
		{
72
			if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id) {
72
			if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id) {
73
				if (listView.View == SWF.View.Details)
73
				if (listView.InvokeSync (c => c.View == SWF.View.Details))
74
					return ControlType.DataGrid.Id;
74
					return ControlType.DataGrid.Id;
75
				else
75
				else
76
					return ControlType.List.Id;
76
					return ControlType.List.Id;
77
			} else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id) {
77
			} else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id) {
78
				if (listView.View == SWF.View.Details)
78
				if (listView.InvokeSync (c => c.View == SWF.View.Details))
79
					return Catalog.GetString ("data grid");
79
					return Catalog.GetString ("data grid");
80
				else
80
				else
81
					return Catalog.GetString ("list");
81
					return Catalog.GetString ("list");
Lines 99-111 namespace Mono.UIAutomation.Winforms Link Here
99
			else if (behavior == SelectionPatternIdentifiers.Pattern) 
99
			else if (behavior == SelectionPatternIdentifiers.Pattern) 
100
				return new SelectionProviderBehavior (this);
100
				return new SelectionProviderBehavior (this);
101
			else if (behavior == GridPatternIdentifiers.Pattern) {
101
			else if (behavior == GridPatternIdentifiers.Pattern) {
102
				if (listView.ShowGroups == false || SWF.Application.VisualStylesEnabled == false
102
				if (listView.InvokeSync (c => !c.ShowGroups
103
				    || listView.View == SWF.View.List || listView.View == SWF.View.Details)
103
				                         || !SWF.Application.VisualStylesEnabled
104
				                         || c.View == SWF.View.List
105
				                         || c.View == SWF.View.Details))
104
				    return new GridProviderBehavior (this);
106
				    return new GridProviderBehavior (this);
105
				else
107
				else
106
					return null;
108
					return null;
107
			} else if (behavior == TablePatternIdentifiers.Pattern) {
109
			} else if (behavior == TablePatternIdentifiers.Pattern) {
108
				if (listView.View == SWF.View.Details)
110
				if (listView.InvokeSync (c => c.View == SWF.View.Details))
109
					return new TableProviderBehavior (this);
111
					return new TableProviderBehavior (this);
110
				else
112
				else
111
					return null;
113
					return null;
Lines 122-146 namespace Mono.UIAutomation.Winforms Link Here
122
				return new ListItemSelectionItemProviderBehavior (listItem);
124
				return new ListItemSelectionItemProviderBehavior (listItem);
123
			else if (behavior == GridItemPatternIdentifiers.Pattern) {
125
			else if (behavior == GridItemPatternIdentifiers.Pattern) {
124
				// LAMESPEC: GridItem implemented *only* when: listView.View != SWF.View.Details
126
				// LAMESPEC: GridItem implemented *only* when: listView.View != SWF.View.Details
125
				if (listView.View != SWF.View.Details
127
				if (listView.InvokeSync (c => c.View != SWF.View.Details)
126
				    || IsBehaviorEnabled (GridPatternIdentifiers.Pattern))
128
				    || IsBehaviorEnabled (GridPatternIdentifiers.Pattern))
127
					return new ListItemGridItemProviderBehavior (listItem);
129
					return new ListItemGridItemProviderBehavior (listItem);
128
				else
130
				else
129
					return null;
131
					return null;
130
			} else if (behavior == InvokePatternIdentifiers.Pattern && Control is SWF.MWFFileView) {
131
				return new ListItemInvokeProviderBehavior (listItem);
132
			} else if (behavior == ValuePatternIdentifiers.Pattern) {
132
			} else if (behavior == ValuePatternIdentifiers.Pattern) {
133
				if (listView.LabelEdit == true)
133
				if (listView.InvokeSync (c => c.LabelEdit))
134
					return new ListItemValueProviderBehavior (listItem);
134
					return new ListItemValueProviderBehavior (listItem);
135
				else
135
				else
136
					return null;
136
					return null;
137
			} else if (behavior == TogglePatternIdentifiers.Pattern) {
137
			} else if (behavior == TogglePatternIdentifiers.Pattern) {
138
				if (listView.CheckBoxes == true)
138
				if (listView.InvokeSync (c => c.CheckBoxes))
139
					return new ListItemToggleProviderBehavior (listItem);
139
					return new ListItemToggleProviderBehavior (listItem);
140
				else
140
				else
141
					return null;
141
					return null;
142
			} else if (behavior == TableItemPatternIdentifiers.Pattern) {
142
			} else if (behavior == TableItemPatternIdentifiers.Pattern) {
143
				if (listView.View == SWF.View.Details)
143
				if (listView.InvokeSync (c => c.View == SWF.View.Details))
144
					return new ListItemTableItemProviderBehavior (listItem);
144
					return new ListItemTableItemProviderBehavior (listItem);
145
				else
145
				else
146
					return null;
146
					return null;
Lines 162-187 namespace Mono.UIAutomation.Winforms Link Here
162
			if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
162
			if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
163
				return ((SWF.ListViewItem) item.ObjectItem).Text;
163
				return ((SWF.ListViewItem) item.ObjectItem).Text;
164
			else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
164
			else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
165
				return listView.Focused && ((SWF.ListViewItem)item.ObjectItem).Focused;
165
				return listView.InvokeSync (c => c.Focused 
166
				                             && ((SWF.ListViewItem) item.ObjectItem).Focused);
166
			else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
167
			else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
167
				int index = item.Index;
168
				int index = item.Index;
168
				if (index == -1 || index >= listView.UIAItemsLocationLength)
169
170
				if (index == -1 
171
				    || listView.InvokeSync (l => index >= l.UIAItemsLocationLength))
169
					return Helper.RectangleToRect (SD.Rectangle.Empty);
172
					return Helper.RectangleToRect (SD.Rectangle.Empty);
170
173
171
				SD.Rectangle itemRec = listView.GetItemRect (index);
174
				SD.Rectangle itemRec 
172
				SD.Rectangle rectangle = listView.Bounds;
175
					= listView.InvokeSync (c => c.GetItemRect (index));
176
				SD.Rectangle rectangle 
177
					= listView.InvokeSync (c => c.Bounds);
173
				
178
				
174
				itemRec.X += rectangle.X;
179
				itemRec.X += rectangle.X;
175
				itemRec.Y += rectangle.Y;
180
				itemRec.Y += rectangle.Y;
176
				
181
				
177
				itemRec = listView.Parent.RectangleToScreen (itemRec);
182
				itemRec = listView.InvokeSync (c => c.Parent.RectangleToScreen (itemRec));
178
				
183
				
179
				return Helper.RectangleToRect (itemRec);
184
				return Helper.RectangleToRect (itemRec);
180
			} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
185
			} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
181
				return Helper.IsListItemOffScreen ((Rect) item.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id),
186
				return Helper.IsListItemOffScreen ((Rect) item.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id),
182
				                                   listView, 
187
				                                   listView, 
183
				                                   HeaderProvider != null,
188
				                                   HeaderProvider != null,
184
				                                   listView.UIAHeaderControl,
189
				                                   listView.InvokeSync (c => c.UIAHeaderControl),
185
				                                   ScrollBehaviorObserver);
190
				                                   ScrollBehaviorObserver);
186
			else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
191
			else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
187
				return true;
192
				return true;
Lines 221-237 namespace Mono.UIAutomation.Winforms Link Here
221
		}
226
		}
222
		
227
		
223
		public override int ItemsCount { 
228
		public override int ItemsCount { 
224
			get { return listView.Items.Count; }
229
			get { return listView.InvokeSync (c => c.Items.Count); }
225
		}
230
		}
226
231
227
		public override int IndexOfObjectItem (object objectItem)
232
		public override int IndexOfObjectItem (object objectItem)
228
		{
233
		{
229
			return listView.Items.IndexOf (objectItem as SWF.ListViewItem);
234
			return listView.InvokeSync (c => c.Items.IndexOf (objectItem as SWF.ListViewItem));
230
		}
235
		}
231
		
236
		
232
		public override void FocusItem (object objectItem)
237
		public override void FocusItem (object objectItem)
233
		{
238
		{
234
			((SWF.ListViewItem)objectItem).Focused = true;
239
			listView.InvokeSync (delegate { 
240
				((SWF.ListViewItem) objectItem).Focused = true; 
241
			});
235
		}
242
		}
236
243
237
		#endregion
244
		#endregion
Lines 239-276 namespace Mono.UIAutomation.Winforms Link Here
239
		#region ListItem: Selection Methods and Properties
246
		#region ListItem: Selection Methods and Properties
240
		
247
		
241
		public override int SelectedItemsCount {
248
		public override int SelectedItemsCount {
242
			get { return listView.SelectedItems.Count; }
249
			get { return listView.InvokeSync (c => c.SelectedIndices.Count); }
243
		}
250
		}
244
		
251
		
245
		public override bool IsItemSelected (ListItemProvider item)
252
		public override bool IsItemSelected (ListItemProvider item)
246
		{
253
		{
247
			return listView.SelectedIndices.Contains (item.Index);
254
			return listView.InvokeSync (c => c.SelectedIndices.Contains (item.Index));
248
		}
255
		}
249
		
256
		
250
		public override IRawElementProviderSimple[] GetSelectedItems ()
257
		public override IRawElementProviderSimple[] GetSelectedItems ()
251
		{
258
		{
252
			if (listView.SelectedIndices.Count == 0)
259
			if (listView == null)
253
				return new ListItemProvider [0];
260
				return new ListItemProvider [0];
254
			else {
255
				ListItemProvider []providers = new ListItemProvider [listView.SelectedItems.Count];
256
257
				for (int index = 0; index < listView.SelectedItems.Count; index++)
258
					providers [index] = GetItemProviderFrom (this, listView.SelectedItems [index], false);
259
			
261
			
260
				return providers;
262
			if (listView.InvokeSync (c => c.SelectedIndices.Count == 0))
263
				return new ListItemProvider [0];
264
			else {
265
				return listView.InvokeSync (c => {
266
					ListItemProvider []providers = new ListItemProvider [c.SelectedItems.Count];
267
	
268
					for (int index = 0; index < c.SelectedItems.Count; index++)
269
						providers [index] = GetItemProviderFrom (this, c.SelectedItems [index], false);
270
					
271
					return providers;
272
				});
261
			}
273
			}
262
		}
274
		}
263
		
275
		
264
		public override void SelectItem (ListItemProvider item)
276
		public override void SelectItem (ListItemProvider item)
265
		{
277
		{
266
			if (ContainsItem (item) == true)
278
			if (ContainsItem (item) == true)
267
				listView.Items [item.Index].Selected = true;
279
				listView.InvokeSync (delegate {
280
					listView.Items [item.Index].Selected = true;
281
				});
268
		}
282
		}
269
283
270
		public override void UnselectItem (ListItemProvider item)
284
		public override void UnselectItem (ListItemProvider item)
271
		{
285
		{
272
			if (ContainsItem (item) == true)
286
			if (ContainsItem (item) == true)
273
				listView.Items [item.Index].Selected = false;
287
				listView.InvokeSync (delegate {
288
					listView.Items [item.Index].Selected = false;
289
				});
274
		}
290
		}
275
		
291
		
276
		#endregion
292
		#endregion
Lines 279-300 namespace Mono.UIAutomation.Winforms Link Here
279
		
295
		
280
		public override ToggleState GetItemToggleState (ListItemProvider item)
296
		public override ToggleState GetItemToggleState (ListItemProvider item)
281
		{
297
		{
282
			if (listView.CheckBoxes == false || item.Index == -1)
298
			if (listView.InvokeSync (c => !c.CheckBoxes)
299
			    || item.Index == -1)
283
				return ToggleState.Indeterminate;
300
				return ToggleState.Indeterminate;
284
301
285
			if (ContainsItem (item) == true)
302
			if (ContainsItem (item) == true)
286
				return listView.Items [item.Index].Checked ? ToggleState.On : ToggleState.Off;
303
				return listView.InvokeSync (c => c.Items [item.Index].Checked)
304
					 ? ToggleState.On : ToggleState.Off;
287
			else
305
			else
288
				return ToggleState.Indeterminate;
306
				return ToggleState.Indeterminate;
289
		}
307
		}
290
		
308
		
291
		public override void ToggleItem (ListItemProvider item)
309
		public override void ToggleItem (ListItemProvider item)
292
		{
310
		{
293
			if (listView.CheckBoxes == false)
311
			if (listView.InvokeSync (c => !c.CheckBoxes))
294
				return;
312
				return;
295
				
313
				
296
			if (ContainsItem (item) == true)
314
			if (ContainsItem (item) == true)
297
				listView.Items [item.Index].Checked = !listView.Items [item.Index].Checked;
315
				listView.InvokeSync (delegate { 
316
					listView.Items [item.Index].Checked = !listView.Items [item.Index].Checked; 
317
				});
298
		}
318
		}
299
		
319
		
300
		#endregion
320
		#endregion
Lines 319-331 namespace Mono.UIAutomation.Winforms Link Here
319
			if (ContainsItem (item) == false)
339
			if (ContainsItem (item) == false)
320
				return;
340
				return;
321
			
341
			
322
			// According to http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.topitem.aspx
342
			listView.InvokeSync(delegate {
323
			if (listView.View == SWF.View.LargeIcon 
343
				// According to http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.topitem.aspx
324
			    || listView.View == SWF.View.SmallIcon
344
				if (listView.View == SWF.View.LargeIcon 
325
			    || listView.View == SWF.View.Tile)
345
				    || listView.View == SWF.View.SmallIcon
326
				return;
346
				    || listView.View == SWF.View.Tile)
327
			
347
					return;
328
			listView.TopItem = listView.Items [item.Index];
348
				
349
				listView.TopItem = listView.Items [item.Index];
350
			});
329
		}
351
		}
330
		
352
		
331
		#endregion
353
		#endregion
Lines 359-369 namespace Mono.UIAutomation.Winforms Link Here
359
		#region Scroll Methods and Properties
381
		#region Scroll Methods and Properties
360
		
382
		
361
		protected override SWF.ScrollBar HorizontalScrollBar { 
383
		protected override SWF.ScrollBar HorizontalScrollBar { 
362
			get { return listView.UIAHScrollBar; }
384
			get { return listView.InvokeSync (c => c.UIAHScrollBar); }
363
		}
385
		}
364
386
365
		protected override SWF.ScrollBar VerticalScrollBar { 
387
		protected override SWF.ScrollBar VerticalScrollBar { 
366
			get { return listView.UIAVScrollBar; }
388
			get { return listView.InvokeSync (c => c.UIAVScrollBar); }
367
		}
389
		}
368
390
369
		#endregion
391
		#endregion
Lines 382-388 namespace Mono.UIAutomation.Winforms Link Here
382
		public SWF.ListViewGroup GetDefaultGroup ()
404
		public SWF.ListViewGroup GetDefaultGroup ()
383
		{
405
		{
384
			if (listViewNullGroup == null)
406
			if (listViewNullGroup == null)
385
				listViewNullGroup = listView.UIADefaultListViewGroup;
407
				listViewNullGroup = listView.InvokeSync (c => c.UIADefaultListViewGroup);
386
408
387
			return listViewNullGroup;
409
			return listViewNullGroup;
388
		}
410
		}
Lines 413-419 namespace Mono.UIAutomation.Winforms Link Here
413
			// no Groups are added.
435
			// no Groups are added.
414
436
415
			// Using groups
437
			// Using groups
416
			if (showGroups == true && listView.View != SWF.View.List
438
			if (showGroups == true 
439
			    && listView.InvokeSync (c => c.View != SWF.View.List)
417
			    && SWF.Application.VisualStylesEnabled == true) {
440
			    && SWF.Application.VisualStylesEnabled == true) {
418
441
419
				SWF.ListViewItem listViewItem = (SWF.ListViewItem) objectItem;
442
				SWF.ListViewItem listViewItem = (SWF.ListViewItem) objectItem;
Lines 456-462 namespace Mono.UIAutomation.Winforms Link Here
456
		private void FinalizeProviderFrom (object objectItem)
479
		private void FinalizeProviderFrom (object objectItem)
457
		{
480
		{
458
			// Using groups
481
			// Using groups
459
			if (showGroups == true && listView.View != SWF.View.List
482
			if (showGroups == true 
483
			    && listView.InvokeSync (c => c.View != SWF.View.List)
460
			    && SWF.Application.VisualStylesEnabled == true) {
484
			    && SWF.Application.VisualStylesEnabled == true) {
461
485
462
				SWF.ListViewItem listViewItem = (SWF.ListViewItem) objectItem;
486
				SWF.ListViewItem listViewItem = (SWF.ListViewItem) objectItem;
Lines 485-491 namespace Mono.UIAutomation.Winforms Link Here
485
509
486
		private void UpdateChildrenStructure (bool forceUpdate)
510
		private void UpdateChildrenStructure (bool forceUpdate)
487
		{
511
		{
488
			bool updateView = lastView != listView.View;
512
			bool updateView = listView.InvokeSync (c => lastView != c.View);
489
			
513
			
490
			if (updateView == true || forceUpdate == true) {			
514
			if (updateView == true || forceUpdate == true) {			
491
				foreach (ListViewGroupProvider groupProvider in groups.Values) {
515
				foreach (ListViewGroupProvider groupProvider in groups.Values) {
Lines 505-512 namespace Mono.UIAutomation.Winforms Link Here
505
				
529
				
506
				ClearItemsList ();
530
				ClearItemsList ();
507
			}
531
			}
508
532
			
509
			if (listView.View == SWF.View.Details) {
533
			if (listView.InvokeSync (c => c.View == SWF.View.Details)) {
510
				if (header == null) {
534
				if (header == null) {
511
					header = new ListViewHeaderProvider (listView);
535
					header = new ListViewHeaderProvider (listView);
512
					header.Initialize ();
536
					header.Initialize ();
Lines 514-520 namespace Mono.UIAutomation.Winforms Link Here
514
				}
538
				}
515
			}
539
			}
516
			
540
			
517
			foreach (object objectItem in listView.Items)
541
			foreach (object objectItem 
542
			         in listView.InvokeSync (c => c.Items))
518
				InitializeProviderFrom (objectItem);
543
				InitializeProviderFrom (objectItem);
519
		}
544
		}
520
545
Lines 533-548 namespace Mono.UIAutomation.Winforms Link Here
533
			
558
			
534
			UpdateChildrenStructure (false);
559
			UpdateChildrenStructure (false);
535
560
536
			lastView = listView.View;
561
			lastView = listView.InvokeSync (c => c.View);
537
		}
562
		}
538
563
539
		private void OnUIAShowGroupsChanged (object sender, EventArgs args)
564
		private void OnUIAShowGroupsChanged (object sender, EventArgs args)
540
		{
565
		{
541
			bool oldValue = showGroups;
566
			bool oldValue = showGroups;
542
			showGroups = listView.ShowGroups;
567
			showGroups = listView.InvokeSync (c => c.ShowGroups);
543
			
568
			
544
			//We will have to regenerate children
569
			//We will have to regenerate children
545
			if (listView.ShowGroups != oldValue && listView.View != SWF.View.List) {
570
			if (listView.InvokeSync (c => c.ShowGroups != oldValue 
571
			                         && c.View != SWF.View.List)) {
546
				UpdateChildrenStructure (true);
572
				UpdateChildrenStructure (true);
547
				if (SWF.Application.VisualStylesEnabled == true)
573
				if (SWF.Application.VisualStylesEnabled == true)
548
					SetBehavior (GridPatternIdentifiers.Pattern,
574
					SetBehavior (GridPatternIdentifiers.Pattern,
Lines 664-682 namespace Mono.UIAutomation.Winforms Link Here
664
690
665
			private Rect HeaderRectangle {
691
			private Rect HeaderRectangle {
666
				get {
692
				get {
667
					// Lets Union the Header Bounds			
693
					return listView.InvokeSync (c => {	
668
					SD.Rectangle headerRec = listView.UIAGetHeaderBounds (group);
694
						// Lets Union the Header Bounds			
669
					SD.Rectangle rectangle = listView.Bounds;
695
						SD.Rectangle headerRec = c.UIAGetHeaderBounds (group);
670
					
696
						SD.Rectangle rectangle = c.Bounds;
671
					headerRec.X += rectangle.X;
697
						
672
					headerRec.Y += rectangle.Y;
698
						headerRec.X += rectangle.X;
673
					
699
						headerRec.Y += rectangle.Y;
674
					if (listView.FindForm () == listView.Parent)
700
						
675
						headerRec = listView.TopLevelControl.RectangleToScreen (headerRec);
701
						if (c.FindForm () == c.Parent)
676
					else
702
							headerRec = c.TopLevelControl.RectangleToScreen (headerRec);
677
						headerRec = listView.Parent.RectangleToScreen (headerRec);
703
						else
678
					
704
							headerRec = c.Parent.RectangleToScreen (headerRec);
679
					return Helper.RectangleToRect (headerRec);
705
						
706
						return Helper.RectangleToRect (headerRec);
707
					});
680
				}
708
				}
681
			}
709
			}
682
710
Lines 780-806 namespace Mono.UIAutomation.Winforms Link Here
780
			public override void InitializeChildControlStructure ()
808
			public override void InitializeChildControlStructure ()
781
			{
809
			{
782
				base.InitializeChildControlStructure ();
810
				base.InitializeChildControlStructure ();
783
811
				
784
				//Event used to update columns in ListItem when View.Details
812
				listView.InvokeSync (delegate {
785
				listView.Columns.UIACollectionChanged += OnUIAColumnsCollectionChanged;
813
					//Event used to update columns in ListItem when View.Details
786
814
					listView.Columns.UIACollectionChanged += OnUIAColumnsCollectionChanged;
787
				foreach (SWF.ColumnHeader column in listView.Columns) {
815
	
788
					ListViewHeaderItemProvider item 
816
					foreach (SWF.ColumnHeader column in listView.Columns) {
789
						= new ListViewHeaderItemProvider (this, column);
817
						ListViewHeaderItemProvider item 
790
					item.Initialize ();
818
							= new ListViewHeaderItemProvider (this, column);
791
					AddChildProvider (item);
819
						item.Initialize ();
792
					headerItems [column] = item;
820
						AddChildProvider (item);
793
				}
821
						headerItems [column] = item;
822
					}
823
				});
794
			}
824
			}
795
825
796
			public override void FinalizeChildControlStructure ()
826
			public override void FinalizeChildControlStructure ()
797
			{
827
			{
798
				base.FinalizeChildControlStructure ();
828
				base.FinalizeChildControlStructure ();
829
				
830
				listView.InvokeSync (delegate {
831
					//Event used to update columns in ListItem when View.Details
832
					listView.Columns.UIACollectionChanged -= OnUIAColumnsCollectionChanged;
833
				});
799
834
800
				//Event used to update columns in ListItem when View.Details
835
				foreach (ListViewHeaderItemProvider item in headerItems.Values)
801
				listView.Columns.UIACollectionChanged -= OnUIAColumnsCollectionChanged;
802
803
				foreach (ListViewHeaderItemProvider item in headerItems .Values)
804
					item.Terminate ();
836
					item.Terminate ();
805
			}
837
			}
806
838
Lines 899-916 namespace Mono.UIAutomation.Winforms Link Here
899
				else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
931
				else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
900
					return true;
932
					return true;
901
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
933
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
902
					int indexOf = headerProvider.ListView.Columns.IndexOf (columnHeader);
934
					return headerProvider.ListView.InvokeSync (c => {
903
					Rect headerBounds
935
						int indexOf = c.Columns.IndexOf (columnHeader);
904
						= (Rect) headerProvider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
936
						Rect headerBounds
905
					if (headerBounds.IsEmpty)
937
							= (Rect) headerProvider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
938
						if (headerBounds.IsEmpty)
939
							return headerBounds;
940
						
941
						for (int index = 0; index < indexOf; index++)
942
							headerBounds.X += c.Columns [index].Width;
943
						
944
						headerBounds.Width = c.Columns [indexOf].Width;
945
						
906
						return headerBounds;
946
						return headerBounds;
907
					
947
					});					
908
					for (int index = 0; index < indexOf; index++)
909
						headerBounds.X += headerProvider.ListView.Columns [index].Width;
910
					
911
					headerBounds.Width = headerProvider.ListView.Columns [indexOf].Width;
912
					
913
					return headerBounds;
914
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
948
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id) {
915
					Rect bounds 
949
					Rect bounds 
916
						= (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
950
						= (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
Lines 960-970 namespace Mono.UIAutomation.Winforms Link Here
960
994
961
			public ListViewListItemEditProvider GetEditProviderAtColumn (int column)
995
			public ListViewListItemEditProvider GetEditProviderAtColumn (int column)
962
			{
996
			{
963
				if (column < 0 || column >= listView.Columns.Count)
997
				if (column < 0 
998
				    || listView.InvokeSync (c => column >= c.Columns.Count))
964
					return null;
999
					return null;
965
1000
966
				ListViewListItemEditProvider editProvider = null;				
1001
				ListViewListItemEditProvider editProvider = null;
967
				providers.TryGetValue (listView.Columns [column], out editProvider);
1002
				providers.TryGetValue (listView.InvokeSync (c => c.Columns [column]), 
1003
				                       out editProvider);
968
1004
969
				return editProvider;
1005
				return editProvider;
970
			}
1006
			}
Lines 975-981 namespace Mono.UIAutomation.Winforms Link Here
975
1011
976
			protected override object GetProviderPropertyValue (int propertyId)
1012
			protected override object GetProviderPropertyValue (int propertyId)
977
			{
1013
			{
978
				if (ListView.View == SWF.View.Details) {
1014
				if (ListView.InvokeSync (c => c.View == SWF.View.Details)) {
979
					//According to: http://msdn.microsoft.com/en-us/library/ms742561.aspx
1015
					//According to: http://msdn.microsoft.com/en-us/library/ms742561.aspx
980
					if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
1016
					if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
981
						return ControlType.DataItem.Id;
1017
						return ControlType.DataItem.Id;
Lines 1013-1019 namespace Mono.UIAutomation.Winforms Link Here
1013
				if (lastView == SWF.View.Details)
1049
				if (lastView == SWF.View.Details)
1014
					AddEditChildren ();
1050
					AddEditChildren ();
1015
1051
1016
				if (listView.CheckBoxes == true) {
1052
				if (listView.InvokeSync (c => c.CheckBoxes)) {
1017
					checkboxProvider = new ListViewListItemCheckBoxProvider (this);
1053
					checkboxProvider = new ListViewListItemCheckBoxProvider (this);
1018
					checkboxProvider.Initialize ();
1054
					checkboxProvider.Initialize ();
1019
					AddChildProvider (checkboxProvider);
1055
					AddChildProvider (checkboxProvider);
Lines 1036-1042 namespace Mono.UIAutomation.Winforms Link Here
1036
1072
1037
			private void AddEditChildren ()
1073
			private void AddEditChildren ()
1038
			{
1074
			{
1039
				foreach (SWF.ColumnHeader column in listView.Columns) {
1075
				foreach (SWF.ColumnHeader column 
1076
				         in listView.InvokeSync (c => c.Columns)) {
1040
					ListViewListItemEditProvider editProvider 
1077
					ListViewListItemEditProvider editProvider 
1041
						= new ListViewListItemEditProvider (column, this);
1078
						= new ListViewListItemEditProvider (column, this);
1042
					editProvider.Initialize ();
1079
					editProvider.Initialize ();
Lines 1072-1087 namespace Mono.UIAutomation.Winforms Link Here
1072
				if (lastView == SWF.View.Details) {
1109
				if (lastView == SWF.View.Details) {
1073
					providers.Clear ();
1110
					providers.Clear ();
1074
					OnNavigationChildrenCleared ();
1111
					OnNavigationChildrenCleared ();
1075
				} else if (listView.View == SWF.View.Details)
1112
				} else if (listView.InvokeSync (c => c.View == SWF.View.Details))
1076
					AddEditChildren ();
1113
					AddEditChildren ();
1077
	
1114
	
1078
				lastView = listView.View;
1115
				lastView = listView.InvokeSync (c => c.View);
1079
			}
1116
			}
1080
1117
1081
			private void OnUIAColumnsCollectionChanged (object sender, 
1118
			private void OnUIAColumnsCollectionChanged (object sender, 
1082
			                                            CollectionChangeEventArgs args)
1119
			                                            CollectionChangeEventArgs args)
1083
			{
1120
			{
1084
				if (listView.View != SWF.View.Details)
1121
				if (listView.InvokeSync (c => c.View != SWF.View.Details))
1085
					return;
1122
					return;
1086
1123
1087
				SWF.ColumnHeader column = (SWF.ColumnHeader) args.Element;
1124
				SWF.ColumnHeader column = (SWF.ColumnHeader) args.Element;
Lines 1188-1194 namespace Mono.UIAutomation.Winforms Link Here
1188
					IValueProvider valueProvider = (IValueProvider) GetBehavior (ValuePatternIdentifiers.Pattern);
1225
					IValueProvider valueProvider = (IValueProvider) GetBehavior (ValuePatternIdentifiers.Pattern);
1189
					return valueProvider.Value;
1226
					return valueProvider.Value;
1190
				} else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
1227
				} else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
1191
					return IsFirstColumn || itemProvider.ListView.FullRowSelect;
1228
					return IsFirstColumn || itemProvider.ListView.InvokeSync (c => c.FullRowSelect);
1192
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id) {
1229
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id) {
1193
					if (IsFirstColumn)
1230
					if (IsFirstColumn)
1194
						return itemProvider.GetPropertyValue (propertyId);
1231
						return itemProvider.GetPropertyValue (propertyId);
Lines 1199-1221 namespace Mono.UIAutomation.Winforms Link Here
1199
				else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
1236
				else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
1200
					return null;
1237
					return null;
1201
				else if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id) {
1238
				else if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id) {
1202
					if (ItemProvider.ListView.Columns.Count == 0 || ItemProvider.ListView.Columns [0] == header)
1239
					if (itemProvider.ListView.InvokeSync (c => c.Columns.Count == 0 
1240
					                                      || c.Columns [0] == header))
1203
						return string.Empty;
1241
						return string.Empty;
1204
					else
1242
					else
1205
						return itemProvider.ListViewItem.ToolTipText;
1243
						return itemProvider.ListViewItem.ToolTipText;
1206
				} else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
1244
				} else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id) {
1207
					int indexOf = itemProvider.ListView.Columns.IndexOf (header);
1245
					return itemProvider.ListView.InvokeSync (c => {
1208
					Rect itemBounds
1246
						int indexOf = c.Columns.IndexOf (header);
1209
						= (Rect) itemProvider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
1247
						Rect itemBounds
1210
					if (itemBounds.IsEmpty)
1248
							= (Rect) itemProvider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
1249
						if (itemBounds.IsEmpty)
1250
							return itemBounds;
1251
	
1252
						for (int index = 0; index < indexOf; index++)
1253
							itemBounds.X += c.Columns [index].Width;
1254
						
1255
						itemBounds.Width = c.Columns [indexOf].Width;
1256
						
1211
						return itemBounds;
1257
						return itemBounds;
1212
1258
					});
1213
					for (int index = 0; index < indexOf; index++)
1214
						itemBounds.X += itemProvider.ListView.Columns [index].Width;
1215
					
1216
					itemBounds.Width = itemProvider.ListView.Columns [indexOf].Width;
1217
					
1218
					return itemBounds;
1219
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
1259
				} else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
1220
					return Helper.IsListItemOffScreen ((Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id),
1260
					return Helper.IsListItemOffScreen ((Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id),
1221
					                                   ItemProvider.ListView, 
1261
					                                   ItemProvider.ListView, 
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/MenuStripProvider.cs (-1 / +1 lines)
Lines 54-60 namespace Mono.UIAutomation.Winforms Link Here
54
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
54
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
55
				return Catalog.GetString ("menu bar");
55
				return Catalog.GetString ("menu bar");
56
			else if (propertyId == AEIds.OrientationProperty.Id) {
56
			else if (propertyId == AEIds.OrientationProperty.Id) {
57
				switch (menu.Orientation) {
57
				switch (menu.InvokeSync (o => menu.Orientation)) {
58
				case Orientation.Vertical:
58
				case Orientation.Vertical:
59
					return OrientationType.Vertical;
59
					return OrientationType.Vertical;
60
				case Orientation.Horizontal:
60
				case Orientation.Horizontal:
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/MessageBoxFormProvider.cs (-6 / +5 lines)
Lines 50-56 namespace Mono.UIAutomation.Winforms Link Here
50
		#region Public Methods
50
		#region Public Methods
51
51
52
		public SWF.MessageBox.MessageBoxForm Form {
52
		public SWF.MessageBox.MessageBoxForm Form {
53
				get { return form; }
53
			get { return form; }
54
		}
54
		}
55
		
55
		
56
		#endregion
56
		#endregion
Lines 67-75 namespace Mono.UIAutomation.Winforms Link Here
67
				AddChildProvider (labelProvider);
67
				AddChildProvider (labelProvider);
68
			}
68
			}
69
			if (imageProvider == null
69
			if (imageProvider == null
70
			    && form.UIAIconRectangle.Width >= 0
70
			    && form.InvokeSync (w => w.UIAIconRectangle.Width >= 0)
71
			    && form.UIAIconRectangle.Height >= 0) {
71
			    && form.InvokeSync (h => h.UIAIconRectangle.Height >= 0)) {
72
				
73
				imageProvider = new MessageBoxImageProvider (this);
72
				imageProvider = new MessageBoxImageProvider (this);
74
				imageProvider.Initialize ();
73
				imageProvider.Initialize ();
75
				AddChildProvider (imageProvider);
74
				AddChildProvider (imageProvider);
Lines 135-141 namespace Mono.UIAutomation.Winforms Link Here
135
				} else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
134
				} else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
136
					return false;
135
					return false;
137
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
136
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
138
					return Helper.RectangleToRect (provider.Control.TopLevelControl.RectangleToScreen (provider.Form.UIAMessageRectangle));
137
					return provider.Control.InvokeSync (r => Helper.RectangleToRect (r.TopLevelControl.RectangleToScreen (provider.Form.UIAMessageRectangle)));
139
				else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
138
				else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
140
					return Helper.GetClickablePoint (this);
139
					return Helper.GetClickablePoint (this);
141
				else
140
				else
Lines 190-196 namespace Mono.UIAutomation.Winforms Link Here
190
				} else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
189
				} else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
191
					return false;
190
					return false;
192
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
191
				else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
193
					return Helper.RectangleToRect (provider.Control.TopLevelControl.RectangleToScreen (provider.Form.UIAIconRectangle));
192
					return provider.Control.InvokeSync (r => Helper.RectangleToRect (r.TopLevelControl.RectangleToScreen (provider.Form.UIAIconRectangle)));
194
				else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
193
				else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
195
					return Helper.GetClickablePoint (this);
194
					return Helper.GetClickablePoint (this);
196
				else
195
				else
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/MonthCalendarDataGridProvider.cs (-18 / +30 lines)
Lines 131-137 namespace Mono.UIAutomation.Winforms Link Here
131
				throw new ArgumentException ("col");
131
				throw new ArgumentException ("col");
132
			}
132
			}
133
133
134
			SelectionRange range = calendar.GetDisplayRange (false);
134
			SelectionRange range
135
				= calendar.InvokeSync (c => c.GetDisplayRange (false));
135
			DateTime date = range.Start.AddDays (
136
			DateTime date = range.Start.AddDays (
136
				col + (row * MonthCalendarProvider.DaysInWeek)
137
				col + (row * MonthCalendarProvider.DaysInWeek)
137
			);
138
			);
Lines 146-164 namespace Mono.UIAutomation.Winforms Link Here
146
147
147
#region Selection Helper Methods
148
#region Selection Helper Methods
148
		public bool CanSelectMultiple {
149
		public bool CanSelectMultiple {
149
			get { return calendar.MaxSelectionCount > 1; }
150
			get { return calendar.InvokeSync (c => c.MaxSelectionCount > 1); }
150
		}
151
		}
151
152
152
		public int SelectedItemCount {
153
		public int SelectedItemCount {
153
			get {
154
			get {
154
				SelectionRange range = calendar.SelectionRange;
155
				SelectionRange range 
156
					= calendar.InvokeSync (c => c.SelectionRange);
155
				return (range.End - range.Start).Days;
157
				return (range.End - range.Start).Days;
156
			}
158
			}
157
		}
159
		}
158
160
159
		public IRawElementProviderSimple[] GetSelection ()
161
		public IRawElementProviderSimple[] GetSelection ()
160
		{
162
		{
161
			SelectionRange range = calendar.SelectionRange;
163
			SelectionRange range 
164
				= calendar.InvokeSync (c => c.SelectionRange);
162
			List<IRawElementProviderSimple> selectedItems
165
			List<IRawElementProviderSimple> selectedItems
163
				= new List<IRawElementProviderSimple> ();
166
				= new List<IRawElementProviderSimple> ();
164
167
Lines 188-198 namespace Mono.UIAutomation.Winforms Link Here
188
				return;
191
				return;
189
			}
192
			}
190
193
191
			SelectionRange range = calendar.SelectionRange;
194
			SelectionRange range 
195
				= calendar.InvokeSync (c => c.SelectionRange);
192
196
193
			int proposedDays = (range.End - itemProvider.Date).Days;
197
			int proposedDays = (range.End - itemProvider.Date).Days;
194
			if (range.Start > itemProvider.Date) {
198
			if (range.Start > itemProvider.Date) {
195
				if (proposedDays > calendar.MaxSelectionCount) {
199
				if (proposedDays > calendar.InvokeSync (c => c.MaxSelectionCount)) {
196
					throw new InvalidOperationException ();
200
					throw new InvalidOperationException ();
197
				}
201
				}
198
202
Lines 201-214 namespace Mono.UIAutomation.Winforms Link Here
201
205
202
			proposedDays = (itemProvider.Date - range.Start).Days;
206
			proposedDays = (itemProvider.Date - range.Start).Days;
203
			if (range.End < itemProvider.Date) {
207
			if (range.End < itemProvider.Date) {
204
				if (proposedDays > calendar.MaxSelectionCount) {
208
				if (proposedDays > calendar.InvokeSync (c => c.MaxSelectionCount)) {
205
					throw new InvalidOperationException ();
209
					throw new InvalidOperationException ();
206
				}
210
				}
207
211
208
				range.End = itemProvider.Date;
212
				range.End = itemProvider.Date;
209
			}
213
			}
210
			
214
211
			calendar.SelectionRange = range;
215
			calendar.InvokeSync (delegate {
216
				calendar.SelectionRange = range;
217
			});
212
		}
218
		}
213
219
214
		// We can only allow removing from selection on the endpoints.
220
		// We can only allow removing from selection on the endpoints.
Lines 219-225 namespace Mono.UIAutomation.Winforms Link Here
219
				throw new InvalidOperationException ();
225
				throw new InvalidOperationException ();
220
			}
226
			}
221
227
222
			SelectionRange range = calendar.SelectionRange;
228
			SelectionRange range 
229
				= calendar.InvokeSync (c => c.SelectionRange);
223
			if (range.Start == range.End) {
230
			if (range.Start == range.End) {
224
				throw new InvalidOperationException ();
231
				throw new InvalidOperationException ();
225
			}
232
			}
Lines 239-252 namespace Mono.UIAutomation.Winforms Link Here
239
246
240
		public void SelectItem (MonthCalendarListItemProvider itemProvider)
247
		public void SelectItem (MonthCalendarListItemProvider itemProvider)
241
		{
248
		{
242
			calendar.SelectionRange
249
			calendar.InvokeSync (delegate {
243
				= new SelectionRange (itemProvider.Date,
250
				calendar.SelectionRange
244
			                              itemProvider.Date);
251
					= new SelectionRange (itemProvider.Date,
252
					                      itemProvider.Date);
253
			});
245
		}
254
		}
246
255
247
		public bool IsItemSelected (MonthCalendarListItemProvider itemProvider)
256
		public bool IsItemSelected (MonthCalendarListItemProvider itemProvider)
248
		{
257
		{
249
			SelectionRange range = calendar.SelectionRange;
258
			SelectionRange range 
259
				= calendar.InvokeSync (c => c.SelectionRange);
250
			return (range.Start <= itemProvider.Date
260
			return (range.Start <= itemProvider.Date
251
			        && range.End >= itemProvider.Date);
261
			        && range.End >= itemProvider.Date);
252
		}
262
		}
Lines 256-263 namespace Mono.UIAutomation.Winforms Link Here
256
		private void AddChildren ()
266
		private void AddChildren ()
257
		{
267
		{
258
			MonthCalendarListItemProvider item;
268
			MonthCalendarListItemProvider item;
259
			SelectionRange range = calendar.GetDisplayRange (false);
269
			SelectionRange range
260
270
				= calendar.InvokeSync (c => c.GetDisplayRange (false));
261
			for (DateTime d = range.Start;
271
			for (DateTime d = range.Start;
262
			     d <= range.End; d = d.AddDays (1)) {
272
			     d <= range.End; d = d.AddDays (1)) {
263
				int days = (d - range.Start).Days;
273
				int days = (d - range.Start).Days;
Lines 303-309 namespace Mono.UIAutomation.Winforms Link Here
303
313
304
		private void OnDateChanged (object o, DateRangeEventArgs args)
314
		private void OnDateChanged (object o, DateRangeEventArgs args)
305
		{
315
		{
306
			SelectionRange range = calendar.GetDisplayRange (false);
316
			SelectionRange range
317
				= calendar.InvokeSync (c => c.GetDisplayRange (false));
307
			if (displayRange != null
318
			if (displayRange != null
308
			    && range.Start == displayRange.Start
319
			    && range.Start == displayRange.Start
309
			    && range.End == displayRange.End)
320
			    && range.End == displayRange.End)
Lines 405-411 namespace Mono.UIAutomation.Winforms Link Here
405
			DateTime[] days = new DateTime[days_in_week];
416
			DateTime[] days = new DateTime[days_in_week];
406
417
407
			DateTime sunday = new DateTime (2006, 10, 1);
418
			DateTime sunday = new DateTime (2006, 10, 1);
408
			DayOfWeek first_day_of_week = calendar.GetDayOfWeek (calendar.FirstDayOfWeek);
419
			DayOfWeek first_day_of_week 
420
				= calendar.InvokeSync (c => c.GetDayOfWeek (c.FirstDayOfWeek));
409
421
410
			for (int i = 0; i < days.Length; i++) {
422
			for (int i = 0; i < days.Length; i++) {
411
				int position = i - (int) first_day_of_week;
423
				int position = i - (int) first_day_of_week;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/MonthCalendarListItemProvider.cs (-1 / +1 lines)
Lines 56-62 namespace Mono.UIAutomation.Winforms Link Here
56
			get { return dataGridProvider; }
56
			get { return dataGridProvider; }
57
		}
57
		}
58
58
59
		public MonthCalendarProvider MonthCalendarProvider {
59
		public MonthCalendarProvider MonthCalendarProvider1 {
60
			get { return calendarProvider; }
60
			get { return calendarProvider; }
61
		}
61
		}
62
62
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/MonthCalendarProvider.cs (-1 / +1 lines)
Lines 95-101 namespace Mono.UIAutomation.Winforms Link Here
95
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
95
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
96
				return Catalog.GetString ("calendar");
96
				return Catalog.GetString ("calendar");
97
			else if (propertyId == AEIds.NameProperty.Id)
97
			else if (propertyId == AEIds.NameProperty.Id)
98
				return monthCalendar.SelectionStart.ToShortDateString ();
98
				return monthCalendar.InvokeSync (m => m.SelectionStart.ToShortDateString ());
99
			return base.GetProviderPropertyValue (propertyId);
99
			return base.GetProviderPropertyValue (propertyId);
100
		}
100
		}
101
101
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/PanelProvider.cs (-1 / +1 lines)
Lines 38-44 namespace Mono.UIAutomation.Winforms Link Here
38
		}
38
		}
39
39
40
		public override Component Container  {
40
		public override Component Container  {
41
			get { return Control.Parent; }
41
			get { return Control.InvokeSync (c => c.Parent); }
42
		}
42
		}
43
43
44
	}
44
	}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/PropertyGridProvider.cs (-2 / +2 lines)
Lines 47-53 namespace Mono.UIAutomation.Winforms Link Here
47
		#region SimpleControlProvider: Specializations
47
		#region SimpleControlProvider: Specializations
48
48
49
		public override Component Container {
49
		public override Component Container {
50
			get { return Control.Parent; }
50
			get { return Control.InvokeSync (c => c.Parent); }
51
		}
51
		}
52
		
52
		
53
		#endregion
53
		#endregion
Lines 68-74 namespace Mono.UIAutomation.Winforms Link Here
68
		#region SimpleControlProvider: Specializations
68
		#region SimpleControlProvider: Specializations
69
			 
69
			 
70
		public override Component Container {
70
		public override Component Container {
71
			get { return Control.Parent; }
71
			get { return Control.InvokeSync (c => c.Parent); }
72
		}
72
		}
73
		
73
		
74
		#endregion
74
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/PropertyGridTextBoxProvider.cs (-3 / +3 lines)
Lines 50-58 namespace Mono.UIAutomation.Winforms Link Here
50
		private static TextBoxBase GetPrivateTextBox (PGTextBox pgTextBox)
50
		private static TextBoxBase GetPrivateTextBox (PGTextBox pgTextBox)
51
		{
51
		{
52
			// TODO: Replace this with an internal property in SWF
52
			// TODO: Replace this with an internal property in SWF
53
			return Helper.GetPrivateField<TextBox> (
53
			return pgTextBox.InvokeSync (t => Helper.GetPrivateField<TextBox> (typeof (PGTextBox), 
54
				typeof (PGTextBox), pgTextBox, "textbox"
54
			                                                                   pgTextBox, 
55
			);
55
			                                                                   "textbox"));
56
		}
56
		}
57
57
58
		#endregion
58
		#endregion
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/PropertyGridViewProvider.cs (-25 / +30 lines)
Lines 47-53 namespace Mono.UIAutomation.Winforms Link Here
47
	{
47
	{
48
#region Public Properties
48
#region Public Properties
49
		public override int SelectedItemsCount {
49
		public override int SelectedItemsCount {
50
			get { return propertyGrid.SelectedGridItem == null ? 0 : 1; }
50
			get {
51
				return propertyGrid.InvokeSync (p => p.SelectedGridItem == null ? 0 : 1);
52
			}
51
		}
53
		}
52
54
53
		public override int ItemsCount {
55
		public override int ItemsCount {
Lines 64-72 namespace Mono.UIAutomation.Winforms Link Here
64
			: base (propertyGridView)
66
			: base (propertyGridView)
65
		{
67
		{
66
			view = propertyGridView;
68
			view = propertyGridView;
67
			propertyGrid = Helper.GetPrivateField<PropertyGrid> (
69
68
				typeof (PropertyGridView), view,
70
			propertyGrid = propertyGridView.InvokeSync (c=> Helper.GetPrivateField<PropertyGrid> (
69
				"property_grid");
71
						typeof (PropertyGridView),
72
						view, "property_grid")
73
			);
70
		}
74
		}
71
75
72
		public override void UnselectItem (ListItemProvider item)
76
		public override void UnselectItem (ListItemProvider item)
Lines 80-86 namespace Mono.UIAutomation.Winforms Link Here
80
			if (gridItem == null)
84
			if (gridItem == null)
81
				return;
85
				return;
82
			
86
			
83
			propertyGrid.SelectedGridItem = gridItem;
87
			propertyGrid.InvokeSync (delegate {
88
				propertyGrid.SelectedGridItem = gridItem;
89
			});
84
		}
90
		}
85
91
86
		public override void ScrollItemIntoView (ListItemProvider item)
92
		public override void ScrollItemIntoView (ListItemProvider item)
Lines 99-105 namespace Mono.UIAutomation.Winforms Link Here
99
105
100
		public override bool IsItemSelected (ListItemProvider item)
106
		public override bool IsItemSelected (ListItemProvider item)
101
		{
107
		{
102
			return (item.ObjectItem == propertyGrid.SelectedGridItem);
108
			return propertyGrid.InvokeSync (p => p.SelectedGridItem == item.ObjectItem);
103
		}
109
		}
104
110
105
		public override int IndexOfObjectItem (object objectItem)
111
		public override int IndexOfObjectItem (object objectItem)
Lines 250-258 namespace Mono.UIAutomation.Winforms Link Here
250
		private void AddChildren ()
256
		private void AddChildren ()
251
		{
257
		{
252
			GridItem root = propertyGrid.RootGridItem;
258
			GridItem root = propertyGrid.RootGridItem;
253
			if (root == null)
254
				return;
255
			
256
			foreach (GridItem cat in root.GridItems) {
259
			foreach (GridItem cat in root.GridItems) {
257
				foreach (GridItem item in cat.GridItems) {
260
				foreach (GridItem item in cat.GridItems) {
258
					PropertyGridListItemProvider itemProvider
261
					PropertyGridListItemProvider itemProvider
Lines 296-317 namespace Mono.UIAutomation.Winforms Link Here
296
	{
299
	{
297
#region Public Properties
300
#region Public Properties
298
		public string Name {
301
		public string Name {
299
			get { return entry.Label; }
302
			get { return view.InvokeSync (v => entry.Label); }
300
		}
303
		}
301
304
302
		public string Value {
305
		public string Value {
303
			get { return entry.ValueText; }
306
			get {
307
				return view.InvokeSync (v => entry.ValueText );
308
			}
304
			set {
309
			set {
305
				string error;
310
				view.InvokeSync (delegate {
306
				if (!entry.SetValue (value, out error)) {
311
					string error;
307
					Log.Warn ("PropertyGridListItemProvider: Unable to set value: {0}",
312
					if (!entry.SetValue (value, out error)) {
308
					          error);
313
						Log.Warn ("PropertyGridListItemProvider: Unable to set value: {0}",
309
				}
314
							  error);
315
					}
316
				});
310
			}
317
			}
311
		}
318
		}
312
319
313
		public bool IsReadOnly {
320
		public bool IsReadOnly {
314
			get { return entry.IsReadOnly && entry.IsEditable; }
321
			get { return view.InvokeSync (v => entry.IsReadOnly && entry.IsEditable); }
315
		}
322
		}
316
323
317
		public PropertyGridView PropertyGridView {
324
		public PropertyGridView PropertyGridView {
Lines 432-449 namespace Mono.UIAutomation.Winforms Link Here
432
		// TODO: Replace this with an internal property
439
		// TODO: Replace this with an internal property
433
		private int RowHeight {
440
		private int RowHeight {
434
			get {
441
			get {
435
				return Helper.GetPrivateField<int> (
442
				return view.InvokeSync (
436
					typeof (PropertyGridView), view,
443
				        v => Helper.GetPrivateField<int> (typeof (PropertyGridView), v, "row_height"));
437
					"row_height"
438
				);
439
			}
444
			}
440
		}
445
		}
441
446
442
		// TODO: Replace this with an internal property
447
		// TODO: Replace this with an internal property
443
		private ScrollBar VerticalScrollBar {
448
		private ScrollBar VerticalScrollBar {
444
			get {
449
			get {
445
				return Helper.GetPrivateField<ScrollBar> (
450
				return view.InvokeSync (
446
					typeof (PropertyGridView), view, "vbar"
451
					v => Helper.GetPrivateField<ScrollBar> (typeof (PropertyGridView), v, "vbar")
447
				);
452
				);
448
			}
453
			}
449
		}
454
		}
Lines 451-458 namespace Mono.UIAutomation.Winforms Link Here
451
		// TODO: Replace this with an internal property
456
		// TODO: Replace this with an internal property
452
		private int SplitterLocation {
457
		private int SplitterLocation {
453
			get {
458
			get {
454
				return Helper.GetPrivateProperty<PropertyGridView, int> (
459
				return view.InvokeSync (
455
					view, "SplitterLocation"
460
					v => Helper.GetPrivateProperty<PropertyGridView, int> (v, "SplitterLocation")
456
				);
461
				);
457
			}
462
			}
458
		}
463
		}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ScrollBehaviorObserver.cs (-2 / +2 lines)
Lines 58-71 namespace Mono.UIAutomation.Winforms Link Here
58
		public bool HasHorizontalScrollbar {
58
		public bool HasHorizontalScrollbar {
59
			get {
59
			get {
60
				return HorizontalScrollBar != null 
60
				return HorizontalScrollBar != null 
61
					&& HorizontalScrollBar.Visible && HorizontalScrollBar.Enabled; 
61
					&& HorizontalScrollBar.InvokeSync (c => c.Visible && c.Enabled); 
62
			}
62
			}
63
		}
63
		}
64
		
64
		
65
		public bool HasVerticalScrollbar {
65
		public bool HasVerticalScrollbar {
66
			get { 
66
			get { 
67
				return VerticalScrollBar != null 
67
				return VerticalScrollBar != null 
68
					&& VerticalScrollBar.Visible && VerticalScrollBar.Enabled; 
68
					&& VerticalScrollBar.InvokeSync (c => c.Visible && c.Enabled); 
69
			}
69
			}
70
		}
70
		}
71
	
71
	
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ScrollableControlProvider.cs (-7 / +9 lines)
Lines 59-76 namespace Mono.UIAutomation.Winforms Link Here
59
59
60
#region FragmentRootControlProvider Implementation
60
#region FragmentRootControlProvider Implementation
61
		public override Component Container {
61
		public override Component Container {
62
			get { return Control.Parent; }
62
			get { return Control.InvokeSync (c => c.Parent); }
63
		}
63
		}
64
64
65
		public override void InitializeChildControlStructure ()
65
		public override void InitializeChildControlStructure ()
66
		{
66
		{
67
			base.InitializeChildControlStructure ();
67
			base.InitializeChildControlStructure ();
68
68
69
			observer = new ScrollBehaviorObserver (
69
			scrollableControl.InvokeSync (delegate {
70
				this, scrollableControl.hscrollbar,
70
				observer = new ScrollBehaviorObserver (
71
				scrollableControl.vscrollbar);
71
					this, scrollableControl.hscrollbar,
72
			observer.ScrollPatternSupportChanged += OnScrollPatternSupportChanged;
72
					scrollableControl.vscrollbar);
73
			observer.Initialize ();
73
				observer.ScrollPatternSupportChanged += OnScrollPatternSupportChanged;
74
				observer.Initialize ();
75
			});
74
			UpdateScrollBehavior ();
76
			UpdateScrollBehavior ();
75
		}
77
		}
76
78
Lines 78-84 namespace Mono.UIAutomation.Winforms Link Here
78
		{
80
		{
79
			// Override Pane's IsKeyboardFocusableProperty
81
			// Override Pane's IsKeyboardFocusableProperty
80
			if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
82
			if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
81
				return Control.CanFocus && Control.CanSelect;
83
				return Control.InvokeSync (c => c.CanFocus && c.CanSelect);
82
84
83
			return base.GetProviderPropertyValue (propertyId);
85
			return base.GetProviderPropertyValue (propertyId);
84
		}
86
		}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/SimpleControlProvider.cs (-14 / +18 lines)
Lines 76-82 namespace Mono.UIAutomation.Winforms Link Here
76
		#region Public Properties
76
		#region Public Properties
77
		
77
		
78
		public virtual Component Container {
78
		public virtual Component Container {
79
			get { return control != null ? control.Parent : null; }
79
			get { return control != null ? control.InvokeSync (c => c.Parent) : null; }
80
		}
80
		}
81
81
82
		public Component Component {
82
		public Component Component {
Lines 209-220 namespace Mono.UIAutomation.Winforms Link Here
209
		protected virtual System.Drawing.Rectangle ScreenBounds
209
		protected virtual System.Drawing.Rectangle ScreenBounds
210
		{
210
		{
211
			get {
211
			get {
212
				if (Control == null || !Control.Visible)
212
				if (Control == null)
213
					return System.Drawing.Rectangle.Empty;
213
					return System.Drawing.Rectangle.Empty;
214
				
215
				return Control.InvokeSync (c => {
216
					if (!c.Visible)
217
						return System.Drawing.Rectangle.Empty;
214
218
215
				return Helper.RectToRectangle (
219
					return Helper.RectToRectangle (Helper.GetControlScreenBounds (c.Bounds, c));
216
					Helper.GetControlScreenBounds (Control.Bounds, Control)
220
				});
217
				);
218
			}
221
			}
219
		}
222
		}
220
223
Lines 281-287 namespace Mono.UIAutomation.Winforms Link Here
281
			if (Control == null)
284
			if (Control == null)
282
				return null;
285
				return null;
283
			else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
286
			else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
284
				return Control.Enabled;
287
				return Control.InvokeSync (c => c.Enabled);
285
			else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) {
288
			else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) {
286
				if (!string.IsNullOrEmpty (Control.AccessibleName)) 
289
				if (!string.IsNullOrEmpty (Control.AccessibleName)) 
287
					return Control.AccessibleName;
290
					return Control.AccessibleName;
Lines 296-302 namespace Mono.UIAutomation.Winforms Link Here
296
					if (controlType == ControlType.Edit.Id || controlType == ControlType.Document.Id)
299
					if (controlType == ControlType.Edit.Id || controlType == ControlType.Document.Id)
297
						return string.Empty;
300
						return string.Empty;
298
					else
301
					else
299
						return Helper.StripAmpersands (Control.Text);
302
						return Helper.StripAmpersands (Control.InvokeSync (c => c.Text));
300
				} else
303
				} else
301
					return label.GetPropertyValue (AutomationElementIdentifiers.NameProperty.Id);
304
					return label.GetPropertyValue (AutomationElementIdentifiers.NameProperty.Id);
302
			} else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id) {
305
			} else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id) {
Lines 326-334 namespace Mono.UIAutomation.Winforms Link Here
326
				return closestLabel;
329
				return closestLabel;
327
				
330
				
328
			} else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
331
			} else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
329
				return Control.CanFocus && Control.CanSelect;
332
				return Control.InvokeSync (c => c.CanFocus && c.CanSelect);
330
			else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
333
			else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
331
				return Control.Focused;
334
				return Control.InvokeSync (c => c.Focused);
332
			else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
335
			else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
333
				return Helper.GetClickablePoint (this);
336
				return Helper.GetClickablePoint (this);
334
			else if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id) {
337
			else if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id) {
Lines 337-347 namespace Mono.UIAutomation.Winforms Link Here
337
				else
340
				else
338
					return ToolTip.GetToolTip (Control);
341
					return ToolTip.GetToolTip (Control);
339
			} else if (propertyId == AutomationElementIdentifiers.AccessKeyProperty.Id) {
342
			} else if (propertyId == AutomationElementIdentifiers.AccessKeyProperty.Id) {
340
				if (!Control.Text.Contains ("&"))
343
				string text = Control.InvokeSync (c => c.Text);
344
				if (!text.Contains ("&"))
341
					return null;
345
					return null;
342
				else {
346
				else {
343
					int index = Control.Text.LastIndexOf ('&') + 1;
347
					int index = text.LastIndexOf ('&') + 1;
344
					return "Alt+" + Control.Text.Substring (index, 1);
348
					return "Alt+" + text.Substring (index, 1);
345
				}
349
				}
346
			} else
350
			} else
347
				return null;
351
				return null;
Lines 390-399 namespace Mono.UIAutomation.Winforms Link Here
390
		public virtual IRawElementProviderSimple HostRawElementProvider {
394
		public virtual IRawElementProviderSimple HostRawElementProvider {
391
			get {
395
			get {
392
				// TODO: Address for Components (*Strip*)
396
				// TODO: Address for Components (*Strip*)
393
				if (Control == null || Control.TopLevelControl == null)
397
				if (Control == null || Control.InvokeSync (c => c.TopLevelControl == null))
394
					return null;
398
					return null;
395
				else
399
				else
396
					return AutomationInteropProvider.HostProviderFromHandle (Control.TopLevelControl.Handle);
400
					return AutomationInteropProvider.HostProviderFromHandle (Control.InvokeSync (c => c.TopLevelControl.Handle));
397
			}
401
			}
398
		}
402
		}
399
		
403
		
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/SplitContainerProvider.cs (-4 / +7 lines)
Lines 95-103 namespace Mono.UIAutomation.Winforms Link Here
95
				return ControlType.Pane.Id;
95
				return ControlType.Pane.Id;
96
			else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
96
			else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
97
				return Catalog.GetString ("pane");
97
				return Catalog.GetString ("pane");
98
				else if (propertyId == AutomationElementIdentifiers.OrientationProperty.Id)
98
			else if (propertyId == AutomationElementIdentifiers.OrientationProperty.Id) {
99
					return ((SplitContainer)Control).Orientation == Orientation.Vertical? OrientationType.Vertical: OrientationType.Horizontal;
99
				if (((SplitContainer)Control).InvokeSync (c => c.Orientation) == Orientation.Vertical)
100
			else
100
					return OrientationType.Vertical;
101
				else
102
					return OrientationType.Horizontal;
103
			} else
101
				return base.GetProviderPropertyValue (propertyId);
104
				return base.GetProviderPropertyValue (propertyId);
102
		}
105
		}
103
		
106
		
Lines 148-154 namespace Mono.UIAutomation.Winforms Link Here
148
				if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
151
				if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
149
					return ControlType.Pane.Id;
152
					return ControlType.Pane.Id;
150
				else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
153
				else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
151
					return "pane";
154
					return Catalog.GetString ("pane");
152
				else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
155
				else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
153
					return false;
156
					return false;
154
				else
157
				else
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/StatusBarProvider.cs (-11 / +13 lines)
Lines 112-130 namespace Mono.UIAutomation.Winforms Link Here
112
		
112
		
113
		public StatusBarPanelProvider GetPanelProvider (int index)
113
		public StatusBarPanelProvider GetPanelProvider (int index)
114
		{
114
		{
115
			StatusBarPanelProvider panel = null;
115
			return statusBar.InvokeSync (p => {
116
			
116
				StatusBarPanelProvider panel = null;
117
			if (index < 0 || index >= statusBar.Panels.Count)
117
				
118
				return null;
118
				if (index < 0 || index >= p.Panels.Count)
119
			else if (index >= panels.Count) {
119
					return null;
120
				for (int loop = panels.Count - 1; loop < index; ++loop) {
120
				else if (index >= panels.Count) {
121
					panel = new StatusBarPanelProvider (statusBar.Panels [index]);
121
					for (int loop = panels.Count - 1; loop < index; ++loop) {
122
					panels.Add (panel);
122
						panel = new StatusBarPanelProvider (p.Panels [index]);
123
					panel.Initialize ();
123
						panels.Add (panel);
124
						panel.Initialize ();
125
					}
124
				}
126
				}
125
			}
127
				return panels [index];
128
			});
126
			
129
			
127
			return panels [index];
128
		}
130
		}
129
		
131
		
130
		public StatusBarPanelProvider RemovePanelAt (int index)
132
		public StatusBarPanelProvider RemovePanelAt (int index)
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/TabControlProvider.cs (-10 / +14 lines)
Lines 17-23 Link Here
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
19
// 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
20
// Copyright (c) 2008,2009 Novell, Inc. (http://www.novell.com) 
21
// 
21
// 
22
// Authors: 
22
// Authors: 
23
//	Brad Taylor <brad@getcoded.net>
23
//	Brad Taylor <brad@getcoded.net>
Lines 65-73 namespace Mono.UIAutomation.Winforms Link Here
65
				return ControlType.Tab.Id;
65
				return ControlType.Tab.Id;
66
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
66
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
67
				return Catalog.GetString ("tab");
67
				return Catalog.GetString ("tab");
68
			else if (propertyId == AEIds.OrientationProperty.Id)
68
			else if (propertyId == AEIds.OrientationProperty.Id) {
69
				return (control.Alignment == TabAlignment.Top || control.Alignment == TabAlignment.Bottom)
69
				TabAlignment align = control.InvokeSync (c => c.Alignment);
70
				return (align == TabAlignment.Top || align == TabAlignment.Bottom)
70
				       ? Orientation.Horizontal : Orientation.Vertical;
71
				       ? Orientation.Horizontal : Orientation.Vertical;
72
			}
71
73
72
			return base.GetProviderPropertyValue (propertyId);
74
			return base.GetProviderPropertyValue (propertyId);
73
		}
75
		}
Lines 83-109 namespace Mono.UIAutomation.Winforms Link Here
83
#endregion
85
#endregion
84
86
85
		internal bool HasSelection {
87
		internal bool HasSelection {
86
			get { return (control.SelectedIndex > -1); }
88
			get { return control.InvokeSync (c => c.SelectedIndex > -1); }
87
		}
89
		}
88
90
89
		internal TabPageProvider GetSelectedTab ()
91
		internal TabPageProvider GetSelectedTab ()
90
		{
92
		{
91
			if (control.SelectedTab == null) {
93
			TabPage page = control.InvokeSync (c => c.SelectedTab);
94
95
			if (page == null)
92
				return null;
96
				return null;
93
			}
94
97
95
			return (TabPageProvider) ProviderFactory.GetProvider (
98
			return (TabPageProvider) ProviderFactory.GetProvider (page);
96
				control.SelectedTab);
97
		}
99
		}
98
100
99
		internal void SelectItem (TabPageProvider tabPage)
101
		internal void SelectItem (TabPageProvider tabPage)
100
		{
102
		{
101
			control.SelectedTab = (TabPage) tabPage.Control;
103
			control.InvokeSync (delegate {
104
				control.SelectedTab = (TabPage) tabPage.Control;
105
			});
102
		}
106
		}
103
107
104
		internal bool IsItemSelected (TabPageProvider tabPage)
108
		internal bool IsItemSelected (TabPageProvider tabPage)
105
		{
109
		{
106
			return (control.SelectedTab == (TabPage) tabPage.Control);
110
			return control.InvokeSync (c => c.SelectedTab == (TabPage) tabPage.Control);
107
		}
111
		}
108
		
112
		
109
#region Private Fields
113
#region Private Fields
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/TabPageProvider.cs (-14 / +5 lines)
Lines 17-23 Link Here
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
19
// 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
20
// Copyright (c) 2008,2009 Novell, Inc. (http://www.novell.com) 
21
// 
21
// 
22
// Authors: 
22
// Authors: 
23
//	Brad Taylor <brad@getcoded.net>
23
//	Brad Taylor <brad@getcoded.net>
Lines 41-49 namespace Mono.UIAutomation.Winforms Link Here
41
		{
41
		{
42
			this.tabPage = control;
42
			this.tabPage = control;
43
43
44
			selectionBehavior = new SelectionItemProviderBehavior (this);
45
			SetBehavior (SelectionItemPatternIdentifiers.Pattern,
44
			SetBehavior (SelectionItemPatternIdentifiers.Pattern,
46
			             selectionBehavior);
45
				     new SelectionItemProviderBehavior (this));
47
		}
46
		}
48
		
47
		
49
		protected override object GetProviderPropertyValue (int propertyId)
48
		protected override object GetProviderPropertyValue (int propertyId)
Lines 57-64 namespace Mono.UIAutomation.Winforms Link Here
57
				// want this control's visiblity managed by the
56
				// want this control's visiblity managed by the
58
				// TabControl, as tab pages are on-screen even
57
				// TabControl, as tab pages are on-screen even
59
				// if they report Visible = false.
58
				// if they report Visible = false.
60
				return Helper.RectangleToRect (
59
				return Control.InvokeSync (v => Helper.RectangleToRect (
61
					Control.Parent.RectangleToScreen (tabPage.TabBounds));
60
						v.Parent.RectangleToScreen (tabPage.TabBounds)));
62
			}
61
			}
63
62
64
			return base.GetProviderPropertyValue (propertyId);
63
			return base.GetProviderPropertyValue (propertyId);
Lines 71-77 namespace Mono.UIAutomation.Winforms Link Here
71
			// seems to keep a TabPages' children visible even if
70
			// seems to keep a TabPages' children visible even if
72
			// the TabPage isn't.  This is to model Vista's
71
			// the TabPage isn't.  This is to model Vista's
73
			// behavior.
72
			// behavior.
74
			return Control.Visible;
73
			return Control.InvokeSync (c => c.Visible);
75
		}
74
		}
76
75
77
		internal TabControlProvider TabControlProvider {
76
		internal TabControlProvider TabControlProvider {
Lines 86-100 namespace Mono.UIAutomation.Winforms Link Here
86
				return TabControlProvider.IsItemSelected (this);
85
				return TabControlProvider.IsItemSelected (this);
87
			}
86
			}
88
		}
87
		}
89
90
		public override void SetFocus ()
91
		{
92
			//because we want to cause a HasKeyboardFocus property changed event on
93
			//the tab control, not on the tabpage (as this is how this works on UIA+Vista)
94
			selectionBehavior.Select ();
95
		}
96
		
88
		
97
		private TabPage tabPage;
89
		private TabPage tabPage;
98
		private SelectionItemProviderBehavior selectionBehavior;
99
	}
90
	}
100
}
91
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/TextBoxProvider.cs (-15 / +17 lines)
Lines 85-93 namespace Mono.UIAutomation.Winforms Link Here
85
		protected override object GetProviderPropertyValue (int propertyId)
85
		protected override object GetProviderPropertyValue (int propertyId)
86
		{
86
		{
87
			if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
87
			if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
88
				return textboxbase.Multiline == true ? ControlType.Document.Id : ControlType.Edit.Id;
88
				return textboxbase.InvokeSync (c => c.Multiline) ? ControlType.Document.Id : ControlType.Edit.Id;
89
			else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
89
			else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
90
				return textboxbase.Multiline == true ? Catalog.GetString ("document")
90
				return textboxbase.InvokeSync (c => c.Multiline) ? Catalog.GetString ("document")
91
				                                     : Catalog.GetString ("edit");
91
				                                     : Catalog.GetString ("edit");
92
			else 
92
			else 
93
				return base.GetProviderPropertyValue (propertyId);
93
				return base.GetProviderPropertyValue (propertyId);
Lines 159-177 namespace Mono.UIAutomation.Winforms Link Here
159
		
159
		
160
		internal int MaxLength {
160
		internal int MaxLength {
161
			get {
161
			get {
162
				if (textboxbase is TextBox) {
162
				return textboxbase.InvokeSync (c => {
163
					return ((TextBox) textboxbase).MaxLength;
163
					if (textboxbase is TextBox) {
164
				} else if (textboxbase is RichTextBox) {
164
						return ((TextBox) c).MaxLength;
165
					return ((RichTextBox) textboxbase).MaxLength;
165
					} else if (textboxbase is RichTextBox) {
166
				} else if (textboxbase is MaskedTextBox) {
166
						return ((RichTextBox) c).MaxLength;
167
					// Length of the mask, removing mask modifiers
167
					} else if (textboxbase is MaskedTextBox) {
168
					MaskedTextBox mtb = (MaskedTextBox) textboxbase;
168
						// Length of the mask, removing mask modifiers
169
					if (mtb.MaskedTextProvider != null)
169
						MaskedTextBox mtb = (MaskedTextBox) c;
170
						return mtb.MaskedTextProvider.Length;
170
						if (mtb.MaskedTextProvider != null)
171
					else
171
							return mtb.MaskedTextProvider.Length;
172
						return mtb.Mask.Length;
172
						else
173
				}
173
							return mtb.Mask.Length;
174
				return 0;
174
					}
175
					return 0;
176
				});
175
			}
177
			}
176
		}
178
		}
177
179
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/TextNormalizer.cs (-3 / +3 lines)
Lines 75-83 namespace Mono.UIAutomation.Winforms Link Here
75
				// TODO: Refactor this so it isn't so hacky
75
				// TODO: Refactor this so it isn't so hacky
76
				MaskedTextBox mtb = textboxbase as MaskedTextBox;
76
				MaskedTextBox mtb = textboxbase as MaskedTextBox;
77
				if (mtb != null && mtb.MaskedTextProvider != null)
77
				if (mtb != null && mtb.MaskedTextProvider != null)
78
					return mtb.MaskedTextProvider.ToDisplayString ();
78
					return mtb.InvokeSync (t => t.MaskedTextProvider.ToDisplayString ());
79
				else
79
				else
80
					return textboxbase.Text;
80
					return textboxbase.InvokeSync (t => textboxbase.Text);
81
			}
81
			}
82
		}
82
		}
83
#endregion
83
#endregion
Lines 153-159 namespace Mono.UIAutomation.Winforms Link Here
153
		
153
		
154
		private void LineParagraphNormalize (bool is_line)
154
		private void LineParagraphNormalize (bool is_line)
155
		{
155
		{
156
			if (textboxbase.Multiline == false) {
156
			if (textboxbase.InvokeSync (t => t.Multiline) == false) {
157
				start_point = 0;
157
				start_point = 0;
158
				end_point = Text.Length;
158
				end_point = Text.Length;
159
				return;
159
				return;
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/TextRangeProvider.cs (+3 lines)
Lines 323-328 namespace Mono.UIAutomation.Winforms Link Here
323
			if (length > maxLength && maxLength != -1)
323
			if (length > maxLength && maxLength != -1)
324
				length = maxLength;
324
				length = maxLength;
325
325
326
			if (startPoint + length >= normalizer.Text.Length)
327
				length = normalizer.Text.Length - startPoint;
328
326
			return normalizer.Text.Substring (startPoint, length);
329
			return normalizer.Text.Substring (startPoint, length);
327
		}
330
		}
328
331
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolBarProvider.cs (-12 / +16 lines)
Lines 107-127 namespace Mono.UIAutomation.Winforms Link Here
107
		public ToolBarButtonProvider RemoveButtonAt (int index)
107
		public ToolBarButtonProvider RemoveButtonAt (int index)
108
		{
108
		{
109
			ToolBarButtonProvider button = null;
109
			ToolBarButtonProvider button = null;
110
			
110
111
			if (index < toolBar.Buttons.Count) {
111
			return toolBar.InvokeSync (t => {
112
				button = (ToolBarButtonProvider)
112
				if (index < t.Buttons.Count) {
113
					ProviderFactory.GetProvider (toolBar.Buttons [index]);
113
					button = (ToolBarButtonProvider)
114
				ProviderFactory.ReleaseProvider (toolBar.Buttons [index]);
114
						ProviderFactory.GetProvider (t.Buttons [index]);
115
			}
115
					ProviderFactory.ReleaseProvider (t.Buttons [index]);
116
			
116
				}
117
			return button;
117
				
118
				return button;
119
			});
118
		}
120
		}
119
		
121
		
120
		public void ClearButtonsCollection ()
122
		public void ClearButtonsCollection ()
121
		{
123
		{
122
			while (toolBar.Buttons.Count > 0) {
124
			toolBar.InvokeSync (delegate {
123
				RemoveButtonAt (toolBar.Buttons.Count - 1);
125
				while (toolBar.Buttons.Count > 0) {
124
			}
126
					RemoveButtonAt (toolBar.Buttons.Count - 1);
127
				}
128
			});
125
		}
129
		}
126
		
130
		
127
		#endregion
131
		#endregion
Lines 134-140 namespace Mono.UIAutomation.Winforms Link Here
134
		{
138
		{
135
			if (e.Action == CollectionChangeAction.Add) {
139
			if (e.Action == CollectionChangeAction.Add) {
136
				ToolBarButtonProvider button = (ToolBarButtonProvider)
140
				ToolBarButtonProvider button = (ToolBarButtonProvider)
137
					ProviderFactory.GetProvider (toolBar.Buttons [(int) e.Element]);
141
					ProviderFactory.GetProvider (toolBar.InvokeSync (c => c.Buttons [(int) e.Element]));
138
				AddChildProvider (button);
142
				AddChildProvider (button);
139
			} else if (e.Action == CollectionChangeAction.Remove) {
143
			} else if (e.Action == CollectionChangeAction.Remove) {
140
				ToolBarButtonProvider button = RemoveButtonAt ((int) e.Element);
144
				ToolBarButtonProvider button = RemoveButtonAt ((int) e.Element);
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolStripButtonProvider.cs (-3 / +11 lines)
Lines 55-65 namespace Mono.UIAutomation.Winforms Link Here
55
55
56
		protected override object GetProviderPropertyValue (int propertyId)
56
		protected override object GetProviderPropertyValue (int propertyId)
57
		{
57
		{
58
			bool checkOnClick = Owner.InvokeSync (t => button.CheckOnClick);
59
58
			if (propertyId == AEIds.ControlTypeProperty.Id)
60
			if (propertyId == AEIds.ControlTypeProperty.Id)
59
				return button.CheckOnClick ? ControlType.CheckBox.Id : ControlType.Button.Id;
61
				return checkOnClick ? ControlType.CheckBox.Id : ControlType.Button.Id;
60
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
62
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
61
				return button.CheckOnClick ? Catalog.GetString ("checkbox")
63
				return checkOnClick ? Catalog.GetString ("checkbox")
62
				                           : Catalog.GetString ("button");
64
				                    : Catalog.GetString ("button");
63
			else if (propertyId == AEIds.LabeledByProperty.Id)
65
			else if (propertyId == AEIds.LabeledByProperty.Id)
64
				return null;
66
				return null;
65
			else
67
			else
Lines 90-95 namespace Mono.UIAutomation.Winforms Link Here
90
#region Private Fields
92
#region Private Fields
91
		private ToolStripButton button;
93
		private ToolStripButton button;
92
#endregion
94
#endregion
95
96
#region Private Properties
97
		private ToolStrip Owner {
98
			get { return ((ToolStripItem) Component).Owner; }
99
		}
100
#endregion
93
	}
101
	}
94
102
95
}
103
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolStripItemProvider.cs (-1 / +4 lines)
Lines 107-113 namespace Mono.UIAutomation.Winforms Link Here
107
107
108
		public override void SetFocus ()
108
		public override void SetFocus ()
109
		{
109
		{
110
			item.Select ();
110
			if (item.Owner != null)
111
				item.Owner.InvokeSync (delegate { item.Select (); });
112
			else
113
				item.Select ();
111
		}
114
		}
112
115
113
	}
116
	}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolStripLabelProvider.cs (-4 / +9 lines)
Lines 84-94 namespace Mono.UIAutomation.Winforms Link Here
84
84
85
		protected override object GetProviderPropertyValue (int propertyId)
85
		protected override object GetProviderPropertyValue (int propertyId)
86
		{
86
		{
87
			bool isLink = label.IsLink;
88
87
			if (propertyId == AEIds.ControlTypeProperty.Id)
89
			if (propertyId == AEIds.ControlTypeProperty.Id)
88
				return label.IsLink ? ControlType.Hyperlink.Id : ControlType.Text.Id;
90
				return isLink ? ControlType.Hyperlink.Id : ControlType.Text.Id;
89
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
91
			else if (propertyId == AEIds.LocalizedControlTypeProperty.Id)
90
				return label.IsLink ? Catalog.GetString ("hyperlink")
92
				return isLink ? Catalog.GetString ("hyperlink")
91
				                    : Catalog.GetString ("text");
93
				              : Catalog.GetString ("text");
92
			else
94
			else
93
				return base.GetProviderPropertyValue (propertyId);
95
				return base.GetProviderPropertyValue (propertyId);
94
		}
96
		}
Lines 97-103 namespace Mono.UIAutomation.Winforms Link Here
97
		
99
		
98
		private void OnIsLinkChanged (object sender, EventArgs args)
100
		private void OnIsLinkChanged (object sender, EventArgs args)
99
		{
101
		{
100
			if (label.IsLink) {
102
			bool isLink = label.IsLink;
103
104
			if (isLink) {
101
				SetBehavior (InvokePatternIdentifiers.Pattern,
105
				SetBehavior (InvokePatternIdentifiers.Pattern,
102
				             new InvokeProviderBehavior (this));
106
				             new InvokeProviderBehavior (this));
103
				SetEvent (ProviderEventType.TextPatternTextChangedEvent,
107
				SetEvent (ProviderEventType.TextPatternTextChangedEvent,
Lines 111-115 namespace Mono.UIAutomation.Winforms Link Here
111
		}
115
		}
112
116
113
		#pragma warning restore 169
117
		#pragma warning restore 169
118
114
	}
119
	}
115
}
120
}
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolStripProvider.cs (-1 / +1 lines)
Lines 59-65 namespace Mono.UIAutomation.Winforms Link Here
59
			else if (propertyId == AEIds.LabeledByProperty.Id)
59
			else if (propertyId == AEIds.LabeledByProperty.Id)
60
				return null;
60
				return null;
61
			else if (propertyId == AEIds.NameProperty.Id)
61
			else if (propertyId == AEIds.NameProperty.Id)
62
				return Helper.StripAmpersands (strip.Text);
62
				return Helper.StripAmpersands (strip.InvokeSync (s => s.Text));
63
			else if (propertyId == AEIds.IsContentElementProperty.Id)
63
			else if (propertyId == AEIds.IsContentElementProperty.Id)
64
				return true;
64
				return true;
65
			else
65
			else
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolTipBaseProvider.cs (+7 lines)
Lines 103-108 namespace Mono.UIAutomation.Winforms Link Here
103
		{
103
		{
104
			if (AutomationInteropProvider.ClientsAreListening == true) {					
104
			if (AutomationInteropProvider.ClientsAreListening == true) {					
105
				message = GetTextFromControl (control);
105
				message = GetTextFromControl (control);
106
107
//				Helper.DelegateQueue.Get ().Enqueue (delegate {
106
				
108
				
107
				//TODO: We need deeper tests in Vista because MS is generating both events
109
				//TODO: We need deeper tests in Vista because MS is generating both events
108
				Helper.RaiseStructureChangedEvent (StructureChangeType.ChildAdded,
110
				Helper.RaiseStructureChangedEvent (StructureChangeType.ChildAdded,
Lines 113-118 namespace Mono.UIAutomation.Winforms Link Here
113
				AutomationInteropProvider.RaiseAutomationEvent (AutomationElementIdentifiers.ToolTipOpenedEvent,
115
				AutomationInteropProvider.RaiseAutomationEvent (AutomationElementIdentifiers.ToolTipOpenedEvent,
114
				                                                this, 
116
				                                                this, 
115
				                                                eventArgs);
117
				                                                eventArgs);
118
119
//				});
116
			}
120
			}
117
		}
121
		}
118
		
122
		
Lines 120-125 namespace Mono.UIAutomation.Winforms Link Here
120
		{
124
		{
121
			if (AutomationInteropProvider.ClientsAreListening == true) {
125
			if (AutomationInteropProvider.ClientsAreListening == true) {
122
				message = GetTextFromControl (control);
126
				message = GetTextFromControl (control);
127
128
//				Helper.DelegateQueue.Get ().Enqueue (delegate {
123
				
129
				
124
				//TODO: We need deeper tests in Vista because MS is generating both events
130
				//TODO: We need deeper tests in Vista because MS is generating both events
125
				Helper.RaiseStructureChangedEvent (StructureChangeType.ChildRemoved,
131
				Helper.RaiseStructureChangedEvent (StructureChangeType.ChildRemoved,
Lines 130-135 namespace Mono.UIAutomation.Winforms Link Here
130
				AutomationInteropProvider.RaiseAutomationEvent (AutomationElementIdentifiers.ToolTipClosedEvent,
136
				AutomationInteropProvider.RaiseAutomationEvent (AutomationElementIdentifiers.ToolTipClosedEvent,
131
				                                                this, 
137
				                                                this, 
132
				                                                eventArgs);
138
				                                                eventArgs);
139
//				});
133
			}
140
			}
134
		}
141
		}
135
142
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/TrackBarProvider.cs (-4 / +6 lines)
Lines 84-93 namespace Mono.UIAutomation.Winforms Link Here
84
				return Catalog.GetString ("slider");
84
				return Catalog.GetString ("slider");
85
			else if (propertyId == AutomationElementIdentifiers.IsContentElementProperty.Id)
85
			else if (propertyId == AutomationElementIdentifiers.IsContentElementProperty.Id)
86
				return true;
86
				return true;
87
			else if (propertyId == AutomationElementIdentifiers.OrientationProperty.Id)
87
			else if (propertyId == AutomationElementIdentifiers.OrientationProperty.Id) {
88
				return trackBar.Orientation == Orientation.Horizontal
88
				if (trackBar.InvokeSync (c => c.Orientation == Orientation.Horizontal))
89
					? OrientationType.Horizontal : OrientationType.Vertical;
89
					return OrientationType.Horizontal;
90
			else
90
				else
91
					return OrientationType.Vertical;
92
			} else
91
				return base.GetProviderPropertyValue (propertyId);
93
				return base.GetProviderPropertyValue (propertyId);
92
		}
94
		}
93
95
(-)a/UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/TreeViewProvider.cs (-1 / +1 lines)
Lines 17-23 Link Here
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
19
// 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
20
// Copyright (c) 2008,2009 Novell, Inc. (http://www.novell.com) 
21
// 
21
// 
22
// Authors: 
22
// Authors: 
23
//	Sandy Armstrong <sanfordarmstrong@gmail.com>
23
//	Sandy Armstrong <sanfordarmstrong@gmail.com>
(-)a/UIAutomationWinforms/UIAutomationWinformsTests/DataGridProviderTest.cs (-1 / +1 lines)
Lines 266-272 namespace MonoTests.Mono.UIAutomation.Winforms Link Here
266
					ValuePatternIdentifiers.Pattern.Id) as IValueProvider;
266
					ValuePatternIdentifiers.Pattern.Id) as IValueProvider;
267
267
268
				Assert.IsNotNull (valueProvider, "Child does not support ValueProvider!");
268
				Assert.IsNotNull (valueProvider, "Child does not support ValueProvider!");
269
				Assert.IsTrue (valueProvider.IsReadOnly, "Child is not read only.");
269
				Assert.IsFalse (valueProvider.IsReadOnly, "Child is read only");
270
			}
270
			}
271
		}
271
		}
272
272
(-)a/UIAutomationWinforms/UIAutomationWinformsTests/FormProviderTest.cs (+1 lines)
Lines 121-126 namespace MonoTests.Mono.UIAutomation.Winforms Link Here
121
		}
121
		}
122
		
122
		
123
		[Test]
123
		[Test]
124
		[Ignore("Locks")]
124
		// FIXME: Add event test
125
		// FIXME: Add event test
125
		public void IsModalTest ()
126
		public void IsModalTest ()
126
		{
127
		{
(-)a/UIAutomationWinforms/UIAutomationWinformsTests/ListViewProviderTest.cs (+1 lines)
Lines 2463-2468 namespace MonoTests.Mono.UIAutomation.Winforms Link Here
2463
		}
2463
		}
2464
2464
2465
		[Test]
2465
		[Test]
2466
		[Ignore("HeaderItemInvokeProvider does not click when Invoke.Invoke()")]
2466
		public void ListViewColumnInvokeTest ()
2467
		public void ListViewColumnInvokeTest ()
2467
		{
2468
		{
2468
			var listview = (ListView)GetControlInstance ();
2469
			var listview = (ListView)GetControlInstance ();

Return to bug 494034