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

(-)test/samples/button_label_linklabel.py (-1 / +1 lines)
Lines 119-125 Link Here
119
        self.Controls.Add(self.insensitive_label)
119
        self.Controls.Add(self.insensitive_label)
120
    
120
    
121
    def button1_click(self, sender, event):
121
    def button1_click(self, sender, event):
122
        MessageBox.Show("successful clicked me", "message")
122
        self.button2.AccessibleName = "new accessible name"
123
123
124
    def change_message(self, sender, event):
124
    def change_message(self, sender, event):
125
        self.count += 1
125
        self.count += 1
(-)UiaAtkBridge/Test/AtkTest/AtkTests.cs (-17 / +99 lines)
Lines 45-50 Link Here
45
			Atk.Object accessible = InterfaceText (type,
45
			Atk.Object accessible = InterfaceText (type,
46
				(type == BasicWidgetType.ToolStripLabel));
46
				(type == BasicWidgetType.ToolStripLabel));
47
			Label (accessible, type);
47
			Label (accessible, type);
48
49
			TestNewAccessibleName (accessible);
48
		}
50
		}
49
51
50
		protected void Label (Atk.Object accessible, BasicWidgetType type)
52
		protected void Label (Atk.Object accessible, BasicWidgetType type)
Lines 63-68 Link Here
63
			
65
			
64
			//TODO: check parent (it seems it only works for real objects)
66
			//TODO: check parent (it seems it only works for real objects)
65
			//Assert.IsNotNull (accessible.Parent, "Label parent");
67
			//Assert.IsNotNull (accessible.Parent, "Label parent");
68
69
			TestNewAccessibleName (accessible);
66
		}
70
		}
67
		
71
		
68
		[Test]
72
		[Test]
Lines 117-122 Link Here
117
			string keyBinding = atkAction.GetKeybinding (0);
121
			string keyBinding = atkAction.GetKeybinding (0);
118
			Assert.IsNotNull (keyBinding, "GetKeybinding (0))");
122
			Assert.IsNotNull (keyBinding, "GetKeybinding (0))");
119
			Assert.AreEqual (keyBinding, "<Alt>e", "<Alt>e");
123
			Assert.AreEqual (keyBinding, "<Alt>e", "<Alt>e");
124
125
			TestNewAccessibleName (accessible);
120
		}
126
		}
121
127
122
		[Test]
128
		[Test]
Lines 165-170 Link Here
165
			string keyBinding = atkAction.GetKeybinding (0);
171
			string keyBinding = atkAction.GetKeybinding (0);
166
			Assert.IsNotNull (keyBinding, "GetKeybinding (0))");
172
			Assert.IsNotNull (keyBinding, "GetKeybinding (0))");
167
			Assert.AreEqual (keyBinding, "<Alt>s", "<Alt>s");
173
			Assert.AreEqual (keyBinding, "<Alt>s", "<Alt>s");
174
175
			TestNewAccessibleName (accessible);
168
		}
176
		}
169
		
177
		
170
		[Test]
178
		[Test]
Lines 225-230 Link Here
225
			string keyBinding = atkAction.GetKeybinding (0);
233
			string keyBinding = atkAction.GetKeybinding (0);
226
			Assert.IsNotNull (keyBinding, "GetKeybinding (0))");
234
			Assert.IsNotNull (keyBinding, "GetKeybinding (0))");
227
			Assert.AreEqual (keyBinding, "<Alt>t", "<Alt>t");
235
			Assert.AreEqual (keyBinding, "<Alt>t", "<Alt>t");
236
237
			TestNewAccessibleName (accessible);
228
		}
238
		}
229
		
239
		
230
		[Test]
240
		[Test]
Lines 245-266 Link Here
245
			InterfaceComponent (type, atkComponent);
255
			InterfaceComponent (type, atkComponent);
246
256
247
			Parent (type, accessible);
257
			Parent (type, accessible);
258
259
			TestNewAccessibleName (accessible);
248
		}
260
		}
249
		
261
		
250
		[Test]
262
		[Test]
251
		public void HScrollBar ()
263
		public void HScrollBar ()
252
		{
264
		{
253
			BasicWidgetType type = BasicWidgetType.HScrollBar;
265
			BasicWidgetType type = BasicWidgetType.HScrollBar;
254
			Atk.Object accessible;
266
			Atk.Object accessible = null, orig;
255
			string name = "test";
267
			string [] names = new string [] { "First item", "Second Item", "Last Item", 
268
			  "A really, really long item that's here to try to ensure that we have a scrollbar, assuming that it's even possible to have a scrollbar just by having a relaly, really long item and we don't also have to perform some other function which I'm not aware of, like display the form on the screen" };
269
			
270
			orig = GetAccessible (type, names, true);
256
271
257
			accessible = GetAccessible (type, name, true);
272
			for (int i = orig.NAccessibleChildren - 1; i >= 0; i--)
273
			{
274
				Atk.Object child = orig.RefAccessibleChild (i);
275
				if (child.Role == Atk.Role.ScrollBar && child.RefStateSet().ContainsState(Atk.StateType.Horizontal))
276
				{
277
					accessible = child;
278
					break;
279
				}
280
			}
281
			PropertyRole (type, accessible);
282
			
258
			Atk.Value atkValue = CastToAtkInterface <Atk.Value> (accessible);
283
			Atk.Value atkValue = CastToAtkInterface <Atk.Value> (accessible);
259
			
284
			
260
			InterfaceValue (type, atkValue);
285
			InterfaceValue (type, atkValue);
261
286
262
			PropertyRole (type, accessible);
263
264
			States (accessible,
287
			States (accessible,
265
				Atk.StateType.Horizontal,
288
				Atk.StateType.Horizontal,
266
				Atk.StateType.Enabled,
289
				Atk.StateType.Enabled,
Lines 308-330 Link Here
308
				Assert.AreEqual (minimumValue,
331
				Assert.AreEqual (minimumValue,
309
				                 (double) glibValue.Val, "Set/Get values failed. (Maximum + 1)");
332
				                 (double) glibValue.Val, "Set/Get values failed. (Maximum + 1)");
310
			}
333
			}
334
335
			TestNewAccessibleName (orig);
311
		}
336
		}
312
		
337
		
313
		[Test]
338
		[Test]
314
		public void VScrollBar ()
339
		public void VScrollBar ()
315
		{
340
		{
316
			BasicWidgetType type = BasicWidgetType.VScrollBar;
341
			BasicWidgetType type = BasicWidgetType.VScrollBar;
317
			Atk.Object accessible;
342
			Atk.Object accessible = null, orig;
318
			string name = "test";
343
			string [] names = new string [100];
344
			for (int i = 0; i < 100; i++)
345
				names [i] = i.ToString ();
319
346
320
			accessible = GetAccessible (type, name, true);
347
			orig = GetAccessible (type, names, true);
321
			
348
			
349
			for (int i = orig.NAccessibleChildren - 1; i >= 0; i--)
350
			{
351
				Atk.Object child = orig.RefAccessibleChild (i);
352
				if (child.Role == Atk.Role.ScrollBar && child.RefStateSet ().ContainsState (Atk.StateType.Vertical))
353
				{
354
					accessible = child;
355
					break;
356
				}
357
			}
358
			
359
			PropertyRole (type, accessible);
360
			
322
			Atk.Value atkValue = CastToAtkInterface <Atk.Value> (accessible);
361
			Atk.Value atkValue = CastToAtkInterface <Atk.Value> (accessible);
323
			
362
			
324
			InterfaceValue (type, atkValue);
363
			InterfaceValue (type, atkValue);
325
364
			
326
			PropertyRole (type, accessible);
327
328
			States (accessible,
365
			States (accessible,
329
				Atk.StateType.Vertical,
366
				Atk.StateType.Vertical,
330
				Atk.StateType.Enabled,
367
				Atk.StateType.Enabled,
Lines 335-341 Link Here
335
			Assert.AreEqual (ValidNChildrenForAScrollBar, accessible.NAccessibleChildren, "VScrollBar numChildren");
372
			Assert.AreEqual (ValidNChildrenForAScrollBar, accessible.NAccessibleChildren, "VScrollBar numChildren");
336
373
337
			Atk.Component atkComponent = CastToAtkInterface <Atk.Component> (accessible);
374
			Atk.Component atkComponent = CastToAtkInterface <Atk.Component> (accessible);
338
339
			InterfaceComponent (type, atkComponent);
375
			InterfaceComponent (type, atkComponent);
340
376
341
			//Simple Set/Get
377
			//Simple Set/Get
Lines 371-376 Link Here
371
				Assert.AreEqual (minimumValue,
407
				Assert.AreEqual (minimumValue,
372
				                 (double) glibValue.Val, "Set/Get values failed. (Maximum + 1)");
408
				                 (double) glibValue.Val, "Set/Get values failed. (Maximum + 1)");
373
			}
409
			}
410
411
			TestNewAccessibleName (orig);
374
		}
412
		}
375
		
413
		
376
 		[Test]
414
 		[Test]
Lines 402-407 Link Here
402
			InterfaceComponent (type, atkComponent);
440
			InterfaceComponent (type, atkComponent);
403
441
404
			Parent (type, accessible);
442
			Parent (type, accessible);
443
444
			TestNewAccessibleName (accessible);
405
		}
445
		}
406
		
446
		
407
 		[Test]
447
 		[Test]
Lines 438-443 Link Here
438
			SetReadOnly (type, accessible, false);
478
			SetReadOnly (type, accessible, false);
439
			ExpectEvents (1, Atk.Role.SpinButton, "object:state-changed:editable");
479
			ExpectEvents (1, Atk.Role.SpinButton, "object:state-changed:editable");
440
			Assert.IsTrue (accessible.RefStateSet().ContainsState (Atk.StateType.Editable), "Non-ReadOnly spinner should be editable");
480
			Assert.IsTrue (accessible.RefStateSet().ContainsState (Atk.StateType.Editable), "Non-ReadOnly spinner should be editable");
481
482
			TestNewAccessibleName (accessible);
441
		}
483
		}
442
		
484
		
443
		[Test]
485
		[Test]
Lines 475-480 Link Here
475
//			PropertyRole (type, accessible);
517
//			PropertyRole (type, accessible);
476
//			
518
//			
477
//			Assert.AreEqual (0, accessible.NAccessibleChildren, "TextBoxEntry numChildren");
519
//			Assert.AreEqual (0, accessible.NAccessibleChildren, "TextBoxEntry numChildren");
520
521
			TestNewAccessibleName (accessible);
478
		}
522
		}
479
523
480
		[Test]
524
		[Test]
Lines 514-519 Link Here
514
				int nAccessibleChildren = (TextBoxHasScrollBar? 1: 0);
558
				int nAccessibleChildren = (TextBoxHasScrollBar? 1: 0);
515
				Assert.AreEqual (nAccessibleChildren, accessible.NAccessibleChildren, "TextBoxView NAccessibleChildren");
559
				Assert.AreEqual (nAccessibleChildren, accessible.NAccessibleChildren, "TextBoxView NAccessibleChildren");
516
			}
560
			}
561
562
			TestNewAccessibleName (accessible);
517
		}
563
		}
518
564
519
		[Test]
565
		[Test]
Lines 535-540 Link Here
535
			  Atk.StateType.Showing,
581
			  Atk.StateType.Showing,
536
			  Atk.StateType.Visible,
582
			  Atk.StateType.Visible,
537
			  Atk.StateType.SingleLine);
583
			  Atk.StateType.SingleLine);
584
585
			TestNewAccessibleName (accessible);
538
		}
586
		}
539
		
587
		
540
		[Test]
588
		[Test]
Lines 582-587 Link Here
582
				names.Add (submenu.Label);
630
				names.Add (submenu.Label);
583
			Atk.Selection atkSelection = CastToAtkInterface <Atk.Selection> (accessible);
631
			Atk.Selection atkSelection = CastToAtkInterface <Atk.Selection> (accessible);
584
			InterfaceSelection (atkSelection, names.ToArray (), accessible, type);
632
			InterfaceSelection (atkSelection, names.ToArray (), accessible, type);
633
634
			TestNewAccessibleName (accessible);
585
		}
635
		}
586
		
636
		
587
		[Test]
637
		[Test]
Lines 658-663 Link Here
658
				currentTopLevelItems = -1;
708
				currentTopLevelItems = -1;
659
				throw;
709
				throw;
660
			} finally {
710
			} finally {
711
				//if we tested this after we close the contextmenu, it would obviously fail
712
				TestNewAccessibleName (accessible);
713
				
661
				if (currentTopLevelItems != -1)
714
				if (currentTopLevelItems != -1)
662
					currentTopLevelItems = GetTopLevelRootItem ().NAccessibleChildren;
715
					currentTopLevelItems = GetTopLevelRootItem ().NAccessibleChildren;
663
				CloseContextMenu (accessible);
716
				CloseContextMenu (accessible);
Lines 706-711 Link Here
706
			InterfaceAction (type, atkAction, accessible);
759
			InterfaceAction (type, atkAction, accessible);
707
760
708
			InterfaceText (type, true, accessible);
761
			InterfaceText (type, true, accessible);
762
763
			TestNewAccessibleName (accessible);
709
		}
764
		}
710
765
711
		
766
		
Lines 770-775 Link Here
770
			menu = new List <MenuLayout> (new MenuLayout [] { new MenuLayout (simpleTestText, firstSubmenus), new MenuLayout ("Help") });
825
			menu = new List <MenuLayout> (new MenuLayout [] { new MenuLayout (simpleTestText, firstSubmenus), new MenuLayout ("Help") });
771
			accessible = GetAccessible (type, menu);
826
			accessible = GetAccessible (type, menu);
772
			InterfaceText (type, true, accessible);
827
			InterfaceText (type, true, accessible);
828
829
			TestNewAccessibleName (accessible);
773
		}
830
		}
774
831
775
		[Test]
832
		[Test]
Lines 878-883 Link Here
878
			//check the Action impl of a comboboxitem (menuitem role)
935
			//check the Action impl of a comboboxitem (menuitem role)
879
			atkAction = CastToAtkInterface <Atk.Action> (secondComboBoxItem);
936
			atkAction = CastToAtkInterface <Atk.Action> (secondComboBoxItem);
880
			InterfaceAction (BasicWidgetType.ComboBoxItem, atkAction, secondComboBoxItem);
937
			InterfaceAction (BasicWidgetType.ComboBoxItem, atkAction, secondComboBoxItem);
938
939
			TestNewAccessibleName (accessible);
881
		}
940
		}
882
		
941
		
883
		//it's safer to put this test the last, apparently Atk makes it unresponsive after dealing with
942
		//it's safer to put this test the last, apparently Atk makes it unresponsive after dealing with
Lines 925-932 Link Here
925
			//check the Action impl of a comboboxitem (menuitem role)
984
			//check the Action impl of a comboboxitem (menuitem role)
926
			atkAction = CastToAtkInterface <Atk.Action> (secondComboBoxItem);
985
			atkAction = CastToAtkInterface <Atk.Action> (secondComboBoxItem);
927
			InterfaceAction (BasicWidgetType.ComboBoxItem, atkAction, secondComboBoxItem);
986
			InterfaceAction (BasicWidgetType.ComboBoxItem, atkAction, secondComboBoxItem);
928
			
987
929
			
930
			if (widget != null)
988
			if (widget != null)
931
				return;
989
				return;
932
			//bug 503281
990
			//bug 503281
Lines 934-939 Link Here
934
			names = new string [] { "Test1", "Test2" };
992
			names = new string [] { "Test1", "Test2" };
935
			accessible = GetAccessible (type, names, selected, widget);
993
			accessible = GetAccessible (type, names, selected, widget);
936
			Assert.AreEqual (names [selected], accessible.Name, "expected " + names [selected] + ", we got " + accessible.Name);
994
			Assert.AreEqual (names [selected], accessible.Name, "expected " + names [selected] + ", we got " + accessible.Name);
995
			
996
			TestNewAccessibleName (accessible);
937
		}
997
		}
938
		
998
		
939
		[Test]
999
		[Test]
Lines 1004-1009 Link Here
1004
					atkSelection.AddSelection (0);
1064
					atkSelection.AddSelection (0);
1005
				});
1065
				});
1006
			}
1066
			}
1067
1068
			TestNewAccessibleName (accessible);
1007
		}
1069
		}
1008
1070
1009
		[Test]
1071
		[Test]
Lines 1029-1034 Link Here
1029
			Assert.AreEqual (0, accessible.NAccessibleChildren, "Button numChildren");
1091
			Assert.AreEqual (0, accessible.NAccessibleChildren, "Button numChildren");
1030
1092
1031
			Parent (type, accessible);
1093
			Parent (type, accessible);
1094
			
1095
			TestNewAccessibleName (accessible);
1032
1096
1033
			Atk.Image atkWithoutImage, atkWithImage;
1097
			Atk.Image atkWithoutImage, atkWithImage;
1034
			atkWithImage = CastToAtkInterface <Atk.Image> (accessible);
1098
			atkWithImage = CastToAtkInterface <Atk.Image> (accessible);
Lines 1106-1111 Link Here
1106
			Relation (Atk.RelationType.NodeChildOf, child1, group);
1170
			Relation (Atk.RelationType.NodeChildOf, child1, group);
1107
1171
1108
			Assert.AreEqual (3, atkTable.NColumns, "Table NumColumns");
1172
			Assert.AreEqual (3, atkTable.NColumns, "Table NumColumns");
1173
1174
			TestNewAccessibleName (accessible);
1109
		}
1175
		}
1110
1176
1111
		protected string simpleTable = "<table>"+
1177
		protected string simpleTable = "<table>"+
Lines 1180-1185 Link Here
1180
				Atk.Selection atkSelection = CastToAtkInterface <Atk.Selection> (accessible);
1246
				Atk.Selection atkSelection = CastToAtkInterface <Atk.Selection> (accessible);
1181
				InterfaceSelection (atkSelection, names, accessible, BasicWidgetType.ComboBoxDropDownEntry);
1247
				InterfaceSelection (atkSelection, names, accessible, BasicWidgetType.ComboBoxDropDownEntry);
1182
			}
1248
			}
1249
1250
			TestNewAccessibleName (accessible);
1183
		}
1251
		}
1184
		
1252
		
1185
		[Test]
1253
		[Test]
Lines 1190-1196 Link Here
1190
1258
1191
			accessible = GetAccessible (type, simpleTable, true);
1259
			accessible = GetAccessible (type, simpleTable, true);
1192
			
1260
			
1193
			Assert.AreEqual (null, accessible.Name, "acc.name==null");
1261
			Assert.AreEqual (String.Empty, accessible.Name ?? String.Empty, "acc.name==null");
1194
1262
1195
			Atk.Component atkComponent = CastToAtkInterface <Atk.Component> (accessible);
1263
			Atk.Component atkComponent = CastToAtkInterface <Atk.Component> (accessible);
1196
			InterfaceComponent (type, atkComponent);
1264
			InterfaceComponent (type, atkComponent);
Lines 1270-1275 Link Here
1270
				int rowIndex = atkTable.GetRowAtIndex (item4Index);
1338
				int rowIndex = atkTable.GetRowAtIndex (item4Index);
1271
				Assert.IsTrue (rowIndex == -1 || rowIndex >= atkTable.NRows, "Child row after collapse");
1339
				Assert.IsTrue (rowIndex == -1 || rowIndex >= atkTable.NRows, "Child row after collapse");
1272
			}
1340
			}
1341
1342
			TestNewAccessibleName (accessible);
1273
		}
1343
		}
1274
1344
1275
		[Test]
1345
		[Test]
Lines 1295-1301 Link Here
1295
			  Atk.StateType.Sensitive,
1365
			  Atk.StateType.Sensitive,
1296
			  Atk.StateType.Resizable,
1366
			  Atk.StateType.Resizable,
1297
			  Atk.StateType.Showing,
1367
			  Atk.StateType.Showing,
1298
			  Atk.StateType.Visible); 
1368
			  Atk.StateType.Visible);
1369
1370
			TestNewAccessibleName (accessible);
1299
		}
1371
		}
1300
1372
1301
		[Test]
1373
		[Test]
Lines 1330-1335 Link Here
1330
			  Atk.StateType.Sensitive,
1402
			  Atk.StateType.Sensitive,
1331
			  Atk.StateType.Showing,
1403
			  Atk.StateType.Showing,
1332
			  Atk.StateType.Visible);
1404
			  Atk.StateType.Visible);
1405
1406
			TestNewAccessibleName (accessible);
1333
		}
1407
		}
1334
1408
1335
		[Test]
1409
		[Test]
Lines 1362-1367 Link Here
1362
1436
1363
			if (accessible.NAccessibleChildren < 1)
1437
			if (accessible.NAccessibleChildren < 1)
1364
				Assert.Fail ("Accessible should have children!");
1438
				Assert.Fail ("Accessible should have children!");
1439
1440
			TestNewAccessibleName (accessible);
1365
		}
1441
		}
1366
1442
1367
		[Test]
1443
		[Test]
Lines 1427-1433 Link Here
1427
				CastToAtkInterface <Atk.Action> (accessible.Parent).DoAction (0);
1503
				CastToAtkInterface <Atk.Action> (accessible.Parent).DoAction (0);
1428
			});
1504
			});
1429
			
1505
			
1430
1506
			TestNewAccessibleName (accessible);
1431
		}
1507
		}
1432
		
1508
		
1433
		[Test]
1509
		[Test]
Lines 1439-1444 Link Here
1439
			string name = "test";
1515
			string name = "test";
1440
			accessible = GetAccessible (type, name, true);
1516
			accessible = GetAccessible (type, name, true);
1441
			HSplitter (accessible);
1517
			HSplitter (accessible);
1518
1519
			TestNewAccessibleName (accessible);
1442
		}
1520
		}
1443
1521
1444
 		[Test]
1522
 		[Test]
Lines 1470-1475 Link Here
1470
				Atk.StateType.Showing,
1548
				Atk.StateType.Showing,
1471
			Atk.StateType.Vertical,
1549
			Atk.StateType.Vertical,
1472
				Atk.StateType.Visible);
1550
				Atk.StateType.Visible);
1551
1552
			TestNewAccessibleName (accessible);
1473
		}
1553
		}
1474
		
1554
		
1475
		[Test]
1555
		[Test]
Lines 1540-1545 Link Here
1540
				Assert.IsTrue (w2 < w1, "Right control width decreased");
1620
				Assert.IsTrue (w2 < w1, "Right control width decreased");
1541
				Assert.AreEqual (h2, h1, "Height should not change");
1621
				Assert.AreEqual (h2, h1, "Height should not change");
1542
			});
1622
			});
1623
1624
			TestNewAccessibleName (accessible);
1543
		}
1625
		}
1544
	}
1626
	}
1545
}
1627
}
(-)UiaAtkBridge/Test/AtkTest/AtkTester.cs (-2 / +21 lines)
Lines 72-78 Link Here
72
72
73
		public abstract void SetReadOnly (BasicWidgetType type, Atk.Object accessible, bool readOnly);
73
		public abstract void SetReadOnly (BasicWidgetType type, Atk.Object accessible, bool readOnly);
74
74
75
		public virtual void SetAccessibleName (Atk.Object accessible, string newName)
76
		{
77
			accessible.Name = newName;
78
		}
79
75
		public abstract Atk.Object ActivateAdditionalForm (string name);
80
		public abstract Atk.Object ActivateAdditionalForm (string name);
81
76
		public abstract void RemoveAdditionalForm (Atk.Object obj);
82
		public abstract void RemoveAdditionalForm (Atk.Object obj);
77
83
78
		public abstract Atk.Object GetTopLevelRootItem ();
84
		public abstract Atk.Object GetTopLevelRootItem ();
Lines 949-954 Link Here
949
		
955
		
950
		protected void PropertyRole (BasicWidgetType type, Atk.Object accessible)
956
		protected void PropertyRole (BasicWidgetType type, Atk.Object accessible)
951
		{
957
		{
958
			if (accessible == null)
959
				throw new ArgumentNullException ("accessible");
952
			Atk.Role role = GetRole (type);
960
			Atk.Role role = GetRole (type);
953
			Assert.AreEqual (role, accessible.Role, "Atk.Role, we got " + accessible.Role);
961
			Assert.AreEqual (role, accessible.Role, "Atk.Role, we got " + accessible.Role);
954
		}
962
		}
Lines 1207-1213 Link Here
1207
			if (Misc.HasReadOnlyText (type))
1215
			if (Misc.HasReadOnlyText (type))
1208
				Assert.AreEqual (name, accessible.Name, "accessible.Name");
1216
				Assert.AreEqual (name, accessible.Name, "accessible.Name");
1209
			else
1217
			else
1210
				Assert.IsNull (accessible.Name, "accessible.Name");
1218
				Assert.AreEqual (accessible.Name ?? String.Empty, String.Empty, "accessible.Name");
1211
			
1219
			
1212
			int caret = 0;
1220
			int caret = 0;
1213
			if ((type == BasicWidgetType.TextBoxView || type == BasicWidgetType.RichTextBox) && TextBoxCaretInitiallyAtEnd)
1221
			if ((type == BasicWidgetType.TextBoxView || type == BasicWidgetType.RichTextBox) && TextBoxCaretInitiallyAtEnd)
Lines 1485-1491 Link Here
1485
			if (Misc.HasReadOnlyText (type) && type != BasicWidgetType.RichTextBox)
1493
			if (Misc.HasReadOnlyText (type) && type != BasicWidgetType.RichTextBox)
1486
				Assert.AreEqual (name, accessible.Name, "accessible.Name");
1494
				Assert.AreEqual (name, accessible.Name, "accessible.Name");
1487
			else
1495
			else
1488
				Assert.IsNull (accessible.Name, "accessible.Name");
1496
				Assert.AreEqual (accessible.Name ?? String.Empty, String.Empty, "accessible.Name");
1489
			
1497
			
1490
			Assert.AreEqual (name.Length, atkText.CharacterCount, "CharacterCount");
1498
			Assert.AreEqual (name.Length, atkText.CharacterCount, "CharacterCount");
1491
			Assert.AreEqual (String.Empty + name [0], String.Empty + atkText.GetCharacterAtOffset (0), "GetCharacterAtOffset");
1499
			Assert.AreEqual (String.Empty + name [0], String.Empty + atkText.GetCharacterAtOffset (0), "GetCharacterAtOffset");
Lines 2282-2287 Link Here
2282
			}
2290
			}
2283
		}
2291
		}
2284
2292
2293
		protected void TestNewAccessibleName (Atk.Object accessible)
2294
		{
2295
			string newName = "new name!";
2296
			string oldName = accessible.Name;
2297
			SetAccessibleName (accessible, newName);
2298
			Assert.AreEqual (newName, accessible.Name, "setting a new accessible Name didn't work");
2299
			if (oldName == null)
2300
				oldName = String.Empty;
2301
			SetAccessibleName (accessible, oldName);
2302
		}
2303
2285
		public abstract void RunInGuiThread (System.Action d);
2304
		public abstract void RunInGuiThread (System.Action d);
2286
	}
2305
	}
2287
}
2306
}
(-)UiaAtkBridge/Test/UiaAtkBridgeTest/BridgeTests.cs (-1 / +1 lines)
Lines 669-675 Link Here
669
				f.Show ();
669
				f.Show ();
670
				Atk.Object accessible = GetAdapterForWidget (f);
670
				Atk.Object accessible = GetAdapterForWidget (f);
671
				Assert.AreEqual (1, accessible.NAccessibleChildren, "Form should have one child");
671
				Assert.AreEqual (1, accessible.NAccessibleChildren, "Form should have one child");
672
				Atk.Object child = accessible.RefAccessibleChild (0);
672
				Atk.Object child = GetAdapterForWidget (splitter);
673
				HSplitter (child);
673
				HSplitter (child);
674
				f.Controls.Remove (splitter);
674
				f.Controls.Remove (splitter);
675
				Assert.AreEqual (2, accessible.NAccessibleChildren, "Form should have two children after removing splitter");
675
				Assert.AreEqual (2, accessible.NAccessibleChildren, "Form should have two children after removing splitter");
(-)UiaAtkBridge/Test/UiaAtkBridgeTest/BridgeTester.cs (-35 / +20 lines)
Lines 35-40 Link Here
35
using System.ComponentModel;
35
using System.ComponentModel;
36
using System.Drawing;
36
using System.Drawing;
37
37
38
using System.Reflection;
39
38
using Mono.UIAutomation.Winforms;
40
using Mono.UIAutomation.Winforms;
39
41
40
using NUnit.Framework;
42
using NUnit.Framework;
Lines 412-417 Link Here
412
			}
414
			}
413
			butWithImage.Focus ();
415
			butWithImage.Focus ();
414
		}
416
		}
417
418
		public override void SetAccessibleName (Atk.Object accessible, string newName)
419
		{
420
			if (accessible == null)
421
				throw new ArgumentNullException ("accessible");
422
423
			var comp = mappings [accessible] as Component;
424
			var control = comp as SWF.Control;
425
			if (control != null)
426
				control.AccessibleName = newName;
427
			else if (comp != null) {
428
				var prop = mappings [accessible].GetType ().GetProperty ("AccessibleName", BindingFlags.Instance | BindingFlags.Public);
429
				if (prop != null)
430
					prop.SetValue (comp, newName, null);
431
			}
432
		}
433
434
		
415
		public override object CastToAtkInterface (Type t, Atk.Object accessible)
435
		public override object CastToAtkInterface (Type t, Atk.Object accessible)
416
		{
436
		{
417
			if (t == typeof (Atk.Action)) {
437
			if (t == typeof (Atk.Action)) {
Lines 708-714 Link Here
708
		private Atk.Object GetAccessible (BasicWidgetType type, string name, object widget, bool real, bool embeddedImage)
728
		private Atk.Object GetAccessible (BasicWidgetType type, string name, object widget, bool real, bool embeddedImage)
709
		{
729
		{
710
			Atk.Object accessible = null;
730
			Atk.Object accessible = null;
711
			string[] names = null;
712
			XmlDocument xml;
731
			XmlDocument xml;
713
			XmlElement root;
732
			XmlElement root;
714
733
Lines 803-842 Link Here
803
					accessible = new UiaAtkBridge.TextContainer (ProviderFactory.GetProvider (sb, true, true));
822
					accessible = new UiaAtkBridge.TextContainer (ProviderFactory.GetProvider (sb, true, true));
804
				break;
823
				break;
805
824
806
			case BasicWidgetType.HScrollBar:
807
				names = new string [] { "First item", "Second Item", "Last Item", "A really, really long item that's here to try to ensure that we have a scrollbar, assuming that it's even possible to have a scrollbar just by having a relaly, really long item and we don't also have to perform some other function which I'm not aware of, like display the form on the screen" };
808
				accessible = GetAccessible (type, names, real);
809
				for (int i = accessible.NAccessibleChildren - 1; i >= 0; i--)
810
				{
811
					Atk.Object child = accessible.RefAccessibleChild (i);
812
					if (child.Role == Atk.Role.ScrollBar && child.RefStateSet().ContainsState(Atk.StateType.Horizontal))
813
					{
814
						accessible = child;
815
						break;
816
					}
817
				}
818
				if (accessible.Role != Atk.Role.ScrollBar)
819
					return null;
820
				break;
821
822
			case BasicWidgetType.VScrollBar:
823
				names = new string [100];
824
				for (int i = 0; i < 100; i++)
825
					names [i] = i.ToString();
826
				accessible = GetAccessible (type, names, real);
827
				for (int i = accessible.NAccessibleChildren - 1; i >= 0; i--)
828
				{
829
					Atk.Object child = accessible.RefAccessibleChild (i);
830
					if (child.Role == Atk.Role.ScrollBar && child.RefStateSet().ContainsState(Atk.StateType.Vertical))
831
					{
832
						accessible = child;
833
						break;
834
					}
835
				}
836
				if (accessible.Role != Atk.Role.ScrollBar)
837
					return null;
838
				break;
839
840
			case BasicWidgetType.ProgressBar:
825
			case BasicWidgetType.ProgressBar:
841
				SWF.ProgressBar pb = new SWF.ProgressBar ();
826
				SWF.ProgressBar pb = new SWF.ProgressBar ();
842
				if (real) {
827
				if (real) {
(-)UiaAtkBridge/UiaAtkBridge/Button.cs (-15 / +3 lines)
Lines 225-247 Link Here
225
				base.RaiseAutomationPropertyChangedEvent (e);
225
				base.RaiseAutomationPropertyChangedEvent (e);
226
		}
226
		}
227
		
227
		
228
		protected override void UpdateNameProperty (string newName, bool fromCtor)
228
		protected override void UpdateNameProperty (string newName)
229
		{
229
		{
230
			base.UpdateNameProperty (newName, fromCtor);
230
			base.UpdateNameProperty (newName);
231
231
232
			// If we're being called from the ctor, textExpert
232
			textExpert.EmitTextChanged (newName);
233
			// won't be initialized yet so bail
234
			if (fromCtor)
235
				return;
236
237
			Atk.TextAdapter adapter = new Atk.TextAdapter (this);
238
239
			// First delete all text, then insert the new text
240
			adapter.EmitTextChanged (Atk.TextChangedDetail.Delete, 0, textExpert.Length);
241
242
			adapter.EmitTextChanged (Atk.TextChangedDetail.Insert, 0,
243
						 newName == null ? 0 : newName.Length);
244
			EmitVisibleDataChanged ();
245
		}
233
		}
246
234
247
		// TODO: although UIA doesn't cover press and release actions, figure out if maybe it's useful to
235
		// TODO: although UIA doesn't cover press and release actions, figure out if maybe it's useful to
(-)UiaAtkBridge/UiaAtkBridge/BaseTextImplementor.cs (+12 lines)
Lines 442-447 Link Here
442
				
442
				
443
			return false;
443
			return false;
444
		}
444
		}
445
		
446
		public void EmitTextChanged (string newName)
447
		{
448
			Atk.TextAdapter adapter = new Atk.TextAdapter ((Atk.TextImplementor)resource);
449
450
			// First delete all text, then insert the new text
451
			adapter.EmitTextChanged (Atk.TextChangedDetail.Delete, 0, Length);
452
453
			adapter.EmitTextChanged (Atk.TextChangedDetail.Insert, 0, newName == null ? 0 : newName.Length);
454
455
			resource.EmitDataChanged ();
456
		}
445
#endregion
457
#endregion
446
458
447
#region Protected Fields
459
#region Protected Fields
(-)UiaAtkBridge/UiaAtkBridge/Tree.cs (-1 / +1 lines)
Lines 178-184 Link Here
178
			}
178
			}
179
		}
179
		}
180
180
181
		protected override void UpdateNameProperty (string newName, bool fromCtor)
181
		protected override void SetNameProperty (string newName)
182
		{
182
		{
183
			// Don't allow the name to be set
183
			// Don't allow the name to be set
184
		}
184
		}
(-)UiaAtkBridge/UiaAtkBridge/List.cs (-2 / +2 lines)
Lines 159-171 Link Here
159
			selectionHelper = new SelectionProviderUserHelper (provider, selectionProvider);
159
			selectionHelper = new SelectionProviderUserHelper (provider, selectionProvider);
160
		}
160
		}
161
161
162
		protected override void UpdateNameProperty (string newName, bool fromCtor)
162
		protected override void UpdateNameProperty (string newName)
163
		{
163
		{
164
			// ControlType.List returns Name from one static label, Atk returns NULL
164
			// ControlType.List returns Name from one static label, Atk returns NULL
165
			int controlTypeId = (int) Provider.GetPropertyValue (
165
			int controlTypeId = (int) Provider.GetPropertyValue (
166
				AutomationElementIdentifiers.ControlTypeProperty.Id);
166
				AutomationElementIdentifiers.ControlTypeProperty.Id);
167
			if (controlTypeId != ControlType.List.Id && controlTypeId != ControlType.Spinner.Id)
167
			if (controlTypeId != ControlType.List.Id && controlTypeId != ControlType.Spinner.Id)
168
				base.UpdateNameProperty (newName, fromCtor);
168
				base.SetNameProperty (newName);
169
		}
169
		}
170
		
170
		
171
		protected override Atk.StateSet OnRefStateSet ()
171
		protected override Atk.StateSet OnRefStateSet ()
(-)UiaAtkBridge/UiaAtkBridge/TextLabel.cs (-16 / +3 lines)
Lines 71-94 Link Here
71
			get { return 0; }
71
			get { return 0; }
72
		}
72
		}
73
73
74
		protected override void UpdateNameProperty (string newName, bool fromCtor)
74
		protected override void UpdateNameProperty (string newName)
75
		{
75
		{
76
			base.UpdateNameProperty (newName, fromCtor);
76
			base.UpdateNameProperty (newName);
77
77
78
			// If we're being called from the ctor, textExpert
78
			textExpert.EmitTextChanged (newName);
79
			// won't be initialized yet so bail
80
			if (fromCtor)
81
				return;
82
83
			Atk.TextAdapter adapter = new Atk.TextAdapter (this);
84
85
			// First delete all text, then insert the new text
86
			adapter.EmitTextChanged (Atk.TextChangedDetail.Delete, 0, textExpert.Length);
87
88
			adapter.EmitTextChanged (Atk.TextChangedDetail.Insert, 0,
89
						 newName == null ? 0 : newName.Length);
90
91
			EmitVisibleDataChanged ();
92
		}
79
		}
93
80
94
		public string GetText (int startOffset, int endOffset)
81
		public string GetText (int startOffset, int endOffset)
(-)UiaAtkBridge/UiaAtkBridge/TextContainer.cs (-16 / +3 lines)
Lines 163-186 Link Here
163
			Log.Warn ("TextContainer: RaiseStructureChangedEvent not implemented.");
163
			Log.Warn ("TextContainer: RaiseStructureChangedEvent not implemented.");
164
		}
164
		}
165
165
166
		protected override void UpdateNameProperty (string newName, bool fromCtor)
166
		protected override void UpdateNameProperty (string newName)
167
		{
167
		{
168
			base.UpdateNameProperty (newName, fromCtor);
168
			base.UpdateNameProperty (newName);
169
169
170
			// If we're being called from the ctor, textExpert
170
			textExpert.EmitTextChanged (newName);
171
			// won't be initialized yet so bail
172
			if (fromCtor)
173
				return;
174
175
			Atk.TextAdapter adapter = new Atk.TextAdapter (this);
176
177
			// First delete all text, then insert the new text
178
			adapter.EmitTextChanged (Atk.TextChangedDetail.Delete, 0, textExpert.Length);
179
180
			adapter.EmitTextChanged (Atk.TextChangedDetail.Insert, 0,
181
						 newName == null ? 0 : newName.Length);
182
183
			EmitVisibleDataChanged ();
184
		}
171
		}
185
	}
172
	}
186
173
(-)UiaAtkBridge/UiaAtkBridge/Tab.cs (-1 / +1 lines)
Lines 46-52 Link Here
46
			Role = Atk.Role.PageTabList;
46
			Role = Atk.Role.PageTabList;
47
		}
47
		}
48
48
49
		protected override void UpdateNameProperty (string newName, bool fromCtor)
49
		protected override void SetNameProperty (string newName)
50
		{
50
		{
51
		}
51
		}
52
52
(-)UiaAtkBridge/UiaAtkBridge/Container.cs (-2 / +2 lines)
Lines 58-71 Link Here
58
				base.RaiseAutomationEvent (eventId, e);
58
				base.RaiseAutomationEvent (eventId, e);
59
		}
59
		}
60
60
61
		protected override void UpdateNameProperty (string newName, bool fromCtor)
61
		protected override void SetNameProperty (string newName)
62
		{
62
		{
63
			int controlTypeId = (int) Provider.GetPropertyValue (
63
			int controlTypeId = (int) Provider.GetPropertyValue (
64
				AutomationElementIdentifiers.ControlTypeProperty.Id);
64
				AutomationElementIdentifiers.ControlTypeProperty.Id);
65
			if (controlTypeId == ControlType.MenuItem.Id)
65
			if (controlTypeId == ControlType.MenuItem.Id)
66
				return;
66
				return;
67
67
68
			base.UpdateNameProperty (newName, fromCtor);
68
			base.SetNameProperty (newName);
69
		}
69
		}
70
70
71
		public override void RaiseStructureChangedEvent (object childProvider, StructureChangedEventArgs e)
71
		public override void RaiseStructureChangedEvent (object childProvider, StructureChangedEventArgs e)
(-)UiaAtkBridge/UiaAtkBridge/Slider.cs (-1 / +1 lines)
Lines 45-51 Link Here
45
			oldText = textExpert.Text;
45
			oldText = textExpert.Text;
46
		}
46
		}
47
47
48
		protected override void UpdateNameProperty (string newName, bool fromCtor)
48
		protected override void SetNameProperty (string newName)
49
		{
49
		{
50
			// ControlType.Slider returns Name from one static label, Atk returns NULL
50
			// ControlType.Slider returns Name from one static label, Atk returns NULL
51
		}
51
		}
(-)UiaAtkBridge/UiaAtkBridge/ComboBoxOptions.cs (-1 / +1 lines)
Lines 164-170 Link Here
164
			base.RaiseAutomationPropertyChangedEvent (e);
164
			base.RaiseAutomationPropertyChangedEvent (e);
165
		}
165
		}
166
166
167
		protected override void UpdateNameProperty (string newName, bool fromCtor)
167
		protected override void SetNameProperty (string newName)
168
		{
168
		{
169
		}
169
		}
170
	}
170
	}
(-)UiaAtkBridge/UiaAtkBridge/WrapperPanel.cs (-1 / +1 lines)
Lines 49-55 Link Here
49
			return states;
49
			return states;
50
		}
50
		}
51
51
52
		protected override void UpdateNameProperty (string newName, bool fromCtor)
52
		protected override void SetNameProperty (string newName)
53
		{
53
		{
54
		}
54
		}
55
	}
55
	}
(-)UiaAtkBridge/UiaAtkBridge/Hyperlink.cs (-4 / +3 lines)
Lines 297-311 Link Here
297
			this.Parent = parent;
297
			this.Parent = parent;
298
			this.hyperlink = parent;
298
			this.hyperlink = parent;
299
			this.index = index;
299
			this.index = index;
300
			UpdateNameProperty (null, false);
300
			UpdateNameProperty (null);
301
			parent.AddOneChild (this);
301
			parent.AddOneChild (this);
302
		}
302
		}
303
303
304
		protected override void UpdateNameProperty (string newName, bool fromCtor)
304
		protected override void SetNameProperty (string newName)
305
		{
305
		{
306
			if (hyperlink != null) {
306
			if (hyperlink != null)
307
				Name = hyperlink.hypertext.Uri (index);
307
				Name = hyperlink.hypertext.Uri (index);
308
			}
309
		}
308
		}
310
		
309
		
311
		protected override Atk.StateSet OnRefStateSet ()
310
		protected override Atk.StateSet OnRefStateSet ()
(-)UiaAtkBridge/UiaAtkBridge/ComboBox.cs (-1 / +1 lines)
Lines 80-86 Link Here
80
			return states;
80
			return states;
81
		}
81
		}
82
82
83
		protected override void UpdateNameProperty (string newName, bool fromCtor)
83
		protected override void SetNameProperty (string newName)
84
		{
84
		{
85
			// We'll manage the name manually
85
			// We'll manage the name manually
86
		}
86
		}
(-)UiaAtkBridge/UiaAtkBridge/TextBoxEntryView.cs (-2 / +2 lines)
Lines 74-83 Link Here
74
			}
74
			}
75
		}
75
		}
76
76
77
		protected override void UpdateNameProperty (string newName, bool fromCtor)
77
		protected override void SetNameProperty (string newName)
78
		{
78
		{
79
			if (IsTableCell)
79
			if (IsTableCell)
80
				base.UpdateNameProperty (newName, fromCtor);
80
				base.SetNameProperty (newName);
81
		}
81
		}
82
82
83
		protected override Atk.StateSet OnRefStateSet ()
83
		protected override Atk.StateSet OnRefStateSet ()
(-)UiaAtkBridge/UiaAtkBridge/Adapter.cs (-15 / +15 lines)
Lines 126-135 Link Here
126
126
127
				// Don't set Name if we don't really want to
127
				// Don't set Name if we don't really want to
128
				// and don't fire events if we're not changing
128
				// and don't fire events if we're not changing
129
				if (!(Name == null && newName == String.Empty)
129
				if (!(Name == null && newName == String.Empty) && Name != newName)
130
				    && Name != newName) {
130
					UpdateNameProperty ((string)e.NewValue);
131
					UpdateNameProperty ((string)e.NewValue, false);
132
				}
133
			}
131
			}
134
		}
132
		}
135
133
Lines 160-179 Link Here
160
			if (!String.IsNullOrEmpty (desc))
158
			if (!String.IsNullOrEmpty (desc))
161
				Description = desc;
159
				Description = desc;
162
160
163
			UpdateNameProperty (Provider.GetPropertyValue (
161
			SetNameProperty (Provider.GetPropertyValue (AutomationElementIdentifiers.NameProperty.Id) as string);
164
				AutomationElementIdentifiers.NameProperty.Id)
165
					as string,
166
				true);
167
		}
162
		}
163
		
164
		internal void EmitDataChanged ()
165
		{
166
			EmitVisibleDataChanged ();
167
		}
168
168
169
		protected virtual void UpdateNameProperty (string newName, bool fromCtor)
169
		protected virtual void SetNameProperty (string newName)
170
		{
170
		{
171
			if (fromCtor) {
171
			if (!String.IsNullOrEmpty (newName))
172
				if (!String.IsNullOrEmpty (newName))
172
				Name = newName;
173
					Name = newName;
173
		}
174
				return;
174
		
175
			}
175
		protected virtual void UpdateNameProperty (string newName)
176
176
		{
177
			if (Name == null && String.IsNullOrEmpty (newName))
177
			if (Name == null && String.IsNullOrEmpty (newName))
178
				return;
178
				return;
179
179
(-)UiaAtkBridge/UiaAtkBridge/SplitContainer.cs (-1 / +2 lines)
Lines 126-132 Link Here
126
		{
126
		{
127
			if (e.Property == RangeValuePatternIdentifiers.ValueProperty) {
127
			if (e.Property == RangeValuePatternIdentifiers.ValueProperty) {
128
				Notify ("accessible-value");
128
				Notify ("accessible-value");
129
			}
129
			} else
130
				base.RaiseAutomationPropertyChangedEvent (e);
130
		}
131
		}
131
	}
132
	}
132
}
133
}
(-)UiaAtkBridge/UiaAtkBridge/ITextImplementor.cs (-2 / +4 lines)
Lines 37-44 Link Here
37
		}
37
		}
38
		
38
		
39
		int NSelections {
39
		int NSelections {
40
				get;
40
			get;
41
			}
41
		}
42
42
43
		string GetSelection (int selectionNum, out int startOffset, out int endOffset);
43
		string GetSelection (int selectionNum, out int startOffset, out int endOffset);
44
		bool AddSelection (int startOffset, int endOffset);
44
		bool AddSelection (int startOffset, int endOffset);
Lines 82-86 Link Here
82
82
83
		bool RaiseAutomationEvent (AutomationEvent eventId, AutomationEventArgs e);
83
		bool RaiseAutomationEvent (AutomationEvent eventId, AutomationEventArgs e);
84
		bool RaiseAutomationPropertyChangedEvent (AutomationPropertyChangedEventArgs e);
84
		bool RaiseAutomationPropertyChangedEvent (AutomationPropertyChangedEventArgs e);
85
		
86
		void EmitTextChanged (string newName);
85
	}
87
	}
86
}
88
}
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolStripItemProvider.cs (-2 / +6 lines)
Lines 66-73 Link Here
66
				return Catalog.GetString ("menu item");
66
				return Catalog.GetString ("menu item");
67
			else if (propertyId == AEIds.LabeledByProperty.Id)
67
			else if (propertyId == AEIds.LabeledByProperty.Id)
68
				return null;
68
				return null;
69
			else if (propertyId == AEIds.NameProperty.Id)
69
			else if (propertyId == AEIds.NameProperty.Id) {
70
				return item.Text;
70
				string baseName = base.GetProviderPropertyValue (propertyId) as string;
71
				if (baseName == null)
72
					return item.Text;
73
				return baseName;
74
			}
71
			else if (propertyId == AEIds.IsOffscreenProperty.Id) {
75
			else if (propertyId == AEIds.IsOffscreenProperty.Id) {
72
				return Helper.ToolStripItemIsOffScreen (item);
76
				return Helper.ToolStripItemIsOffScreen (item);
73
			} else if (propertyId == AEIds.IsEnabledProperty.Id)
77
			} else if (propertyId == AEIds.IsEnabledProperty.Id)
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/SimpleControlProvider.cs (-22 / +51 lines)
Lines 35-40 Link Here
35
using Mono.UIAutomation.Winforms.Navigation;
35
using Mono.UIAutomation.Winforms.Navigation;
36
using AEIds = System.Windows.Automation.AutomationElementIdentifiers;
36
using AEIds = System.Windows.Automation.AutomationElementIdentifiers;
37
37
38
using System.Reflection;
39
38
namespace Mono.UIAutomation.Winforms
40
namespace Mono.UIAutomation.Winforms
39
{
41
{
40
	internal abstract class SimpleControlProvider : IRawElementProviderSimple
42
	internal abstract class SimpleControlProvider : IRawElementProviderSimple
Lines 61-67 Link Here
61
		
63
		
62
		protected SimpleControlProvider (Component component)
64
		protected SimpleControlProvider (Component component)
63
		{
65
		{
64
			this.component = component;
66
			Component = component;
65
			control = component as SWF.Control;
67
			control = component as SWF.Control;
66
			
68
			
67
			events = new Dictionary<ProviderEventType,IConnectable> ();
69
			events = new Dictionary<ProviderEventType,IConnectable> ();
Lines 86-91 Link Here
86
88
87
		public Component Component {
89
		public Component Component {
88
			get { return component; }
90
			get { return component; }
91
			protected set { 
92
				if (component != value) {
93
					component = value;
94
					componentAccessibleNameProp = value.GetType ().GetProperty ("AccessibleName", BindingFlags.Instance | BindingFlags.Public);
95
					var handler = ComponentChanged;
96
					if (handler != null)
97
						ComponentChanged ();
98
				}
99
			}
89
		}
100
		}
90
		
101
		
91
		public SWF.Control Control {
102
		public SWF.Control Control {
Lines 107-112 Link Here
107
		#region Public Events
118
		#region Public Events
108
		
119
		
109
		public event ProviderBehaviorEventHandler ProviderBehaviorSet;
120
		public event ProviderBehaviorEventHandler ProviderBehaviorSet;
121
		public event Action ComponentChanged;
110
		
122
		
111
		#endregion
123
		#endregion
112
		
124
		
Lines 119-124 Link Here
119
			SetEvent (ProviderEventType.AutomationElementIsPatternAvailableProperty,
131
			SetEvent (ProviderEventType.AutomationElementIsPatternAvailableProperty,
120
			          new AutomationIsPatternAvailablePropertyEvent (this));
132
			          new AutomationIsPatternAvailablePropertyEvent (this));
121
133
134
			SetEvent (ProviderEventType.AutomationElementNameProperty,
135
			          new AutomationNamePropertyEvent (this));
136
			
122
			// These events only apply to Control providers
137
			// These events only apply to Control providers
123
			if (Control == null)
138
			if (Control == null)
124
				return;
139
				return;
Lines 127-134 Link Here
127
			          new AutomationIsOffscreenPropertyEvent (this));
142
			          new AutomationIsOffscreenPropertyEvent (this));
128
			SetEvent (ProviderEventType.AutomationElementIsEnabledProperty, 
143
			SetEvent (ProviderEventType.AutomationElementIsEnabledProperty, 
129
			          new AutomationIsEnabledPropertyEvent (this));
144
			          new AutomationIsEnabledPropertyEvent (this));
130
			SetEvent (ProviderEventType.AutomationElementNameProperty,
131
			          new AutomationNamePropertyEvent (this));
132
			SetEvent (ProviderEventType.AutomationElementHasKeyboardFocusProperty,
145
			SetEvent (ProviderEventType.AutomationElementHasKeyboardFocusProperty,
133
			          new AutomationHasKeyboardFocusPropertyEvent (this));
146
			          new AutomationHasKeyboardFocusPropertyEvent (this));
134
			SetEvent (ProviderEventType.AutomationElementBoundingRectangleProperty,
147
			SetEvent (ProviderEventType.AutomationElementBoundingRectangleProperty,
Lines 223-228 Link Here
223
			}
236
			}
224
		}
237
		}
225
238
239
		PropertyInfo componentAccessibleNameProp = null;
240
		
226
		protected virtual object GetProviderPropertyValue (int propertyId)
241
		protected virtual object GetProviderPropertyValue (int propertyId)
227
		{
242
		{
228
			if (propertyId == AutomationElementIdentifiers.IsExpandCollapsePatternAvailableProperty.Id)
243
			if (propertyId == AutomationElementIdentifiers.IsExpandCollapsePatternAvailableProperty.Id)
Lines 281-310 Link Here
281
			}
296
			}
282
			else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
297
			else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
283
				return Helper.RectangleToRect (ScreenBounds);
298
				return Helper.RectangleToRect (ScreenBounds);
299
			else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
300
				return GetNameProperty ();
284
			
301
			
285
			//Control-like properties
302
			//Control-like properties
286
			if (Control == null)
303
			if (Control == null)
287
				return null;
304
				return null;
288
			else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
305
			else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
289
				return Control.Enabled;
306
				return Control.Enabled;
290
			else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) {
307
			else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id) {
291
				if (!string.IsNullOrEmpty (Control.AccessibleName)) 
292
					return Control.AccessibleName;
293
				
294
				IRawElementProviderSimple label =
295
					GetPropertyValue (AutomationElementIdentifiers.LabeledByProperty.Id)
296
						as IRawElementProviderSimple;
297
				if (label == null) {
298
					int controlType = (int) GetPropertyValue (AutomationElementIdentifiers.ControlTypeProperty.Id);
299
					// http://msdn.microsoft.com/en-us/library/ms748367.aspx
300
					// "The Name property should never contain the textual contents of the edit control."
301
					if (controlType == ControlType.Edit.Id || controlType == ControlType.Document.Id)
302
						return string.Empty;
303
					else
304
						return Helper.StripAmpersands (Control.Text);
305
				} else
306
					return label.GetPropertyValue (AutomationElementIdentifiers.NameProperty.Id);
307
			} else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id) {
308
				IRawElementProviderFragment sibling = this as IRawElementProviderFragment;
308
				IRawElementProviderFragment sibling = this as IRawElementProviderFragment;
309
				if (sibling == null)
309
				if (sibling == null)
310
					return null;
310
					return null;
Lines 395-401 Link Here
395
				if (val != null)
395
				if (val != null)
396
					return val;
396
					return val;
397
			}
397
			}
398
399
			return GetProviderPropertyValue (propertyId) ?? Helper.GetDefaultAutomationPropertyValue (propertyId);
398
			return GetProviderPropertyValue (propertyId) ?? Helper.GetDefaultAutomationPropertyValue (propertyId);
400
		}
399
		}
401
400
Lines 417-422 Link Here
417
		
416
		
418
		#region Private Methods
417
		#region Private Methods
419
		
418
		
419
		private string GetNameProperty ()
420
		{
421
			if (Control != null && !string.IsNullOrEmpty (Control.AccessibleName))
422
				return Control.AccessibleName;
423
424
			if (Component != null && Control != Component) {
425
				if (componentAccessibleNameProp != null) {
426
					var val = (string)componentAccessibleNameProp.GetValue (Component, null);
427
					if (!string.IsNullOrEmpty (val))
428
						return val;
429
				}
430
			}
431
432
			IRawElementProviderSimple label =
433
				GetPropertyValue (AutomationElementIdentifiers.LabeledByProperty.Id)
434
					as IRawElementProviderSimple;
435
			if (label == null) {
436
				int controlType = (int) GetPropertyValue (AutomationElementIdentifiers.ControlTypeProperty.Id);
437
				// http://msdn.microsoft.com/en-us/library/ms748367.aspx
438
				// "The Name property should never contain the textual contents of the edit control."
439
				if (controlType == ControlType.Edit.Id || controlType == ControlType.Document.Id)
440
					return string.Empty;
441
				else if (Control != null)
442
					return Helper.StripAmpersands (Control.Text);
443
			} else
444
				return label.GetPropertyValue (AutomationElementIdentifiers.NameProperty.Id) as string;
445
446
			return null;
447
		}
448
		
420
		private double DistanceFrom (IRawElementProviderSimple otherProvider)
449
		private double DistanceFrom (IRawElementProviderSimple otherProvider)
421
		{
450
		{
422
			Rect bounds = (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
451
			Rect bounds = (Rect) GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolStripDropDownItemProvider.cs (-3 / +6 lines)
Lines 48-62 Link Here
48
		{
48
		{
49
			this.dropDrownItem = dropDrownItem;
49
			this.dropDrownItem = dropDrownItem;
50
			itemProviders = new Dictionary<ToolStripItem, FragmentControlProvider> ();
50
			itemProviders = new Dictionary<ToolStripItem, FragmentControlProvider> ();
51
			
52
		}
51
		}
53
52
54
		#region FragmentRootControlProvider: Specializations
53
		#region FragmentRootControlProvider: Specializations
55
54
56
		protected override object GetProviderPropertyValue (int propertyId)
55
		protected override object GetProviderPropertyValue (int propertyId)
57
		{
56
		{
58
			if (propertyId == AEIds.NameProperty.Id)
57
			if (propertyId == AEIds.NameProperty.Id) {
59
				return Helper.StripAmpersands (dropDrownItem.Text);
58
				string baseName = base.GetProviderPropertyValue (propertyId) as string;
59
				if (baseName == null)
60
					return Helper.StripAmpersands (dropDrownItem.Text);
61
				return baseName;
62
			}
60
			else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
63
			else if (propertyId == AEIds.HasKeyboardFocusProperty.Id)
61
				return dropDrownItem.Selected;
64
				return dropDrownItem.Selected;
62
			else
65
			else
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/StatusBarProvider.cs (-2 lines)
Lines 75-82 Link Here
75
				return Catalog.GetString ("status bar");
75
				return Catalog.GetString ("status bar");
76
			else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
76
			else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
77
				return null;
77
				return null;
78
			else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
79
				return statusBar.Text;
80
			else
78
			else
81
				return base.GetProviderPropertyValue (propertyId);
79
				return base.GetProviderPropertyValue (propertyId);
82
		}
80
		}
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/PaneProvider.cs (-8 / +1 lines)
Lines 39-45 Link Here
39
		
39
		
40
		public PaneProvider (Component component) : base (component)
40
		public PaneProvider (Component component) : base (component)
41
		{
41
		{
42
			this.component = component;
43
		}
42
		}
44
		
43
		
45
		#endregion
44
		#endregion
Lines 47-53 Link Here
47
		#region SimpleControlProvider: Specialization
46
		#region SimpleControlProvider: Specialization
48
		
47
		
49
		public override Component Container  {
48
		public override Component Container  {
50
			get { return component.Container as Component; }
49
			get { return Component.Container as Component; }
51
		}
50
		}
52
		
51
		
53
		protected override object GetProviderPropertyValue (int propertyId)
52
		protected override object GetProviderPropertyValue (int propertyId)
Lines 63-74 Link Here
63
		}
62
		}
64
63
65
		#endregion
64
		#endregion
66
		
67
		#region Private Fields
68
		
69
		private Component component;
70
		
71
		#endregion
72
65
73
	}
66
	}
74
}
67
}
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ListViewProvider.cs (-1 / +3 lines)
Lines 1186-1192 Link Here
1186
					return Catalog.GetString ("edit");
1186
					return Catalog.GetString ("edit");
1187
				else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) {
1187
				else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) {
1188
					IValueProvider valueProvider = (IValueProvider) GetBehavior (ValuePatternIdentifiers.Pattern);
1188
					IValueProvider valueProvider = (IValueProvider) GetBehavior (ValuePatternIdentifiers.Pattern);
1189
					return valueProvider.Value;
1189
					if (valueProvider != null)
1190
						return valueProvider.Value;
1191
					return null;
1190
				} else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
1192
				} else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
1191
					return IsFirstColumn || itemProvider.ListView.FullRowSelect;
1193
					return IsFirstColumn || itemProvider.ListView.FullRowSelect;
1192
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id) {
1194
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id) {
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolStripProvider.cs (-2 lines)
Lines 59-66 Link Here
59
				return Catalog.GetString ("tool bar");
59
				return Catalog.GetString ("tool bar");
60
			else if (propertyId == AEIds.LabeledByProperty.Id)
60
			else if (propertyId == AEIds.LabeledByProperty.Id)
61
				return null;
61
				return null;
62
			else if (propertyId == AEIds.NameProperty.Id)
63
				return Helper.StripAmpersands (strip.Text);
64
			else if (propertyId == AEIds.IsContentElementProperty.Id)
62
			else if (propertyId == AEIds.IsContentElementProperty.Id)
65
				return true;
63
				return true;
66
			else
64
			else
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms/ToolStripProgressBar.cs (-3 / +4 lines)
Lines 38-47 Link Here
38
	{
38
	{
39
		private ToolStripProgressBar item = null;
39
		private ToolStripProgressBar item = null;
40
40
41
		public ToolStripProgressBarProvider (ToolStripProgressBar control)
41
		public ToolStripProgressBarProvider (ToolStripProgressBar component)
42
			: base (control.ProgressBar)
42
			: base (component.ProgressBar)
43
		{
43
		{
44
			item = control;
44
			item = component;
45
			Component = item;
45
		}
46
		}
46
47
47
		protected override object GetProviderPropertyValue (int propertyId)
48
		protected override object GetProviderPropertyValue (int propertyId)
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/AutomationNamePropertyEvent.cs (-3 / +54 lines)
Lines 28-39 Link Here
28
using System.Windows.Automation.Provider;
28
using System.Windows.Automation.Provider;
29
using System.Windows.Forms;
29
using System.Windows.Forms;
30
30
31
using System.Reflection;
32
31
namespace Mono.UIAutomation.Winforms.Events
33
namespace Mono.UIAutomation.Winforms.Events
32
{
34
{
33
	
35
	
34
	internal class AutomationNamePropertyEvent 
36
	internal class AutomationNamePropertyEvent 
35
		: BaseAutomationPropertyEvent
37
		: BaseAutomationPropertyEvent
36
	{
38
	{
39
		SimpleControlProvider provider;
37
		
40
		
38
		#region Constructors
41
		#region Constructors
39
42
Lines 41-46 Link Here
41
			: base (provider,
44
			: base (provider,
42
			        AutomationElementIdentifiers.NameProperty)
45
			        AutomationElementIdentifiers.NameProperty)
43
		{
46
		{
47
			this.provider = provider;
44
		}
48
		}
45
49
46
		#endregion
50
		#endregion
Lines 49-67 Link Here
49
53
50
		public override void Connect ()
54
		public override void Connect ()
51
		{
55
		{
52
			Provider.Control.TextChanged += new EventHandler (OnTextChanged);
56
			if (Provider.Control != null) {
57
				Provider.Control.TextChanged += new EventHandler (OnTextChanged);
58
				Provider.Control.UIAAccessibleNameChanged += new EventHandler (OnTextChanged);
59
			}
60
			
61
			ConnectComponent ();
62
			
63
			provider.ComponentChanged += ConnectComponent;
53
		}
64
		}
65
		
66
		private void ConnectComponent ()
67
		{
68
			if (Provider.Component == null || Provider.Component == Provider.Control)
69
				return;
70
			
71
			/*
72
			 * the usage of reflection here is *not* only because we want to be backwards compatible (with previous Mono 
73
			 * versions that may not have these events), but because we want to simplify the code for all the scenarios
74
			 * in which Component-based widgets are involved
75
			 */
76
			try {
77
				Helper.AddPrivateEvent (Provider.Component.GetType (),
78
				                        Provider.Component,
79
				                        "UIAAccessibleNameChanged",
80
				                        this,
81
				                        "OnTextChanged");
82
			} catch (NotSupportedException) { }
83
		}
54
84
55
		public override void Disconnect ()
85
		public override void Disconnect ()
56
		{
86
		{
57
			Provider.Control.TextChanged -= new EventHandler (OnTextChanged);
87
			if (Provider.Control != null) {
88
				Provider.Control.TextChanged -= new EventHandler (OnTextChanged);
89
				Provider.Control.UIAAccessibleNameChanged -= new EventHandler (OnTextChanged);
90
			}
91
			
92
			provider.ComponentChanged -= ConnectComponent;
93
			
94
			DisconnectComponent ();
58
		}
95
		}
59
		
96
		
97
		private void DisconnectComponent ()
98
		{
99
			if (Provider.Component == null || Provider.Component == Provider.Control)
100
				return;
101
			
102
			try {
103
				Helper.RemovePrivateEvent (Provider.Component.GetType (),
104
				                           Provider.Component,
105
				                           "UIAAccessibleNameChanged",
106
				                           this,
107
				                           "OnTextChanged");
108
			} catch (NotSupportedException) { }
109
		}
110
		
60
		#endregion
111
		#endregion
61
		
112
		
62
		#region Private Methods
113
		#region Private Methods
63
114
64
		private void OnTextChanged (object sender, EventArgs e)
115
		protected void OnTextChanged (object sender, EventArgs e)
65
		{
116
		{
66
			RaiseAutomationPropertyChangedEvent ();
117
			RaiseAutomationPropertyChangedEvent ();
67
		}
118
		}
(-)UIAutomationWinforms/UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ToolStripItem/AutomationNamePropertyEvent.cs (-12 / +4 lines)
Lines 32-45 Link Here
32
{
32
{
33
	
33
	
34
	internal class AutomationNamePropertyEvent 
34
	internal class AutomationNamePropertyEvent 
35
		: BaseAutomationPropertyEvent
35
		: Mono.UIAutomation.Winforms.Events.AutomationNamePropertyEvent
36
	{
36
	{
37
		
37
		
38
		#region Constructors
38
		#region Constructors
39
39
40
		public AutomationNamePropertyEvent (ToolStripItemProvider provider) 
40
		public AutomationNamePropertyEvent (ToolStripItemProvider provider) 
41
			: base (provider,
41
			: base (provider)
42
			        AutomationElementIdentifiers.NameProperty)
43
		{
42
		{
44
		}
43
		}
45
44
Lines 49-72 Link Here
49
48
50
		public override void Connect ()
49
		public override void Connect ()
51
		{
50
		{
51
			base.Connect ();
52
			((SWF.ToolStripItem)Provider.Component).TextChanged += new EventHandler (OnTextChanged);
52
			((SWF.ToolStripItem)Provider.Component).TextChanged += new EventHandler (OnTextChanged);
53
		}
53
		}
54
54
55
		public override void Disconnect ()
55
		public override void Disconnect ()
56
		{
56
		{
57
			base.Disconnect ();
57
			((SWF.ToolStripItem)Provider.Component).TextChanged -= new EventHandler (OnTextChanged);
58
			((SWF.ToolStripItem)Provider.Component).TextChanged -= new EventHandler (OnTextChanged);
58
		}
59
		}
59
		
60
		
60
		#endregion
61
		#endregion
61
		
62
		#region Private Methods
63
62
64
		private void OnTextChanged (object sender, EventArgs e)
65
		{
66
			RaiseAutomationPropertyChangedEvent ();
67
		}
68
69
		#endregion
70
71
	}
63
	}
72
}
64
}

Return to bug 457845