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

(-)UIAutomationWinforms/Mono.UIAutomation.Winforms.mdp (+4 lines)
Lines 279-284 Link Here
279
    <File name="Mono.UIAutomation.Winforms.Events/TabPage/SelectionItemPatternElementRemovedEvent.cs" subtype="Code" buildaction="Compile" />
279
    <File name="Mono.UIAutomation.Winforms.Events/TabPage/SelectionItemPatternElementRemovedEvent.cs" subtype="Code" buildaction="Compile" />
280
    <File name="Mono.UIAutomation.Winforms.Events/TabPage/SelectionItemPatternElementSelectedEvent.cs" subtype="Code" buildaction="Compile" />
280
    <File name="Mono.UIAutomation.Winforms.Events/TabPage/SelectionItemPatternElementSelectedEvent.cs" subtype="Code" buildaction="Compile" />
281
    <File name="Mono.UIAutomation.Winforms/MonthCalendarProvider.cs" subtype="Code" buildaction="Compile" />
281
    <File name="Mono.UIAutomation.Winforms/MonthCalendarProvider.cs" subtype="Code" buildaction="Compile" />
282
    <File name="Mono.UIAutomation.Winforms/ToolBarProvider.cs" subtype="Code" buildaction="Compile" />
283
    <File name="Mono.UIAutomation.Winforms.Behaviors/ToolBar/ToolBarButtonInvokeProviderBehavior.cs" subtype="Code" buildaction="Compile" />
284
    <File name="Mono.UIAutomation.Winforms.Events/ToolBar" subtype="Directory" buildaction="Compile" />
285
    <File name="Mono.UIAutomation.Winforms.Events/ToolBar/ToolBarButtonInvokePatternInvokedEvent.cs" subtype="Code" buildaction="Compile" />
282
  </Contents>
286
  </Contents>
283
  <References>
287
  <References>
284
    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
288
    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
(-)UIAutomationWinforms/Makefile.am (+3 lines)
Lines 102-107 Link Here
102
	Mono.UIAutomation.Winforms.Behaviors/TextBox/ScrollProviderBehavior.cs \
102
	Mono.UIAutomation.Winforms.Behaviors/TextBox/ScrollProviderBehavior.cs \
103
	Mono.UIAutomation.Winforms.Behaviors/TextBox/TextProviderBehavior.cs \
103
	Mono.UIAutomation.Winforms.Behaviors/TextBox/TextProviderBehavior.cs \
104
	Mono.UIAutomation.Winforms.Behaviors/TextBox/ValueProviderBehavior.cs \
104
	Mono.UIAutomation.Winforms.Behaviors/TextBox/ValueProviderBehavior.cs \
105
	Mono.UIAutomation.Winforms.Behaviors/ToolBar/ToolBarButtonInvokeProviderBehavior.cs \
105
	Mono.UIAutomation.Winforms.Behaviors/ToolStripItem/InvokeProviderBehavior.cs \
106
	Mono.UIAutomation.Winforms.Behaviors/ToolStripItem/InvokeProviderBehavior.cs \
106
	Mono.UIAutomation.Winforms.Behaviors/ToolStripSplitButton/ExpandCollapseProviderBehavior.cs \
107
	Mono.UIAutomation.Winforms.Behaviors/ToolStripSplitButton/ExpandCollapseProviderBehavior.cs \
107
	Mono.UIAutomation.Winforms.Behaviors/UpDownBase/ButtonInvokeProviderBehavior.cs \
108
	Mono.UIAutomation.Winforms.Behaviors/UpDownBase/ButtonInvokeProviderBehavior.cs \
Lines 218-223 Link Here
218
	Mono.UIAutomation.Winforms.Events/TextBox/HasKeyBoardFocusPropertyEvent.cs \
219
	Mono.UIAutomation.Winforms.Events/TextBox/HasKeyBoardFocusPropertyEvent.cs \
219
	Mono.UIAutomation.Winforms.Events/TextBox/ValuePatternValueIsReadOnlyEvent.cs \
220
	Mono.UIAutomation.Winforms.Events/TextBox/ValuePatternValueIsReadOnlyEvent.cs \
220
	Mono.UIAutomation.Winforms.Events/TextBox/ValuePatternValueValueEvent.cs \
221
	Mono.UIAutomation.Winforms.Events/TextBox/ValuePatternValueValueEvent.cs \
222
	Mono.UIAutomation.Winforms.Events/ToolBar/ToolBarButtonInvokePatternInvokedEvent.cs \
221
	Mono.UIAutomation.Winforms.Events/ToolStripItem/AutomationBoundingRectanglePropertyEvent.cs \
223
	Mono.UIAutomation.Winforms.Events/ToolStripItem/AutomationBoundingRectanglePropertyEvent.cs \
222
	Mono.UIAutomation.Winforms.Events/ToolStripItem/AutomationFocusChangedEvent.cs \
224
	Mono.UIAutomation.Winforms.Events/ToolStripItem/AutomationFocusChangedEvent.cs \
223
	Mono.UIAutomation.Winforms.Events/ToolStripItem/AutomationHasKeyboardFocusPropertyEvent.cs \
225
	Mono.UIAutomation.Winforms.Events/ToolStripItem/AutomationHasKeyboardFocusPropertyEvent.cs \
Lines 292-297 Link Here
292
	Mono.UIAutomation.Winforms/TextNormalizer.cs \
294
	Mono.UIAutomation.Winforms/TextNormalizer.cs \
293
	Mono.UIAutomation.Winforms/TextNormalizerPoints.cs \
295
	Mono.UIAutomation.Winforms/TextNormalizerPoints.cs \
294
	Mono.UIAutomation.Winforms/TextRangeProvider.cs \
296
	Mono.UIAutomation.Winforms/TextRangeProvider.cs \
297
	Mono.UIAutomation.Winforms/ToolBarProvider.cs \
295
	Mono.UIAutomation.Winforms/ToolStripComboBoxProvider.cs \
298
	Mono.UIAutomation.Winforms/ToolStripComboBoxProvider.cs \
296
	Mono.UIAutomation.Winforms/ToolStripDropDownItemProvider.cs \
299
	Mono.UIAutomation.Winforms/ToolStripDropDownItemProvider.cs \
297
	Mono.UIAutomation.Winforms/ToolStripItemProvider.cs \
300
	Mono.UIAutomation.Winforms/ToolStripItemProvider.cs \
(-)UIAutomationWinforms/Mono.UIAutomation.Winforms/ProviderFactory.cs (+3 lines)
Lines 111-116 Link Here
111
			SWF.MonthCalendar mc;
111
			SWF.MonthCalendar mc;
112
			SWF.SplitContainer sc;
112
			SWF.SplitContainer sc;
113
			SWF.Splitter s;
113
			SWF.Splitter s;
114
			SWF.ToolBar tb;
114
			
115
			
115
			SWF.StatusStrip ss;
116
			SWF.StatusStrip ss;
116
			SWF.MenuStrip ms;
117
			SWF.MenuStrip ms;
Lines 226-231 Link Here
226
				provider = new SplitContainerProvider (sc);
227
				provider = new SplitContainerProvider (sc);
227
			else if ((s = component as SWF.Splitter) != null)
228
			else if ((s = component as SWF.Splitter) != null)
228
				provider = new SplitterProvider (s);
229
				provider = new SplitterProvider (s);
230
			else if ((tb = component as SWF.ToolBar) != null)
231
				provider = new ToolBarProvider (tb);
229
			else {
232
			else {
230
				//TODO: We have to solve the problem when there's a Custom control
233
				//TODO: We have to solve the problem when there's a Custom control
231
				//	Ideally the first thing we do is send a wndproc message to
234
				//	Ideally the first thing we do is send a wndproc message to
(-)UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolBarProvider.cs (+220 lines)
Line 0 Link Here
1
// Permission is hereby granted, free of charge, to any person obtaining 
2
// a copy of this software and associated documentation files (the 
3
// "Software"), to deal in the Software without restriction, including 
4
// without limitation the rights to use, copy, modify, merge, publish, 
5
// distribute, sublicense, and/or sell copies of the Software, and to 
6
// permit persons to whom the Software is furnished to do so, subject to 
7
// the following conditions: 
8
//  
9
// The above copyright notice and this permission notice shall be 
10
// included in all copies or substantial portions of the Software. 
11
//  
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
13
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
14
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
16
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
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. 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
21
// 
22
// Authors: 
23
//	Neville Gao <nevillegao@gmail.com>
24
// 
25
26
using System;
27
using System.ComponentModel;
28
using System.Collections.Generic;
29
using System.Windows.Forms;
30
using System.Windows.Automation;
31
using System.Windows.Automation.Provider;
32
using Mono.UIAutomation.Winforms.Behaviors;
33
using Mono.UIAutomation.Winforms.Behaviors.ToolBar;
34
35
namespace Mono.UIAutomation.Winforms
36
{
37
	internal class ToolBarProvider : FragmentRootControlProvider
38
	{
39
		#region Constructor
40
41
		public ToolBarProvider (ToolBar toolBar) : base (toolBar)
42
		{
43
			this.toolBar = toolBar;
44
			buttons = new List<ToolBarButtonProvider> ();
45
		}
46
47
		#endregion
48
		
49
		#region SimpleControlProvider: Specializations
50
		
51
		protected override object GetProviderPropertyValue (int propertyId)
52
		{
53
			if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
54
				return ControlType.ToolBar.Id;
55
			else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
56
				return "tool bar";
57
			else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
58
				return toolBar.Text;
59
			else
60
				return base.GetProviderPropertyValue (propertyId);
61
		}
62
		
63
		#endregion
64
		
65
		#region FragmentRootControlProvider: Specializations
66
		
67
		public override void InitializeChildControlStructure ()
68
		{	
69
			try {
70
				Helper.AddPrivateEvent (typeof (ToolBar.ToolBarButtonCollection),
71
				                        toolBar.Buttons,
72
				                        "UIACollectionChanged",
73
				                        this,
74
				                        "OnCollectionChanged");
75
			} catch (NotSupportedException) { }
76
			
77
			for (int i = 0; i < toolBar.Buttons.Count; ++i) {
78
				ToolBarButtonProvider button = GetButtonProvider (i);
79
				OnNavigationChildAdded (false, button);
80
			}
81
		}
82
		
83
		public override void FinalizeChildControlStructure ()
84
		{
85
			try {
86
				Helper.RemovePrivateEvent (typeof (ToolBar.ToolBarButtonCollection),
87
				                           toolBar.Buttons,
88
				                           "UIACollectionChanged",
89
				                           this,
90
				                           "OnCollectionChanged");
91
			} catch (NotSupportedException) { }
92
			
93
			foreach (ToolBarButtonProvider button in buttons)
94
				OnNavigationChildRemoved (false, button);
95
			OnNavigationChildrenCleared (false);
96
		}
97
		
98
		#endregion
99
		
100
		#region Public Methods
101
		
102
		public ToolBarButtonProvider GetButtonProvider (int index)
103
		{
104
			ToolBarButtonProvider button = null;
105
			
106
			if (index < 0 || index >= toolBar.Buttons.Count)
107
				return null;
108
			else if (index >= buttons.Count) {
109
				for (int loop = buttons.Count - 1; loop < index; ++loop) {
110
					button = new ToolBarButtonProvider (toolBar.Buttons [index]);
111
					buttons.Add (button);
112
					button.Initialize ();
113
				}
114
			}
115
			
116
			return buttons [index];
117
		}
118
		
119
		public ToolBarButtonProvider RemoveButtonAt (int index)
120
		{
121
			ToolBarButtonProvider button = null;
122
			
123
			if (index < buttons.Count) {
124
				button = buttons [index];
125
				buttons.RemoveAt (index);
126
				button.Terminate ();
127
			}
128
			
129
			return button;
130
		}
131
		
132
		public void ClearButtonsCollection ()
133
		{
134
			while (buttons.Count > 0) {
135
				RemoveButtonAt (buttons.Count - 1);
136
			}
137
		}
138
		
139
		#endregion
140
		
141
		#region Private Methods
142
143
		#pragma warning disable 169
144
		
145
		private void OnCollectionChanged (object sender, CollectionChangeEventArgs e)
146
		{
147
			if (e.Action == CollectionChangeAction.Add) {
148
				ToolBarButtonProvider button = GetButtonProvider ((int) e.Element);
149
				OnNavigationChildAdded (true, button);
150
			} else if (e.Action == CollectionChangeAction.Remove) {
151
				ToolBarButtonProvider button = RemoveButtonAt ((int) e.Element);
152
				OnNavigationChildRemoved (true, button);
153
			} else if (e.Action == CollectionChangeAction.Refresh) {
154
				ClearButtonsCollection ();
155
				OnNavigationChildrenCleared (true);
156
			}
157
		}
158
		
159
		#pragma warning restore 169
160
		
161
		#endregion
162
		
163
		#region Private Fields
164
		
165
		private ToolBar toolBar;
166
		private List<ToolBarButtonProvider> buttons;
167
		
168
		#endregion
169
		
170
		#region Internal Class: ToolBarButton Provider
171
		
172
		internal class ToolBarButtonProvider : FragmentControlProvider
173
		{
174
			#region Constructor
175
176
			public ToolBarButtonProvider (ToolBarButton toolBarButton) : base (toolBarButton)
177
			{
178
				this.toolBarButton = toolBarButton;
179
			}
180
		
181
			#endregion
182
			
183
			#region SimpleControlProvider: Specializations
184
		
185
			public override void Initialize ()
186
			{
187
				base.Initialize ();
188
				
189
				SetBehavior (InvokePatternIdentifiers.Pattern,
190
				             new ToolBarButtonInvokeProviderBehavior (this));
191
			}
192
			
193
			#endregion
194
			
195
			#region Public Methods
196
		
197
			protected override object GetProviderPropertyValue (int propertyId)
198
			{
199
				if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
200
					return ControlType.MenuItem.Id;
201
				else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
202
					return "menu item";
203
				else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
204
					return toolBarButton.Text;
205
				else
206
					return base.GetProviderPropertyValue (propertyId);
207
			}
208
		
209
			#endregion
210
			
211
			#region Private Fields
212
		
213
			private ToolBarButton toolBarButton;
214
		
215
			#endregion
216
		}
217
		
218
		#endregion
219
	}
220
}
(-)UIAutomationWinforms/Mono.UIAutomation.Winforms.Behaviors/ToolBar/ToolBarButtonInvokeProviderBehavior.cs (+76 lines)
Line 0 Link Here
1
// Permission is hereby granted, free of charge, to any person obtaining 
2
// a copy of this software and associated documentation files (the 
3
// "Software"), to deal in the Software without restriction, including 
4
// without limitation the rights to use, copy, modify, merge, publish, 
5
// distribute, sublicense, and/or sell copies of the Software, and to 
6
// permit persons to whom the Software is furnished to do so, subject to 
7
// the following conditions: 
8
//  
9
// The above copyright notice and this permission notice shall be 
10
// included in all copies or substantial portions of the Software. 
11
//  
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
13
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
14
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
16
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
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. 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
21
// 
22
// Authors: 
23
//	Neville Gao <nevillegao@gmail.com>
24
// 
25
26
using System;
27
using System.Windows.Automation;
28
using System.Windows.Automation.Provider;
29
using SWF = System.Windows.Forms;
30
using Mono.UIAutomation.Winforms;
31
using Mono.UIAutomation.Winforms.Events;
32
using Mono.UIAutomation.Winforms.Events.ToolBar;
33
34
namespace Mono.UIAutomation.Winforms.Behaviors.ToolBar
35
{
36
	internal class ToolBarButtonInvokeProviderBehavior : ProviderBehavior, IInvokeProvider
37
	{
38
		#region Constructor
39
40
		public ToolBarButtonInvokeProviderBehavior (ToolBarProvider.ToolBarButtonProvider provider)
41
			: base (provider)
42
		{
43
		}
44
		
45
		#endregion
46
		
47
		#region IProviderBehavior Interface		
48
		
49
		public override AutomationPattern ProviderPattern { 
50
			get { return InvokePatternIdentifiers.Pattern; }
51
		}
52
53
		public override void Connect ()
54
		{
55
			Provider.SetEvent (ProviderEventType.InvokePatternInvokedEvent,
56
			                   new ToolBarButtonInvokePatternInvokedEvent (Provider));
57
		}
58
		
59
		public override void Disconnect ()
60
		{
61
			Provider.SetEvent (ProviderEventType.InvokePatternInvokedEvent,
62
			                   null);
63
		}
64
65
		#endregion
66
		
67
		#region IInvokeProvider Members
68
		
69
		public void Invoke ()
70
		{
71
			// TODO:
72
		}
73
		
74
		#endregion
75
	}
76
}
(-)UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ToolBar/ToolBarButtonInvokePatternInvokedEvent.cs (+74 lines)
Line 0 Link Here
1
// Permission is hereby granted, free of charge, to any person obtaining 
2
// a copy of this software and associated documentation files (the 
3
// "Software"), to deal in the Software without restriction, including 
4
// without limitation the rights to use, copy, modify, merge, publish, 
5
// distribute, sublicense, and/or sell copies of the Software, and to 
6
// permit persons to whom the Software is furnished to do so, subject to 
7
// the following conditions: 
8
//  
9
// The above copyright notice and this permission notice shall be 
10
// included in all copies or substantial portions of the Software. 
11
//  
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
13
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
14
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
16
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
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. 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
21
// 
22
// Authors: 
23
//	Neville Gao <nevillegao@gmail.com>
24
// 
25
26
using System;
27
using System.Windows.Automation;
28
using System.Windows.Automation.Provider;
29
using SWF = System.Windows.Forms;
30
using Mono.UIAutomation.Winforms.Events;
31
32
namespace Mono.UIAutomation.Winforms.Events.ToolBar
33
{
34
	internal class ToolBarButtonInvokePatternInvokedEvent : BaseAutomationEvent
35
	{
36
		#region Constructor
37
38
		public ToolBarButtonInvokePatternInvokedEvent (SimpleControlProvider provider) 
39
			: base (provider, InvokePatternIdentifiers.InvokedEvent)
40
		{
41
		}
42
		
43
		#endregion
44
		
45
		#region IConnectable Overrides
46
47
		public override void Connect ()
48
		{
49
//			((SWF.ToolBar) Provider.Control).ButtonClick +=
50
//				new SWF.ToolBarButtonClickEventHandler (OnButtonClick);
51
		}
52
		
53
		public override void Disconnect ()
54
		{
55
//			((SWF.ToolBar) Provider.Control).ButtonClick -=
56
//				new SWF.ToolBarButtonClickEventHandler (OnButtonClick);
57
		}
58
		
59
		#endregion
60
		
61
		#region Private Methods
62
63
		#pragma warning disable 169
64
		
65
		private void OnButtonClick (object sender, SWF.ToolBarButtonClickEventArgs e)
66
		{
67
			RaiseAutomationEvent ();
68
		}
69
70
		#pragma warning restore 169
71
		
72
		#endregion
73
	}
74
}
(-)UIAutomationWinformsTests/UIAutomationWinformsTests.mdp (+2 lines)
Lines 58-63 Link Here
58
    <File name="TextBoxBaseProviderTest.cs" subtype="Code" buildaction="Compile" />
58
    <File name="TextBoxBaseProviderTest.cs" subtype="Code" buildaction="Compile" />
59
    <File name="SplitContainerProviderTest.cs" subtype="Code" buildaction="Compile" />
59
    <File name="SplitContainerProviderTest.cs" subtype="Code" buildaction="Compile" />
60
    <File name="SplitterProviderTest.cs" subtype="Code" buildaction="Compile" />
60
    <File name="SplitterProviderTest.cs" subtype="Code" buildaction="Compile" />
61
    <File name="MonthCalendarProviderTest.cs" subtype="Code" buildaction="Compile" />
62
    <File name="ToolBarProviderTest.cs" subtype="Code" buildaction="Compile" />
61
  </Contents>
63
  </Contents>
62
  <References>
64
  <References>
63
    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
65
    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
(-)UIAutomationWinformsTests/Makefile.am (+1 lines)
Lines 87-92 Link Here
87
	TextBoxBaseProviderTest.cs \
87
	TextBoxBaseProviderTest.cs \
88
	TextBoxProviderTest.cs \
88
	TextBoxProviderTest.cs \
89
	TextRangeProviderTest.cs \
89
	TextRangeProviderTest.cs \
90
	ToolBarProviderTest.cs \
90
	ToolStripComboBoxProviderTest.cs \
91
	ToolStripComboBoxProviderTest.cs \
91
	ToolStripDropDownItemProviderTest.cs \
92
	ToolStripDropDownItemProviderTest.cs \
92
	ToolStripLabelProviderTest.cs \
93
	ToolStripLabelProviderTest.cs \
(-)UIAutomationWinformsTests/ToolBarProviderTest.cs (+168 lines)
Line 0 Link Here
1
// Permission is hereby granted, free of charge, to any person obtaining 
2
// a copy of this software and associated documentation files (the 
3
// "Software"), to deal in the Software without restriction, including 
4
// without limitation the rights to use, copy, modify, merge, publish, 
5
// distribute, sublicense, and/or sell copies of the Software, and to 
6
// permit persons to whom the Software is furnished to do so, subject to 
7
// the following conditions: 
8
//  
9
// The above copyright notice and this permission notice shall be 
10
// included in all copies or substantial portions of the Software. 
11
//  
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
13
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
14
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
16
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
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. 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
21
// 
22
// Authors: 
23
//	Neville Gao <nevillegao@gmail.com>
24
// 
25
26
using System;
27
using System.Collections.Generic;
28
using System.Windows.Forms;
29
using System.Windows.Automation;
30
using System.Windows.Automation.Provider;
31
using Mono.UIAutomation.Winforms;
32
using NUnit.Framework;
33
34
namespace MonoTests.Mono.UIAutomation.Winforms
35
{
36
    	[TestFixture]
37
    	public class ToolBarProviderTest : BaseProviderTest
38
    	{
39
		#region Test
40
41
        	[Test]
42
        	public void BasicPropertiesTest ()
43
        	{
44
            		ToolBar toolBar = new ToolBar ();
45
            		IRawElementProviderSimple provider =
46
				ProviderFactory.GetProvider (toolBar);
47
48
			TestProperty (provider,
49
			              AutomationElementIdentifiers.ControlTypeProperty,
50
			              ControlType.ToolBar.Id);
51
52
			TestProperty (provider,
53
			              AutomationElementIdentifiers.LocalizedControlTypeProperty,
54
			              "tool bar");
55
56
			string value = "ToolBar Name Property";
57
			toolBar.Text = value;
58
			TestProperty (provider,
59
			              AutomationElementIdentifiers.NameProperty,
60
			              value);
61
		}
62
63
		#endregion
64
65
		#region Navigation Test
66
67
		[Test]
68
		public void NavigationTest ()
69
		{
70
			ToolBar toolBar = (ToolBar) GetControlInstance ();
71
			IRawElementProviderFragmentRoot rootProvider;
72
			IRawElementProviderFragment childProvider;
73
			IRawElementProviderFragment childParent;
74
75
			rootProvider = (IRawElementProviderFragmentRoot) GetProviderFromControl (toolBar);
76
			
77
			int index = 0, elements = 10;
78
			string name = string.Empty;
79
			for (; index < elements; ++index)
80
				toolBar.Buttons.Add (string.Format ("Button: {0}", index));
81
			index = 0;
82
			
83
			childProvider = rootProvider.Navigate (NavigateDirection.FirstChild);
84
			Assert.IsNotNull (childProvider, "We must have a child");
85
			
86
			do {
87
				childParent = childProvider.Navigate (NavigateDirection.Parent);
88
				Assert.AreSame (rootProvider, childParent,
89
				                "Each child must have same parent");
90
				name = (string) childProvider.GetPropertyValue (AutomationElementIdentifiers.NameProperty.Id);
91
				Assert.AreEqual (string.Format ("Button: {0}", index++), 
92
				                 name, "Different names");
93
				childProvider = childProvider.Navigate (NavigateDirection.NextSibling);
94
			} while (childProvider != null);
95
			Assert.AreEqual (elements, index, "Elements Added = Elements Navigated");
96
97
			toolBar.Buttons.Clear ();
98
99
			childProvider = rootProvider.Navigate (NavigateDirection.FirstChild);
100
			Assert.IsNull (childProvider, "We shouldn't have a child");
101
		}
102
103
		#endregion
104
105
		#region ToolBarButton Test
106
107
		[Test]
108
        	public void ToolBarButtonBasicPropertiesTest ()
109
        	{
110
            		ToolBar toolBar = new ToolBar ();
111
            		IRawElementProviderFragmentRoot rootProvider =
112
				(IRawElementProviderFragmentRoot) GetProviderFromControl (toolBar);
113
			
114
			toolBar.Buttons.Add ("Button");
115
			IRawElementProviderFragment childProvider =
116
				rootProvider.Navigate (NavigateDirection.FirstChild);
117
118
			TestProperty (childProvider,
119
			              AutomationElementIdentifiers.ControlTypeProperty,
120
			              ControlType.MenuItem.Id);
121
122
			TestProperty (childProvider,
123
			              AutomationElementIdentifiers.LocalizedControlTypeProperty,
124
			              "menu item");
125
			
126
			string value = "ToolBarButton Name Property";
127
			toolBar.Buttons [0].Text = value;
128
			TestProperty (childProvider,
129
			              AutomationElementIdentifiers.NameProperty,
130
			              value);
131
		}
132
133
		[Test]
134
		public void ToolBarButtonProviderPatternTest ()
135
		{
136
			ToolBar toolBar = new ToolBar ();
137
            		IRawElementProviderFragmentRoot rootProvider =
138
				(IRawElementProviderFragmentRoot) GetProviderFromControl (toolBar);
139
			
140
			toolBar.Buttons.Add ("Button");
141
			IRawElementProviderFragment childProvider =
142
				rootProvider.Navigate (NavigateDirection.FirstChild);
143
			
144
			object invokeProvider =
145
				childProvider.GetPatternProvider (InvokePatternIdentifiers.Pattern.Id);
146
			Assert.IsNotNull (invokeProvider,
147
			                  "Not returning InvokePatternIdentifiers.");
148
			Assert.IsTrue (invokeProvider is IInvokeProvider,
149
			               "Not returning InvokePatternIdentifiers.");
150
		}
151
152
		#endregion
153
154
		#region BaseProviderTest Overrides
155
156
        	protected override Control GetControlInstance ()
157
        	{
158
            		return new ToolBar ();
159
        	}
160
161
		public override void LabeledByAndNamePropertyTest ()
162
		{
163
			TestLabeledByAndName (false, false);
164
		}
165
166
		#endregion
167
	}
168
}

Return to bug 428759