diff options
author | Bertrand Le Roy <beleroy@microsoft.com> | 2017-09-27 03:14:01 +0300 |
---|---|---|
committer | Bertrand Le Roy <beleroy@microsoft.com> | 2017-09-27 03:14:01 +0300 |
commit | 63456902df43c32d0764d213be13f05a42429c8e (patch) | |
tree | fb1e48c0946e7078f08679fd0ff89fb64f3a5d95 | |
parent | 6abbffe4162041414601f922acf9d5d5b217a2b6 (diff) |
Add sample mocked control support to standalone mac app, fix Size and Point mac support.
14 files changed, 168 insertions, 80 deletions
diff --git a/Xamarin.PropertyEditing.Mac.Standalone/IMockedControl.cs b/Xamarin.PropertyEditing.Mac.Standalone/IMockedControl.cs new file mode 100644 index 0000000..5f0b62d --- /dev/null +++ b/Xamarin.PropertyEditing.Mac.Standalone/IMockedControl.cs @@ -0,0 +1,9 @@ +using System; + +namespace Xamarin.PropertyEditing.Mac.Standalone +{ + interface IMockedControl + { + object MockedControl { get; } + } +} diff --git a/Xamarin.PropertyEditing.Mac.Standalone/Main.storyboard b/Xamarin.PropertyEditing.Mac.Standalone/Main.storyboard index 052ee00..56adc52 100644 --- a/Xamarin.PropertyEditing.Mac.Standalone/Main.storyboard +++ b/Xamarin.PropertyEditing.Mac.Standalone/Main.storyboard @@ -674,10 +674,32 @@ <rect key="frame" x="0.0" y="0.0" width="480" height="270"/> <autoresizingMask key="autoresizingMask"/> <subviews> + <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Lao-X4-Foo"> + <rect key="frame" x="1" y="236" width="110" height="32"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> + <buttonCell key="cell" type="push" title="Mocked 1" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="0bJ-RB-Foo" customClass="MockedSampleControlButton"> + <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> + <font key="font" metaFont="system"/> + </buttonCell> + <connections> + <action selector="OnClickEvent:" target="XfG-lQ-9wD" id="CqZ-JO-Foo"/> + </connections> + </button> + <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Lao-X4-Bar"> + <rect key="frame" x="111" y="236" width="110" height="32"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> + <buttonCell key="cell" type="push" title="Mocked 2" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="0bJ-RB-Bar" customClass="MockedSampleControlButton"> + <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> + <font key="font" metaFont="system"/> + </buttonCell> + <connections> + <action selector="OnClickEvent:" target="XfG-lQ-9wD" id="CqZ-JO-Bar"/> + </connections> + </button> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Lao-X4-NZl"> - <rect key="frame" x="1" y="236" width="81" height="32"/> + <rect key="frame" x="221" y="236" width="110" height="32"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> - <buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="0bJ-RB-L5x" customClass="MockedAppKitButton"> + <buttonCell key="cell" type="push" title="Mock AppKit" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="0bJ-RB-L5x" customClass="MockedAppKitButton"> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <font key="font" metaFont="system"/> </buttonCell> @@ -686,9 +708,9 @@ </connections> </button> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fbd-bO-O5O"> - <rect key="frame" x="92" y="236" width="81" height="32"/> + <rect key="frame" x="331" y="236" width="110" height="32"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> - <buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Ttv-Om-Ige"> + <buttonCell key="cell" type="push" title="AppKit" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Ttv-Om-Ige"> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <font key="font" metaFont="system"/> </buttonCell> diff --git a/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitButton.cs b/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitButton.cs new file mode 100644 index 0000000..81e9957 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitButton.cs @@ -0,0 +1,21 @@ +using System; +using Foundation; +using Xamarin.PropertyEditing.Tests.MockControls; + +namespace Xamarin.PropertyEditing.Mac.Standalone +{ + [Foundation.Register ("MockedAppKitButton")] + public class MockedAppKitButton : MockedControlButton<MockNSButton> + { + // Called when created from unmanaged code + public MockedAppKitButton (IntPtr handle) : base (new MockNSButton (), handle) + { + } + + // Called when created directly from a XIB file + [Export ("initWithCoder:")] + public MockedAppKitButton (NSCoder coder) : base (new MockNSButton (), coder) + { + } + } +} diff --git a/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitControlButton.cs b/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitControlButton.cs deleted file mode 100644 index ad2e4d0..0000000 --- a/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitControlButton.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using Foundation; -using AppKit; -using Xamarin.PropertyEditing.Tests.MockControls; - -namespace Xamarin.PropertyEditing.Mac.Standalone -{ - public abstract class MockedAppKitControlButton<T> : AppKit.NSButtonCell where T : MockControl - { - protected MockedAppKitControlButton (T mockedControl, IntPtr handle) : base (handle) - { - MockedControl = mockedControl; - Initialize (); - } - - protected MockedAppKitControlButton (T mockedControl, NSCoder coder) : base (coder) - { - Initialize (); - MockedControl = mockedControl; - } - - // Shared initialization code - void Initialize () - { - } - - public T MockedControl { get; } - } - - public partial class MockedAppKitButton : MockedAppKitControlButton<MockNSButton> - { - // Called when created from unmanaged code - public MockedAppKitButton (IntPtr handle) : base (new MockNSButton (), handle) - { - } - - // Called when created directly from a XIB file - [Export ("initWithCoder:")] - public MockedAppKitButton (NSCoder coder) : base (new MockNSButton (), coder) - { - } - } -} diff --git a/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitControlButton.designer.cs b/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitControlButton.designer.cs deleted file mode 100644 index c81fc16..0000000 --- a/Xamarin.PropertyEditing.Mac.Standalone/MockedAppKitControlButton.designer.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Xamarin.PropertyEditing.Mac.Standalone -{ - - // Should subclass AppKit.NSView - [Foundation.Register ("MockedAppKitButton")] - public partial class MockedAppKitButton - { - } -} diff --git a/Xamarin.PropertyEditing.Mac.Standalone/MockedControlButton.cs b/Xamarin.PropertyEditing.Mac.Standalone/MockedControlButton.cs new file mode 100644 index 0000000..91e3acf --- /dev/null +++ b/Xamarin.PropertyEditing.Mac.Standalone/MockedControlButton.cs @@ -0,0 +1,32 @@ +using System; +using Foundation; +using AppKit; +using Xamarin.PropertyEditing.Tests.MockControls; + +namespace Xamarin.PropertyEditing.Mac.Standalone +{ + public abstract class MockedControlButton<T> : NSButtonCell, IMockedControl + where T : MockControl + { + protected MockedControlButton (T mockedControl, IntPtr handle) : base (handle) + { + MockedControl = mockedControl; + Initialize (); + } + + protected MockedControlButton (T mockedControl, NSCoder coder) : base (coder) + { + Initialize (); + MockedControl = mockedControl; + } + + // Shared initialization code + void Initialize () + { + } + + public T MockedControl { get; } + + object IMockedControl.MockedControl => MockedControl; + } +} diff --git a/Xamarin.PropertyEditing.Mac.Standalone/MockedSampleControlButton.cs b/Xamarin.PropertyEditing.Mac.Standalone/MockedSampleControlButton.cs new file mode 100644 index 0000000..8a441a7 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac.Standalone/MockedSampleControlButton.cs @@ -0,0 +1,21 @@ +using System; +using Foundation; +using Xamarin.PropertyEditing.Tests.MockControls; + +namespace Xamarin.PropertyEditing.Mac.Standalone +{ + [Foundation.Register ("MockedSampleControlButton")] + public class MockedSampleControlButton : MockedControlButton<MockSampleControl> + { + // Called when created from unmanaged code + public MockedSampleControlButton (IntPtr handle) : base (new MockSampleControl (), handle) + { + } + + // Called when created directly from a XIB file + [Export ("initWithCoder:")] + public MockedSampleControlButton (NSCoder coder) : base (new MockSampleControl (), coder) + { + } + } +} diff --git a/Xamarin.PropertyEditing.Mac.Standalone/ViewController.cs b/Xamarin.PropertyEditing.Mac.Standalone/ViewController.cs index 9e38609..25571c7 100644 --- a/Xamarin.PropertyEditing.Mac.Standalone/ViewController.cs +++ b/Xamarin.PropertyEditing.Mac.Standalone/ViewController.cs @@ -35,7 +35,7 @@ namespace Xamarin.PropertyEditing.Mac.Standalone partial void OnClickEvent (NSObject sender) { var clickedButton = sender as NSButton; - var mockedButton = clickedButton?.Cell as MockedAppKitButton; + var mockedButton = clickedButton?.Cell as IMockedControl; var inspectedObject = (mockedButton == null || mockedButton.MockedControl == null) ? (object)sender : mockedButton.MockedControl; if (PropertyPanel.SelectedItems.Contains (inspectedObject)) { diff --git a/Xamarin.PropertyEditing.Mac.Standalone/Xamarin.PropertyEditing.Mac.Standalone.csproj b/Xamarin.PropertyEditing.Mac.Standalone/Xamarin.PropertyEditing.Mac.Standalone.csproj index b7503e1..620721d 100644 --- a/Xamarin.PropertyEditing.Mac.Standalone/Xamarin.PropertyEditing.Mac.Standalone.csproj +++ b/Xamarin.PropertyEditing.Mac.Standalone/Xamarin.PropertyEditing.Mac.Standalone.csproj @@ -81,10 +81,10 @@ <Compile Include="ViewController.designer.cs">
<DependentUpon>ViewController.cs</DependentUpon>
</Compile>
- <Compile Include="MockedAppKitControlButton.cs" />
- <Compile Include="MockedAppKitControlButton.designer.cs">
- <DependentUpon>MockedAppKitControlButton.cs</DependentUpon>
- </Compile>
+ <Compile Include="MockedControlButton.cs" />
+ <Compile Include="MockedAppKitButton.cs" />
+ <Compile Include="IMockedControl.cs" />
+ <Compile Include="MockedSampleControlButton.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Main.storyboard" />
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs index 602bf7e..cf6914e 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs @@ -1,10 +1,7 @@ using System; using System.Collections; using System.Diagnostics; -using System.Drawing; using AppKit; -using CoreGraphics; -using Foundation; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac diff --git a/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs index d889242..00801d8 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs @@ -1,10 +1,12 @@ using System; using System.Drawing; using CoreGraphics; +using Xamarin.PropertyEditing.Drawing; namespace Xamarin.PropertyEditing.Mac { - internal class PointEditorControl : BasePointEditorControl<Point> + internal abstract class PointEditorControl<T> : BasePointEditorControl<T> + where T : struct { public PointEditorControl () { @@ -19,6 +21,18 @@ namespace Xamarin.PropertyEditing.Mac YEditor.Frame = new CGRect (110, 0, 50, 20); } + protected override void UpdateAccessibilityValues () + { + XEditor.AccessibilityEnabled = XEditor.Enabled; + XEditor.AccessibilityTitle = ViewModel.Property.Name + " X Editor"; // TODO Localization + + YEditor.AccessibilityEnabled = YEditor.Enabled; + YEditor.AccessibilityTitle = ViewModel.Property.Name + " Y Editor"; // TODO Localization + } + } + + internal class SystemPointEditorControl : PointEditorControl<Point> + { protected override void UpdateValue () { XEditor.StringValue = ViewModel.Value.X.ToString (); @@ -29,14 +43,19 @@ namespace Xamarin.PropertyEditing.Mac { ViewModel.Value = new Point (XEditor.IntValue, YEditor.IntValue); } + } - protected override void UpdateAccessibilityValues () + internal class CommonPointEditorControl : PointEditorControl<CommonPoint> + { + protected override void UpdateValue () { - XEditor.AccessibilityEnabled = XEditor.Enabled; - XEditor.AccessibilityTitle = ViewModel.Property.Name + " X Editor"; // TODO Localization + XEditor.StringValue = ViewModel.Value.X.ToString (); + YEditor.StringValue = ViewModel.Value.Y.ToString (); + } - YEditor.AccessibilityEnabled = YEditor.Enabled; - YEditor.AccessibilityTitle = ViewModel.Property.Name + " Y Editor"; // TODO Localization + protected override void OnInputUpdated (object sender, EventArgs e) + { + ViewModel.Value = new CommonPoint (XEditor.IntValue, YEditor.IntValue); } } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/SizeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/SizeEditorControl.cs index 29495fb..9477016 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/SizeEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/SizeEditorControl.cs @@ -1,10 +1,12 @@ using System; using System.Drawing; using CoreGraphics; +using Xamarin.PropertyEditing.Drawing; namespace Xamarin.PropertyEditing.Mac { - internal class SizeEditorControl : BasePointEditorControl<Size> + internal abstract class SizeEditorControl<T> : BasePointEditorControl<T> + where T : struct { public SizeEditorControl () { @@ -19,6 +21,15 @@ namespace Xamarin.PropertyEditing.Mac YEditor.Frame = new CGRect (155, 0, 50, 20); } + protected override void UpdateAccessibilityValues () + { + XEditor.AccessibilityTitle = ViewModel.Property.Name + " Width Editor"; // TODO Localization + YEditor.AccessibilityTitle = ViewModel.Property.Name + " Height Editor"; // TODO Localization + } + } + + internal class SystemSizeEditorControl : SizeEditorControl<Size> + { protected override void UpdateValue () { XEditor.StringValue = ViewModel.Value.Width.ToString (); @@ -29,11 +40,19 @@ namespace Xamarin.PropertyEditing.Mac { ViewModel.Value = new Size (XEditor.IntValue, YEditor.IntValue); } + } - protected override void UpdateAccessibilityValues () + internal class CommonSizeEditorControl : SizeEditorControl<CommonSize> + { + protected override void UpdateValue () { - XEditor.AccessibilityTitle = ViewModel.Property.Name + " Width Editor"; // TODO Localization - YEditor.AccessibilityTitle = ViewModel.Property.Name + " Height Editor"; // TODO Localization + XEditor.StringValue = ViewModel.Value.Width.ToString (); + YEditor.StringValue = ViewModel.Value.Height.ToString (); + } + + protected override void OnInputUpdated (object sender, EventArgs e) + { + ViewModel.Value = new CommonSize (XEditor.IntValue, YEditor.IntValue); } } } diff --git a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs index f095ae5..28ac845 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs @@ -166,10 +166,10 @@ namespace Xamarin.PropertyEditing.Mac {typeof (PropertyViewModel<CoreGraphics.CGRect>), typeof (CGRectEditorControl)}, {typeof (PredefinedValuesViewModel<>), typeof(PredefinedValuesEditor<>)}, {typeof (PropertyViewModel<CoreGraphics.CGSize>), typeof (CGSizeEditorControl)}, - {typeof (PropertyViewModel<Point>), typeof (PointEditorControl)}, - {typeof (PropertyViewModel<CommonPoint>), typeof (PointEditorControl) }, - {typeof (PropertyViewModel<Size>), typeof (SizeEditorControl)}, - {typeof (PropertyViewModel<CommonSize>), typeof (SizeEditorControl) }, + {typeof (PropertyViewModel<Point>), typeof (SystemPointEditorControl)}, + {typeof (PropertyViewModel<CommonPoint>), typeof (CommonPointEditorControl) }, + {typeof (PropertyViewModel<Size>), typeof (SystemSizeEditorControl)}, + {typeof (PropertyViewModel<CommonSize>), typeof (CommonSizeEditorControl) }, {typeof (PropertyViewModel<Rectangle>), typeof (RectangleEditorControl)} }; } diff --git a/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs b/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs index b49ab79..00eb7a6 100644 --- a/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs +++ b/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs @@ -15,7 +15,7 @@ namespace Xamarin.PropertyEditing.Tests.MockControls AddProperty<Flags> ("Flags", ReadWrite, canWrite: true, flag: true); AddProperty<CommonPoint> ("Point", ReadWrite); AddProperty<CommonSize> ("Size", ReadWrite); - AddProperty<CommonThickness> ("Thickness", ReadWrite); + // AddProperty<CommonThickness> ("Thickness", ReadWrite); // Lacking support on the mac at this point in time. AddReadOnlyProperty<bool> ("ReadOnlyBoolean", ReadOnly); AddReadOnlyProperty<long> ("ReadOnlyInteger", ReadOnly); @@ -25,7 +25,7 @@ namespace Xamarin.PropertyEditing.Tests.MockControls AddProperty<Flags> ("ReadOnlyFlags", ReadOnly, canWrite: false, flag: true); AddReadOnlyProperty<CommonPoint> ("ReadOnlyPoint", ReadOnly); AddReadOnlyProperty<CommonSize> ("ReadOnlySize", ReadOnly); - AddReadOnlyProperty<CommonThickness> ("ReadOnlyThickness", ReadOnly); + // AddReadOnlyProperty<CommonThickness> ("ReadOnlyThickness", ReadOnly); AddProperty<NotImplemented> ("Uncategorized", None); |