Skip to content

Commit 0aa0635

Browse files
author
Morten Nielsen
committed
Initial work for adding TransformPattern2 to WPF
1 parent 28843aa commit 0aa0635

File tree

19 files changed

+693
-4
lines changed

19 files changed

+693
-4
lines changed
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
//
6+
//
7+
//
8+
// Description: Transform pattern provider wrapper for WCP
9+
//
10+
//
11+
12+
using System;
13+
using System.Windows.Threading;
14+
using System.Windows.Media;
15+
using System.Windows.Automation;
16+
using System.Windows.Automation.Provider;
17+
using System.Windows.Automation.Peers;
18+
19+
namespace MS.Internal.Automation
20+
{
21+
// Automation/WCP Wrapper class: Implements that UIAutomation I...Provider
22+
// interface, and calls through to a WCP AutomationPeer which implements the corresponding
23+
// I...Provider inteface. Marshalls the call from the RPC thread onto the
24+
// target AutomationPeer's context.
25+
//
26+
// Class has two major parts to it:
27+
// * Implementation of the I...Provider, which uses Dispatcher.Invoke
28+
// to call a private method (lives in second half of the class) via a delegate,
29+
// if necessary, packages any params into an object param. Return type of Invoke
30+
// must be cast from object to appropriate type.
31+
// * private methods - one for each interface entry point - which get called back
32+
// on the right context. These call through to the peer that's actually
33+
// implenting the I...Provider version of the interface.
34+
internal class TransformProvider2Wrapper: TransformProviderWrapper, ITransformProvider2
35+
{
36+
//------------------------------------------------------
37+
//
38+
// Constructors
39+
//
40+
//------------------------------------------------------
41+
42+
#region Constructors
43+
44+
private TransformProvider2Wrapper( AutomationPeer peer, ITransformProvider2 iface ) : base(peer, iface)
45+
{
46+
_peer = peer;
47+
_iface = iface;
48+
}
49+
50+
#endregion Constructors
51+
52+
53+
//------------------------------------------------------
54+
//
55+
// Interface IWindowProvider
56+
//
57+
//------------------------------------------------------
58+
59+
#region Interface ITransformProvider2
60+
61+
62+
public void Zoom( double zoomAmount )
63+
{
64+
ElementUtil.Invoke( _peer, new DispatcherOperationCallback( Zoom ), zoomAmount );
65+
}
66+
67+
public void ZoomByUnit( ZoomUnit zoomUnit )
68+
{
69+
ElementUtil.Invoke( _peer, new DispatcherOperationCallback( ZoomByUnit ), zoomUnit );
70+
}
71+
72+
public bool CanZoom
73+
{
74+
get
75+
{
76+
return (bool) ElementUtil.Invoke( _peer, new DispatcherOperationCallback( GetCanZoom ), null );
77+
}
78+
}
79+
80+
public double ZoomLevel
81+
{
82+
get
83+
{
84+
return (double) ElementUtil.Invoke( _peer, new DispatcherOperationCallback( GetZoomLevel ), null );
85+
}
86+
}
87+
88+
public double ZoomMinimum
89+
{
90+
get
91+
{
92+
return (double) ElementUtil.Invoke( _peer, new DispatcherOperationCallback(GetZoomMinimum ), null );
93+
}
94+
}
95+
96+
97+
public double ZoomMaximum
98+
{
99+
get
100+
{
101+
return (double)ElementUtil.Invoke(_peer, new DispatcherOperationCallback(GetZoomMaximum), null);
102+
}
103+
}
104+
105+
#endregion Interface ITransformProvider2
106+
107+
108+
//------------------------------------------------------
109+
//
110+
// Internal Methods
111+
//
112+
//------------------------------------------------------
113+
114+
#region Internal Methods
115+
116+
internal static new object Wrap( AutomationPeer peer, object iface )
117+
{
118+
return new TransformProvider2Wrapper( peer, (ITransformProvider2) iface );
119+
}
120+
121+
#endregion Internal Methods
122+
123+
//------------------------------------------------------
124+
//
125+
// Private Methods
126+
//
127+
//------------------------------------------------------
128+
129+
#region Private Methods
130+
131+
private object Zoom( object arg )
132+
{
133+
_iface.Zoom( (double)arg );
134+
return null;
135+
}
136+
137+
private object ZoomByUnit( object arg )
138+
{
139+
_iface.ZoomByUnit( (ZoomUnit)arg );
140+
return null;
141+
}
142+
143+
private object GetCanZoom( object unused )
144+
{
145+
return _iface.CanZoom;
146+
}
147+
148+
private object GetZoomLevel( object unused )
149+
{
150+
return _iface.ZoomLevel;
151+
}
152+
153+
private object GetZoomMinimum( object unused )
154+
{
155+
return _iface.ZoomMinimum;
156+
}
157+
158+
private object GetZoomMaximum(object unused)
159+
{
160+
return _iface.ZoomMaximum;
161+
}
162+
163+
#endregion Private Methods
164+
165+
166+
//------------------------------------------------------
167+
//
168+
// Private Fields
169+
//
170+
//------------------------------------------------------
171+
172+
#region Private Fields
173+
174+
private AutomationPeer _peer;
175+
private ITransformProvider2 _iface;
176+
177+
#endregion Private Fields
178+
}
179+
}

src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/TransformProviderWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal class TransformProviderWrapper: MarshalByRefObject, ITransformProvider
3737

3838
#region Constructors
3939

40-
private TransformProviderWrapper( AutomationPeer peer, ITransformProvider iface )
40+
private protected TransformProviderWrapper( AutomationPeer peer, ITransformProvider iface )
4141
{
4242
_peer = peer;
4343
_iface = iface;

src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
<Compile Include="MS\Internal\Automation\TextRangeProviderWrapper.cs" />
159159
<Compile Include="MS\Internal\Automation\ToggleProviderWrapper.cs" />
160160
<Compile Include="MS\Internal\Automation\TransformProviderWrapper.cs" />
161+
<Compile Include="MS\Internal\Automation\TransformProvider2Wrapper.cs" />
161162
<Compile Include="MS\Internal\Automation\ValueProviderWrapper.cs" />
162163
<Compile Include="MS\Internal\Automation\VirtualizedItemProviderWrapper.cs" />
163164
<Compile Include="MS\Internal\Automation\WindowProviderWrapper.cs" />
@@ -706,7 +707,7 @@
706707
<Compile Include="System\Windows\Media\ColorContextHelper.cs" />
707708
<Compile Include="System\Windows\Media\ColorConverter.cs" />
708709
<Compile Include="System\Windows\Media\ColorTransform.cs" />
709-
<Compile Include="System\Windows\Media\ColorTransformHelper.cs" />
710+
<Compile Include="System\Windows\Media\ColorTransformHelper.cs" />
710711
<Compile Include="System\Windows\Media\CombinedGeometry.cs" />
711712
<Compile Include="System\Windows\Media\Composition.cs" />
712713
<Compile Include="System\Windows\Media\CompositionTarget.cs" />

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Automation/Peers/AutomationPeer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public enum PatternInterface
5656
VirtualizedItem,
5757
///
5858
SynchronizedInput,
59+
///
60+
Transform2
5961
}
6062

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

23842387
// To avoid the worst situation on legacy systems which may not have new unmanaged core. with this change with old unmanaged core

src/Microsoft.DotNet.Wpf/src/PresentationCore/ref/PresentationCore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,6 +2471,7 @@ public enum PatternInterface
24712471
ItemContainer = 18,
24722472
VirtualizedItem = 19,
24732473
SynchronizedInput = 20,
2474+
Transform2 = 21
24742475
}
24752476
public partial class UIElement3DAutomationPeer : System.Windows.Automation.Peers.AutomationPeer
24762477
{

src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Schema.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ private static object ConvertToAutomationHeadingLevel(object value)
319319
new AutomationPropertyInfo( convertToBool, AutomationElement.IsTextPatternAvailableProperty, typeof(bool), false ),
320320
new AutomationPropertyInfo( convertToBool, AutomationElement.IsTogglePatternAvailableProperty, typeof(bool), false ),
321321
new AutomationPropertyInfo( convertToBool, AutomationElement.IsTransformPatternAvailableProperty, typeof(bool), false ),
322+
new AutomationPropertyInfo( convertToBool, AutomationElement.IsTransformPattern2AvailableProperty, typeof(bool), false ),
322323
new AutomationPropertyInfo( convertToBool, AutomationElement.IsValuePatternAvailableProperty, typeof(bool), false ),
323324
new AutomationPropertyInfo( convertToBool, AutomationElement.IsWindowPatternAvailableProperty, typeof(bool), false ),
324325

@@ -369,6 +370,11 @@ private static object ConvertToAutomationHeadingLevel(object value)
369370
new AutomationPropertyInfo( convertToBool, TransformPattern.CanMoveProperty, typeof(bool), false ),
370371
new AutomationPropertyInfo( convertToBool, TransformPattern.CanResizeProperty, typeof(bool), false ),
371372
new AutomationPropertyInfo( convertToBool, TransformPattern.CanRotateProperty, typeof(bool), false ),
373+
new AutomationPropertyInfo( convertToBool, TransformPattern2.CanZoomProperty, typeof(bool), false ),
374+
new AutomationPropertyInfo( null, TransformPattern2.ZoomLevelProperty, typeof(double), (double)0 ),
375+
new AutomationPropertyInfo( null, TransformPattern2.ZoomMinimumProperty, typeof(double), (double)0 ),
376+
new AutomationPropertyInfo( null, TransformPattern2.ZoomMaximumProperty, typeof(double), (double)0 ),
377+
372378
};
373379

374380
// Basic properties assumed to be always supported
@@ -463,6 +469,13 @@ private static object ConvertToAutomationHeadingLevel(object value)
463469
private static readonly AutomationProperty [ ] TransformProperties = { TransformPattern.CanMoveProperty,
464470
TransformPattern.CanResizeProperty,
465471
TransformPattern.CanRotateProperty};
472+
473+
474+
private static readonly AutomationProperty[] Transform2Properties = { TransformPattern2.CanZoomProperty,
475+
TransformPattern2.ZoomLevelProperty,
476+
TransformPattern2.ZoomMinimumProperty,
477+
TransformPattern2.ZoomMaximumProperty};
478+
466479
private static readonly AutomationPatternInfo [ ] _patternInfoTable =
467480
{
468481
new AutomationPatternInfo( InvokePattern.Pattern, null, new WrapObjectClientSide(InvokePattern.Wrap) ),
@@ -481,7 +494,8 @@ private static object ConvertToAutomationHeadingLevel(object value)
481494
new AutomationPatternInfo( TableItemPattern.Pattern, TableItemProperties, new WrapObjectClientSide(TableItemPattern.Wrap) ),
482495
new AutomationPatternInfo( TextPattern.Pattern, null, new WrapObjectClientSide(TextPattern.Wrap) ),
483496
new AutomationPatternInfo( TogglePattern.Pattern, ToggleProperties, new WrapObjectClientSide(TogglePattern.Wrap) ),
484-
new AutomationPatternInfo( TransformPattern.Pattern, TransformProperties, new WrapObjectClientSide(TransformPattern.Wrap) ),
497+
new AutomationPatternInfo( TransformPattern.Pattern, TransformProperties, new WrapObjectClientSide(TransformPattern.Wrap) ),
498+
new AutomationPatternInfo( TransformPattern2.Pattern, Transform2Properties, new WrapObjectClientSide(TransformPattern2.Wrap) ),
485499
new AutomationPatternInfo( ScrollItemPattern.Pattern, null, new WrapObjectClientSide(ScrollItemPattern.Wrap) ),
486500
new AutomationPatternInfo( SynchronizedInputPattern.Pattern, null, new WrapObjectClientSide(SynchronizedInputPattern.Wrap) ),
487501
new AutomationPatternInfo( VirtualizedItemPattern.Pattern, null, new WrapObjectClientSide(VirtualizedItemPattern.Wrap)),

src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,16 @@ internal static void TransformPattern_Rotate(SafePatternHandle hobj, double degr
809809
CheckError(RawTransformPattern_Rotate(hobj, degrees));
810810
}
811811

812+
internal static void TransformPattern2_Zoom(SafePatternHandle hobj, double zoomValue)
813+
{
814+
CheckError(RawTransformPattern2_Zoom(hobj, zoomValue));
815+
}
816+
817+
internal static void TransformPattern2_ZoomByUnit(SafePatternHandle hobj, ZoomUnit zoomUnit)
818+
{
819+
CheckError(RawTransformPattern2_ZoomByUnit(hobj, zoomUnit));
820+
}
821+
812822
internal static void ValuePattern_SetValue(SafePatternHandle hobj, string pVal)
813823
{
814824
CheckError(RawValuePattern_SetValue(hobj, pVal));
@@ -1337,6 +1347,12 @@ private static void CheckError(int hr)
13371347
[DllImport(DllImport.UIAutomationCore, EntryPoint = "TransformPattern_Rotate", CharSet = CharSet.Unicode)]
13381348
private static extern int RawTransformPattern_Rotate(SafePatternHandle hobj, double degrees);
13391349

1350+
[DllImport(DllImport.UIAutomationCore, EntryPoint = "TransformPattern2_Zoom", CharSet = CharSet.Unicode)]
1351+
private static extern int RawTransformPattern2_Zoom(SafePatternHandle hobj, double degrees); // TODO: Needs to use Microsoft UI Automation Component Object Model (COM) interfaces instead.
1352+
1353+
[DllImport(DllImport.UIAutomationCore, EntryPoint = "TransformPattern2_ZoomByUnit", CharSet = CharSet.Unicode)]
1354+
private static extern int RawTransformPattern2_ZoomByUnit(SafePatternHandle hobj, ZoomUnit unit); // TODO: Needs to use Microsoft UI Automation Component Object Model (COM) interfaces instead.
1355+
13401356
[DllImport(DllImport.UIAutomationCore, EntryPoint = "ValuePattern_SetValue", CharSet = CharSet.Unicode)]
13411357
private static extern int RawValuePattern_SetValue(SafePatternHandle hobj, [MarshalAs(UnmanagedType.LPWStr)] string pVal);
13421358

src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/AutomationElement.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ internal static AutomationElement Wrap(SafeNodeHandle hnode)
237237
public static readonly AutomationProperty IsTogglePatternAvailableProperty = AutomationElementIdentifiers.IsTogglePatternAvailableProperty;
238238
/// <summary>Property that indicates whether the TransformPattern is available for this AutomationElement</summary>
239239
public static readonly AutomationProperty IsTransformPatternAvailableProperty = AutomationElementIdentifiers.IsTransformPatternAvailableProperty;
240+
/// <summary>Property that indicates whether the TransformPattern2 is available for this AutomationElement</summary>
241+
public static readonly AutomationProperty IsTransformPattern2AvailableProperty = AutomationElementIdentifiers.IsTransformPattern2AvailableProperty;
240242
/// <summary>Property that indicates whether the ValuePattern is available for this AutomationElement</summary>
241243
public static readonly AutomationProperty IsValuePatternAvailableProperty = AutomationElementIdentifiers.IsValuePatternAvailableProperty;
242244
/// <summary>Property that indicates whether the WindowPattern is available for this AutomationElement</summary>

src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/TransformPattern.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class TransformPattern: BasePattern
2222

2323
#region Constructors
2424

25-
private TransformPattern(AutomationElement el, SafePatternHandle hPattern, bool cached)
25+
private protected TransformPattern(AutomationElement el, SafePatternHandle hPattern, bool cached)
2626
: base(el, hPattern)
2727
{
2828
_hPattern = hPattern;

0 commit comments

Comments
 (0)