1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter;
5: using System.Collections.ObjectModel;
6:
7: namespace ExtendedDDA
8: {
9: public class ExtendedWinDDA : WinDataDrivenAdapter
10: {
11: const string EventNameTextChanged = "TextChanged";
12:
13: public ExtendedWinDDA(System.Xml.XmlDocument initStr, object appObj)
14: : base(initStr, appObj)
15: {
16: this.AccEventListener.AccEventOccurred += new EventHandler<Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter.AccEventArgs>(AccEventListener_AccEventOccurred);
17: }
18:
19: public override ReadOnlyCollection<string> GetAvailableApplicationEvents()
20: {
21: return base.GetAvailableApplicationEvents();
22: }
23:
24: public override ReadOnlyCollection<string> GetAvailableControlEvents()
25: {
26: ReadOnlyCollection<string> baseColl = base.GetAvailableControlEvents();
27: string[] coll = new string[baseColl.Count + 1];
28: coll[0] = EventNameTextChanged;
29: baseColl.CopyTo(coll, 1);
30: return new ReadOnlyCollection<string>(coll);
31: }
32:
33: void AccEventListener_AccEventOccurred(object sender, Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter.AccEventArgs e)
34: {
35:
36: if (e.WinEvent == "EVENT_OBJECT_VALUECHANGE")
37: {
38: System.Diagnostics.Trace.WriteLine("************* AccEventOccurred - RAISED ON TEXT CHANGED **************");
39:
40: // Get the control name
41: string strControlName = KnownControls.GetControlName(e.AutomationId);
42:
43: // for the given control raise the "TextChanged" event
44: base.RaiseEvent(sender, EventNameTextChanged, strControlName, e.Value);
45: }
46: }
47:
48: public override bool RegisterEventListener(string eventName, string controlName, EventHandler<ControlChangedEventArgs> listenerCallback)
49: {
50: bool isSuccessful = false;
51:
52: switch (eventName)
53: {
54: case "TextChanged":
55: isSuccessful = base.RegisterEventListenerBase(eventName, controlName, listenerCallback);
56: if (isSuccessful)
57: {
58: this.StartAccEventListenerIfNecessary();
59: if (((controlName != null) && !this.KnownControls.IsKnown(controlName)) && !this.OperationHandler(OperationType.FindControl, controlName, null).Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
60: {
61: throw new DataDrivenAdapterException("DDA0400: Unable to find control on the user interface.");
62: }
63: }
64: return isSuccessful;
65: }
66: base.RegisterEventListener(eventName, controlName, listenerCallback);
67: return isSuccessful;
68: }
69: }
70: }