lib/rautomation/adapter/ms_uia/uia_dll.rb in rautomation-0.9.0 vs lib/rautomation/adapter/ms_uia/uia_dll.rb in rautomation-0.9.1

- old
+ new

@@ -102,16 +102,19 @@ ffi_convention :stdcall # Generic Control methods attach_function :ElementExists, [SearchCriteria.by_ref], :bool attach_function :process_id, :ProcessId, [SearchCriteria.by_ref], :int - attach_function :Control_GetValue, [:long, :pointer, :int], :void - attach_function :set_control_value, :Control_SetValue, [:long, :string], :void + attach_function :Control_GetValue, [SearchCriteria.by_ref, :pointer, :int], :void + attach_function :set_control_value, :Control_SetValue, [SearchCriteria.by_ref, :string], :void attach_function :BoundingRectangle, [SearchCriteria.by_ref, :pointer], :int attach_function :current_control_type, :ControlType, [SearchCriteria.by_ref], :int attach_function :Name, [SearchCriteria.by_ref, :pointer, :int], :void attach_function :ClassName, [SearchCriteria.by_ref, :pointer, :int], :void + attach_function :is_enabled, :IsEnabled, [SearchCriteria.by_ref], :bool + attach_function :is_focused, :IsFocused, [SearchCriteria.by_ref], :bool + attach_function :set_focus, :SetControlFocus, [SearchCriteria.by_ref], :bool attach_function :GetClassNames, [SearchCriteria.by_ref, :pointer], :int def self.exists?(search_information) ElementExists search_information @@ -121,12 +124,12 @@ boundary = FFI::MemoryPointer.new :long, 4 BoundingRectangle search_information, boundary boundary.read_array_of_long(4) end - def self.get_control_value(hwnd) - string_from(:Control_GetValue, hwnd) + def self.get_control_value(search_information) + string_from(:Control_GetValue, search_information) end def self.name(search_information) string_from(:Name, search_information) end @@ -146,21 +149,27 @@ attach_function :is_selected, :IsSelected, [SearchCriteria.by_ref], :bool # Select List methods attach_function :SelectList_Selection, [SearchCriteria.by_ref, :pointer, :int], :void + attach_function :SelectList_Options, + [SearchCriteria.by_ref, :pointer], :int attach_function :select_list_count, :SelectList_Count, [SearchCriteria.by_ref], :int attach_function :select_list_selected_index, :SelectList_SelectedIndex, - [:long], :int + [SearchCriteria.by_ref], :int attach_function :select_list_value_at, :SelectList_ValueAt, - [:long, :int, :pointer, :int], :bool + [SearchCriteria.by_ref, :int, :pointer, :int], :bool attach_function :select_list_select_index, :SelectList_SelectIndex, [SearchCriteria.by_ref, :int], :bool attach_function :select_list_select_value, :SelectList_SelectValue, [SearchCriteria.by_ref, :pointer], :int + def self.select_options(search_information) + strings_from(:SelectList_Options, search_information) + end + def self.selection(search_information) string_from(:SelectList_Selection, search_information) end # Menu methods @@ -169,51 +178,51 @@ attach_function :menu_item_exists, :Menu_ItemExists, [:long, :varargs], :bool # Table methods attach_function :Table_GetHeaders, - [:long, :pointer], :int + [SearchCriteria.by_ref, :pointer], :int attach_function :Table_GetValues, - [:long, :pointer], :int + [SearchCriteria.by_ref, :pointer], :int attach_function :Table_FindValues, [SearchCriteria.by_ref, :pointer], :int attach_function :table_row_count, :Table_RowCount, - [:long], :int + [SearchCriteria.by_ref], :int attach_function :Table_CoordinateIsValid, - [:long, :int, :int], :bool + [SearchCriteria.by_ref, :int, :int], :bool attach_function :Table_ValueAt, - [:long, :int, :int, :pointer, :int], :void + [SearchCriteria.by_ref, :int, :int, :pointer, :int], :void attach_function :Table_SelectByIndex, - [:long, :int], :void + [SearchCriteria.by_ref, :int], :void attach_function :Table_SelectByValue, - [:long, :string], :void + [SearchCriteria.by_ref, :string], :void attach_function :table_row_is_selected, :Table_IsSelectedByIndex, - [:long, :int], :bool + [SearchCriteria.by_ref, :int], :bool - def self.table_select(hwnd, which_item) + def self.table_select(search_information, which_item) case which_item when Integer - Table_SelectByIndex hwnd, which_item + Table_SelectByIndex search_information, which_item when String - Table_SelectByValue hwnd, which_item + Table_SelectByValue search_information, which_item end end - def self.table_value_at(hwnd, row, column=0) - string_from(:Table_ValueAt, hwnd, row, column) + def self.table_value_at(search_information, row, column=0) + string_from(:Table_ValueAt, search_information, row, column) end - def self.table_coordinate_valid?(hwnd, row, column=0) - Table_CoordinateIsValid hwnd, row, column + def self.table_coordinate_valid?(search_information, row, column=0) + Table_CoordinateIsValid search_information, row, column end - def self.table_headers(hwnd) - strings_from :Table_GetHeaders, hwnd + def self.table_headers(search_information) + strings_from :Table_GetHeaders, search_information end - def self.table_values(hwnd) - strings_from :Table_GetValues, hwnd + def self.table_values(search_information) + strings_from :Table_GetValues, search_information end def self.find_table_values(search_information) strings_from :Table_FindValues, search_information end @@ -228,12 +237,10 @@ [:int, :int], :pointer attach_function :find_child_by_id, :RA_FindChildById, [:pointer, :string], :pointer attach_function :current_native_window_handle, :RA_CurrentNativeWindowHandle, [:pointer], :long - attach_function :set_focus, :RA_SetFocus, - [:pointer], :bool attach_function :move_mouse, :RA_MoveMouse, [:int,:int], :long attach_function :click_mouse, :RA_ClickMouse, [], :long attach_function :is_offscreen, :RA_CurrentIsOffscreen, @@ -243,22 +250,26 @@ attach_function :get_control_name, :RA_GetControlName, [:long, :pointer, :int], :bool attach_function :select, :RA_Select, [:pointer], :int attach_function :expand_by_value, :RA_ExpandItemByValue, - [:long, :string], :void + [SearchCriteria.by_ref, :string], :void attach_function :expand_by_index, :RA_ExpandItemByIndex, - [:long, :int], :void + [SearchCriteria.by_ref, :int], :void attach_function :collapse_by_value, :RA_CollapseItemByValue, - [:long, :string], :void + [SearchCriteria.by_ref, :string], :void attach_function :collapse_by_index, :RA_CollapseItemByIndex, - [:long, :int], :void - attach_function :control_click, :RA_Click, - [:long, :pointer, :int], :void + [SearchCriteria.by_ref, :int], :void + attach_function :RA_Click, + [SearchCriteria.by_ref, :pointer, :int], :void attach_function :control_mouse_click, :RA_PointAndClick, [:long, :pointer, :int], :void + def self.control_click(search_information) + can_throw(:RA_Click, search_information) + end + private def self.strings_from(method, hwnd) string_count = send method, hwnd, nil pointer = FFI::MemoryPointer.new :pointer, string_count send method, hwnd, pointer @@ -269,9 +280,17 @@ def self.string_from(method, *args) pointer = FFI::MemoryPointer.new :pointer, 1024 send method, *(args << pointer << 1024) pointer.read_string + end + + def self.can_throw(method, *args) + string_buffer = FFI::MemoryPointer.new :char, 1024 + send method, *(args << string_buffer << 1024) + error_info = string_buffer.read_string + raise error_info unless error_info.empty? + true end end end end end