rautomation 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +3 -3
  4. data/History.rdoc +17 -0
  5. data/README.rdoc +2 -1
  6. data/Rakefile +23 -6
  7. data/VERSION +1 -1
  8. data/ext/IAccessibleDLL/Release/IAccessibleDLL.dll +0 -0
  9. data/ext/UiaDll/Release/UiaDll.dll +0 -0
  10. data/ext/UiaDll/UiaDll/{AutomatedComboBox.cpp → AutomatedSelectList.cpp} +22 -11
  11. data/ext/UiaDll/UiaDll/{AutomatedComboBox.h → AutomatedSelectList.h} +17 -4
  12. data/ext/UiaDll/UiaDll/AutomatedTable.cpp +55 -13
  13. data/ext/UiaDll/UiaDll/AutomatedTable.h +16 -3
  14. data/ext/UiaDll/UiaDll/AutomationControl.cpp +28 -0
  15. data/ext/UiaDll/UiaDll/AutomationControl.h +56 -0
  16. data/ext/UiaDll/UiaDll/AutomationFinder.cpp +57 -0
  17. data/ext/UiaDll/UiaDll/AutomationFinder.h +48 -0
  18. data/ext/UiaDll/UiaDll/ControlMethods.cpp +15 -0
  19. data/ext/UiaDll/UiaDll/MenuItemSelector.h +2 -0
  20. data/ext/UiaDll/UiaDll/MenuMethods.cpp +58 -0
  21. data/ext/UiaDll/UiaDll/SelectListMethods.cpp +37 -0
  22. data/ext/UiaDll/UiaDll/SelectionItem.cpp +10 -0
  23. data/ext/UiaDll/UiaDll/SelectionItem.h +21 -0
  24. data/ext/UiaDll/UiaDll/StringHelper.cpp +33 -2
  25. data/ext/UiaDll/UiaDll/StringHelper.h +6 -0
  26. data/ext/UiaDll/UiaDll/StringMethods.cpp +8 -0
  27. data/ext/UiaDll/UiaDll/TableMethods.cpp +76 -0
  28. data/ext/UiaDll/UiaDll/Toggle.cpp +2 -0
  29. data/ext/UiaDll/UiaDll/Toggle.h +22 -0
  30. data/ext/UiaDll/UiaDll/UiaDll.cpp +96 -327
  31. data/ext/UiaDll/UiaDll/UiaDll.vcxproj +15 -4
  32. data/ext/UiaDll/UiaDll/UiaDll.vcxproj.filters +91 -22
  33. data/ext/UiaDll/UiaDll/dllmain.cpp +1 -1
  34. data/ext/UiaDll/UiaDll/stdafx.h +38 -21
  35. data/ext/WindowsForms/Release/WindowsForms.exe +0 -0
  36. data/ext/WindowsForms/WindowsForms.sln +10 -0
  37. data/ext/WindowsForms/WindowsForms/AutomatableMonthCalendar.cs +59 -0
  38. data/ext/WindowsForms/WindowsForms/AutomationHelpers/AutomationProvider.cs +91 -0
  39. data/ext/WindowsForms/WindowsForms/MainFormWindow.Designer.cs +32 -10
  40. data/ext/WindowsForms/WindowsForms/MainFormWindow.cs +10 -0
  41. data/ext/WindowsForms/WindowsForms/WindowsForms.csproj +15 -6
  42. data/lib/rautomation/adapter/ms_uia.rb +1 -0
  43. data/lib/rautomation/adapter/ms_uia/checkbox.rb +2 -10
  44. data/lib/rautomation/adapter/ms_uia/constants.rb +1 -0
  45. data/lib/rautomation/adapter/ms_uia/control.rb +14 -67
  46. data/lib/rautomation/adapter/ms_uia/functions.rb +2 -18
  47. data/lib/rautomation/adapter/ms_uia/list_box.rb +5 -27
  48. data/lib/rautomation/adapter/ms_uia/list_item.rb +2 -29
  49. data/lib/rautomation/adapter/ms_uia/radio.rb +1 -1
  50. data/lib/rautomation/adapter/ms_uia/select_list.rb +5 -6
  51. data/lib/rautomation/adapter/ms_uia/table.rb +15 -50
  52. data/lib/rautomation/adapter/ms_uia/text_field.rb +1 -1
  53. data/lib/rautomation/adapter/ms_uia/uia_dll.rb +226 -58
  54. data/lib/rautomation/adapter/ms_uia/value_control.rb +21 -0
  55. data/lib/rautomation/adapter/ms_uia/window.rb +6 -104
  56. data/lib/rautomation/adapter/win_32/functions.rb +0 -23
  57. data/lib/rautomation/adapter/win_32/keys.rb +64 -61
  58. data/rautomation.gemspec +6 -1
  59. data/spec/adapter/autoit/mouse_spec.rb +1 -1
  60. data/spec/adapter/ms_uia/select_list_spec.rb +0 -21
  61. data/spec/adapter/ms_uia/table_spec.rb +13 -11
  62. data/spec/adapter/ms_uia/text_field_spec.rb +15 -8
  63. data/spec/adapter/ms_uia/value_control_spec.rb +11 -0
  64. data/spec/adapter/ms_uia/window_spec.rb +7 -1
  65. data/spec/adapter/win_32/mouse_spec.rb +1 -1
  66. data/spec/adapter/win_32/text_field_spec.rb +5 -5
  67. data/spec/adapter/win_32/window_spec.rb +1 -1
  68. data/spec/text_field_spec.rb +18 -23
  69. data/spec/window_spec.rb +1 -3
  70. metadata +45 -34
  71. data/ext/UiaDll/UiaDll/ToggleStateHelper.cpp +0 -33
@@ -0,0 +1,57 @@
1
+ #include "StdAfx.h"
2
+ #include "AutomationFinder.h"
3
+
4
+ AutomationFinder::AutomationFinder(AutomationElement^ automationElement)
5
+ {
6
+ _automationElement = automationElement;
7
+ }
8
+
9
+ AutomationElementCollection^ AutomationFinder::Find(...array<Condition^>^ conditions)
10
+ {
11
+ return _automationElement->FindAll(System::Windows::Automation::TreeScope::Subtree, SomethingOrEverything(conditions));
12
+ }
13
+
14
+ AutomationElement^ AutomationFinder::FindFirst(...array<Condition^>^ conditions)
15
+ {
16
+ return _automationElement->FindFirst(System::Windows::Automation::TreeScope::Subtree, SomethingOrEverything(conditions));
17
+ }
18
+
19
+ AutomationElement^ AutomationFinder::Find(const FindInformation& findInformation)
20
+ {
21
+ switch(findInformation.how) {
22
+ case FindMethod::Id:
23
+ {
24
+ auto searchCondition = gcnew PropertyCondition(AutomationElement::AutomationIdProperty, gcnew String(findInformation.data.stringData));
25
+ return FindAt(findInformation.index, searchCondition);
26
+ }
27
+ case FindMethod::Value:
28
+ {
29
+ auto searchCondition = gcnew PropertyCondition(AutomationElement::NameProperty, gcnew String(findInformation.data.stringData));
30
+ return FindAt(findInformation.index, searchCondition);
31
+ }
32
+ case FindMethod::Focus:
33
+ return AutomationElement::FocusedElement;
34
+ case FindMethod::ScreenPoint:
35
+ return AutomationElement::FromPoint(Point(findInformation.data.pointData[0], findInformation.data.pointData[1]));
36
+ case FindMethod::Handle:
37
+ return AutomationElement::FromHandle(IntPtr(findInformation.data.intData));
38
+ }
39
+
40
+ return nullptr;
41
+ }
42
+
43
+ AutomationElement^ AutomationFinder::FindAt(const int whichItem, ...array<Condition^>^ conditions)
44
+ {
45
+ return Find(conditions)[whichItem];
46
+ }
47
+
48
+ Condition^ AutomationFinder::SomethingOrEverything(...array<Condition^>^ conditions)
49
+ {
50
+ if( conditions->Length == 0 ) {
51
+ return Condition::TrueCondition;
52
+ } else if( conditions->Length == 1 ) {
53
+ return conditions[0];
54
+ }
55
+
56
+ return gcnew AndCondition(conditions);
57
+ }
@@ -0,0 +1,48 @@
1
+ #pragma once
2
+ using namespace System::Windows;
3
+ using namespace System::Windows::Automation;
4
+
5
+ ref class AutomationFinder
6
+ {
7
+ public:
8
+ AutomationFinder(AutomationElement^ automationElement);
9
+ AutomationElementCollection^ Find(...array<Condition^>^ conditions);
10
+ AutomationElement^ Find(const FindInformation& findInformation);
11
+ AutomationElement^ FindFirst(...array<Condition^>^ conditions);
12
+ AutomationElement^ FindAt(const int whichItem, ...array<Condition^>^ conditions);
13
+
14
+ static property Condition^ IsSelectionItem {
15
+ Condition^ get() {
16
+ return gcnew PropertyCondition(AutomationElement::IsSelectionItemPatternAvailableProperty, true);
17
+ }
18
+ }
19
+
20
+ static property Condition^ IsTableItem {
21
+ Condition^ get() {
22
+ return gcnew PropertyCondition(AutomationElement::IsTableItemPatternAvailableProperty, true);
23
+ }
24
+ }
25
+
26
+ static property Condition^ IsDataItem {
27
+ Condition^ get() {
28
+ return gcnew PropertyCondition(AutomationElement::ControlTypeProperty, ControlType::DataItem);
29
+ }
30
+ }
31
+
32
+ static property Condition^ IsHeaderItem {
33
+ Condition^ get() {
34
+ return gcnew PropertyCondition(AutomationElement::ControlTypeProperty, ControlType::HeaderItem);
35
+ }
36
+ }
37
+
38
+ static property Condition^ IsListItem {
39
+ Condition^ get() {
40
+ return gcnew PropertyCondition(AutomationElement::ControlTypeProperty, ControlType::ListItem);
41
+ }
42
+ }
43
+
44
+ private:
45
+ AutomationElement^ _automationElement;
46
+ Condition^ SomethingOrEverything(...array<Condition^>^ conditions);
47
+ };
48
+
@@ -0,0 +1,15 @@
1
+ #include "stdafx.h"
2
+ #include "AutomationControl.h"
3
+ #include "StringHelper.h"
4
+
5
+ extern "C" {
6
+ __declspec ( dllexport ) void Control_GetValue(const HWND windowHandle, char* theValue, const int maximumLength) {
7
+ auto control = gcnew AutomationControl(windowHandle);
8
+ StringHelper::CopyToUnmanagedString(control->Value, theValue, maximumLength);
9
+ }
10
+
11
+ __declspec ( dllexport ) void Control_SetValue(const HWND windowHandle, const char* theValue) {
12
+ auto control = gcnew AutomationControl(windowHandle);
13
+ control->Value = gcnew String(theValue);
14
+ }
15
+ }
@@ -1,4 +1,6 @@
1
1
  #pragma once
2
+ #include "StringHelper.h"
3
+
2
4
  using namespace System::Windows::Automation;
3
5
 
4
6
  public ref class MenuItemSelector
@@ -0,0 +1,58 @@
1
+ #include "stdafx.h"
2
+ #include "MenuItemSelector.h"
3
+
4
+ BOOL MenuItemExists(const HWND windowHandle, std::list<const char*>& menuItems);
5
+ void MenuSelectPath(const HWND windowHandle, char* errorInfo, const int errorInfoSize, std::list<const char*>& menuItems);
6
+
7
+ extern "C" {
8
+
9
+ __declspec ( dllexport ) void Menu_SelectPath(const HWND windowHandle, char* errorInfo, const int errorInfoSize, const char* arg0, ...) {
10
+ va_list arguments;
11
+ va_start(arguments, arg0);
12
+
13
+ std::list<const char*> menuItems;
14
+
15
+ const char* lastArgument = arg0;
16
+ while( NULL != lastArgument ) {
17
+ menuItems.push_back(lastArgument);
18
+ lastArgument = va_arg(arguments, const char*);
19
+ }
20
+ va_end(arguments);
21
+
22
+ MenuSelectPath(windowHandle, errorInfo, errorInfoSize, menuItems);
23
+ }
24
+
25
+ __declspec ( dllexport ) BOOL Menu_ItemExists(const HWND windowHandle, const char* arg0, ...) {
26
+ va_list arguments;
27
+ va_start(arguments, arg0);
28
+
29
+ std::list<const char*> menuItems;
30
+
31
+ const char* lastArgument = arg0;
32
+ while( NULL != lastArgument ) {
33
+ menuItems.push_back(lastArgument);
34
+ lastArgument = va_arg(arguments, const char*);
35
+ }
36
+ va_end(arguments);
37
+
38
+ return MenuItemExists(windowHandle, menuItems);
39
+ }
40
+ }
41
+
42
+ BOOL MenuItemExists(const HWND windowHandle, std::list<const char*>& menuItems)
43
+ {
44
+ auto menuSelector = gcnew MenuItemSelector();
45
+ return menuSelector->MenuItemExists(windowHandle, menuItems);
46
+ }
47
+
48
+ void MenuSelectPath(const HWND windowHandle, char* errorInfo, const int errorInfoSize, std::list<const char*>& menuItems)
49
+ {
50
+ try {
51
+ auto menuSelector = gcnew MenuItemSelector();
52
+ menuSelector->SelectMenuPath(windowHandle, menuItems);
53
+ } catch(Exception^ e) {
54
+ if( errorInfo ) {
55
+ StringHelper::CopyToUnmanagedString(e->ToString(), errorInfo, errorInfoSize);
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,37 @@
1
+ #include "stdafx.h"
2
+ #include "AutomatedSelectList.h"
3
+
4
+ extern "C" {
5
+
6
+ __declspec ( dllexport ) int SelectList_Count(const FindInformation& findInformation) {
7
+ auto autoSelectList = gcnew AutomatedSelectList(findInformation);
8
+ return autoSelectList->Count;
9
+ }
10
+
11
+ __declspec ( dllexport ) int SelectList_SelectedIndex(const HWND windowHandle) {
12
+ auto autoSelectList = gcnew AutomatedSelectList(windowHandle);
13
+ return autoSelectList->SelectedIndex;
14
+ }
15
+
16
+ __declspec ( dllexport ) void SelectList_Selection(const FindInformation& findInformation, char* selection, const int selectionLength) {
17
+ auto selectList = gcnew AutomatedSelectList(findInformation);
18
+ auto currentSelections = selectList->Selection;
19
+ auto firstSelection = currentSelections.Length == 0 ? "" : currentSelections[0];
20
+ StringHelper::CopyToUnmanagedString(firstSelection, selection, selectionLength);
21
+ }
22
+
23
+ __declspec ( dllexport ) bool SelectList_ValueAt(const HWND windowHandle, const int whichItem, char* comboValue, const int comboValueSize) {
24
+ auto autoSelectList = gcnew AutomatedSelectList(windowHandle);
25
+ return autoSelectList->GetValueByIndex(whichItem, comboValue, comboValueSize);
26
+ }
27
+
28
+ __declspec ( dllexport ) bool SelectList_SelectIndex(const FindInformation& findInformation, const int whichItem) {
29
+ auto autoSelectList = gcnew AutomatedSelectList(findInformation);
30
+ return autoSelectList->SelectByIndex(whichItem);
31
+ }
32
+
33
+ __declspec ( dllexport ) int SelectList_SelectValue(const FindInformation& findInformation, char *pValue) {
34
+ auto autoSelectList = gcnew AutomatedSelectList(findInformation);
35
+ return autoSelectList->SelectByValue(pValue);
36
+ }
37
+ }
@@ -0,0 +1,10 @@
1
+ #include "StdAfx.h"
2
+ #include "SelectionItem.h"
3
+
4
+ SelectionItem::SelectionItem(const HWND windowHandle) : AutomationControl(windowHandle)
5
+ {
6
+ }
7
+
8
+ SelectionItem::SelectionItem(const FindInformation& findInformation) : AutomationControl(findInformation)
9
+ {
10
+ }
@@ -0,0 +1,21 @@
1
+ #pragma once
2
+ #include "automationcontrol.h"
3
+ ref class SelectionItem :
4
+ public AutomationControl
5
+ {
6
+ public:
7
+ SelectionItem(const HWND windowHandle);
8
+ SelectionItem(const FindInformation& findInformation);
9
+
10
+ property bool IsSelected {
11
+ bool get() { return AsSelectionItemPattern->Current.IsSelected; }
12
+ }
13
+
14
+ private:
15
+ property SelectionItemPattern^ AsSelectionItemPattern {
16
+ SelectionItemPattern^ get() {
17
+ return dynamic_cast<SelectionItemPattern^>(_control->GetCurrentPattern(SelectionItemPattern::Pattern));
18
+ }
19
+ }
20
+ };
21
+
@@ -4,6 +4,37 @@
4
4
  void StringHelper::CopyToUnmanagedString(String^ source, char* destination, const int destinationSize)
5
5
  {
6
6
  auto unmanagedString = Marshal::StringToHGlobalAnsi(source);
7
- strncpy(destination, (const char*)(void*)unmanagedString, destinationSize - 1);
8
- Marshal::FreeHGlobal(unmanagedString);
7
+ strncpy(destination, (const char*)(void*)unmanagedString, destinationSize);
8
+ Marshal::FreeHGlobal(unmanagedString);
9
9
  }
10
+
11
+ char* StringHelper::UnmanagedStringFrom(String^ source)
12
+ {
13
+ const int numberOfBytes = source->Length + 1;
14
+ auto unmanagedString = new char[numberOfBytes];
15
+ CopyToUnmanagedString(source, unmanagedString, numberOfBytes);
16
+ return unmanagedString;
17
+ }
18
+
19
+ void StringHelper::FreeUp(const char* unmanagedStrings[], const int numberOfStrings)
20
+ {
21
+ for(auto whichString = 0; whichString < numberOfStrings; ++whichString) {
22
+ delete[] unmanagedStrings[whichString];
23
+ }
24
+ }
25
+
26
+ void StringHelper::CopyNames(AutomationElementCollection^ automationElements, const char* unmanagedStrings[])
27
+ {
28
+ auto whichItem = 0;
29
+ for each(AutomationElement^ automationElement in automationElements) {
30
+ unmanagedStrings[whichItem++] = UnmanagedStringFrom(automationElement->Current.Name);
31
+ }
32
+ }
33
+
34
+ void StringHelper::CopyClassNames(AutomationElementCollection^ automationElements, const char* unmanagedStrings[])
35
+ {
36
+ auto whichItem = 0;
37
+ for each(AutomationElement^ automationElement in automationElements) {
38
+ unmanagedStrings[whichItem++] = UnmanagedStringFrom(automationElement->Current.ClassName);
39
+ }
40
+ }
@@ -1,7 +1,13 @@
1
1
  #pragma once
2
+ using namespace System::Windows::Automation;
3
+
2
4
  ref class StringHelper
3
5
  {
4
6
  public:
5
7
  static void CopyToUnmanagedString(String^ source, char* destination, const int destinationSize);
8
+ static char* UnmanagedStringFrom(String^ source);
9
+ static void FreeUp(const char* unmanagedStrings[], const int numberOfStrings);
10
+ static void CopyNames(AutomationElementCollection^ automationElements, const char* unmanagedStrings[]);
11
+ static void CopyClassNames(AutomationElementCollection^ automationElements, const char* unmanagedStrings[]);
6
12
  };
7
13
 
@@ -0,0 +1,8 @@
1
+ #include "stdafx.h"
2
+ #include "StringHelper.h"
3
+
4
+ extern "C" {
5
+ __declspec ( dllexport ) void String_CleanUp(const char* strings[], const int numberOfStrings) {
6
+ StringHelper::FreeUp(strings, numberOfStrings);
7
+ }
8
+ }
@@ -0,0 +1,76 @@
1
+ #include "stdafx.h"
2
+ #include "AutomatedTable.h"
3
+
4
+ extern "C" {
5
+
6
+ __declspec ( dllexport ) int Table_GetHeaders(const HWND windowHandle, const char* headers[]) {
7
+ auto tableControl = gcnew AutomatedTable(windowHandle);
8
+ return tableControl->GetHeaders(headers);
9
+ }
10
+
11
+ __declspec ( dllexport ) int Table_GetValues(const HWND windowHandle, const char* values[]) {
12
+ auto tableControl = gcnew AutomatedTable(windowHandle);
13
+ return tableControl->GetValues(values);
14
+ }
15
+
16
+ __declspec ( dllexport ) int Table_FindValues(const FindInformation& findInformation, const char* values[]) {
17
+ auto tableControl = gcnew AutomatedTable(findInformation);
18
+ return tableControl->GetValues(values);
19
+ }
20
+
21
+ __declspec ( dllexport ) int Table_RowCount(const HWND windowHandle) {
22
+ try {
23
+ auto tableControl = gcnew AutomatedTable(windowHandle);
24
+ return tableControl->RowCount;
25
+ } catch(Exception^ e) {
26
+ Console::WriteLine(e->ToString());
27
+ }
28
+ }
29
+
30
+ __declspec ( dllexport ) bool Table_CoordinateIsValid(const HWND windowHandle, const int whichItemIndex, const int whichColumnIndex) {
31
+ try {
32
+ auto tableControl = gcnew AutomatedTable(windowHandle);
33
+ return tableControl->Exists(whichItemIndex, whichColumnIndex);
34
+ } catch(Exception^ e) {
35
+ Console::WriteLine(e->ToString());
36
+ return false;
37
+ }
38
+ }
39
+
40
+ __declspec ( dllexport ) void Table_ValueAt(const HWND windowHandle, const int row, const int column, char *foundValue, const int foundValueLength) {
41
+ try {
42
+ auto tableControl = gcnew AutomatedTable(windowHandle);
43
+ auto rowValue = tableControl->ValueAt(row, column);
44
+ StringHelper::CopyToUnmanagedString(rowValue, foundValue, foundValueLength);
45
+ } catch(Exception^ e) {
46
+ Console::WriteLine(e->ToString());
47
+ }
48
+ }
49
+
50
+ __declspec ( dllexport ) void Table_SelectByIndex(const HWND windowHandle, const int dataItemIndex) {
51
+ try {
52
+ auto tableControl = gcnew AutomatedTable(windowHandle);
53
+ tableControl->Select(dataItemIndex);
54
+ } catch(Exception^ e) {
55
+ Console::WriteLine(e->ToString());
56
+ }
57
+ }
58
+
59
+ __declspec ( dllexport ) bool Table_IsSelectedByIndex(const HWND windowHandle, const int dataItemIndex) {
60
+ try {
61
+ auto tableControl = gcnew AutomatedTable(windowHandle);
62
+ return tableControl->IsSelected(dataItemIndex);
63
+ } catch(Exception^ e) {
64
+ Console::WriteLine(e->ToString());
65
+ }
66
+ }
67
+
68
+ __declspec ( dllexport ) void Table_SelectByValue(const HWND windowHandle, const char* dataItemValue) {
69
+ try {
70
+ auto tableControl = gcnew AutomatedTable(windowHandle);
71
+ tableControl->Select(dataItemValue);
72
+ } catch(Exception^ e) {
73
+ Console::WriteLine(e->ToString());
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,2 @@
1
+ #include "StdAfx.h"
2
+ #include "Toggle.h"
@@ -0,0 +1,22 @@
1
+ #pragma once
2
+ #include "AutomationControl.h"
3
+
4
+ ref class Toggle : public AutomationControl
5
+ {
6
+ public:
7
+ Toggle(const HWND windowHandle) : AutomationControl(windowHandle) {}
8
+ Toggle(const FindInformation& findInformation) : AutomationControl(findInformation) {}
9
+
10
+ property bool IsSet {
11
+ bool get() { return AsTogglePattern->Current.ToggleState == System::Windows::Automation::ToggleState::On; }
12
+ }
13
+
14
+ private:
15
+ property TogglePattern^ AsTogglePattern {
16
+ TogglePattern^ get() {
17
+ return dynamic_cast<TogglePattern^>(_control->GetCurrentPattern(TogglePattern::Pattern));
18
+ }
19
+ }
20
+
21
+ };
22
+
@@ -2,77 +2,90 @@
2
2
  //
3
3
 
4
4
  #include "stdafx.h"
5
- #include "AutomatedComboBox.h"
6
- #include "AutomatedTable.h"
7
5
  #include "AutomationClicker.h"
6
+ #include "AutomationControl.h"
7
+ #include "AutomationFinder.h"
8
8
  #include "ExpandCollapseHelper.h"
9
- #include "MenuItemSelector.h"
10
- #include "ToggleStateHelper.h"
9
+ #include "StringHelper.h"
10
+ #include "SelectionItem.h"
11
+ #include "Toggle.h"
11
12
 
12
13
  IUIAutomation* getGlobalIUIAutomation() ;
13
14
 
14
-
15
- BOOL MenuItemExists(const HWND windowHandle, std::list<const char*>& menuItems);
16
- void SelectMenuItem(const HWND windowHandle, char* errorInfo, const int errorInfoSize, std::list<const char*>& menuItems);
17
- int McppHowManyDataItemsFor(const HWND windowHandle);
18
-
19
15
  extern "C" {
20
- __declspec( dllexport ) IUIAutomationElement *RA_FindWindow(char *pszAutomationId) {
21
- IUIAutomationElement *pRootElement ;
22
-
23
- HRESULT hr = getGlobalIUIAutomation()->GetRootElement(&pRootElement) ;
24
- if (SUCCEEDED(hr)) {
25
- IUIAutomationCondition *pCondition ;
26
- VARIANT varProperty ;
27
-
28
- VariantInit(&varProperty) ;
29
- varProperty.vt = VT_BSTR ;
30
- varProperty.bstrVal = _bstr_t(pszAutomationId) ;
31
16
 
32
- hr = getGlobalIUIAutomation()->CreatePropertyCondition(UIA_AutomationIdPropertyId, varProperty, &pCondition) ;
33
- if (SUCCEEDED(hr)) {
34
- IUIAutomationElement *pFound ;
35
-
36
- hr = pRootElement->FindFirst(TreeScope_Children, pCondition, &pFound) ;
37
- if (SUCCEEDED(hr)) {
38
- return pFound ;
39
- }
40
- }
17
+ __declspec ( dllexport ) bool ElementExists(const FindInformation& findInformation) {
18
+ auto automationElement = gcnew AutomationControl(findInformation);
19
+ return automationElement->Exists;
20
+ }
21
+
22
+ __declspec ( dllexport ) int BoundingRectangle(const FindInformation& findInformation, long *rectangle) {
23
+ try {
24
+ auto automationElement = gcnew AutomationControl(findInformation);
25
+ auto boundary = automationElement->BoundingRectangle;
26
+
27
+ rectangle[0] = boundary.Left;
28
+ rectangle[1] = boundary.Top;
29
+ rectangle[2] = boundary.Right;
30
+ rectangle[3] = boundary.Bottom;
31
+ return 1;
32
+ }
33
+ catch(Exception^ e) {
34
+ Console::WriteLine("BoundingRectangle: {0}", e->Message);
35
+ return 0;
36
+ }
37
+ }
38
+
39
+ __declspec ( dllexport ) int ControlType(const FindInformation& findInformation) {
40
+ try {
41
+ auto automationElement = gcnew AutomationControl(findInformation);
42
+ return automationElement->ControlType->Id;
43
+ } catch(Exception^ e) {
44
+ Console::WriteLine("ControlType: {0}", e->Message);
45
+ return 0;
46
+ }
47
+ }
48
+
49
+ __declspec ( dllexport ) int ProcessId(const FindInformation& findInformation) {
50
+ try {
51
+ auto automationElement = gcnew AutomationControl(findInformation);
52
+ return automationElement->ProcessId;
53
+ } catch(Exception^ e) {
54
+ Console::WriteLine("ProcessId: {0}", e->Message);
55
+ return 0;
56
+ }
57
+ }
58
+
59
+ __declspec ( dllexport ) void Name(const FindInformation& findInformation, char* name, const int nameLength) {
60
+ try {
61
+ auto control = gcnew AutomationControl(findInformation);
62
+ StringHelper::CopyToUnmanagedString(control->Name, name, nameLength);
63
+ } catch(Exception^ e) {
64
+ Console::WriteLine("Name: {0}", e->Message);
41
65
  }
42
- return NULL ;
43
- }
66
+ }
44
67
 
45
- //This doesn't work
46
- __declspec( dllexport ) int RA_FindWindowByPID(int processId, IUIAutomationElement *pElement) {
47
- IUIAutomationElement *pRootElement;
68
+ __declspec ( dllexport ) void ClassName(const FindInformation& findInformation, char* className, const int classNameLength) {
69
+ try {
70
+ auto control = gcnew AutomationControl(findInformation);
71
+ StringHelper::CopyToUnmanagedString(control->ClassName, className, classNameLength);
72
+ } catch(Exception^ e) {
73
+ Console::WriteLine("ClassName: {0}", e->Message);
74
+ }
75
+ }
48
76
 
49
- HRESULT hr = getGlobalIUIAutomation()->GetRootElement(&pRootElement);
50
- if (SUCCEEDED(hr)) {
51
- IUIAutomationCondition *pCondition;
52
- VARIANT varProperty;
77
+ __declspec ( dllexport ) int GetClassNames(const FindInformation& findInformation, const char* classNames[]) {
78
+ auto control = gcnew AutomationControl(findInformation);
79
+ auto finder = gcnew AutomationFinder(control->Element);
53
80
 
54
- VariantInit(&varProperty);
55
- varProperty.vt = VT_I4;
56
- varProperty.intVal = (processId);
81
+ auto allChildren = finder->Find();
57
82
 
58
- hr = getGlobalIUIAutomation()->CreatePropertyCondition(UIA_ProcessIdPropertyId, varProperty, &pCondition);
59
- if (SUCCEEDED(hr)) {
83
+ if( NULL != classNames ) {
84
+ StringHelper::CopyClassNames(allChildren, classNames);
85
+ }
60
86
 
61
- hr = pRootElement->FindFirst(TreeScope_Children, pCondition, &pElement);
62
- if (SUCCEEDED(hr)) {
63
- return 1;
64
- }
65
- }
66
- }
67
- return 0;
68
- }
69
-
70
- __declspec( dllexport ) BOOL RA_IsOffscreen(IUIAutomationElement *pElement) {
71
- BOOL isOffscreen ;
72
- pElement->get_CurrentIsOffscreen(&isOffscreen) ;
73
-
74
- return isOffscreen ;
75
- }
87
+ return allChildren->Count;
88
+ }
76
89
 
77
90
  __declspec ( dllexport ) IUIAutomationElement *RA_ElementFromHandle(HWND hwnd) {
78
91
  IUIAutomationElement *pElement ;
@@ -86,19 +99,6 @@ extern "C" {
86
99
  }
87
100
  }
88
101
 
89
- __declspec ( dllexport ) IUIAutomationElement *RA_GetFocusedElement() {
90
- IUIAutomationElement *pelement;
91
-
92
- HRESULT hr = getGlobalIUIAutomation()->GetFocusedElement(&pelement);
93
-
94
- if (SUCCEEDED(hr))
95
- return pelement;
96
- else {
97
- printf("RA_GetFocusedElement: Cannot find element from focus. HRESULT was 0x%x\r\n", hr) ;
98
- return false ;
99
- }
100
- }
101
-
102
102
  __declspec ( dllexport ) IUIAutomationElement *RA_ElementFromPoint(int xCoord, int yCoord) {
103
103
  IUIAutomationElement *pElement ;
104
104
  POINT point;
@@ -143,34 +143,6 @@ extern "C" {
143
143
  }
144
144
  }
145
145
 
146
- __declspec ( dllexport ) IUIAutomationElement *RA_FindChildByName(IUIAutomationElement *pElement, char *elementName) {
147
- IUIAutomationCondition *pCondition ;
148
- VARIANT varProperty ;
149
-
150
- VariantInit(&varProperty) ;
151
- varProperty.vt = VT_BSTR ;
152
- varProperty.bstrVal = _bstr_t(elementName) ;
153
-
154
- HRESULT hr = getGlobalIUIAutomation()->CreatePropertyCondition(UIA_NamePropertyId, varProperty, &pCondition) ;
155
- if (SUCCEEDED(hr)) {
156
- IUIAutomationElement *pFound ;
157
-
158
- hr = pElement->FindFirst(TreeScope_Descendants, pCondition, &pFound) ;
159
- if (SUCCEEDED(hr)) {
160
- if (pFound == NULL)
161
- printf("RA_FindChildByName: Element with automation name %s was not found\r\n", elementName) ;
162
- //printf("RA_FindChildByName: success with value %s\r\n", elementName) ;
163
- return pFound ;
164
- } else {
165
- printf("RA_FindChildByName: FindFirst for children looking for %s failed. hr = 0x%x\r\n", elementName, hr) ;
166
- return NULL ;
167
- }
168
- } else {
169
- printf("RA_FindChildByName: Cannot create search condition. hr = 0x%x\r\n", hr) ;
170
- return NULL ;
171
- }
172
- }
173
-
174
146
  __declspec ( dllexport ) HWND RA_CurrentNativeWindowHandle(IUIAutomationElement *pElement) {
175
147
  UIA_HWND uia_hwnd ;
176
148
 
@@ -183,21 +155,6 @@ extern "C" {
183
155
  return (HWND)uia_hwnd ;
184
156
  }
185
157
 
186
- __declspec ( dllexport ) int RA_GetCurrentProcessId(IUIAutomationElement *pElement) {
187
- HRESULT hr;
188
- int process_id;
189
-
190
- hr = pElement->get_CurrentProcessId(&process_id);
191
-
192
- if (SUCCEEDED(hr)){
193
- return process_id;
194
- }
195
- else {
196
- printf("RA_GetCurrentProcessId: get_CurrentProcessId returned 0x%x\r\n", hr) ;
197
- return 0 ;
198
- }
199
- }
200
-
201
158
  __declspec ( dllexport ) BOOL RA_SetFocus(IUIAutomationElement *pElement) {
202
159
  HRESULT hr = pElement->SetFocus() ;
203
160
  if (hr != S_OK)
@@ -228,29 +185,6 @@ extern "C" {
228
185
  return SetCursorPos(x,y);
229
186
  }
230
187
 
231
- __declspec ( dllexport ) long RA_GetDesktopHandle() {
232
- return (long)GetDesktopWindow();
233
- }
234
-
235
- __declspec ( dllexport ) int RA_CurrentBoundingRectangle(IUIAutomationElement *pElement, long *rectangle) {
236
- RECT boundary;
237
-
238
- HRESULT hr = pElement->get_CurrentBoundingRectangle(&boundary) ;
239
- if (SUCCEEDED(hr)) {
240
-
241
- rectangle[0] = boundary.left;
242
- rectangle[1] = boundary.top;
243
- rectangle[2] = boundary.right;
244
- rectangle[3] = boundary.bottom;
245
-
246
- return 1;
247
- }
248
- else {
249
- printf("RA_CurrentBoundingRectangle: get_CurrentBoundingRectangle failed 0x%x\r\n", hr) ;
250
- return 0 ;
251
- }
252
- }
253
-
254
188
  __declspec ( dllexport ) int RA_CurrentIsOffscreen(IUIAutomationElement *pElement, int *visible) {
255
189
  BOOL offscreen;
256
190
 
@@ -311,74 +245,35 @@ extern "C" {
311
245
  return element_count ;
312
246
  }
313
247
 
314
- __declspec ( dllexport ) int RA_GetName(IUIAutomationElement *pElement, char *pName) {
315
- BSTR bstrName ;
316
- HRESULT hr = pElement->get_CurrentName(&bstrName) ;
317
-
318
- if (FAILED(hr)) {
319
- printf("RA_GetName: get_CurrentName failed 0x%x\r\n", hr) ;
320
- return -1 ;
321
- }
322
-
323
- char *pszName = _com_util::ConvertBSTRToString(bstrName) ;
324
-
325
- if (pszName != NULL){
326
- if (pName == NULL) {
327
- return strlen(pszName) ;
328
- } else {
329
- strcpy(pName, pszName) ;
330
- return strlen(pszName) ;
331
- }
332
- } else {
333
- return -1;
334
- }
335
- }
336
-
337
- __declspec ( dllexport ) int RA_GetClassName(IUIAutomationElement *pElement, char *pClass) {
338
- BSTR bstrClass ;
339
- HRESULT hr = pElement->get_CurrentClassName(&bstrClass) ;
340
-
341
- if (FAILED(hr)) {
342
- printf("RA_GetName: get_CurrentClassName failed 0x%x\r\n", hr) ;
343
- return -1 ;
344
- }
345
-
346
- char *pszClass = _com_util::ConvertBSTRToString(bstrClass) ;
347
-
348
- if (pszClass != NULL){
349
- if (pClass == NULL) {
350
- return strlen(pszClass) ;
351
- } else {
352
- strcpy(pClass, pszClass) ;
353
- return strlen(pszClass) ;
354
- }
355
- } else {
356
- return -1;
248
+ __declspec ( dllexport ) bool RA_GetControlName(const HWND windowHandle, char* windowName, const int windowNameLength) {
249
+ try {
250
+ auto control = gcnew AutomationControl(windowHandle);
251
+ StringHelper::CopyToUnmanagedString(control->Name, windowName, windowNameLength);
252
+ return true;
253
+ } catch(Exception^ e) {
254
+ return false;
357
255
  }
358
256
  }
359
257
 
360
- __declspec ( dllexport ) BOOL RA_GetIsSet(IUIAutomationElement *pElement) {
361
- return ToggleStateHelper().IsSet(pElement);
362
- }
258
+ __declspec ( dllexport ) bool IsSet(const FindInformation& findInformation) {
259
+ try {
260
+ auto toggle = gcnew Toggle(findInformation);
261
+ return toggle->IsSet;
262
+ } catch(Exception^ e) {
263
+ Debug::WriteLine("IsSet: {0}", e->Message);
264
+ return false;
265
+ }
266
+ }
363
267
 
364
- __declspec ( dllexport ) BOOL RA_GetIsSelected(IUIAutomationElement *pElement) {
365
- ISelectionItemProvider *pSelectionPattern ;
366
- HRESULT hr = pElement->GetCurrentPattern(UIA_SelectionItemPatternId, (IUnknown**)&pSelectionPattern) ;
367
-
368
- if (FAILED(hr)) {
369
- printf("RA_GetIsSelected: getCurrentPattern failed 0x%x\r\n") ;
370
- return FALSE ;
371
- }
372
-
373
- BOOL RetVal ;
374
- hr = pSelectionPattern->get_IsSelected(&RetVal) ;
375
- if (FAILED(hr)) {
376
- printf("RA_GetIsSelected: get_IsSelected failed 0x%x\r\n", hr) ;
377
- return FALSE ;
378
- } else {
379
- return RetVal ;
380
- }
381
- }
268
+ __declspec ( dllexport ) bool IsSelected(const FindInformation& findInformation) {
269
+ try {
270
+ auto selectionItem = gcnew SelectionItem(findInformation);
271
+ return selectionItem->IsSelected;
272
+ } catch(Exception^ e) {
273
+ Debug::WriteLine("IsSelected: {0}", e->Message);
274
+ return false;
275
+ }
276
+ }
382
277
 
383
278
  __declspec ( dllexport ) int RA_Select(IUIAutomationElement *pElement) {
384
279
  ISelectionItemProvider *pSelectionPattern ;
@@ -419,114 +314,6 @@ extern "C" {
419
314
  }
420
315
  }
421
316
 
422
- __declspec ( dllexport ) int RA_GetComboOptionsCount(const HWND windowHandle) {
423
- auto autoComboBox = gcnew AutomatedComboBox(windowHandle);
424
- return autoComboBox->Count;
425
- }
426
-
427
- __declspec ( dllexport ) int RA_GetSelectedComboIndex(const HWND windowHandle) {
428
- auto autoComboBox = gcnew AutomatedComboBox(windowHandle);
429
- return autoComboBox->SelectedIndex;
430
- }
431
-
432
- __declspec ( dllexport ) bool RA_GetComboValueByIndex(const HWND windowHandle, const int whichItem, char* comboValue, const int comboValueSize) {
433
- auto autoComboBox = gcnew AutomatedComboBox(windowHandle);
434
- return autoComboBox->GetValueByIndex(whichItem, comboValue, comboValueSize);
435
- }
436
-
437
- __declspec ( dllexport ) bool RA_SelectComboByIndex(const HWND windowHandle, const int whichItem) {
438
- auto autoComboBox = gcnew AutomatedComboBox(windowHandle);
439
- return autoComboBox->SelectByIndex(whichItem);
440
- }
441
-
442
- __declspec ( dllexport ) int RA_SelectComboByValue(IUIAutomationElement *pElement, char *pValue) {
443
- UIA_HWND windowHandle = 0;
444
- pElement->get_CurrentNativeWindowHandle(&windowHandle);
445
-
446
- auto autoComboBox = gcnew AutomatedComboBox((const HWND) windowHandle);
447
- return autoComboBox->SelectByValue(pValue);
448
- }
449
-
450
- __declspec ( dllexport ) void RA_SelectMenuItem(const HWND windowHandle, char* errorInfo, const int errorInfoSize, const char* arg0, ...) {
451
- va_list arguments;
452
- va_start(arguments, arg0);
453
-
454
- std::list<const char*> menuItems;
455
-
456
- const char* lastArgument = arg0;
457
- while( NULL != lastArgument ) {
458
- menuItems.push_back(lastArgument);
459
- lastArgument = va_arg(arguments, const char*);
460
- }
461
- va_end(arguments);
462
-
463
- SelectMenuItem(windowHandle, errorInfo, errorInfoSize, menuItems);
464
- }
465
-
466
- __declspec ( dllexport ) BOOL RA_MenuItemExists(const HWND windowHandle, const char* arg0, ...) {
467
- va_list arguments;
468
- va_start(arguments, arg0);
469
-
470
- std::list<const char*> menuItems;
471
-
472
- const char* lastArgument = arg0;
473
- while( NULL != lastArgument ) {
474
- menuItems.push_back(lastArgument);
475
- lastArgument = va_arg(arguments, const char*);
476
- }
477
- va_end(arguments);
478
-
479
- return MenuItemExists(windowHandle, menuItems);
480
- }
481
-
482
- __declspec ( dllexport ) int RA_GetDataItemCount(const HWND windowHandle) {
483
- try {
484
- auto tableControl = gcnew AutomatedTable(windowHandle);
485
- return tableControl->RowCount;
486
- } catch(Exception^ e) {
487
- Console::WriteLine(e->ToString());
488
- }
489
- }
490
-
491
- __declspec ( dllexport ) bool RA_DataItemExistsByValue(const HWND windowHandle, const char* whichItem) {
492
- try {
493
- auto tableControl = gcnew AutomatedTable(windowHandle);
494
- return tableControl->Exists(whichItem);
495
- } catch(Exception^ e) {
496
- Console::WriteLine(e->ToString());
497
- return false;
498
- }
499
- }
500
-
501
- __declspec ( dllexport ) bool RA_DataItemExists(const HWND windowHandle, const int whichItemIndex, const int whichColumnIndex) {
502
- try {
503
- auto tableControl = gcnew AutomatedTable(windowHandle);
504
- return tableControl->Exists(whichItemIndex, whichColumnIndex);
505
- } catch(Exception^ e) {
506
- Console::WriteLine(e->ToString());
507
- return false;
508
- }
509
- }
510
-
511
- __declspec ( dllexport ) void RA_CellValueAt(const HWND windowHandle, const int row, const int column, char *foundValue, const int foundValueLength) {
512
- try {
513
- auto tableControl = gcnew AutomatedTable(windowHandle);
514
- auto rowValue = tableControl->ValueAt(row, column);
515
- StringHelper::CopyToUnmanagedString(rowValue, foundValue, foundValueLength);
516
- } catch(Exception^ e) {
517
- Console::WriteLine(e->ToString());
518
- }
519
- }
520
-
521
- __declspec ( dllexport ) void RA_SelectDataItem(const HWND windowHandle, const int dataItemIndex) {
522
- try {
523
- auto tableControl = gcnew AutomatedTable(windowHandle);
524
- tableControl->Select(dataItemIndex);
525
- } catch(Exception^ e) {
526
- Console::WriteLine(e->ToString());
527
- }
528
- }
529
-
530
317
  __declspec ( dllexport ) void RA_ExpandItemByValue(const HWND windowHandle, const char* whichItem) {
531
318
  try {
532
319
  auto expandCollapseHelper = gcnew ExpandCollapseHelper();
@@ -563,21 +350,3 @@ extern "C" {
563
350
  }
564
351
  }
565
352
  }
566
-
567
- BOOL MenuItemExists(const HWND windowHandle, std::list<const char*>& menuItems)
568
- {
569
- auto menuSelector = gcnew MenuItemSelector();
570
- return menuSelector->MenuItemExists(windowHandle, menuItems);
571
- }
572
-
573
- void SelectMenuItem(const HWND windowHandle, char* errorInfo, const int errorInfoSize, std::list<const char*>& menuItems)
574
- {
575
- try {
576
- auto menuSelector = gcnew MenuItemSelector();
577
- menuSelector->SelectMenuPath(windowHandle, menuItems);
578
- } catch(Exception^ e) {
579
- if( errorInfo ) {
580
- StringHelper::CopyToUnmanagedString(e->ToString(), errorInfo, errorInfoSize);
581
- }
582
- }
583
- }