Skip to content

UIAutomation: ITransformPattern2 #10953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
//
//
// Description: Transform pattern provider wrapper for WCP
//
//

using System;
using System.Windows.Threading;
using System.Windows.Media;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Windows.Automation.Peers;

namespace MS.Internal.Automation
{
// Automation/WCP Wrapper class: Implements that UIAutomation I...Provider
// interface, and calls through to a WCP AutomationPeer which implements the corresponding
// I...Provider inteface. Marshalls the call from the RPC thread onto the
// target AutomationPeer's context.
//
// Class has two major parts to it:
// * Implementation of the I...Provider, which uses Dispatcher.Invoke
// to call a private method (lives in second half of the class) via a delegate,
// if necessary, packages any params into an object param. Return type of Invoke
// must be cast from object to appropriate type.
// * private methods - one for each interface entry point - which get called back
// on the right context. These call through to the peer that's actually
// implenting the I...Provider version of the interface.
internal class TransformProvider2Wrapper: TransformProviderWrapper, ITransformProvider2
{
//------------------------------------------------------
//
// Constructors
//
//------------------------------------------------------

#region Constructors

private TransformProvider2Wrapper( AutomationPeer peer, ITransformProvider2 iface ) : base(peer, iface)
{
_peer = peer;
_iface = iface;
}

#endregion Constructors


//------------------------------------------------------
//
// Interface IWindowProvider
//
//------------------------------------------------------

#region Interface ITransformProvider2


public void Zoom( double zoomAmount )
{
ElementUtil.Invoke( _peer, new DispatcherOperationCallback( Zoom ), zoomAmount );
}

public void ZoomByUnit( ZoomUnit zoomUnit )
{
ElementUtil.Invoke( _peer, new DispatcherOperationCallback( ZoomByUnit ), zoomUnit );
}

public bool CanZoom
{
get
{
return (bool) ElementUtil.Invoke( _peer, new DispatcherOperationCallback( GetCanZoom ), null );
}
}

public double ZoomLevel
{
get
{
return (double) ElementUtil.Invoke( _peer, new DispatcherOperationCallback( GetZoomLevel ), null );
}
}

public double ZoomMinimum
{
get
{
return (double) ElementUtil.Invoke( _peer, new DispatcherOperationCallback(GetZoomMinimum ), null );
}
}


public double ZoomMaximum
{
get
{
return (double)ElementUtil.Invoke(_peer, new DispatcherOperationCallback(GetZoomMaximum), null);
}
}

#endregion Interface ITransformProvider2


//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------

#region Internal Methods

internal static new object Wrap( AutomationPeer peer, object iface )
{
return new TransformProvider2Wrapper( peer, (ITransformProvider2) iface );
}

#endregion Internal Methods

//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------

#region Private Methods

private object Zoom( object arg )
{
_iface.Zoom( (double)arg );
return null;
}

private object ZoomByUnit( object arg )
{
_iface.ZoomByUnit( (ZoomUnit)arg );
return null;
}

private object GetCanZoom( object unused )
{
return _iface.CanZoom;
}

private object GetZoomLevel( object unused )
{
return _iface.ZoomLevel;
}

private object GetZoomMinimum( object unused )
{
return _iface.ZoomMinimum;
}

private object GetZoomMaximum(object unused)
{
return _iface.ZoomMaximum;
}

#endregion Private Methods


//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------

#region Private Fields

private AutomationPeer _peer;
private ITransformProvider2 _iface;

#endregion Private Fields
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class TransformProviderWrapper: MarshalByRefObject, ITransformProvider

#region Constructors

private TransformProviderWrapper( AutomationPeer peer, ITransformProvider iface )
private protected TransformProviderWrapper( AutomationPeer peer, ITransformProvider iface )
{
_peer = peer;
_iface = iface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<Compile Include="MS\Internal\Automation\TextRangeProviderWrapper.cs" />
<Compile Include="MS\Internal\Automation\ToggleProviderWrapper.cs" />
<Compile Include="MS\Internal\Automation\TransformProviderWrapper.cs" />
<Compile Include="MS\Internal\Automation\TransformProvider2Wrapper.cs" />
<Compile Include="MS\Internal\Automation\ValueProviderWrapper.cs" />
<Compile Include="MS\Internal\Automation\VirtualizedItemProviderWrapper.cs" />
<Compile Include="MS\Internal\Automation\WindowProviderWrapper.cs" />
Expand Down Expand Up @@ -706,7 +707,7 @@
<Compile Include="System\Windows\Media\ColorContextHelper.cs" />
<Compile Include="System\Windows\Media\ColorConverter.cs" />
<Compile Include="System\Windows\Media\ColorTransform.cs" />
<Compile Include="System\Windows\Media\ColorTransformHelper.cs" />
<Compile Include="System\Windows\Media\ColorTransformHelper.cs" />
<Compile Include="System\Windows\Media\CombinedGeometry.cs" />
<Compile Include="System\Windows\Media\Composition.cs" />
<Compile Include="System\Windows\Media\CompositionTarget.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public enum PatternInterface
VirtualizedItem,
///
SynchronizedInput,
///
Transform2
}

///
Expand Down Expand Up @@ -2379,6 +2381,7 @@ private static void Initialize()
s_patternInfo[TableItemPatternIdentifiers.Pattern.Id] = new PatternInfo(TableItemPatternIdentifiers.Pattern.Id, new WrapObject(TableItemProviderWrapper.Wrap), PatternInterface.TableItem);
s_patternInfo[TogglePatternIdentifiers.Pattern.Id] = new PatternInfo(TogglePatternIdentifiers.Pattern.Id, new WrapObject(ToggleProviderWrapper.Wrap), PatternInterface.Toggle);
s_patternInfo[TransformPatternIdentifiers.Pattern.Id] = new PatternInfo(TransformPatternIdentifiers.Pattern.Id, new WrapObject(TransformProviderWrapper.Wrap), PatternInterface.Transform);
s_patternInfo[TransformPattern2Identifiers.Pattern.Id] = new PatternInfo(TransformPattern2Identifiers.Pattern.Id, new WrapObject(TransformProvider2Wrapper.Wrap), PatternInterface.Transform2);
s_patternInfo[TextPatternIdentifiers.Pattern.Id] = new PatternInfo(TextPatternIdentifiers.Pattern.Id, new WrapObject(TextProviderWrapper.Wrap), PatternInterface.Text);

// To avoid the worst situation on legacy systems which may not have new unmanaged core. with this change with old unmanaged core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2471,6 +2471,7 @@ public enum PatternInterface
ItemContainer = 18,
VirtualizedItem = 19,
SynchronizedInput = 20,
Transform2 = 21
}
public partial class UIElement3DAutomationPeer : System.Windows.Automation.Peers.AutomationPeer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ private static object ConvertToAutomationHeadingLevel(object value)
new AutomationPropertyInfo( convertToBool, AutomationElement.IsTextPatternAvailableProperty, typeof(bool), false ),
new AutomationPropertyInfo( convertToBool, AutomationElement.IsTogglePatternAvailableProperty, typeof(bool), false ),
new AutomationPropertyInfo( convertToBool, AutomationElement.IsTransformPatternAvailableProperty, typeof(bool), false ),
new AutomationPropertyInfo( convertToBool, AutomationElement.IsTransformPattern2AvailableProperty, typeof(bool), false ),
new AutomationPropertyInfo( convertToBool, AutomationElement.IsValuePatternAvailableProperty, typeof(bool), false ),
new AutomationPropertyInfo( convertToBool, AutomationElement.IsWindowPatternAvailableProperty, typeof(bool), false ),

Expand Down Expand Up @@ -369,6 +370,11 @@ private static object ConvertToAutomationHeadingLevel(object value)
new AutomationPropertyInfo( convertToBool, TransformPattern.CanMoveProperty, typeof(bool), false ),
new AutomationPropertyInfo( convertToBool, TransformPattern.CanResizeProperty, typeof(bool), false ),
new AutomationPropertyInfo( convertToBool, TransformPattern.CanRotateProperty, typeof(bool), false ),
new AutomationPropertyInfo( convertToBool, TransformPattern2.CanZoomProperty, typeof(bool), false ),
new AutomationPropertyInfo( null, TransformPattern2.ZoomLevelProperty, typeof(double), (double)0 ),
new AutomationPropertyInfo( null, TransformPattern2.ZoomMinimumProperty, typeof(double), (double)0 ),
new AutomationPropertyInfo( null, TransformPattern2.ZoomMaximumProperty, typeof(double), (double)0 ),

};

// Basic properties assumed to be always supported
Expand Down Expand Up @@ -463,6 +469,13 @@ private static object ConvertToAutomationHeadingLevel(object value)
private static readonly AutomationProperty [ ] TransformProperties = { TransformPattern.CanMoveProperty,
TransformPattern.CanResizeProperty,
TransformPattern.CanRotateProperty};


private static readonly AutomationProperty[] Transform2Properties = { TransformPattern2.CanZoomProperty,
TransformPattern2.ZoomLevelProperty,
TransformPattern2.ZoomMinimumProperty,
TransformPattern2.ZoomMaximumProperty};

private static readonly AutomationPatternInfo [ ] _patternInfoTable =
{
new AutomationPatternInfo( InvokePattern.Pattern, null, new WrapObjectClientSide(InvokePattern.Wrap) ),
Expand All @@ -481,7 +494,8 @@ private static object ConvertToAutomationHeadingLevel(object value)
new AutomationPatternInfo( TableItemPattern.Pattern, TableItemProperties, new WrapObjectClientSide(TableItemPattern.Wrap) ),
new AutomationPatternInfo( TextPattern.Pattern, null, new WrapObjectClientSide(TextPattern.Wrap) ),
new AutomationPatternInfo( TogglePattern.Pattern, ToggleProperties, new WrapObjectClientSide(TogglePattern.Wrap) ),
new AutomationPatternInfo( TransformPattern.Pattern, TransformProperties, new WrapObjectClientSide(TransformPattern.Wrap) ),
new AutomationPatternInfo( TransformPattern.Pattern, TransformProperties, new WrapObjectClientSide(TransformPattern.Wrap) ),
new AutomationPatternInfo( TransformPattern2.Pattern, Transform2Properties, new WrapObjectClientSide(TransformPattern2.Wrap) ),
new AutomationPatternInfo( ScrollItemPattern.Pattern, null, new WrapObjectClientSide(ScrollItemPattern.Wrap) ),
new AutomationPatternInfo( SynchronizedInputPattern.Pattern, null, new WrapObjectClientSide(SynchronizedInputPattern.Wrap) ),
new AutomationPatternInfo( VirtualizedItemPattern.Pattern, null, new WrapObjectClientSide(VirtualizedItemPattern.Wrap)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,16 @@ internal static void TransformPattern_Rotate(SafePatternHandle hobj, double degr
CheckError(RawTransformPattern_Rotate(hobj, degrees));
}

internal static void TransformPattern2_Zoom(SafePatternHandle hobj, double zoomValue)
{
CheckError(RawTransformPattern2_Zoom(hobj, zoomValue));
}

internal static void TransformPattern2_ZoomByUnit(SafePatternHandle hobj, ZoomUnit zoomUnit)
{
CheckError(RawTransformPattern2_ZoomByUnit(hobj, zoomUnit));
}

internal static void ValuePattern_SetValue(SafePatternHandle hobj, string pVal)
{
CheckError(RawValuePattern_SetValue(hobj, pVal));
Expand Down Expand Up @@ -1337,6 +1347,12 @@ private static void CheckError(int hr)
[DllImport(DllImport.UIAutomationCore, EntryPoint = "TransformPattern_Rotate", CharSet = CharSet.Unicode)]
private static extern int RawTransformPattern_Rotate(SafePatternHandle hobj, double degrees);

[DllImport(DllImport.UIAutomationCore, EntryPoint = "TransformPattern2_Zoom", CharSet = CharSet.Unicode)]
private static extern int RawTransformPattern2_Zoom(SafePatternHandle hobj, double degrees); // TODO: Needs to use Microsoft UI Automation Component Object Model (COM) interfaces instead.

[DllImport(DllImport.UIAutomationCore, EntryPoint = "TransformPattern2_ZoomByUnit", CharSet = CharSet.Unicode)]
private static extern int RawTransformPattern2_ZoomByUnit(SafePatternHandle hobj, ZoomUnit unit); // TODO: Needs to use Microsoft UI Automation Component Object Model (COM) interfaces instead.

[DllImport(DllImport.UIAutomationCore, EntryPoint = "ValuePattern_SetValue", CharSet = CharSet.Unicode)]
private static extern int RawValuePattern_SetValue(SafePatternHandle hobj, [MarshalAs(UnmanagedType.LPWStr)] string pVal);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ internal static AutomationElement Wrap(SafeNodeHandle hnode)
public static readonly AutomationProperty IsTogglePatternAvailableProperty = AutomationElementIdentifiers.IsTogglePatternAvailableProperty;
/// <summary>Property that indicates whether the TransformPattern is available for this AutomationElement</summary>
public static readonly AutomationProperty IsTransformPatternAvailableProperty = AutomationElementIdentifiers.IsTransformPatternAvailableProperty;
/// <summary>Property that indicates whether the TransformPattern2 is available for this AutomationElement</summary>
public static readonly AutomationProperty IsTransformPattern2AvailableProperty = AutomationElementIdentifiers.IsTransformPattern2AvailableProperty;
/// <summary>Property that indicates whether the ValuePattern is available for this AutomationElement</summary>
public static readonly AutomationProperty IsValuePatternAvailableProperty = AutomationElementIdentifiers.IsValuePatternAvailableProperty;
/// <summary>Property that indicates whether the WindowPattern is available for this AutomationElement</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TransformPattern: BasePattern

#region Constructors

private TransformPattern(AutomationElement el, SafePatternHandle hPattern, bool cached)
private protected TransformPattern(AutomationElement el, SafePatternHandle hPattern, bool cached)
: base(el, hPattern)
{
_hPattern = hPattern;
Expand Down
Loading