diff --git a/.gitattributes b/.gitattributes index be0f7e0e50..549c347bd9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,7 @@ -/Resources/MacAppTemplate.app/Contents/MacOS/* eol=lf -*.sh eol=lf + +* text=auto +*.sh eol=lf +*.sln eol=crlf +*.cmd eol=crlf +*.csproj text +*.xaml text diff --git a/.gitignore b/.gitignore index b0ee2ad689..21fdaa6575 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,7 @@ obj/ UpgradeLog*.htm Source/packages Source/Components +AppPackages +Resources/packages +Samples/packages +Source/Addins/Eto.Addin.XamarinStudio/packages diff --git a/Help/Help.shfbproj b/Help/Help.shfbproj index 6544698e54..21f67067dc 100644 --- a/Help/Help.shfbproj +++ b/Help/Help.shfbproj @@ -1,69 +1,68 @@ - - - + + + - Debug - AnyCPU - 2.0 - {130627a0-3530-4939-8d7a-c447563618d1} - 1.9.3.0 + sources --> + Debug + AnyCPU + 2.0 + {130627a0-3530-4939-8d7a-c447563618d1} + 1.9.9.0 - Documentation - Documentation - Documentation - - ..\BuildOutput\Help\html-shfb\ - EtoForms - en-US - Website - - - - - Eto.Forms documentation - vs2010 - InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected - Eto.Forms Cross Platform UI Framework - - Eto - Eto.Forms User Interface - Eto.IO Input/Output abstractions - Misc - - + Studio adds them anyway --> + Documentation + Documentation + Documentation + + ..\BuildOutput\Help\html-shfb\ + EtoForms + en-US + Website + + + + Eto.Forms documentation + vs2010 + InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected + Eto.Forms Cross Platform UI Framework + + Eto + Eto.Forms User Interface + Eto.IO Input/Output abstractions + Misc + + - - - - - - - - - - - - - - - - - - - BuildOutput\Debug\Eto.dll - - - - - - - - - - + common platform types that may appear. --> + + + + + + + + + + + + + + + + + + + BuildOutput\Debug\Eto.dll + + + + + + + + + + \ No newline at end of file diff --git a/Help/Site Map.sitemap b/Help/Site Map.sitemap index 5dbcacac1e..32441796f1 100644 --- a/Help/Site Map.sitemap +++ b/Help/Site Map.sitemap @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/Help/Top.html b/Help/Top.html index 9d414b4220..68037abdd1 100644 --- a/Help/Top.html +++ b/Help/Top.html @@ -1,11 +1,11 @@ - - - - Eto.Forms Documentation - - - - - - - + + + + Eto.Forms Documentation + + + + + + + diff --git a/LICENSE b/LICENSE index 7e1f571848..dbc60f0153 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ AUTHORS -Copyright © 2011-2013 Curtis Wensley. All Rights Reserved. +Copyright © 2011-2014 Curtis Wensley. All Rights Reserved. Copyright © 2012-2013 Vivek Jhaveri. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted diff --git a/Libraries/GtkSharp3/atk-sharp.dll b/Libraries/GtkSharp3/atk-sharp.dll old mode 100755 new mode 100644 index e4a33fc05a..c37e889b0c Binary files a/Libraries/GtkSharp3/atk-sharp.dll and b/Libraries/GtkSharp3/atk-sharp.dll differ diff --git a/Libraries/GtkSharp3/atk-sharp.dll.config b/Libraries/GtkSharp3/atk-sharp.dll.config index 348f1e4a2c..b77122d51f 100644 --- a/Libraries/GtkSharp3/atk-sharp.dll.config +++ b/Libraries/GtkSharp3/atk-sharp.dll.config @@ -1,4 +1,5 @@ + diff --git a/Libraries/GtkSharp3/cairo-sharp.dll b/Libraries/GtkSharp3/cairo-sharp.dll old mode 100755 new mode 100644 index 581836f9f9..4fe7a030d2 Binary files a/Libraries/GtkSharp3/cairo-sharp.dll and b/Libraries/GtkSharp3/cairo-sharp.dll differ diff --git a/Libraries/GtkSharp3/gdk-sharp.dll b/Libraries/GtkSharp3/gdk-sharp.dll old mode 100755 new mode 100644 index 2e84c1b634..04982f9a0c Binary files a/Libraries/GtkSharp3/gdk-sharp.dll and b/Libraries/GtkSharp3/gdk-sharp.dll differ diff --git a/Libraries/GtkSharp3/gio-sharp.dll b/Libraries/GtkSharp3/gio-sharp.dll old mode 100755 new mode 100644 index 4df1526edf..f106b0e429 Binary files a/Libraries/GtkSharp3/gio-sharp.dll and b/Libraries/GtkSharp3/gio-sharp.dll differ diff --git a/Libraries/GtkSharp3/gio-sharp.dll.config b/Libraries/GtkSharp3/gio-sharp.dll.config index 8b61325e4e..d2b8f89bda 100644 --- a/Libraries/GtkSharp3/gio-sharp.dll.config +++ b/Libraries/GtkSharp3/gio-sharp.dll.config @@ -3,4 +3,5 @@ + diff --git a/Libraries/GtkSharp3/glib-sharp.dll b/Libraries/GtkSharp3/glib-sharp.dll old mode 100755 new mode 100644 index c54f257900..0e9209f1a8 Binary files a/Libraries/GtkSharp3/glib-sharp.dll and b/Libraries/GtkSharp3/glib-sharp.dll differ diff --git a/Libraries/GtkSharp3/gtk-dotnet.dll b/Libraries/GtkSharp3/gtk-dotnet.dll deleted file mode 100755 index a04c529de0..0000000000 Binary files a/Libraries/GtkSharp3/gtk-dotnet.dll and /dev/null differ diff --git a/Libraries/GtkSharp3/gtk-dotnet.dll.config b/Libraries/GtkSharp3/gtk-dotnet.dll.config deleted file mode 100644 index 9e12841d07..0000000000 --- a/Libraries/GtkSharp3/gtk-dotnet.dll.config +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/Libraries/GtkSharp3/gtk-dotnet.dll.mdb b/Libraries/GtkSharp3/gtk-dotnet.dll.mdb deleted file mode 100644 index 53daf895de..0000000000 Binary files a/Libraries/GtkSharp3/gtk-dotnet.dll.mdb and /dev/null differ diff --git a/Libraries/GtkSharp3/gtk-sharp.dll b/Libraries/GtkSharp3/gtk-sharp.dll old mode 100755 new mode 100644 index 67c06ce19e..9495e459a7 Binary files a/Libraries/GtkSharp3/gtk-sharp.dll and b/Libraries/GtkSharp3/gtk-sharp.dll differ diff --git a/Libraries/GtkSharp3/gtk-sharp.dll.config b/Libraries/GtkSharp3/gtk-sharp.dll.config index 72599c1703..f58f0e67ac 100644 --- a/Libraries/GtkSharp3/gtk-sharp.dll.config +++ b/Libraries/GtkSharp3/gtk-sharp.dll.config @@ -3,4 +3,5 @@ + diff --git a/Libraries/GtkSharp3/libatksharpglue-3.so b/Libraries/GtkSharp3/libatksharpglue-3.so new file mode 100644 index 0000000000..d17e19fce0 Binary files /dev/null and b/Libraries/GtkSharp3/libatksharpglue-3.so differ diff --git a/Libraries/GtkSharp3/libgiosharpglue-3.so b/Libraries/GtkSharp3/libgiosharpglue-3.so new file mode 100644 index 0000000000..a5cae508b5 Binary files /dev/null and b/Libraries/GtkSharp3/libgiosharpglue-3.so differ diff --git a/Libraries/GtkSharp3/libgtksharpglue-3.so b/Libraries/GtkSharp3/libgtksharpglue-3.so new file mode 100644 index 0000000000..cc1fb4aa9d Binary files /dev/null and b/Libraries/GtkSharp3/libgtksharpglue-3.so differ diff --git a/Libraries/GtkSharp3/libpangosharpglue-3.so b/Libraries/GtkSharp3/libpangosharpglue-3.so new file mode 100644 index 0000000000..880322d8e2 Binary files /dev/null and b/Libraries/GtkSharp3/libpangosharpglue-3.so differ diff --git a/Libraries/GtkSharp3/pango-sharp.dll b/Libraries/GtkSharp3/pango-sharp.dll old mode 100755 new mode 100644 index 26359ac18b..77dde0bf88 Binary files a/Libraries/GtkSharp3/pango-sharp.dll and b/Libraries/GtkSharp3/pango-sharp.dll differ diff --git a/Libraries/GtkSharp3/pango-sharp.dll.config b/Libraries/GtkSharp3/pango-sharp.dll.config index 400bb06ea2..0c89f5c547 100644 --- a/Libraries/GtkSharp3/pango-sharp.dll.config +++ b/Libraries/GtkSharp3/pango-sharp.dll.config @@ -3,4 +3,5 @@ + diff --git a/Libraries/MonoMac64/MonoMac-License.txt b/Libraries/MonoMac64/MonoMac-License.txt new file mode 100644 index 0000000000..c69cf76be8 --- /dev/null +++ b/Libraries/MonoMac64/MonoMac-License.txt @@ -0,0 +1,217 @@ +Dual licensed under either the Apache 2 license or the MIT X11 license + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the +copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other +entities that control, are controlled by, or are under common control +with that entity. For the purposes of this definition, "control" means +(i) the power, direct or indirect, to cause the direction or +management of such entity, whether by contract or otherwise, or (ii) +ownership of fifty percent (50%) or more of the outstanding shares, or +(iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation +source, and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but not +limited to compiled object code, generated documentation, and +conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object +form, made available under the License, as indicated by a copyright +notice that is included in or attached to the work (an example is +provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based on (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the +purposes of this License, Derivative Works shall not include works +that remain separable from, or merely link (or bind by name) to the +interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the +original version of the Work and any modifications or additions to +that Work or Derivative Works thereof, that is intentionally submitted +to Licensor for inclusion in the Work by the copyright owner or by an +individual or Legal Entity authorized to submit on behalf of the +copyright owner. For the purposes of this definition, "submitted" +means any form of electronic, verbal, or written communication sent to +the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control +systems, and issue tracking systems that are managed by, or on behalf +of, the Licensor for the purpose of discussing and improving the Work, +but excluding communication that is conspicuously marked or otherwise +designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor +hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, +royalty-free, irrevocable copyright license to reproduce, prepare +Derivative Works of, publicly display, publicly perform, sublicense, +and distribute the Work and such Derivative Works in Source or Object +form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor +hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, +royalty-free, irrevocable (except as stated in this section) patent +license to make, have made, use, offer to sell, sell, import, and +otherwise transfer the Work, where such license applies only to those +patent claims licensable by such Contributor that are necessarily +infringed by their Contribution(s) alone or by combination of their +Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that +the Work or a Contribution incorporated within the Work constitutes +direct or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate as of +the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative +Works thereof in any medium, with or without modifications, and in +Source or Object form, provided that You meet the following +conditions: + +You must give any other recipients of the Work or Derivative Works a +copy of this License; and You must cause any modified files to carry +prominent notices stating that You changed the files; and You must +retain, in the Source form of any Derivative Works that You +distribute, all copyright, patent, trademark, and attribution notices +from the Source form of the Work, excluding those notices that do not +pertain to any part of the Derivative Works; and If the Work includes +a "NOTICE" text file as part of its distribution, then any Derivative +Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those +notices that do not pertain to any part of the Derivative Works, in at +least one of the following places: within a NOTICE text file +distributed as part of the Derivative Works; within the Source form or +documentation, if provided along with the Derivative Works; or, within +a display generated by the Derivative Works, if and wherever such +third-party notices normally appear. The contents of the NOTICE file +are for informational purposes only and do not modify the License. You +may add Your own attribution notices within Derivative Works that You +distribute, alongside or as an addendum to the NOTICE text from the +Work, provided that such additional attribution notices cannot be +construed as modifying the License. You may add Your own copyright +statement to Your modifications and may provide additional or +different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works +as a whole, provided Your use, reproduction, and distribution of the +Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally +submitted for inclusion in the Work by You to the Licensor shall be +under the terms and conditions of this License, without any additional +terms or conditions. Notwithstanding the above, nothing herein shall +supersede or modify the terms of any separate license agreement you +may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, +trademarks, service marks, or product names of the Licensor, except as +required for reasonable and customary use in describing the origin of +the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor +provides the Work (and each Contributor provides its Contributions) on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +express or implied, including, without limitation, any warranties or +conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR +A PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including +negligence), contract, or otherwise, unless required by applicable law +(such as deliberate and grossly negligent acts) or agreed to in +writing, shall any Contributor be liable to You for damages, including +any direct, indirect, special, incidental, or consequential damages of +any character arising as a result of this License or out of the use or +inability to use the Work (including but not limited to damages for +loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such +Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" replaced +with your own identifying information. (Don't include the brackets!) +The text should be enclosed in the appropriate comment syntax for the +file format. We also recommend that a file or class name and +description of purpose be included on the same "printed page" as the +copyright notice for easier identification within third-party +archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/Libraries/MonoMac64/MonoMac.CFNetwork.dll b/Libraries/MonoMac64/MonoMac.CFNetwork.dll new file mode 100755 index 0000000000..c8e2ad48fd Binary files /dev/null and b/Libraries/MonoMac64/MonoMac.CFNetwork.dll differ diff --git a/Libraries/MonoMac64/MonoMac.CFNetwork.dll.mdb b/Libraries/MonoMac64/MonoMac.CFNetwork.dll.mdb new file mode 100644 index 0000000000..1eb68bcbcb Binary files /dev/null and b/Libraries/MonoMac64/MonoMac.CFNetwork.dll.mdb differ diff --git a/Libraries/MonoMac64/MonoMac.dll b/Libraries/MonoMac64/MonoMac.dll new file mode 100755 index 0000000000..10def97599 Binary files /dev/null and b/Libraries/MonoMac64/MonoMac.dll differ diff --git a/Libraries/MonoMac64/MonoMac.dll.mdb b/Libraries/MonoMac64/MonoMac.dll.mdb new file mode 100644 index 0000000000..00853cf2ce Binary files /dev/null and b/Libraries/MonoMac64/MonoMac.dll.mdb differ diff --git a/Libraries/WPFColorPicker/ColorPickerLib/ColorPicker.cs b/Libraries/WPFColorPicker/ColorPickerLib/ColorPicker.cs index 87fd395411..031e386916 100644 --- a/Libraries/WPFColorPicker/ColorPickerLib/ColorPicker.cs +++ b/Libraries/WPFColorPicker/ColorPickerLib/ColorPicker.cs @@ -1,719 +1,719 @@ -// -// ColorPicker.cs -// An HSB (hue, saturation, brightness) based -// color picker. -// -// -using System; -using System.Windows; -using System.Windows.Navigation; -using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Shapes; -using System.Windows.Ink; -using System.Windows.Controls; -using System.Collections.Generic; -using System.Windows.Input; -using System.Windows.Data; -using System.Windows.Markup; -using System.Text; - -namespace Microsoft.Samples.CustomControls -{ - - - #region ColorPicker - - public class ColorPicker : Control - { - - - static ColorPicker() - { - DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorPicker), new FrameworkPropertyMetadata(typeof(ColorPicker))); - } - - public ColorPicker() - { - templateApplied = false; - m_color = Colors.White; - shouldFindPoint = true; - SetValue(AProperty, m_color.A); - SetValue(RProperty, m_color.R); - SetValue(GProperty, m_color.G); - SetValue(BProperty, m_color.B); - SetValue(SelectedColorProperty, m_color); - SetValue (AlphaVisibilityProperty, System.Windows.Visibility.Visible); - } - - - #region Public Methods - - - public override void OnApplyTemplate() - { - - base.OnApplyTemplate(); - m_ColorDetail = GetTemplateChild(ColorDetailName) as FrameworkElement; - m_ColorMarker = GetTemplateChild(ColorMarkerName) as Path; - m_ColorSlider = GetTemplateChild(ColorSliderName) as SpectrumSlider; - m_ColorSlider.ValueChanged += new RoutedPropertyChangedEventHandler(BaseColorChanged); - - - m_ColorMarker.RenderTransform = markerTransform; - m_ColorMarker.RenderTransformOrigin = new Point(0.5, 0.5); - m_ColorDetail.MouseLeftButtonDown += new MouseButtonEventHandler(OnMouseLeftButtonDown); - m_ColorDetail.PreviewMouseMove += new MouseEventHandler(OnMouseMove); - m_ColorDetail.SizeChanged += new SizeChangedEventHandler(ColorDetailSizeChanged); - - templateApplied = true; - shouldFindPoint = true; - isAlphaChange = false; - - SelectedColor = m_color; - - - - - } - - - - #endregion - - - #region Public Properties - - // Gets or sets the selected color. - public System.Windows.Media.Color SelectedColor - { - get - { - - return (System.Windows.Media.Color)GetValue(SelectedColorProperty); - } - set - { - SetValue(SelectedColorProperty, m_color); - setColor((Color)value); - } - } - - - #region RGB Properties - // Gets or sets the ARGB alpha value of the selected color. - public byte A - { - get - { - return (byte)GetValue(AProperty); - } - set - { - SetValue(AProperty, value); - } - } - - // Gets or sets the ARGB red value of the selected color. - public byte R - { - get - { - return (byte)GetValue(RProperty); - } - set - { - SetValue(RProperty, value); - } - } - - // Gets or sets the ARGB green value of the selected color. - public byte G - { - get - { - return (byte)GetValue(GProperty); - } - set - { - SetValue(GProperty, value); - } - } - - // Gets or sets the ARGB blue value of the selected color. - public byte B - { - get - { - return (byte)GetValue(BProperty); - } - set - { - SetValue(BProperty, value); - } - } - #endregion RGB Properties - - #region ScRGB Properties - - // Gets or sets the ScRGB alpha value of the selected color. - public double ScA - { - get - { - return (double)GetValue(ScAProperty); - } - set - { - SetValue(ScAProperty, value); - } - } - - // Gets or sets the ScRGB red value of the selected color. - public double ScR - { - get - { - return (double)GetValue(ScRProperty); - } - set - { - SetValue(RProperty, value); - } - } - - // Gets or sets the ScRGB green value of the selected color. - public double ScG - { - get - { - return (double)GetValue(ScGProperty); - } - set - { - SetValue(GProperty, value); - } - } - - // Gets or sets the ScRGB blue value of the selected color. - public double ScB - { - get - { - return (double)GetValue(BProperty); - } - set - { - SetValue(BProperty, value); - } - } - #endregion ScRGB Properties - - // Gets or sets the the selected color in hexadecimal notation. - public string HexadecimalString - { - get - { - return (string)GetValue(HexadecimalStringProperty); - } - set - { - SetValue(HexadecimalStringProperty, value); - } - } - - public bool ShowAlpha - { - get - { - return (Visibility)GetValue (AlphaVisibilityProperty) == System.Windows.Visibility.Visible; - } - set - { - SetValue (AlphaVisibilityProperty, value ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed); - if (!ShowAlpha) this.A = 255; - } - } - - #endregion - - - #region Public Events - - public event RoutedPropertyChangedEventHandler SelectedColorChanged - { - add - { - AddHandler(SelectedColorChangedEvent, value); - } - - remove - { - RemoveHandler(SelectedColorChangedEvent, value); - } - } - - #endregion - - - #region Dependency Property Fields - public static readonly DependencyProperty SelectedColorProperty = - DependencyProperty.Register - ("SelectedColor", typeof(System.Windows.Media.Color), typeof(ColorPicker), - new PropertyMetadata(System.Windows.Media.Colors.Transparent, - new PropertyChangedCallback(selectedColor_changed) - - )); - - public static readonly DependencyProperty ScAProperty = - - DependencyProperty.Register - ("ScA", typeof(float), typeof(ColorPicker), - new PropertyMetadata((float)1, - new PropertyChangedCallback(ScAChanged) - )); - - public static readonly DependencyProperty ScRProperty = - DependencyProperty.Register - ("ScR", typeof(float), typeof(ColorPicker), - new PropertyMetadata((float)1, - new PropertyChangedCallback(ScRChanged) - )); - - public static readonly DependencyProperty ScGProperty = - DependencyProperty.Register - ("ScG", typeof(float), typeof(ColorPicker), - new PropertyMetadata((float)1, - new PropertyChangedCallback(ScGChanged) - )); - - public static readonly DependencyProperty ScBProperty = - DependencyProperty.Register - ("ScB", typeof(float), typeof(ColorPicker), - new PropertyMetadata((float)1, - new PropertyChangedCallback(ScBChanged) - )); - - public static readonly DependencyProperty AProperty = - DependencyProperty.Register - ("A", typeof(byte), typeof(ColorPicker), - new PropertyMetadata((byte)255, - new PropertyChangedCallback(AChanged) - )); - - public static readonly DependencyProperty RProperty = - DependencyProperty.Register - ("R", typeof(byte), typeof(ColorPicker), - new PropertyMetadata((byte)255, - new PropertyChangedCallback(RChanged) - )); - - public static readonly DependencyProperty GProperty = - DependencyProperty.Register - ("G", typeof(byte), typeof(ColorPicker), - new PropertyMetadata((byte)255, - new PropertyChangedCallback(GChanged) - )); - - public static readonly DependencyProperty BProperty = - DependencyProperty.Register - ("B", typeof(byte), typeof(ColorPicker), - new PropertyMetadata((byte)255, - new PropertyChangedCallback(BChanged) - )); - - public static readonly DependencyProperty HexadecimalStringProperty = - DependencyProperty.Register - ("HexadecimalString", typeof(string), typeof(ColorPicker), - new PropertyMetadata("#FFFFFFFF", - new PropertyChangedCallback(HexadecimalStringChanged) - )); - - public static readonly DependencyProperty AlphaVisibilityProperty = - DependencyProperty.Register - ("AlphaVisibility", typeof (Visibility), typeof (ColorPicker), - new PropertyMetadata (Visibility.Visible)); - - #endregion - - - #region RoutedEvent Fields - - public static readonly RoutedEvent SelectedColorChangedEvent = EventManager.RegisterRoutedEvent( - "SelectedColorChanged", - RoutingStrategy.Bubble, - typeof(RoutedPropertyChangedEventHandler), - typeof(ColorPicker) - ); - #endregion - - - #region Property Changed Callbacks - - private static void AChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnAChanged((byte)e.NewValue); - } - - protected virtual void OnAChanged(byte newValue) - { - - m_color.A = newValue; - SetValue(ScAProperty, m_color.ScA); - SetValue(SelectedColorProperty, m_color); - - } - - private static void RChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnRChanged((byte)e.NewValue); - } - - protected virtual void OnRChanged(byte newValue) - { - m_color.R = newValue; - SetValue(ScRProperty, m_color.ScR); - SetValue(SelectedColorProperty, m_color); - } - - - private static void GChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnGChanged((byte)e.NewValue); - } - - protected virtual void OnGChanged(byte newValue) - { - - m_color.G = newValue; - SetValue(ScGProperty, m_color.ScG); - SetValue(SelectedColorProperty, m_color); - } - - - private static void BChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnBChanged((byte)e.NewValue); - } - - protected virtual void OnBChanged(byte newValue) - { - m_color.B = newValue; - SetValue(ScBProperty, m_color.ScB); - SetValue(SelectedColorProperty, m_color); - } - - - private static void ScAChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnScAChanged((float)e.NewValue); - } - - protected virtual void OnScAChanged(float newValue) - { - isAlphaChange = true; - if (shouldFindPoint) - { - m_color.ScA = newValue; - SetValue(AProperty, m_color.A); - SetValue(SelectedColorProperty, m_color); - SetValue (HexadecimalStringProperty, GetHexadecimal ()); - } - isAlphaChange = false; - } - - - private static void ScRChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnScRChanged((float)e.NewValue); - - } - - protected virtual void OnScRChanged(float newValue) - { - if (shouldFindPoint) - { - m_color.ScR = newValue; - SetValue(RProperty, m_color.R); - SetValue(SelectedColorProperty, m_color); - SetValue (HexadecimalStringProperty, GetHexadecimal ()); - } - } - - - private static void ScGChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnScGChanged((float)e.NewValue); - } - - protected virtual void OnScGChanged(float newValue) - { - - if (shouldFindPoint) - { - m_color.ScG = newValue; - SetValue(GProperty, m_color.G); - SetValue(SelectedColorProperty, m_color); - SetValue (HexadecimalStringProperty, GetHexadecimal ()); - } - } - - - private static void ScBChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnScBChanged((float)e.NewValue); - } - - protected virtual void OnScBChanged(float newValue) - { - if (shouldFindPoint) - { - m_color.ScB = newValue; - SetValue(BProperty, m_color.B); - SetValue(SelectedColorProperty, m_color); - SetValue (HexadecimalStringProperty, GetHexadecimal ()); - } - } - - private static void HexadecimalStringChanged(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker c = (ColorPicker)d; - c.OnHexadecimalStringChanged((string)e.OldValue, (string)e.NewValue); - } - - protected virtual void OnHexadecimalStringChanged(string oldValue, string newValue) - { - - try - { - - if (shouldFindPoint) - { - - m_color = (Color)ColorConverter.ConvertFromString(newValue); - - } - - SetValue(AProperty, m_color.A); - SetValue(RProperty, m_color.R); - SetValue(GProperty, m_color.G); - SetValue(BProperty, m_color.B); - - - if (shouldFindPoint && !isAlphaChange && templateApplied) - { - updateMarkerPosition(m_color); - } - } - catch (FormatException fException) - { - - SetValue(HexadecimalStringProperty, oldValue); - } - - } - - private static void selectedColor_changed(DependencyObject d, - DependencyPropertyChangedEventArgs e) - { - ColorPicker cPicker = (ColorPicker)d; - cPicker.OnSelectedColorChanged((Color)e.OldValue, (Color)e.NewValue); - } - - protected virtual void OnSelectedColorChanged(Color oldColor, Color newColor) - { - - RoutedPropertyChangedEventArgs newEventArgs = - new RoutedPropertyChangedEventArgs(oldColor, newColor); - newEventArgs.RoutedEvent = ColorPicker.SelectedColorChangedEvent; - RaiseEvent(newEventArgs); - } - - #endregion - - - #region Template Part Event Handlers - - - protected override void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate) - { - - templateApplied = false; - if (oldTemplate != null) - { - m_ColorSlider.ValueChanged -= new RoutedPropertyChangedEventHandler(BaseColorChanged); - m_ColorDetail.MouseLeftButtonDown -= new MouseButtonEventHandler(OnMouseLeftButtonDown); - m_ColorDetail.PreviewMouseMove -= new MouseEventHandler(OnMouseMove); - m_ColorDetail.SizeChanged -= new SizeChangedEventHandler(ColorDetailSizeChanged); - m_ColorDetail = null; - m_ColorMarker = null; - m_ColorSlider = null; - } - base.OnTemplateChanged(oldTemplate, newTemplate); - } - - - private void BaseColorChanged( - object sender, - RoutedPropertyChangedEventArgs e) - { - - if (m_ColorPosition != null) - { - - determineColor((Point)m_ColorPosition); - } - - } - - private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - - Point p = e.GetPosition(m_ColorDetail); - updateMarkerPosition(p); - } - - private void OnMouseMove(object sender, MouseEventArgs e) - { - - - if (e.LeftButton == MouseButtonState.Pressed) - { - - Point p = e.GetPosition(m_ColorDetail); - updateMarkerPosition(p); - Mouse.Synchronize(); - - } - } - - private void ColorDetailSizeChanged(object sender, SizeChangedEventArgs args) - { - - if (args.PreviousSize != Size.Empty && - args.PreviousSize.Width != 0 && args.PreviousSize.Height != 0) - { - double widthDifference = args.NewSize.Width / args.PreviousSize.Width; - double heightDifference = args.NewSize.Height / args.PreviousSize.Height; - markerTransform.X = markerTransform.X * widthDifference; - markerTransform.Y = markerTransform.Y * heightDifference; - } - else if (m_ColorPosition != null) - { - markerTransform.X = ((Point)m_ColorPosition).X * args.NewSize.Width; - markerTransform.Y = ((Point)m_ColorPosition).Y * args.NewSize.Height; - } - } - - #endregion - - - #region Color Resolution Helpers - - string GetHexadecimal () - { - if (ShowAlpha) - return m_color.ToString (); - else - return string.Format ("#{0:X2}{1:X2}{2:X2}", m_color.R, m_color.G, m_color.B); - } - - - private void setColor(Color theColor) - { - m_color = theColor; - - if (templateApplied) { - SetValue(AProperty, m_color.A); - SetValue(RProperty, m_color.R); - SetValue(GProperty, m_color.G); - SetValue(BProperty, m_color.B); - updateMarkerPosition(theColor); - } - - } - - private void updateMarkerPosition(Point p) - { - markerTransform.X = p.X; - markerTransform.Y = p.Y; - p.X = p.X / m_ColorDetail.ActualWidth; - p.Y = p.Y / m_ColorDetail.ActualHeight; - m_ColorPosition = p; - determineColor(p); - } - - private void updateMarkerPosition(Color theColor) - { - m_ColorPosition = null; - - - HsvColor hsv = ColorUtilities.ConvertRgbToHsv(theColor.R, theColor.G, theColor.B); - - m_ColorSlider.Value = hsv.H; - - Point p = new Point(hsv.S, 1 - hsv.V); - - m_ColorPosition = p; - p.X = p.X * m_ColorDetail.ActualWidth; - p.Y = p.Y * m_ColorDetail.ActualHeight; - markerTransform.X = p.X; - markerTransform.Y = p.Y; - - } - - private void determineColor(Point p) - { - - HsvColor hsv = new HsvColor(360 - m_ColorSlider.Value, 1, 1); - hsv.S = p.X; - hsv.V = 1 - p.Y; - m_color = ColorUtilities.ConvertHsvToRgb(hsv.H, hsv.S, hsv.V); - shouldFindPoint = false; - m_color.ScA = (float)GetValue(ScAProperty); - SetValue (HexadecimalStringProperty, GetHexadecimal ()); - shouldFindPoint = true; - - } - - #endregion - - - #region Private Fields - private SpectrumSlider m_ColorSlider; - private static readonly string ColorSliderName = "PART_ColorSlider"; - private FrameworkElement m_ColorDetail; - private static readonly string ColorDetailName = "PART_ColorDetail"; - private TranslateTransform markerTransform = new TranslateTransform(); - private Path m_ColorMarker; - private static readonly string ColorMarkerName = "PART_ColorMarker"; - private Point? m_ColorPosition; - private Color m_color; - private bool shouldFindPoint; - private bool templateApplied; - private bool isAlphaChange; - #endregion - - } - - #endregion ColorPicker - - +// +// ColorPicker.cs +// An HSB (hue, saturation, brightness) based +// color picker. +// +// +using System; +using System.Windows; +using System.Windows.Navigation; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.Windows.Ink; +using System.Windows.Controls; +using System.Collections.Generic; +using System.Windows.Input; +using System.Windows.Data; +using System.Windows.Markup; +using System.Text; + +namespace Microsoft.Samples.CustomControls +{ + + + #region ColorPicker + + public class ColorPicker : Control + { + + + static ColorPicker() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorPicker), new FrameworkPropertyMetadata(typeof(ColorPicker))); + } + + public ColorPicker() + { + templateApplied = false; + m_color = Colors.White; + shouldFindPoint = true; + SetValue(AProperty, m_color.A); + SetValue(RProperty, m_color.R); + SetValue(GProperty, m_color.G); + SetValue(BProperty, m_color.B); + SetValue(SelectedColorProperty, m_color); + SetValue (AlphaVisibilityProperty, System.Windows.Visibility.Visible); + } + + + #region Public Methods + + + public override void OnApplyTemplate() + { + + base.OnApplyTemplate(); + m_ColorDetail = GetTemplateChild(ColorDetailName) as FrameworkElement; + m_ColorMarker = GetTemplateChild(ColorMarkerName) as Path; + m_ColorSlider = GetTemplateChild(ColorSliderName) as SpectrumSlider; + m_ColorSlider.ValueChanged += new RoutedPropertyChangedEventHandler(BaseColorChanged); + + + m_ColorMarker.RenderTransform = markerTransform; + m_ColorMarker.RenderTransformOrigin = new Point(0.5, 0.5); + m_ColorDetail.MouseLeftButtonDown += new MouseButtonEventHandler(OnMouseLeftButtonDown); + m_ColorDetail.PreviewMouseMove += new MouseEventHandler(OnMouseMove); + m_ColorDetail.SizeChanged += new SizeChangedEventHandler(ColorDetailSizeChanged); + + templateApplied = true; + shouldFindPoint = true; + isAlphaChange = false; + + SelectedColor = m_color; + + + + + } + + + + #endregion + + + #region Public Properties + + // Gets or sets the selected color. + public System.Windows.Media.Color SelectedColor + { + get + { + + return (System.Windows.Media.Color)GetValue(SelectedColorProperty); + } + set + { + SetValue(SelectedColorProperty, m_color); + setColor((Color)value); + } + } + + + #region RGB Properties + // Gets or sets the ARGB alpha value of the selected color. + public byte A + { + get + { + return (byte)GetValue(AProperty); + } + set + { + SetValue(AProperty, value); + } + } + + // Gets or sets the ARGB red value of the selected color. + public byte R + { + get + { + return (byte)GetValue(RProperty); + } + set + { + SetValue(RProperty, value); + } + } + + // Gets or sets the ARGB green value of the selected color. + public byte G + { + get + { + return (byte)GetValue(GProperty); + } + set + { + SetValue(GProperty, value); + } + } + + // Gets or sets the ARGB blue value of the selected color. + public byte B + { + get + { + return (byte)GetValue(BProperty); + } + set + { + SetValue(BProperty, value); + } + } + #endregion RGB Properties + + #region ScRGB Properties + + // Gets or sets the ScRGB alpha value of the selected color. + public double ScA + { + get + { + return (double)GetValue(ScAProperty); + } + set + { + SetValue(ScAProperty, value); + } + } + + // Gets or sets the ScRGB red value of the selected color. + public double ScR + { + get + { + return (double)GetValue(ScRProperty); + } + set + { + SetValue(RProperty, value); + } + } + + // Gets or sets the ScRGB green value of the selected color. + public double ScG + { + get + { + return (double)GetValue(ScGProperty); + } + set + { + SetValue(GProperty, value); + } + } + + // Gets or sets the ScRGB blue value of the selected color. + public double ScB + { + get + { + return (double)GetValue(BProperty); + } + set + { + SetValue(BProperty, value); + } + } + #endregion ScRGB Properties + + // Gets or sets the the selected color in hexadecimal notation. + public string HexadecimalString + { + get + { + return (string)GetValue(HexadecimalStringProperty); + } + set + { + SetValue(HexadecimalStringProperty, value); + } + } + + public bool ShowAlpha + { + get + { + return (Visibility)GetValue (AlphaVisibilityProperty) == System.Windows.Visibility.Visible; + } + set + { + SetValue (AlphaVisibilityProperty, value ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed); + if (!ShowAlpha) this.A = 255; + } + } + + #endregion + + + #region Public Events + + public event RoutedPropertyChangedEventHandler SelectedColorChanged + { + add + { + AddHandler(SelectedColorChangedEvent, value); + } + + remove + { + RemoveHandler(SelectedColorChangedEvent, value); + } + } + + #endregion + + + #region Dependency Property Fields + public static readonly DependencyProperty SelectedColorProperty = + DependencyProperty.Register + ("SelectedColor", typeof(System.Windows.Media.Color), typeof(ColorPicker), + new PropertyMetadata(System.Windows.Media.Colors.Transparent, + new PropertyChangedCallback(selectedColor_changed) + + )); + + public static readonly DependencyProperty ScAProperty = + + DependencyProperty.Register + ("ScA", typeof(float), typeof(ColorPicker), + new PropertyMetadata((float)1, + new PropertyChangedCallback(ScAChanged) + )); + + public static readonly DependencyProperty ScRProperty = + DependencyProperty.Register + ("ScR", typeof(float), typeof(ColorPicker), + new PropertyMetadata((float)1, + new PropertyChangedCallback(ScRChanged) + )); + + public static readonly DependencyProperty ScGProperty = + DependencyProperty.Register + ("ScG", typeof(float), typeof(ColorPicker), + new PropertyMetadata((float)1, + new PropertyChangedCallback(ScGChanged) + )); + + public static readonly DependencyProperty ScBProperty = + DependencyProperty.Register + ("ScB", typeof(float), typeof(ColorPicker), + new PropertyMetadata((float)1, + new PropertyChangedCallback(ScBChanged) + )); + + public static readonly DependencyProperty AProperty = + DependencyProperty.Register + ("A", typeof(byte), typeof(ColorPicker), + new PropertyMetadata((byte)255, + new PropertyChangedCallback(AChanged) + )); + + public static readonly DependencyProperty RProperty = + DependencyProperty.Register + ("R", typeof(byte), typeof(ColorPicker), + new PropertyMetadata((byte)255, + new PropertyChangedCallback(RChanged) + )); + + public static readonly DependencyProperty GProperty = + DependencyProperty.Register + ("G", typeof(byte), typeof(ColorPicker), + new PropertyMetadata((byte)255, + new PropertyChangedCallback(GChanged) + )); + + public static readonly DependencyProperty BProperty = + DependencyProperty.Register + ("B", typeof(byte), typeof(ColorPicker), + new PropertyMetadata((byte)255, + new PropertyChangedCallback(BChanged) + )); + + public static readonly DependencyProperty HexadecimalStringProperty = + DependencyProperty.Register + ("HexadecimalString", typeof(string), typeof(ColorPicker), + new PropertyMetadata("#FFFFFFFF", + new PropertyChangedCallback(HexadecimalStringChanged) + )); + + public static readonly DependencyProperty AlphaVisibilityProperty = + DependencyProperty.Register + ("AlphaVisibility", typeof (Visibility), typeof (ColorPicker), + new PropertyMetadata (Visibility.Visible)); + + #endregion + + + #region RoutedEvent Fields + + public static readonly RoutedEvent SelectedColorChangedEvent = EventManager.RegisterRoutedEvent( + "SelectedColorChanged", + RoutingStrategy.Bubble, + typeof(RoutedPropertyChangedEventHandler), + typeof(ColorPicker) + ); + #endregion + + + #region Property Changed Callbacks + + private static void AChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnAChanged((byte)e.NewValue); + } + + protected virtual void OnAChanged(byte newValue) + { + + m_color.A = newValue; + SetValue(ScAProperty, m_color.ScA); + SetValue(SelectedColorProperty, m_color); + + } + + private static void RChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnRChanged((byte)e.NewValue); + } + + protected virtual void OnRChanged(byte newValue) + { + m_color.R = newValue; + SetValue(ScRProperty, m_color.ScR); + SetValue(SelectedColorProperty, m_color); + } + + + private static void GChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnGChanged((byte)e.NewValue); + } + + protected virtual void OnGChanged(byte newValue) + { + + m_color.G = newValue; + SetValue(ScGProperty, m_color.ScG); + SetValue(SelectedColorProperty, m_color); + } + + + private static void BChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnBChanged((byte)e.NewValue); + } + + protected virtual void OnBChanged(byte newValue) + { + m_color.B = newValue; + SetValue(ScBProperty, m_color.ScB); + SetValue(SelectedColorProperty, m_color); + } + + + private static void ScAChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnScAChanged((float)e.NewValue); + } + + protected virtual void OnScAChanged(float newValue) + { + isAlphaChange = true; + if (shouldFindPoint) + { + m_color.ScA = newValue; + SetValue(AProperty, m_color.A); + SetValue(SelectedColorProperty, m_color); + SetValue (HexadecimalStringProperty, GetHexadecimal ()); + } + isAlphaChange = false; + } + + + private static void ScRChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnScRChanged((float)e.NewValue); + + } + + protected virtual void OnScRChanged(float newValue) + { + if (shouldFindPoint) + { + m_color.ScR = newValue; + SetValue(RProperty, m_color.R); + SetValue(SelectedColorProperty, m_color); + SetValue (HexadecimalStringProperty, GetHexadecimal ()); + } + } + + + private static void ScGChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnScGChanged((float)e.NewValue); + } + + protected virtual void OnScGChanged(float newValue) + { + + if (shouldFindPoint) + { + m_color.ScG = newValue; + SetValue(GProperty, m_color.G); + SetValue(SelectedColorProperty, m_color); + SetValue (HexadecimalStringProperty, GetHexadecimal ()); + } + } + + + private static void ScBChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnScBChanged((float)e.NewValue); + } + + protected virtual void OnScBChanged(float newValue) + { + if (shouldFindPoint) + { + m_color.ScB = newValue; + SetValue(BProperty, m_color.B); + SetValue(SelectedColorProperty, m_color); + SetValue (HexadecimalStringProperty, GetHexadecimal ()); + } + } + + private static void HexadecimalStringChanged(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker c = (ColorPicker)d; + c.OnHexadecimalStringChanged((string)e.OldValue, (string)e.NewValue); + } + + protected virtual void OnHexadecimalStringChanged(string oldValue, string newValue) + { + + try + { + + if (shouldFindPoint) + { + + m_color = (Color)ColorConverter.ConvertFromString(newValue); + + } + + SetValue(AProperty, m_color.A); + SetValue(RProperty, m_color.R); + SetValue(GProperty, m_color.G); + SetValue(BProperty, m_color.B); + + + if (shouldFindPoint && !isAlphaChange && templateApplied) + { + updateMarkerPosition(m_color); + } + } + catch (FormatException fException) + { + + SetValue(HexadecimalStringProperty, oldValue); + } + + } + + private static void selectedColor_changed(DependencyObject d, + DependencyPropertyChangedEventArgs e) + { + ColorPicker cPicker = (ColorPicker)d; + cPicker.OnSelectedColorChanged((Color)e.OldValue, (Color)e.NewValue); + } + + protected virtual void OnSelectedColorChanged(Color oldColor, Color newColor) + { + + RoutedPropertyChangedEventArgs newEventArgs = + new RoutedPropertyChangedEventArgs(oldColor, newColor); + newEventArgs.RoutedEvent = ColorPicker.SelectedColorChangedEvent; + RaiseEvent(newEventArgs); + } + + #endregion + + + #region Template Part Event Handlers + + + protected override void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate) + { + + templateApplied = false; + if (oldTemplate != null) + { + m_ColorSlider.ValueChanged -= new RoutedPropertyChangedEventHandler(BaseColorChanged); + m_ColorDetail.MouseLeftButtonDown -= new MouseButtonEventHandler(OnMouseLeftButtonDown); + m_ColorDetail.PreviewMouseMove -= new MouseEventHandler(OnMouseMove); + m_ColorDetail.SizeChanged -= new SizeChangedEventHandler(ColorDetailSizeChanged); + m_ColorDetail = null; + m_ColorMarker = null; + m_ColorSlider = null; + } + base.OnTemplateChanged(oldTemplate, newTemplate); + } + + + private void BaseColorChanged( + object sender, + RoutedPropertyChangedEventArgs e) + { + + if (m_ColorPosition != null) + { + + determineColor((Point)m_ColorPosition); + } + + } + + private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + + Point p = e.GetPosition(m_ColorDetail); + updateMarkerPosition(p); + } + + private void OnMouseMove(object sender, MouseEventArgs e) + { + + + if (e.LeftButton == MouseButtonState.Pressed) + { + + Point p = e.GetPosition(m_ColorDetail); + updateMarkerPosition(p); + Mouse.Synchronize(); + + } + } + + private void ColorDetailSizeChanged(object sender, SizeChangedEventArgs args) + { + + if (args.PreviousSize != Size.Empty && + args.PreviousSize.Width != 0 && args.PreviousSize.Height != 0) + { + double widthDifference = args.NewSize.Width / args.PreviousSize.Width; + double heightDifference = args.NewSize.Height / args.PreviousSize.Height; + markerTransform.X = markerTransform.X * widthDifference; + markerTransform.Y = markerTransform.Y * heightDifference; + } + else if (m_ColorPosition != null) + { + markerTransform.X = ((Point)m_ColorPosition).X * args.NewSize.Width; + markerTransform.Y = ((Point)m_ColorPosition).Y * args.NewSize.Height; + } + } + + #endregion + + + #region Color Resolution Helpers + + string GetHexadecimal () + { + if (ShowAlpha) + return m_color.ToString (); + else + return string.Format ("#{0:X2}{1:X2}{2:X2}", m_color.R, m_color.G, m_color.B); + } + + + private void setColor(Color theColor) + { + m_color = theColor; + + if (templateApplied) { + SetValue(AProperty, m_color.A); + SetValue(RProperty, m_color.R); + SetValue(GProperty, m_color.G); + SetValue(BProperty, m_color.B); + updateMarkerPosition(theColor); + } + + } + + private void updateMarkerPosition(Point p) + { + markerTransform.X = p.X; + markerTransform.Y = p.Y; + p.X = p.X / m_ColorDetail.ActualWidth; + p.Y = p.Y / m_ColorDetail.ActualHeight; + m_ColorPosition = p; + determineColor(p); + } + + private void updateMarkerPosition(Color theColor) + { + m_ColorPosition = null; + + + HsvColor hsv = ColorUtilities.ConvertRgbToHsv(theColor.R, theColor.G, theColor.B); + + m_ColorSlider.Value = hsv.H; + + Point p = new Point(hsv.S, 1 - hsv.V); + + m_ColorPosition = p; + p.X = p.X * m_ColorDetail.ActualWidth; + p.Y = p.Y * m_ColorDetail.ActualHeight; + markerTransform.X = p.X; + markerTransform.Y = p.Y; + + } + + private void determineColor(Point p) + { + + HsvColor hsv = new HsvColor(360 - m_ColorSlider.Value, 1, 1); + hsv.S = p.X; + hsv.V = 1 - p.Y; + m_color = ColorUtilities.ConvertHsvToRgb(hsv.H, hsv.S, hsv.V); + shouldFindPoint = false; + m_color.ScA = (float)GetValue(ScAProperty); + SetValue (HexadecimalStringProperty, GetHexadecimal ()); + shouldFindPoint = true; + + } + + #endregion + + + #region Private Fields + private SpectrumSlider m_ColorSlider; + private static readonly string ColorSliderName = "PART_ColorSlider"; + private FrameworkElement m_ColorDetail; + private static readonly string ColorDetailName = "PART_ColorDetail"; + private TranslateTransform markerTransform = new TranslateTransform(); + private Path m_ColorMarker; + private static readonly string ColorMarkerName = "PART_ColorMarker"; + private Point? m_ColorPosition; + private Color m_color; + private bool shouldFindPoint; + private bool templateApplied; + private bool isAlphaChange; + #endregion + + } + + #endregion ColorPicker + + } \ No newline at end of file diff --git a/Libraries/WPFColorPicker/ColorPickerLib/ColorPicker.csproj b/Libraries/WPFColorPicker/ColorPickerLib/ColorPicker.csproj index 3ac23413bb..ed8b5702e3 100644 --- a/Libraries/WPFColorPicker/ColorPickerLib/ColorPicker.csproj +++ b/Libraries/WPFColorPicker/ColorPickerLib/ColorPicker.csproj @@ -1,70 +1,70 @@ - - - - - Microsoft.Samples.ColorPickerExample - ColorPicker - library - Release - MSBuild - False - 8.0.50727 - 2.0 - {99E90579-62FC-4898-B168-24F7DBD3A34D} - bin\$(Configuration)\ - Microsoft.Samples.CustomControls - - - Library - v4.0 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - 2.0 - - - - - - - - - - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - - Code - - - Code - - - ColorPickerDialog.xaml - Code - - - - - - - - - - - - - - - + + + + + Microsoft.Samples.ColorPickerExample + ColorPicker + library + Release + MSBuild + False + 8.0.50727 + 2.0 + {99E90579-62FC-4898-B168-24F7DBD3A34D} + bin\$(Configuration)\ + Microsoft.Samples.CustomControls + + + Library + v4.0 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + 2.0 + + + + + + + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + Code + + + Code + + + ColorPickerDialog.xaml + Code + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Libraries/WPFColorPicker/ColorPickerLib/ColorPickerDialog.xaml b/Libraries/WPFColorPicker/ColorPickerLib/ColorPickerDialog.xaml index c756801f8e..f4941f2ed8 100644 --- a/Libraries/WPFColorPicker/ColorPickerLib/ColorPickerDialog.xaml +++ b/Libraries/WPFColorPicker/ColorPickerLib/ColorPickerDialog.xaml @@ -1,27 +1,27 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/Libraries/WPFColorPicker/ColorPickerLib/ColorPickerDialog.xaml.cs b/Libraries/WPFColorPicker/ColorPickerLib/ColorPickerDialog.xaml.cs index f5728faa91..e2367e8d25 100644 --- a/Libraries/WPFColorPicker/ColorPickerLib/ColorPickerDialog.xaml.cs +++ b/Libraries/WPFColorPicker/ColorPickerLib/ColorPickerDialog.xaml.cs @@ -1,103 +1,103 @@ - -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Windows.Data; -using System.Windows.Media; -using System.Windows.Media.Animation; - -namespace Microsoft.Samples.CustomControls -{ - /// - /// Interaction logic for ColorPickerDialog.xaml - /// - - public partial class ColorPickerDialog : Window - { - - - public ColorPickerDialog() - { - InitializeComponent(); - } - - private void okButtonClicked(object sender, RoutedEventArgs e) - { - - OKButton.IsEnabled = false; - m_color = cPicker.SelectedColor; - DialogResult = true; - Hide(); - - } - - - private void cancelButtonClicked(object sender, RoutedEventArgs e) - { - - OKButton.IsEnabled = false; - DialogResult = false; - - } - - private void onSelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) - { - - if (e.NewValue != m_color) - { - - OKButton.IsEnabled = true; - } - } - - protected override void OnClosing(System.ComponentModel.CancelEventArgs e) - { - - OKButton.IsEnabled = false; - base.OnClosing(e); - } - - - private Color m_color = new Color(); - private Color startingColor = new Color(); - - public Color SelectedColor - { - get - { - return m_color; - } - - } - - public Color StartingColor - { - get - { - return startingColor; - } - set - { - cPicker.SelectedColor = value; - OKButton.IsEnabled = false; - - } - - } - - public bool ShowAlpha - { - get - { - return cPicker.ShowAlpha; - } - set - { - cPicker.ShowAlpha = value; - } - } - } + +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Data; +using System.Windows.Media; +using System.Windows.Media.Animation; + +namespace Microsoft.Samples.CustomControls +{ + /// + /// Interaction logic for ColorPickerDialog.xaml + /// + + public partial class ColorPickerDialog : Window + { + + + public ColorPickerDialog() + { + InitializeComponent(); + } + + private void okButtonClicked(object sender, RoutedEventArgs e) + { + + OKButton.IsEnabled = false; + m_color = cPicker.SelectedColor; + DialogResult = true; + Hide(); + + } + + + private void cancelButtonClicked(object sender, RoutedEventArgs e) + { + + OKButton.IsEnabled = false; + DialogResult = false; + + } + + private void onSelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) + { + + if (e.NewValue != m_color) + { + + OKButton.IsEnabled = true; + } + } + + protected override void OnClosing(System.ComponentModel.CancelEventArgs e) + { + + OKButton.IsEnabled = false; + base.OnClosing(e); + } + + + private Color m_color = new Color(); + private Color startingColor = new Color(); + + public Color SelectedColor + { + get + { + return m_color; + } + + } + + public Color StartingColor + { + get + { + return startingColor; + } + set + { + cPicker.SelectedColor = value; + OKButton.IsEnabled = false; + + } + + } + + public bool ShowAlpha + { + get + { + return cPicker.ShowAlpha; + } + set + { + cPicker.ShowAlpha = value; + } + } + } } \ No newline at end of file diff --git a/Libraries/WPFColorPicker/ColorPickerLib/Properties/AssemblyInfo.cs b/Libraries/WPFColorPicker/ColorPickerLib/Properties/AssemblyInfo.cs index 780a602c93..90f3b6ae58 100644 --- a/Libraries/WPFColorPicker/ColorPickerLib/Properties/AssemblyInfo.cs +++ b/Libraries/WPFColorPicker/ColorPickerLib/Properties/AssemblyInfo.cs @@ -1,39 +1,39 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; -// -//used to let loading assemblies know that theme resources are stored in this assembly -[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] -// -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ColorPickerDialog")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("ColorPickerDialog")] -[assembly: AssemblyCopyright("Copyright MSFT 2006")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM componenets. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("99E90579-62FC-4898-B168-24F7DBD3A34D")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; +// +//used to let loading assemblies know that theme resources are stored in this assembly +[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ColorPickerDialog")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ColorPickerDialog")] +[assembly: AssemblyCopyright("Copyright MSFT 2006")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM componenets. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("99E90579-62FC-4898-B168-24F7DBD3A34D")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Libraries/WPFColorPicker/ColorPickerLib/SupportingClasses.cs b/Libraries/WPFColorPicker/ColorPickerLib/SupportingClasses.cs index 897803fe84..645b6e3a29 100644 --- a/Libraries/WPFColorPicker/ColorPickerLib/SupportingClasses.cs +++ b/Libraries/WPFColorPicker/ColorPickerLib/SupportingClasses.cs @@ -1,384 +1,384 @@ -// -// SupportingClasses.cs -// -// -using System; -using System.Windows; -using System.Windows.Navigation; -using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Shapes; -using System.Windows.Ink; -using System.Windows.Controls; -using System.Collections.Generic; -using System.Windows.Input; -using System.Windows.Data; -using System.Windows.Markup; - -namespace Microsoft.Samples.CustomControls -{ - - - - #region SpectrumSlider - - public class SpectrumSlider : Slider - { - - - static SpectrumSlider() - { - - DefaultStyleKeyProperty.OverrideMetadata(typeof(SpectrumSlider), - new FrameworkPropertyMetadata(typeof(SpectrumSlider))); - } - - - #region Public Properties - public Color SelectedColor - { - get - { - - return (Color)GetValue(SelectedColorProperty); - } - set - { - SetValue(SelectedColorProperty, value); - } - - } - #endregion - - - #region Dependency Property Fields - public static readonly DependencyProperty SelectedColorProperty = - DependencyProperty.Register - ("SelectedColor", typeof(Color), typeof(SpectrumSlider), - new PropertyMetadata(System.Windows.Media.Colors.Transparent)); - - #endregion - - - #region Public Methods - - public override void OnApplyTemplate() - { - - base.OnApplyTemplate(); - m_spectrumDisplay = GetTemplateChild(SpectrumDisplayName) as Rectangle; - updateColorSpectrum(); - OnValueChanged(Double.NaN, Value); - - } - - #endregion - - - #region Protected Methods - protected override void OnValueChanged(double oldValue, double newValue) - { - - base.OnValueChanged(oldValue, newValue); - Color theColor = ColorUtilities.ConvertHsvToRgb(360 - newValue, 1, 1); - SetValue(SelectedColorProperty, theColor); - } - #endregion - - - #region Private Methods - - private void updateColorSpectrum() - { - if (m_spectrumDisplay != null) - { - createSpectrum(); - } - } - - - - private void createSpectrum() - { - - pickerBrush = new LinearGradientBrush(); - pickerBrush.StartPoint = new Point(0.5, 0); - pickerBrush.EndPoint = new Point(0.5, 1); - pickerBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; - - - List colorsList = ColorUtilities.GenerateHsvSpectrum(); - double stopIncrement = (double)1 / colorsList.Count; - - int i; - for (i = 0; i < colorsList.Count; i++) - { - pickerBrush.GradientStops.Add(new GradientStop(colorsList[i], i * stopIncrement)); - } - - pickerBrush.GradientStops[i - 1].Offset = 1.0; - m_spectrumDisplay.Fill = pickerBrush; - - } - #endregion - - - #region Private Fields - private static string SpectrumDisplayName = "PART_SpectrumDisplay"; - private Rectangle m_spectrumDisplay; - private LinearGradientBrush pickerBrush; - #endregion - - } - - #endregion SpectrumSlider - - - #region ColorUtilities - - static class ColorUtilities - { - - // Converts an RGB color to an HSV color. - public static HsvColor ConvertRgbToHsv(int r, int b, int g) - { - - double delta, min; - double h = 0, s, v; - - min = Math.Min(Math.Min(r, g), b); - v = Math.Max(Math.Max(r, g), b); - delta = v - min; - - if (v == 0.0) { - s = 0; - - } - else - s = delta / v; - - if (s == 0) - h = 0.0; - - else - { - if (r == v) - h = (g - b) / delta; - else if (g == v) - h = 2 + (b - r) / delta; - else if (b == v) - h = 4 + (r - g) / delta; - - h *= 60; - if (h < 0.0) - h = h + 360; - - } - - HsvColor hsvColor = new HsvColor(); - hsvColor.H = h; - hsvColor.S = s; - hsvColor.V = v / 255; - - return hsvColor; - - } - - // Converts an HSV color to an RGB color. - public static Color ConvertHsvToRgb(double h, double s, double v) - { - - double r = 0, g = 0, b = 0; - - if (s == 0) - { - r = v; - g = v; - b = v; - } - else - { - int i; - double f, p, q, t; - - - if (h == 360) - h = 0; - else - h = h / 60; - - i = (int)Math.Truncate(h); - f = h - i; - - p = v * (1.0 - s); - q = v * (1.0 - (s * f)); - t = v * (1.0 - (s * (1.0 - f))); - - switch (i) - { - case 0: - r = v; - g = t; - b = p; - break; - - case 1: - r = q; - g = v; - b = p; - break; - - case 2: - r = p; - g = v; - b = t; - break; - - case 3: - r = p; - g = q; - b = v; - break; - - case 4: - r = t; - g = p; - b = v; - break; - - default: - r = v; - g = p; - b = q; - break; - } - - } - - - - return Color.FromArgb(255, (byte)(r * 255), (byte)(g * 255), (byte)(b * 255)); - - } - - // Generates a list of colors with hues ranging from 0 360 - // and a saturation and value of 1. - public static List GenerateHsvSpectrum() - { - - List colorsList = new List(8); - - - for (int i = 0; i < 29; i++) - { - - colorsList.Add( - ColorUtilities.ConvertHsvToRgb(i * 12, 1, 1) - - ); - - } - colorsList.Add(ColorUtilities.ConvertHsvToRgb(0, 1, 1)); - - - return colorsList; - - } - - } - - #endregion ColorUtilities - - - // Describes a color in terms of - // Hue, Saturation, and Value (brightness) - #region HsvColor - struct HsvColor - { - - public double H; - public double S; - public double V; - - public HsvColor(double h, double s, double v) - { - this.H = h; - this.S = s; - this.V = v; - - } - } - #endregion HsvColor - - #region ColorThumb - public class ColorThumb : System.Windows.Controls.Primitives.Thumb - { - - static ColorThumb() - { - - DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorThumb), - new FrameworkPropertyMetadata(typeof(ColorThumb))); - } - - - public static readonly DependencyProperty ThumbColorProperty = - DependencyProperty.Register - ("ThumbColor", typeof(Color), typeof(ColorThumb), - new FrameworkPropertyMetadata(Colors.Transparent)); - - public static readonly DependencyProperty PointerOutlineThicknessProperty = - DependencyProperty.Register - ("PointerOutlineThickness", typeof(double), typeof(ColorThumb), - new FrameworkPropertyMetadata(1.0)); - - public static readonly DependencyProperty PointerOutlineBrushProperty = - DependencyProperty.Register - ("PointerOutlineBrush", typeof(Brush), typeof(ColorThumb), - new FrameworkPropertyMetadata(null)); - - - - public Color ThumbColor - { - get - { - return (Color)GetValue(ThumbColorProperty); - } - set - { - - SetValue(ThumbColorProperty, value); - } - } - - public double PointerOutlineThickness - { - get - { - return (double)GetValue(PointerOutlineThicknessProperty); - } - set - { - SetValue(PointerOutlineThicknessProperty, value); - } - } - - public Brush PointerOutlineBrush - { - get - { - return (Brush)GetValue(PointerOutlineBrushProperty); - } - set - { - SetValue(PointerOutlineBrushProperty, value); - } - } - - - } - #endregion ColorThumb - - +// +// SupportingClasses.cs +// +// +using System; +using System.Windows; +using System.Windows.Navigation; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.Windows.Ink; +using System.Windows.Controls; +using System.Collections.Generic; +using System.Windows.Input; +using System.Windows.Data; +using System.Windows.Markup; + +namespace Microsoft.Samples.CustomControls +{ + + + + #region SpectrumSlider + + public class SpectrumSlider : Slider + { + + + static SpectrumSlider() + { + + DefaultStyleKeyProperty.OverrideMetadata(typeof(SpectrumSlider), + new FrameworkPropertyMetadata(typeof(SpectrumSlider))); + } + + + #region Public Properties + public Color SelectedColor + { + get + { + + return (Color)GetValue(SelectedColorProperty); + } + set + { + SetValue(SelectedColorProperty, value); + } + + } + #endregion + + + #region Dependency Property Fields + public static readonly DependencyProperty SelectedColorProperty = + DependencyProperty.Register + ("SelectedColor", typeof(Color), typeof(SpectrumSlider), + new PropertyMetadata(System.Windows.Media.Colors.Transparent)); + + #endregion + + + #region Public Methods + + public override void OnApplyTemplate() + { + + base.OnApplyTemplate(); + m_spectrumDisplay = GetTemplateChild(SpectrumDisplayName) as Rectangle; + updateColorSpectrum(); + OnValueChanged(Double.NaN, Value); + + } + + #endregion + + + #region Protected Methods + protected override void OnValueChanged(double oldValue, double newValue) + { + + base.OnValueChanged(oldValue, newValue); + Color theColor = ColorUtilities.ConvertHsvToRgb(360 - newValue, 1, 1); + SetValue(SelectedColorProperty, theColor); + } + #endregion + + + #region Private Methods + + private void updateColorSpectrum() + { + if (m_spectrumDisplay != null) + { + createSpectrum(); + } + } + + + + private void createSpectrum() + { + + pickerBrush = new LinearGradientBrush(); + pickerBrush.StartPoint = new Point(0.5, 0); + pickerBrush.EndPoint = new Point(0.5, 1); + pickerBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; + + + List colorsList = ColorUtilities.GenerateHsvSpectrum(); + double stopIncrement = (double)1 / colorsList.Count; + + int i; + for (i = 0; i < colorsList.Count; i++) + { + pickerBrush.GradientStops.Add(new GradientStop(colorsList[i], i * stopIncrement)); + } + + pickerBrush.GradientStops[i - 1].Offset = 1.0; + m_spectrumDisplay.Fill = pickerBrush; + + } + #endregion + + + #region Private Fields + private static string SpectrumDisplayName = "PART_SpectrumDisplay"; + private Rectangle m_spectrumDisplay; + private LinearGradientBrush pickerBrush; + #endregion + + } + + #endregion SpectrumSlider + + + #region ColorUtilities + + static class ColorUtilities + { + + // Converts an RGB color to an HSV color. + public static HsvColor ConvertRgbToHsv(int r, int b, int g) + { + + double delta, min; + double h = 0, s, v; + + min = Math.Min(Math.Min(r, g), b); + v = Math.Max(Math.Max(r, g), b); + delta = v - min; + + if (v == 0.0) { + s = 0; + + } + else + s = delta / v; + + if (s == 0) + h = 0.0; + + else + { + if (r == v) + h = (g - b) / delta; + else if (g == v) + h = 2 + (b - r) / delta; + else if (b == v) + h = 4 + (r - g) / delta; + + h *= 60; + if (h < 0.0) + h = h + 360; + + } + + HsvColor hsvColor = new HsvColor(); + hsvColor.H = h; + hsvColor.S = s; + hsvColor.V = v / 255; + + return hsvColor; + + } + + // Converts an HSV color to an RGB color. + public static Color ConvertHsvToRgb(double h, double s, double v) + { + + double r = 0, g = 0, b = 0; + + if (s == 0) + { + r = v; + g = v; + b = v; + } + else + { + int i; + double f, p, q, t; + + + if (h == 360) + h = 0; + else + h = h / 60; + + i = (int)Math.Truncate(h); + f = h - i; + + p = v * (1.0 - s); + q = v * (1.0 - (s * f)); + t = v * (1.0 - (s * (1.0 - f))); + + switch (i) + { + case 0: + r = v; + g = t; + b = p; + break; + + case 1: + r = q; + g = v; + b = p; + break; + + case 2: + r = p; + g = v; + b = t; + break; + + case 3: + r = p; + g = q; + b = v; + break; + + case 4: + r = t; + g = p; + b = v; + break; + + default: + r = v; + g = p; + b = q; + break; + } + + } + + + + return Color.FromArgb(255, (byte)(r * 255), (byte)(g * 255), (byte)(b * 255)); + + } + + // Generates a list of colors with hues ranging from 0 360 + // and a saturation and value of 1. + public static List GenerateHsvSpectrum() + { + + List colorsList = new List(8); + + + for (int i = 0; i < 29; i++) + { + + colorsList.Add( + ColorUtilities.ConvertHsvToRgb(i * 12, 1, 1) + + ); + + } + colorsList.Add(ColorUtilities.ConvertHsvToRgb(0, 1, 1)); + + + return colorsList; + + } + + } + + #endregion ColorUtilities + + + // Describes a color in terms of + // Hue, Saturation, and Value (brightness) + #region HsvColor + struct HsvColor + { + + public double H; + public double S; + public double V; + + public HsvColor(double h, double s, double v) + { + this.H = h; + this.S = s; + this.V = v; + + } + } + #endregion HsvColor + + #region ColorThumb + public class ColorThumb : System.Windows.Controls.Primitives.Thumb + { + + static ColorThumb() + { + + DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorThumb), + new FrameworkPropertyMetadata(typeof(ColorThumb))); + } + + + public static readonly DependencyProperty ThumbColorProperty = + DependencyProperty.Register + ("ThumbColor", typeof(Color), typeof(ColorThumb), + new FrameworkPropertyMetadata(Colors.Transparent)); + + public static readonly DependencyProperty PointerOutlineThicknessProperty = + DependencyProperty.Register + ("PointerOutlineThickness", typeof(double), typeof(ColorThumb), + new FrameworkPropertyMetadata(1.0)); + + public static readonly DependencyProperty PointerOutlineBrushProperty = + DependencyProperty.Register + ("PointerOutlineBrush", typeof(Brush), typeof(ColorThumb), + new FrameworkPropertyMetadata(null)); + + + + public Color ThumbColor + { + get + { + return (Color)GetValue(ThumbColorProperty); + } + set + { + + SetValue(ThumbColorProperty, value); + } + } + + public double PointerOutlineThickness + { + get + { + return (double)GetValue(PointerOutlineThicknessProperty); + } + set + { + SetValue(PointerOutlineThicknessProperty, value); + } + } + + public Brush PointerOutlineBrush + { + get + { + return (Brush)GetValue(PointerOutlineBrushProperty); + } + set + { + SetValue(PointerOutlineBrushProperty, value); + } + } + + + } + #endregion ColorThumb + + } \ No newline at end of file diff --git a/Libraries/WPFColorPicker/ColorPickerLib/Themes/generic.xaml b/Libraries/WPFColorPicker/ColorPickerLib/Themes/generic.xaml index 6fb49b28bd..358ba5d00c 100644 --- a/Libraries/WPFColorPicker/ColorPickerLib/Themes/generic.xaml +++ b/Libraries/WPFColorPicker/ColorPickerLib/Themes/generic.xaml @@ -1,773 +1,773 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Libraries/WPFColorPicker/ColorPickerSampleApplication/ColorPickerSampleApplication.csproj b/Libraries/WPFColorPicker/ColorPickerSampleApplication/ColorPickerSampleApplication.csproj index 41d778b2ff..86163fc1f3 100644 --- a/Libraries/WPFColorPicker/ColorPickerSampleApplication/ColorPickerSampleApplication.csproj +++ b/Libraries/WPFColorPicker/ColorPickerSampleApplication/ColorPickerSampleApplication.csproj @@ -1,64 +1,64 @@ - - - - Debug - AnyCPU - {1091F084-417B-42A8-A590-4F5F011ED1A0} - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ColorPickerSampleApplication - ColorPickerSampleApplication - 4 - winexe - 1.0.0.* - - false - v4.0 - - - 2.0 - - - - true - full - false - .\bin\Debug\ - DEBUG;TRACE - - - false - true - .\bin\Release\ - TRACE - - - - - - - - - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - SampleViewer.xaml - Code - - - - - {99E90579-62FC-4898-B168-24F7DBD3A34D} - ColorPicker - - - + + + + Debug + AnyCPU + {1091F084-417B-42A8-A590-4F5F011ED1A0} + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ColorPickerSampleApplication + ColorPickerSampleApplication + 4 + winexe + 1.0.0.* + + false + v4.0 + + + 2.0 + + + + true + full + false + .\bin\Debug\ + DEBUG;TRACE + + + false + true + .\bin\Release\ + TRACE + + + + + + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + SampleViewer.xaml + Code + + + + + {99E90579-62FC-4898-B168-24F7DBD3A34D} + ColorPicker + + + \ No newline at end of file diff --git a/Libraries/WPFColorPicker/ColorPickerSampleApplication/ColorPickerSampleApplication.sln b/Libraries/WPFColorPicker/ColorPickerSampleApplication/ColorPickerSampleApplication.sln index 804846cb2e..7df5790a4c 100644 --- a/Libraries/WPFColorPicker/ColorPickerSampleApplication/ColorPickerSampleApplication.sln +++ b/Libraries/WPFColorPicker/ColorPickerSampleApplication/ColorPickerSampleApplication.sln @@ -1,26 +1,26 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual C# Express 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorPickerSampleApplication", "ColorPickerSampleApplication.csproj", "{1091F084-417B-42A8-A590-4F5F011ED1A0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorPicker", "..\ColorPickerLib\ColorPicker.csproj", "{99E90579-62FC-4898-B168-24F7DBD3A34D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1091F084-417B-42A8-A590-4F5F011ED1A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1091F084-417B-42A8-A590-4F5F011ED1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1091F084-417B-42A8-A590-4F5F011ED1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1091F084-417B-42A8-A590-4F5F011ED1A0}.Release|Any CPU.Build.0 = Release|Any CPU - {99E90579-62FC-4898-B168-24F7DBD3A34D}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {99E90579-62FC-4898-B168-24F7DBD3A34D}.Debug|Any CPU.Build.0 = Release|Any CPU - {99E90579-62FC-4898-B168-24F7DBD3A34D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {99E90579-62FC-4898-B168-24F7DBD3A34D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorPickerSampleApplication", "ColorPickerSampleApplication.csproj", "{1091F084-417B-42A8-A590-4F5F011ED1A0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorPicker", "..\ColorPickerLib\ColorPicker.csproj", "{99E90579-62FC-4898-B168-24F7DBD3A34D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1091F084-417B-42A8-A590-4F5F011ED1A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1091F084-417B-42A8-A590-4F5F011ED1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1091F084-417B-42A8-A590-4F5F011ED1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1091F084-417B-42A8-A590-4F5F011ED1A0}.Release|Any CPU.Build.0 = Release|Any CPU + {99E90579-62FC-4898-B168-24F7DBD3A34D}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {99E90579-62FC-4898-B168-24F7DBD3A34D}.Debug|Any CPU.Build.0 = Release|Any CPU + {99E90579-62FC-4898-B168-24F7DBD3A34D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99E90579-62FC-4898-B168-24F7DBD3A34D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Libraries/WPFColorPicker/ColorPickerSampleApplication/SampleViewer.xaml b/Libraries/WPFColorPicker/ColorPickerSampleApplication/SampleViewer.xaml index e65a802221..6036deb0d2 100644 --- a/Libraries/WPFColorPicker/ColorPickerSampleApplication/SampleViewer.xaml +++ b/Libraries/WPFColorPicker/ColorPickerSampleApplication/SampleViewer.xaml @@ -1,249 +1,249 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Fill - - - - - - - Stroke - - - Stroke Thickness - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fill + + + + + + + Stroke + + + Stroke Thickness + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Libraries/WPFColorPicker/ColorPickerSampleApplication/SampleViewer.xaml.cs b/Libraries/WPFColorPicker/ColorPickerSampleApplication/SampleViewer.xaml.cs index dfe87c13c8..084eb6132d 100644 --- a/Libraries/WPFColorPicker/ColorPickerSampleApplication/SampleViewer.xaml.cs +++ b/Libraries/WPFColorPicker/ColorPickerSampleApplication/SampleViewer.xaml.cs @@ -1,351 +1,351 @@ -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; -using System.Windows.Input; - - -namespace ColorPickerSampleApplication -{ - - public partial class SampleViewer : Window - { - - public SampleViewer() - { - InitializeComponent(); - - } - - - - #region Dependency Property Fields - - public static readonly DependencyProperty SelectedShapeProperty = - DependencyProperty.Register - ("SelectedShape", typeof(Shape), typeof(SampleViewer), - new PropertyMetadata(null, selectedShape_Changed)); - - public static readonly DependencyProperty DrawingModeProperty = - DependencyProperty.Register - ("DrawingMode", typeof(DrawingMode), typeof(SampleViewer), - new PropertyMetadata(DrawingMode.Select)); - - public static readonly DependencyProperty FillColorProperty = - DependencyProperty.Register - ("FillColor", typeof(Color), typeof(SampleViewer), - new PropertyMetadata(Colors.LightGray)); - - public static readonly DependencyProperty StrokeColorProperty = - DependencyProperty.Register - ("StrokeColor", typeof(Color), typeof(SampleViewer), - new PropertyMetadata(Colors.Black)); - - public static readonly DependencyProperty StrokeThicknessProperty = - DependencyProperty.Register - ("StrokeThickness", typeof(double), typeof(SampleViewer), - new PropertyMetadata(1.0, strokeThickness_Changed)); - - #endregion - - - #region Public Properties - - public DrawingMode DrawingMode - { - get - { - return (DrawingMode)GetValue(DrawingModeProperty); - } - set - { - SetValue(DrawingModeProperty, value); - } - } - - - public Color FillColor - { - get - { - return (Color)GetValue(FillColorProperty); - } - set - { - SetValue(FillColorProperty, value); - } - } - - public Color StrokeColor - { - get - { - return (Color)GetValue(StrokeColorProperty); - } - set - { - SetValue(StrokeColorProperty, value); - } - } - - public double StrokeThickness - { - get - { - return (double)GetValue(StrokeThicknessProperty); - } - set - { - SetValue(StrokeThicknessProperty, value); - } - } - - #endregion - - - - - private static void selectedShape_Changed(object sender, - DependencyPropertyChangedEventArgs e) - { - - SampleViewer sViewer = (SampleViewer)sender; - sViewer.OnSelectedShapeChanged((Shape)e.OldValue, (Shape)e.NewValue); - - } - - protected void OnSelectedShapeChanged(Shape oldShape, Shape newShape) - { - if (newShape != null) - { - FillColor = ((SolidColorBrush)newShape.Fill).Color; - StrokeColor = ((SolidColorBrush)newShape.Stroke).Color; - StrokeThickness = newShape.StrokeThickness; - } - } - - private static void strokeThickness_Changed(object sender, - DependencyPropertyChangedEventArgs e) - { - - SampleViewer sViewer = (SampleViewer)sender; - sViewer.OnStrokeThicknessChanged((double)e.OldValue, (double)e.NewValue); - - } - - protected void OnStrokeThicknessChanged(double oldThickness, double newThickness) - { - Shape currentShape = (Shape)GetValue(SelectedShapeProperty); - if (currentShape != null) - { - currentShape.StrokeThickness = newThickness; - } - } - - - private void OnDrawingCanvasMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - Point clickPoint = e.GetPosition(DrawingCanvas); - if (DrawingMode == DrawingMode.Select) - { - if (e.OriginalSource is Shape) - { - Shape s = (Shape)e.OriginalSource; - SetValue(SelectedShapeProperty, s); - shapeClickPoint = e.GetPosition(s); - } - else - SetValue(SelectedShapeProperty, null); - } - else if (DrawingMode == DrawingMode.DrawRectangle && e.LeftButton == MouseButtonState.Pressed) - { - newRectangle = new Rectangle(); - newRectangle.Stroke = new SolidColorBrush(StrokeColor); - newRectangle.StrokeThickness = StrokeThickness; - newRectangle.Fill = new SolidColorBrush(FillColor); - Canvas.SetLeft(newRectangle, clickPoint.X); - Canvas.SetTop(newRectangle, clickPoint.Y); - DrawingCanvas.Children.Add(newRectangle); - SetValue(SelectedShapeProperty, newRectangle); - } - else if (DrawingMode == DrawingMode.DrawEllipse && e.LeftButton == MouseButtonState.Pressed) - { - newEllipse = new Ellipse(); - newEllipse.Stroke = new SolidColorBrush(StrokeColor); - newEllipse.StrokeThickness = StrokeThickness; - newEllipse.Fill = new SolidColorBrush(FillColor); - Canvas.SetLeft(newEllipse, clickPoint.X); - Canvas.SetTop(newEllipse, clickPoint.Y); - DrawingCanvas.Children.Add(newEllipse); - SetValue(SelectedShapeProperty, newEllipse); - } - else if (DrawingMode == DrawingMode.DrawLine && e.LeftButton == MouseButtonState.Pressed) - { - newLine = new Line(); - newLine.Stroke = new SolidColorBrush(StrokeColor); - newLine.Fill = new SolidColorBrush(FillColor);; - newLine.X1 = clickPoint.X; - newLine.Y1 = clickPoint.Y; - newLine.StrokeThickness = StrokeThickness; - DrawingCanvas.Children.Add(newLine); - SetValue(SelectedShapeProperty, newLine); - } - } - - private void OnDrawingCanvasMouseLeftButtonUp(object sender, MouseButtonEventArgs e) - { - - if (DrawingMode == DrawingMode.DrawRectangle) - { - newRectangle = null; - - } - else if (DrawingMode == DrawingMode.DrawEllipse) - { - newEllipse = null; - - } - else if (DrawingMode == DrawingMode.DrawLine) - { - newLine = null; - - } - } - - private void OnDrawingCanvasMouseMove(object sender, MouseEventArgs e) - { - Point dropPoint = e.GetPosition(DrawingCanvas); - if (DrawingMode == DrawingMode.Select) - { - Shape s = (Shape)GetValue(SelectedShapeProperty); - if (s != null && e.LeftButton == MouseButtonState.Pressed) - { - - Canvas.SetLeft(s, dropPoint.X - shapeClickPoint.X); - Canvas.SetTop(s, dropPoint.Y - shapeClickPoint.Y); - s.BitmapEffect = null; - } - } - else if (DrawingMode == DrawingMode.DrawRectangle) - { - if (newRectangle != null) - { - if (dropPoint.X > Canvas.GetLeft(newRectangle)) - newRectangle.Width = dropPoint.X - Canvas.GetLeft(newRectangle); - if (dropPoint.Y > Canvas.GetTop(newRectangle)) - newRectangle.Height = dropPoint.Y - Canvas.GetTop(newRectangle); - } - } - else if (DrawingMode == DrawingMode.DrawEllipse) - { - if (newEllipse != null) - { - if (dropPoint.X > Canvas.GetLeft(newEllipse)) - newEllipse.Width = dropPoint.X - Canvas.GetLeft(newEllipse); - if (dropPoint.Y > Canvas.GetTop(newEllipse)) - newEllipse.Height = dropPoint.Y - Canvas.GetTop(newEllipse); - } - } - else if (DrawingMode == DrawingMode.DrawLine) - { - if (newLine != null) - { - newLine.X2 = dropPoint.X; - newLine.Y2 = dropPoint.Y; - } - } - } - - private void OnDrawingCanvasKeyDown(object sender, KeyEventArgs e) - { - - Shape s = (Shape)GetValue(SelectedShapeProperty); - if (e.Key == Key.Delete && s!= null) - { - DrawingCanvas.Children.Remove(s); - SetValue(SelectedShapeProperty, null); - } - } - - - private void SetStroke(object sender, RoutedEventArgs e) - { - Shape selectedShape = (Shape)GetValue(SelectedShapeProperty); - - - Microsoft.Samples.CustomControls.ColorPickerDialog cPicker - = new Microsoft.Samples.CustomControls.ColorPickerDialog(); - cPicker.StartingColor = StrokeColor; - cPicker.Owner = this; - cPicker.ShowAlpha = false; - - bool? dialogResult = cPicker.ShowDialog(); - if (dialogResult != null && (bool)dialogResult == true) - { - - if (selectedShape != null) - selectedShape.Stroke = new SolidColorBrush(cPicker.SelectedColor); - StrokeColor = cPicker.SelectedColor; - - } - - } - - - private void SetFill(object sender, RoutedEventArgs e) - { - Shape selectedShape = (Shape)GetValue(SelectedShapeProperty); - - Microsoft.Samples.CustomControls.ColorPickerDialog cPicker - = new Microsoft.Samples.CustomControls.ColorPickerDialog(); - cPicker.StartingColor = FillColor; - cPicker.Owner = this; - - bool? dialogResult = cPicker.ShowDialog(); - if (dialogResult != null && (bool)dialogResult == true) - { - - if (selectedShape != null) - selectedShape.Fill = new SolidColorBrush(cPicker.SelectedColor); - FillColor = cPicker.SelectedColor; - - } - - } - - private void drawingModeChanged(object sender, EventArgs e) - { - - RadioButton r = (RadioButton)sender; - SetValue(DrawingModeProperty, Enum.Parse(typeof(DrawingMode), r.Name)); - - } - - - private void exitMenuItemClicked(object sender, RoutedEventArgs e) - { - Application.Current.Shutdown(); - } - - - - #region Private Fields - private Point shapeClickPoint; - private Rectangle newRectangle; - private Line newLine; - private Ellipse newEllipse; - - #endregion - - } - - public enum DrawingMode - { - Select=0, DrawLine=1, DrawRectangle=2, DrawEllipse=3 - - } +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using System.Windows.Input; + + +namespace ColorPickerSampleApplication +{ + + public partial class SampleViewer : Window + { + + public SampleViewer() + { + InitializeComponent(); + + } + + + + #region Dependency Property Fields + + public static readonly DependencyProperty SelectedShapeProperty = + DependencyProperty.Register + ("SelectedShape", typeof(Shape), typeof(SampleViewer), + new PropertyMetadata(null, selectedShape_Changed)); + + public static readonly DependencyProperty DrawingModeProperty = + DependencyProperty.Register + ("DrawingMode", typeof(DrawingMode), typeof(SampleViewer), + new PropertyMetadata(DrawingMode.Select)); + + public static readonly DependencyProperty FillColorProperty = + DependencyProperty.Register + ("FillColor", typeof(Color), typeof(SampleViewer), + new PropertyMetadata(Colors.LightGray)); + + public static readonly DependencyProperty StrokeColorProperty = + DependencyProperty.Register + ("StrokeColor", typeof(Color), typeof(SampleViewer), + new PropertyMetadata(Colors.Black)); + + public static readonly DependencyProperty StrokeThicknessProperty = + DependencyProperty.Register + ("StrokeThickness", typeof(double), typeof(SampleViewer), + new PropertyMetadata(1.0, strokeThickness_Changed)); + + #endregion + + + #region Public Properties + + public DrawingMode DrawingMode + { + get + { + return (DrawingMode)GetValue(DrawingModeProperty); + } + set + { + SetValue(DrawingModeProperty, value); + } + } + + + public Color FillColor + { + get + { + return (Color)GetValue(FillColorProperty); + } + set + { + SetValue(FillColorProperty, value); + } + } + + public Color StrokeColor + { + get + { + return (Color)GetValue(StrokeColorProperty); + } + set + { + SetValue(StrokeColorProperty, value); + } + } + + public double StrokeThickness + { + get + { + return (double)GetValue(StrokeThicknessProperty); + } + set + { + SetValue(StrokeThicknessProperty, value); + } + } + + #endregion + + + + + private static void selectedShape_Changed(object sender, + DependencyPropertyChangedEventArgs e) + { + + SampleViewer sViewer = (SampleViewer)sender; + sViewer.OnSelectedShapeChanged((Shape)e.OldValue, (Shape)e.NewValue); + + } + + protected void OnSelectedShapeChanged(Shape oldShape, Shape newShape) + { + if (newShape != null) + { + FillColor = ((SolidColorBrush)newShape.Fill).Color; + StrokeColor = ((SolidColorBrush)newShape.Stroke).Color; + StrokeThickness = newShape.StrokeThickness; + } + } + + private static void strokeThickness_Changed(object sender, + DependencyPropertyChangedEventArgs e) + { + + SampleViewer sViewer = (SampleViewer)sender; + sViewer.OnStrokeThicknessChanged((double)e.OldValue, (double)e.NewValue); + + } + + protected void OnStrokeThicknessChanged(double oldThickness, double newThickness) + { + Shape currentShape = (Shape)GetValue(SelectedShapeProperty); + if (currentShape != null) + { + currentShape.StrokeThickness = newThickness; + } + } + + + private void OnDrawingCanvasMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + Point clickPoint = e.GetPosition(DrawingCanvas); + if (DrawingMode == DrawingMode.Select) + { + if (e.OriginalSource is Shape) + { + Shape s = (Shape)e.OriginalSource; + SetValue(SelectedShapeProperty, s); + shapeClickPoint = e.GetPosition(s); + } + else + SetValue(SelectedShapeProperty, null); + } + else if (DrawingMode == DrawingMode.DrawRectangle && e.LeftButton == MouseButtonState.Pressed) + { + newRectangle = new Rectangle(); + newRectangle.Stroke = new SolidColorBrush(StrokeColor); + newRectangle.StrokeThickness = StrokeThickness; + newRectangle.Fill = new SolidColorBrush(FillColor); + Canvas.SetLeft(newRectangle, clickPoint.X); + Canvas.SetTop(newRectangle, clickPoint.Y); + DrawingCanvas.Children.Add(newRectangle); + SetValue(SelectedShapeProperty, newRectangle); + } + else if (DrawingMode == DrawingMode.DrawEllipse && e.LeftButton == MouseButtonState.Pressed) + { + newEllipse = new Ellipse(); + newEllipse.Stroke = new SolidColorBrush(StrokeColor); + newEllipse.StrokeThickness = StrokeThickness; + newEllipse.Fill = new SolidColorBrush(FillColor); + Canvas.SetLeft(newEllipse, clickPoint.X); + Canvas.SetTop(newEllipse, clickPoint.Y); + DrawingCanvas.Children.Add(newEllipse); + SetValue(SelectedShapeProperty, newEllipse); + } + else if (DrawingMode == DrawingMode.DrawLine && e.LeftButton == MouseButtonState.Pressed) + { + newLine = new Line(); + newLine.Stroke = new SolidColorBrush(StrokeColor); + newLine.Fill = new SolidColorBrush(FillColor);; + newLine.X1 = clickPoint.X; + newLine.Y1 = clickPoint.Y; + newLine.StrokeThickness = StrokeThickness; + DrawingCanvas.Children.Add(newLine); + SetValue(SelectedShapeProperty, newLine); + } + } + + private void OnDrawingCanvasMouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + + if (DrawingMode == DrawingMode.DrawRectangle) + { + newRectangle = null; + + } + else if (DrawingMode == DrawingMode.DrawEllipse) + { + newEllipse = null; + + } + else if (DrawingMode == DrawingMode.DrawLine) + { + newLine = null; + + } + } + + private void OnDrawingCanvasMouseMove(object sender, MouseEventArgs e) + { + Point dropPoint = e.GetPosition(DrawingCanvas); + if (DrawingMode == DrawingMode.Select) + { + Shape s = (Shape)GetValue(SelectedShapeProperty); + if (s != null && e.LeftButton == MouseButtonState.Pressed) + { + + Canvas.SetLeft(s, dropPoint.X - shapeClickPoint.X); + Canvas.SetTop(s, dropPoint.Y - shapeClickPoint.Y); + s.BitmapEffect = null; + } + } + else if (DrawingMode == DrawingMode.DrawRectangle) + { + if (newRectangle != null) + { + if (dropPoint.X > Canvas.GetLeft(newRectangle)) + newRectangle.Width = dropPoint.X - Canvas.GetLeft(newRectangle); + if (dropPoint.Y > Canvas.GetTop(newRectangle)) + newRectangle.Height = dropPoint.Y - Canvas.GetTop(newRectangle); + } + } + else if (DrawingMode == DrawingMode.DrawEllipse) + { + if (newEllipse != null) + { + if (dropPoint.X > Canvas.GetLeft(newEllipse)) + newEllipse.Width = dropPoint.X - Canvas.GetLeft(newEllipse); + if (dropPoint.Y > Canvas.GetTop(newEllipse)) + newEllipse.Height = dropPoint.Y - Canvas.GetTop(newEllipse); + } + } + else if (DrawingMode == DrawingMode.DrawLine) + { + if (newLine != null) + { + newLine.X2 = dropPoint.X; + newLine.Y2 = dropPoint.Y; + } + } + } + + private void OnDrawingCanvasKeyDown(object sender, KeyEventArgs e) + { + + Shape s = (Shape)GetValue(SelectedShapeProperty); + if (e.Key == Key.Delete && s!= null) + { + DrawingCanvas.Children.Remove(s); + SetValue(SelectedShapeProperty, null); + } + } + + + private void SetStroke(object sender, RoutedEventArgs e) + { + Shape selectedShape = (Shape)GetValue(SelectedShapeProperty); + + + Microsoft.Samples.CustomControls.ColorPickerDialog cPicker + = new Microsoft.Samples.CustomControls.ColorPickerDialog(); + cPicker.StartingColor = StrokeColor; + cPicker.Owner = this; + cPicker.ShowAlpha = false; + + bool? dialogResult = cPicker.ShowDialog(); + if (dialogResult != null && (bool)dialogResult == true) + { + + if (selectedShape != null) + selectedShape.Stroke = new SolidColorBrush(cPicker.SelectedColor); + StrokeColor = cPicker.SelectedColor; + + } + + } + + + private void SetFill(object sender, RoutedEventArgs e) + { + Shape selectedShape = (Shape)GetValue(SelectedShapeProperty); + + Microsoft.Samples.CustomControls.ColorPickerDialog cPicker + = new Microsoft.Samples.CustomControls.ColorPickerDialog(); + cPicker.StartingColor = FillColor; + cPicker.Owner = this; + + bool? dialogResult = cPicker.ShowDialog(); + if (dialogResult != null && (bool)dialogResult == true) + { + + if (selectedShape != null) + selectedShape.Fill = new SolidColorBrush(cPicker.SelectedColor); + FillColor = cPicker.SelectedColor; + + } + + } + + private void drawingModeChanged(object sender, EventArgs e) + { + + RadioButton r = (RadioButton)sender; + SetValue(DrawingModeProperty, Enum.Parse(typeof(DrawingMode), r.Name)); + + } + + + private void exitMenuItemClicked(object sender, RoutedEventArgs e) + { + Application.Current.Shutdown(); + } + + + + #region Private Fields + private Point shapeClickPoint; + private Rectangle newRectangle; + private Line newLine; + private Ellipse newEllipse; + + #endregion + + } + + public enum DrawingMode + { + Select=0, DrawLine=1, DrawRectangle=2, DrawEllipse=3 + + } } \ No newline at end of file diff --git a/Libraries/WPFColorPicker/ColorPickerSampleApplication/app.xaml b/Libraries/WPFColorPicker/ColorPickerSampleApplication/app.xaml index 467027e7d8..664a2bb892 100644 --- a/Libraries/WPFColorPicker/ColorPickerSampleApplication/app.xaml +++ b/Libraries/WPFColorPicker/ColorPickerSampleApplication/app.xaml @@ -1,157 +1,157 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index adda37b809..85a45c8532 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,15 @@ Eto.Forms ========= ### A cross platform desktop and mobile user interface framework +[![Build status](http://img.shields.io/appveyor/ci/cwensley/eto.svg?style=flat)](https://ci.appveyor.com/project/cwensley/eto/branch/develop) + Links ----- * Join the [forums](http://groups.google.com/group/eto-forms) * Chat in [#eto.forms](http://chat.mibbit.com/?server=irc.gimp.org&channel=%23eto.forms) on irc.gimp.org -* Download using [nuget](https://www.nuget.org/packages/Eto.Forms.Sample/) with Visual Studio or [Xamarin Studio nuget addin](https://github.com/mrward/monodevelop-nuget-addin) +* Download binaries using NuGet [![NuGet](http://img.shields.io/nuget/v/Eto.Forms.svg?style=flat)](https://www.nuget.org/packages/Eto.Forms.Sample/) with Visual Studio or Xamarin Studio. +* For bleeding edge nuget packages, add the MyGet development feed [![MyGet](http://img.shields.io/myget/eto/vpre/Eto.Forms.svg?style=flat)](https://www.myget.org/F/eto/) to your sources list. Description @@ -22,23 +25,22 @@ There is a Mobile/iOS port in the works, but is considered incomplete. This framework was built so that using it in .NET is natural. For example, a simple hello-world application might look like: + using Eto.Forms; + using Eto.Drawing; + public class MyForm : Form { public MyForm () { - Text = "My Cross-Platform App"; - Size = new Size (200, 200); + Title = "My Cross-Platform App"; + ClientSize = new Size(200, 200); Content = new Label { Text = "Hello World!" }; } [STAThread] - static void Main () { - var app = new Application(); - app.Initialized += delegate { - app.MainForm = new MyForm (); - app.MainForm.Show (); - }; - app.Run (); + static void Main() + { + new Application().Run(new MyForm()); } } @@ -50,13 +52,22 @@ Applications * [Notedown](https://github.com/modmonkeys/Notedown) - Note taking application * [Eto.Test](https://github.com/picoe/Eto/tree/master/Source/Eto.Test) - Application to test the functionality of each widget -Namespaces +Assemblies ---------- -* [Eto.Forms](https://github.com/picoe/Eto/tree/master/Source/Eto/Forms) - User interface -* [Eto.Drawing](https://github.com/picoe/Eto/tree/master/Source/Eto/Drawing) - Drawing/graphical routines -* [Eto.IO](https://github.com/picoe/Eto/tree/master/Source/Eto/IO) - Disk/Virtual directory abstraction -* Eto.Platform.[Platform] - platform implementations +Your project only needs to reference Eto.dll, and include the corresponding platform assembly that you wish to target. To run on a Mac platform, you need to [bundle your app](https://github.com/picoe/Eto/wiki/Running-your-application). + +* Eto.dll - Eto.Forms (UI), Eto.Drawing (Graphics), and platform loading +* Eto.Mac.dll - MonoMac platform for OS X using 32-bit mono +* Eto.Mac64.dll - MonoMac platform for OS X using 64-bit mono +* Eto.XamMac.dll - Xamarin.Mac platform for OS X to embed mono +* Eto.WinForms.dll - Windows Forms platform using GDI+ for graphics +* Eto.Direct2D.dll - Windows Forms platform using Direct2D for graphics +* Eto.Wpf.dll - Windows Presentation Foundation platform +* Eto.Gtk2.dll - Gtk2 platform +* Eto.Gtk3.dll - Gtk3 platform +* Eto.iOS.dll - Xamarin.iOS platform +* Eto.Android.dll - Xamarin.Android platform Currently supported targets --------------------------- @@ -69,4 +80,7 @@ Currently supported targets Under development ----------------- -* Android using Xamarin.Android +These platforms are currently in development. Any eager bodies willing to help feel free to do so! + +* Android using Xamarin.Android (Eto.Android) +* Windows 8.x and Windows Phone (Eto.WinRT) diff --git a/Resources/MacAppTemplate.app/Contents/Info.plist b/Resources/MacAppTemplate.app/Contents/Info.plist index fc9a6a39e5..4eafedf790 100644 --- a/Resources/MacAppTemplate.app/Contents/Info.plist +++ b/Resources/MacAppTemplate.app/Contents/Info.plist @@ -17,7 +17,7 @@ CFBundleIconFile Icon.icns CFBundleExecutable - Launcher + Launcher.exec BuildMachineOSBuild 12A269 CFBundleDevelopmentRegion diff --git a/Resources/MacAppTemplate.app/Contents/MacOS/Launcher b/Resources/MacAppTemplate.app/Contents/MacOS/Launcher.exec similarity index 100% rename from Resources/MacAppTemplate.app/Contents/MacOS/Launcher rename to Resources/MacAppTemplate.app/Contents/MacOS/Launcher.exec diff --git a/Resources/MacAppTemplate.app/Contents/MonoBundle/README.txt b/Resources/MacAppTemplate.app/Contents/MonoBundle/README.txt index f2d7d13603..e3dbab22f0 100644 --- a/Resources/MacAppTemplate.app/Contents/MonoBundle/README.txt +++ b/Resources/MacAppTemplate.app/Contents/MonoBundle/README.txt @@ -3,7 +3,7 @@ Next Steps: 1. Copy your .exe, .dll's, and any external resources here - - Make sure to include Eto.dll, Eto.Platform.Mac.dll, and MonoMac.dll + - Make sure to include Eto.dll, Eto.Mac.dll, and MonoMac.dll 2. Modify Contents/Info.plist and update these properties: diff --git a/Resources/Publish.targets b/Resources/Publish.targets index bd6ea141a4..80ab62e281 100644 --- a/Resources/Publish.targets +++ b/Resources/Publish.targets @@ -2,58 +2,165 @@ Release - ..\Source - ..\BuildOutput\$(Configuration) - ..\BuildOutput\Pcl\$(Configuration) - ..\BuildOutput\Nuget\$(Configuration) - Clean;Build + .. + $(BaseDir)\Source + $(SourceDir) + $(BaseDir)\BuildOutput\$(Configuration) + $(BaseDir)\BuildOutput\Pcl\$(Configuration) + $(BaseDir)\BuildOutput\Nuget\$(Configuration) + Build $(TargetDir.Trim('\\')) + Windows + 1.4.0.78 + $(MSBuildThisFileDirectory)\packages\MSBuildTasks.$(MSBuildCommunityVersion)\tools + $([MSBUILD]::Unescape($(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.dll)) + + $(SourceDir)\Addins\Eto.Addin.XamarinStudio\Eto.Addin.XamarinStudio.csproj + $(SourceDir)\Addins\Eto.Addin.VisualStudio\Eto.Addin.VisualStudio.sln + "/Applications/Xamarin Studio.app/Contents/MacOS/mdtool" + "c:\Program Files (x86)\Xamarin Studio\bin\mdtool.exe" - - - - "/Applications/Xamarin Studio.app/Contents/MacOS/mdtool" - - - - + + + + + + + + + + + + + + + + + + + + + - + + + + + + + - + + - - - + + + + + + + + - - + + + Eto.dll + + + Eto.Gtk2.dll + + + Eto.Gtk3.dll + + + Eto.Mac.dll + + + Eto.Mac64.dll + + + Eto.XamMac.dll + + + Eto.XamMac2.dll + + + Eto.WinForms.dll + + + Eto.Direct2D.dll + + + Eto.Wpf.dll + + + Eto.WinRT.dll + + + Eto.iOS.dll + + + Eto.Serialization.Json.dll + + + Eto.Serialization.Xaml.dll + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + - + + - + + + + + \ No newline at end of file diff --git a/Resources/Utilities.targets b/Resources/Utilities.targets new file mode 100644 index 0000000000..42b8a9478d --- /dev/null +++ b/Resources/Utilities.targets @@ -0,0 +1,91 @@ + + + + true + packages + $(UtilitiesBasePath)\Eto.UtilitiesTasks + + + + + + + + (); + if (informationalVersion != null) + AssemblyInformationalVersion = informationalVersion.InformationalVersion; + var title = assembly.GetCustomAttribute(); + if (title != null) + AssemblyTitle = title.Title; + var description = assembly.GetCustomAttribute(); + if (description != null) + AssemblyDescription = description.Description; + var copyright = assembly.GetCustomAttribute(); + if (copyright != null) + AssemblyCopyright = copyright.Copyright; + var company = assembly.GetCustomAttribute(); + if (company != null) + AssemblyCompany = company.Company; + AssemblyName = assembly.GetName().Name; + return true; + } + catch (Exception ex) + { + Log.LogErrorFromException(ex); + return false; + } + } +}]]> + + + + + + + \ No newline at end of file diff --git a/Resources/nuget.exe b/Resources/nuget.exe index 3ffdd33c61..c41a0d0deb 100644 Binary files a/Resources/nuget.exe and b/Resources/nuget.exe differ diff --git a/Resources/nuspec/Eto.Forms.Sample/Eto.Forms.Sample.nuspec b/Resources/nuspec/Eto.Forms.Sample/Eto.Forms.Sample.nuspec index 346bd351f3..2c3be5f0f8 100644 --- a/Resources/nuspec/Eto.Forms.Sample/Eto.Forms.Sample.nuspec +++ b/Resources/nuspec/Eto.Forms.Sample/Eto.Forms.Sample.nuspec @@ -11,28 +11,30 @@ false Eto.Forms - Sample Cross Platform Application - This sample application provides a starting point for your Eto.Forms application. +This sample application provides a starting point for your Eto.Forms application. - Add this package to a blank console application, then delete the Program.cs of the existing application to use MyEtoApplication.Main() as your program startup. +Add this package to a blank console application, which will replace your Program.cs with the Eto.Forms startup code and include a MainForm.cs as a sample form to get you started. - You should also change the console application's output type to 'Windows Application' to suppress the console window from showing. +You will need to change the console application's output type to 'Windows Application' to suppress the console window from showing. + +In Xamarin Studio, set the compile target to 'Executable with GUI' and uncheck 'Run on external console' in Run > Build. Copyright 2014 by Curtis Wensley cross platform gui framework desktop winforms wpf mac osx gtk eto.forms sample - - - - - - + + + + + + - - + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Forms.Sample/MainForm.cs.pp b/Resources/nuspec/Eto.Forms.Sample/MainForm.cs.pp new file mode 100644 index 0000000000..704c60bf46 --- /dev/null +++ b/Resources/nuspec/Eto.Forms.Sample/MainForm.cs.pp @@ -0,0 +1,60 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace $rootnamespace$ +{ + /// + /// Your application's main form + /// + public class MainForm : Form + { + public MainForm() + { + Title = "My Eto Form"; + ClientSize = new Size(400, 350); + + // scrollable region as the main content + Content = new Scrollable + { + // table with three rows + Content = new TableLayout( + null, + // row with three columns + new TableRow(null, new Label { Text = "Hello World!" }, null), + null + ) + }; + + // create a few commands that can be used for the menu and toolbar + var clickMe = new Command { MenuText = "Click Me!", ToolBarText = "Click Me!" }; + clickMe.Executed += (sender, e) => MessageBox.Show(this, "I was clicked!"); + + var quitCommand = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q }; + quitCommand.Executed += (sender, e) => Application.Instance.Quit(); + + var aboutCommand = new Command { MenuText = "About..." }; + aboutCommand.Executed += (sender, e) => MessageBox.Show(this, "About my app..."); + + // create menu + Menu = new MenuBar + { + Items = { + // File submenu + new ButtonMenuItem { Text = "&File", Items = { clickMe } }, + // new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } }, + // new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } }, + }, + ApplicationItems = { + // application (OS X) or file menu (others) + new ButtonMenuItem { Text = "&Preferences..." }, + }, + QuitItem = quitCommand, + AboutItem = aboutCommand + }; + + // create toolbar + ToolBar = new ToolBar { Items = { clickMe } }; + } + } +} \ No newline at end of file diff --git a/Resources/nuspec/Eto.Forms.Sample/MyEtoApplication.cs.pp b/Resources/nuspec/Eto.Forms.Sample/MyEtoApplication.cs.pp deleted file mode 100644 index 090cbe6615..0000000000 --- a/Resources/nuspec/Eto.Forms.Sample/MyEtoApplication.cs.pp +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; - -namespace $rootnamespace$ -{ - /// - /// Set this class as your startup object - /// - public class MyEtoApplication : Application - { - [STAThread] - public static void Main(string[] args) - { - var app = new MyEtoApplication(); - app.Run(args); - } - - /// - /// Handles when the application is initialized and running - /// - public override void OnInitialized(EventArgs e) - { - base.OnInitialized(e); - - MainForm = new MyEtoForm(); - MainForm.Show(); - } - } -} diff --git a/Resources/nuspec/Eto.Forms.Sample/MyEtoForm.cs.pp b/Resources/nuspec/Eto.Forms.Sample/MyEtoForm.cs.pp deleted file mode 100644 index a45dd56182..0000000000 --- a/Resources/nuspec/Eto.Forms.Sample/MyEtoForm.cs.pp +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; - -namespace $rootnamespace$ -{ - /// - /// Your form - /// - public class MyEtoForm : Form - { - public MyEtoForm() - { - Title = "My Eto Form"; - ClientSize = new Size(400, 350); - - // DynamicLayout is the typical layout to use - // but you can also use TableLayout or PixelLayout - var layout = new DynamicLayout(); - - layout.BeginHorizontal(); - - layout.Add(null); - layout.Add(new Label { Text = "Hello World!" }); - layout.Add(null); - - layout.EndHorizontal(); - - // scrollable gives you a scrolling region - Content = new Scrollable { Content = layout }; - - GenerateMenuAndToolBar(); - } - - void GenerateMenuAndToolBar() - { - // your commands! - var clickMe = new Command { MenuText = "Click Me!", ShowLabel = true, ToolBarText = "Click Me!" }; - clickMe.Executed += (sender, e) => MessageBox.Show(this, "I was clicked!"); - - var quitAction = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q }; - quitAction.Executed += (sender, e) => Application.Instance.Quit(); - - - // create menu & get standard menu items (e.g. needed for OS X) - var menu = new MenuBar(); - Application.Instance.CreateStandardMenu(menu.Items); - - // add commands to the menu - var myMenu = menu.Items.GetSubmenu("&File"); - myMenu.Items.Add(clickMe, 500); - myMenu.Items.AddSeparator(500); - myMenu.Items.Add(quitAction, 1000); - - menu.Items.Trim(); - this.Menu = menu; - - - // create toolbar - var toolbar = new ToolBar(); - toolbar.Items.Add(clickMe); - this.ToolBar = toolbar; - } - } -} \ No newline at end of file diff --git a/Resources/nuspec/Eto.Forms.Sample/Program.cs.pp b/Resources/nuspec/Eto.Forms.Sample/Program.cs.pp new file mode 100644 index 0000000000..3361177c6c --- /dev/null +++ b/Resources/nuspec/Eto.Forms.Sample/Program.cs.pp @@ -0,0 +1,16 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace $rootnamespace$ +{ + public static class Program + { + [STAThread] + public static void Main(string[] args) + { + // run application with our main form + new Application().Run(new MainForm()); + } + } +} diff --git a/Resources/nuspec/Eto.Forms.Sample/README.txt b/Resources/nuspec/Eto.Forms.Sample/README.txt index 6eab2e547b..bd4418e6bd 100644 --- a/Resources/nuspec/Eto.Forms.Sample/README.txt +++ b/Resources/nuspec/Eto.Forms.Sample/README.txt @@ -1,14 +1,13 @@ Welcome to your first Eto.Forms cross-platform application! -To get started, ensure you use MyEtoApplication.Main() as your program startup, so delete -the existing Program.cs and/or Main() method. +To get started, ensure you use Program.Main() as your program startup. Here's a breakdown of what's included: -MyEtoForm.cs - Contains your main form -MyEtoApplication.cs - Your startup code and Main() method -MyApp.app - A template for packaging your app for Mac users +MainForm.cs - Contains your main form +Program.cs - Your startup code +MyApp.app - A template for packaging your app for Mac users This framework can be used to build applications that run across multiple platforms using their native toolkit using a single UI codebase. This will make your applications look and diff --git a/Resources/nuspec/Eto.Json.nuspec b/Resources/nuspec/Eto.Json.nuspec deleted file mode 100644 index f6f9defca7..0000000000 --- a/Resources/nuspec/Eto.Json.nuspec +++ /dev/null @@ -1,32 +0,0 @@ - - - - Eto.Forms.Json - $version$ - Eto.Forms Json serializer - Picoe Software Solutions Inc. - Picoe Software Solutions Inc. - https://github.com/picoe/Eto/raw/master/LICENSE - https://github.com/picoe/Eto - false - Eto.Forms Json serializer - - Eto.Json allows you to load json UI definitions for the Eto.Forms framework - - To get more information about how to get started, read the wiki: - - https://github.com/picoe/Eto/wiki - - Copyright 2014 by Curtis Wensley - cross platform gui ui framework desktop json eto.forms - - - - - - - - - - - \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.Direct2D.nuspec b/Resources/nuspec/Eto.Platform.Direct2D.nuspec index 68d9ef63e7..cf4182bde8 100644 --- a/Resources/nuspec/Eto.Platform.Direct2D.nuspec +++ b/Resources/nuspec/Eto.Platform.Direct2D.nuspec @@ -1,30 +1,30 @@ - $id$ + Eto.Platform.Direct2D $version$ $title$ - Picoe Software Solutions Inc. - Picoe Software Solutions Inc. + $author$ + $author$ https://github.com/picoe/Eto/raw/master/LICENSE https://github.com/picoe/Eto false $description$ - This is the Direct2D platform for Eto.Forms UI Framework. +This is the Direct2D platform for Eto.Forms UI Framework. - Include this along with your Eto.Forms application to provide a WinForms interface with Direct2D drawing for your windows users. +Include this along with your Eto.Forms application to provide a WinForms interface with Direct2D drawing for your windows users. - The Direct2D platform allows for increased performance when custom drawing by using the GPU. This does not affect the behaviour or performance of regular controls, which will use the Windows Forms platform. +The Direct2D platform allows for increased performance when custom drawing by using the GPU. This does not affect the behaviour or performance of regular controls, which will use the Windows Forms platform. - You do not need to use any of the classes of this assembly (unless customizing the functionality of the platform), and should just use the UI controls from the Eto assembly. +You do not need to use any of the classes of this assembly (unless customizing the functionality of the platform), and should just use the UI controls from the Eto assembly. - Copyright 2014 by Curtis Wensley + $copyright$ cross platform gui ui framework desktop wpf eto.forms - - + + @@ -32,7 +32,8 @@ - - + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.Gtk.nuspec b/Resources/nuspec/Eto.Platform.Gtk.nuspec index 9cce8ff0df..3280ac3a2f 100644 --- a/Resources/nuspec/Eto.Platform.Gtk.nuspec +++ b/Resources/nuspec/Eto.Platform.Gtk.nuspec @@ -1,7 +1,7 @@ - $id$ + Eto.Platform.Gtk $version$ $title$ $author$ @@ -11,24 +11,25 @@ false $description$ - This is the GTK2 platform for Eto.Forms UI Framework. +This is the GTK2 platform for Eto.Forms UI Framework. - Include this along with your Eto.Forms application to provide a GTK interface, typically for Linux users. +Include this along with your Eto.Forms application to provide a GTK2 interface, typically for Linux users. - You do not need to use any of the classes of this assembly (unless customizing the GTK functionality of the platform), and should just use the UI controls from the Eto assembly. +You do not need to use any of the classes of this assembly (unless customizing the GTK functionality of the platform), and should just use the UI controls from the Eto assembly. - On Linux, mono framework 2.10 or higher and gtk-sharp2 are required. +On Linux, mono framework 2.10 or higher and gtk-sharp2 are required. - Copyright 2014 by Curtis Wensley + $copyright$ cross platform gui ui framework desktop gtk eto.forms - + - - + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.Gtk3.nuspec b/Resources/nuspec/Eto.Platform.Gtk3.nuspec index c5c206fefb..d8245ad060 100644 --- a/Resources/nuspec/Eto.Platform.Gtk3.nuspec +++ b/Resources/nuspec/Eto.Platform.Gtk3.nuspec @@ -1,7 +1,7 @@ - $id$ + Eto.Platform.Gtk3 $version$ $title$ $author$ @@ -11,24 +11,25 @@ false $description$ - This is the GTK3 platform for Eto.Forms UI Framework. +This is the GTK3 platform for Eto.Forms UI Framework. - Include this along with your Eto.Forms application to provide a GTK interface, typically for Linux users. +Include this along with your Eto.Forms application to provide a GTK3 interface, typically for Linux users. - You do not need to use any of the classes of this assembly (unless customizing the GTK functionality of the platform), and should just use the UI controls from the Eto assembly. +You do not need to use any of the classes of this assembly (unless customizing the GTK functionality of the platform), and should just use the UI controls from the Eto assembly. - On Linux, mono framework 2.10 or higher and gtk-sharp2 are required. +On Linux, mono framework 2.10 or higher and gtk-sharp2 are required. - Copyright 2014 by Curtis Wensley + $copyright$ cross platform gui ui framework desktop gtk eto.forms - + - - + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.Mac.Template.nuspec b/Resources/nuspec/Eto.Platform.Mac.Template.nuspec deleted file mode 100644 index f360940516..0000000000 --- a/Resources/nuspec/Eto.Platform.Mac.Template.nuspec +++ /dev/null @@ -1,27 +0,0 @@ - - - - Eto.Platform.Mac.Template - $version$ - Eto.Forms - Mac App Template - Curtis Wensley - Curtis Wensley - https://github.com/picoe/Eto/raw/master/LICENSE - https://github.com/picoe/Eto - false - Eto.Forms - Mac Application Template - - This package provides an .app template for your Eto.Forms application when packaging for Mac. - - Copyright 2014 by Curtis Wensley - cross platform gui ui framework desktop monomac osx mac eto.forms - - - - - - - - - - \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.Mac.nuspec b/Resources/nuspec/Eto.Platform.Mac.nuspec index ae3fa6dcf8..6629a74146 100644 --- a/Resources/nuspec/Eto.Platform.Mac.nuspec +++ b/Resources/nuspec/Eto.Platform.Mac.nuspec @@ -1,7 +1,7 @@ - $id$ + Eto.Platform.Mac $version$ $title$ $author$ @@ -11,30 +11,32 @@ false $description$ - This is the MonoMac platform for Eto.Forms UI Framework. +This is the MonoMac platform for Eto.Forms UI Framework. - Include this along with your Eto.Forms application to provide an OS X interface for Mac users. +Include this along with your Eto.Forms application to provide an OS X interface for Mac users. - Eto.Platform.Mac uses the open source MonoMac, which allows you to create OS X Applications with no cost. However, it does require mono to be installed. +Eto.Platform.Mac uses the open source MonoMac, which allows you to create OS X Applications with no cost. However, it does require mono to be installed. - Using Eto.Platform.XamMac instead allows you to bundle mono inside your .app, however it requires purchasing Xamarin.Mac and using Xamarin Studio on OS X. +Using Eto.Platform.XamMac instead allows you to bundle mono inside your .app, however it requires purchasing Xamarin.Mac and using Xamarin Studio on OS X. - You can create your own .app bundle to run your app on OS X, without an OS X machine. This is included as the MyApp.app folder. Read MyApp.app\Contents\MonoBundle\README.txt for instructions on next steps. +You can create your own .app bundle to run your app on OS X, without using a Mac. Use the Eto.Platform.Mac.Template nuget package to build one for your app automatically. - You do not need to use any of the classes of this assembly (unless customizing the MonoMac functionality of the platform), and should just use the UI controls from the Eto assembly. +You do not need to use any of the classes of this assembly (unless customizing the MonoMac functionality of the platform), and should just use the UI controls from the Eto assembly. - Copyright 2014 by Curtis Wensley + $copyright$ cross platform gui ui framework desktop monomac osx mac eto.forms - + - - - - + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.Mac64.nuspec b/Resources/nuspec/Eto.Platform.Mac64.nuspec new file mode 100644 index 0000000000..9b3dcb9ebf --- /dev/null +++ b/Resources/nuspec/Eto.Platform.Mac64.nuspec @@ -0,0 +1,44 @@ + + + + Eto.Platform.Mac64 + $version$ + $title$ + $author$ + $author$ + https://github.com/picoe/Eto/raw/master/LICENSE + https://github.com/picoe/Eto + false + $description$ + +This is the MonoMac 64-bit platform for Eto.Forms UI Framework. + +This is used only when running a 64-bit version of mono, which is typically useful for embedding scenarios as the default mono on OS X is only 32-bit currently. + +Eto.Platform.Mac64 uses a modified version of the open source MonoMac for 64-bit, which allows you to create OS X Applications at no cost. However, it does require 64-bit mono to be installed. + +If you want to run using the standard mono install for OS X, use Eto.Platform.Mac. + +Using Eto.Platform.XamMac instead allows you to bundle mono inside your .app, however it requires purchasing Xamarin.Mac and using Xamarin Studio on OS X. + +You can create your own .app bundle to run your app on OS X, without an OS X machine. This is included as the MyApp.app folder. Read MyApp.app\Contents\MonoBundle\README.txt for instructions on next steps. + +You do not need to use any of the classes of this assembly (unless customizing the MonoMac functionality of the platform), and should just use the UI controls from the Eto assembly. + + $copyright$ + cross platform gui ui framework desktop monomac osx mac eto.forms + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.MacAppTemplate/Eto.Platform.Mac.Template.nuspec b/Resources/nuspec/Eto.Platform.MacAppTemplate/Eto.Platform.Mac.Template.nuspec new file mode 100644 index 0000000000..deb74e0094 --- /dev/null +++ b/Resources/nuspec/Eto.Platform.MacAppTemplate/Eto.Platform.Mac.Template.nuspec @@ -0,0 +1,38 @@ + + + + Eto.Platform.Mac.Template + $version$ + Eto.Forms - Mac App Template + Curtis Wensley + Curtis Wensley + https://github.com/picoe/Eto/raw/master/LICENSE + https://github.com/picoe/Eto + false + Eto.Forms - Mac Application Template + +This package provides an .app template for your Eto.Forms application when packaging for Mac. +When building, an .app bundle will be created for your app when you use this package. + +You can create apps that run on OS X natively from windows using this package. +Note that Mono will need to be installed for your app to run. + +Alternatively, you can package for a mac so it does not require Mono and can be distributed through the App Store using Xamarin Studio on OS X and Eto.Platform.XamMac. + + Copyright 2014 by Curtis Wensley + cross platform gui ui framework desktop monomac osx mac eto.forms + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.MacAppTemplate/Eto.Platform.Mac.Template.targets b/Resources/nuspec/Eto.Platform.MacAppTemplate/Eto.Platform.Mac.Template.targets new file mode 100644 index 0000000000..3f3be951f4 --- /dev/null +++ b/Resources/nuspec/Eto.Platform.MacAppTemplate/Eto.Platform.Mac.Template.targets @@ -0,0 +1,66 @@ + + + + + $(BuildDependsOn); + _CreateAppBundle + + + + + $(MSBuildProjectName) + $(MSBuildProjectDirectory)\Mac\MyApp.app + + + + + + + $(OutputAppPath)\Contents\MonoBundle + $(OutputAppPath)\Contents\MacOS\Launcher.exec + + + + + + + + + + + + + + + + + $(PListContents.Replace('>MyApp.exe</', '>$(TargetFileName)</')) + $(PListContents.Replace('>MacAppTemplate</', '>$(AppBundleName)</')) + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/Info.plist b/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/Info.plist new file mode 100644 index 0000000000..4eafedf790 --- /dev/null +++ b/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/Info.plist @@ -0,0 +1,38 @@ + + + + + MonoBundleExecutable + MyApp.exe + CFBundleName + MacAppTemplate + CFBundleIdentifier + com.yourcompany.myapp + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSHumanReadableCopyright + Copyright © Yourself + CFBundleIconFile + Icon.icns + CFBundleExecutable + Launcher.exec + BuildMachineOSBuild + 12A269 + CFBundleDevelopmentRegion + en + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + CFBundleResourceSpecification + ResourceRules.plist + CFBundleSignature + ???? + LSMinimumSystemVersion + 10.5 + NSPrincipalClass + NSApplication + + diff --git a/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/MacOS/Launcher.exec b/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/MacOS/Launcher.exec new file mode 100755 index 0000000000..f1e0fd19fe Binary files /dev/null and b/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/MacOS/Launcher.exec differ diff --git a/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/MonoBundle/README.txt b/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/MonoBundle/README.txt new file mode 100644 index 0000000000..e3dbab22f0 --- /dev/null +++ b/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/MonoBundle/README.txt @@ -0,0 +1,24 @@ + +Next Steps: + +1. Copy your .exe, .dll's, and any external resources here + + - Make sure to include Eto.dll, Eto.Mac.dll, and MonoMac.dll + +2. Modify Contents/Info.plist and update these properties: + + - MonoBundleExecutable: Name of your exe to launch + - CFBundleName: Short name of your application to display on the menu bar + - CFBundleIdentifier: An identifier string that specifies the app type of the + bundle. The string should be in reverse DNS format using + only the Roman alphabet in upper and lower case + (A–Z, a–z), the dot (“.”), and the hyphen (“-”). + - CFBundleShortVersionString: The release-version-number string for the bundle. + - CFBundleVersion: The build-version-number string for the bundle + - NSHumanReadableCopyright: Copyright of your app + - CFBundleIconFile: Name of your application's icns file + +Notes: + + - The MacOS/Launcher must have the executable bit set. Simply zipping the .app folder + and unzipping on OS X will set things up properly. \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/Resources/Icon.icns b/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/Resources/Icon.icns new file mode 100644 index 0000000000..10a8cbfd5b Binary files /dev/null and b/Resources/nuspec/Eto.Platform.MacAppTemplate/MacAppTemplate.app/Contents/Resources/Icon.icns differ diff --git a/Resources/nuspec/Eto.Platform.MacAppTemplate/README.txt b/Resources/nuspec/Eto.Platform.MacAppTemplate/README.txt new file mode 100644 index 0000000000..f228931aa4 --- /dev/null +++ b/Resources/nuspec/Eto.Platform.MacAppTemplate/README.txt @@ -0,0 +1,28 @@ + +This contains a template for creating an application that runs on OS X using Eto.Forms. + +If you are using Xamarin Studio on OS X, it is recommended to create a MonoMac or XamMac +project directly, as it will allow you to debug and deploy the app directly. + +The nuget package automatically adds a targets include, which will +package up your application into $(TargetName).app in the output directory. + +Next Steps: + +Modify MyApp.app/Contents/Info.plist and update these properties: + + - MonoBundleExecutable: Name of your exe to launch (set automatically to your .exe) + - CFBundleName: Short name of your application to display on the menu bar (set automatically to the project name) + - CFBundleIdentifier: An identifier string that specifies the app type of the + bundle. The string should be in reverse DNS format using + only the Roman alphabet in upper and lower case + (A–Z, a–z), the dot (“.”), and the hyphen (“-”). + - CFBundleShortVersionString: The release-version-number string for the bundle. + - CFBundleVersion: The build-version-number string for the bundle + - NSHumanReadableCopyright: Copyright of your app + - CFBundleIconFile: Name of your application's icns file + +Notes: + + - The MacOS/Launcher must have the executable bit set. Simply zipping the .app folder + and unzipping on OS X will set things up properly. \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.WinRT.nuspec b/Resources/nuspec/Eto.Platform.WinRT.nuspec new file mode 100644 index 0000000000..995037c7f3 --- /dev/null +++ b/Resources/nuspec/Eto.Platform.WinRT.nuspec @@ -0,0 +1,37 @@ + + + + Eto.Platform.WinRT + $version$ + $title$ + $author$ + $author$ + https://github.com/picoe/Eto/raw/master/LICENSE + https://github.com/picoe/Eto + false + $description$ + +This is the Windows 8 platform for Eto.Forms UI Framework. + +Include this along with your Eto.Forms application to provide a Windows 8 interface for your windows users. + +You do not need to use any of the classes of this assembly (unless customizing the functionality of the platform), and should just use the UI controls from the Eto assembly. + + $copyright$ + cross platform gui ui framework desktop wpf eto.forms + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.Windows.nuspec b/Resources/nuspec/Eto.Platform.Windows.nuspec index 281654f2ad..2bcc844b43 100644 --- a/Resources/nuspec/Eto.Platform.Windows.nuspec +++ b/Resources/nuspec/Eto.Platform.Windows.nuspec @@ -1,7 +1,7 @@ - $id$ + Eto.Platform.Windows $version$ $title$ $author$ @@ -11,22 +11,23 @@ false $description$ - This is the Windows Forms platform for Eto.Forms UI Framework. +This is the Windows Forms platform for Eto.Forms UI Framework. - Include this along with your Eto.Forms application to provide a Windows Forms interface for your windows users. +Include this along with your Eto.Forms application to provide a Windows Forms interface for your windows users. - You do not need to use any of the classes of this assembly (unless customizing the Windows Forms functionality of the platform), and should just use the UI controls from the Eto assembly. +You do not need to use any of the classes of this assembly (unless customizing the Windows Forms functionality of the platform), and should just use the UI controls from the Eto assembly. - Copyright 2014 by Curtis Wensley + $copyright$ cross platform gui ui framework desktop wpf eto.forms - + - - + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.Wpf.nuspec b/Resources/nuspec/Eto.Platform.Wpf.nuspec index 08d2a3ae2c..3ab3d928f9 100644 --- a/Resources/nuspec/Eto.Platform.Wpf.nuspec +++ b/Resources/nuspec/Eto.Platform.Wpf.nuspec @@ -1,7 +1,7 @@ - $id$ + Eto.Platform.Wpf $version$ $title$ $author$ @@ -11,22 +11,23 @@ false $description$ - This is the WPF platform for Eto.Forms UI Framework. +This is the WPF platform for Eto.Forms UI Framework. - Include this along with your Eto.Forms application to provide a WPF interface for your windows users. WPF is by default preferred over the Eto.Platform.Windows platform, so if both are included, WPF will be selected. +Include this along with your Eto.Forms application to provide a WPF interface for your windows users. WPF is by default preferred over the Eto.Platform.Windows platform, so if both are included, WPF will be selected. - You do not need to use any of the classes of this assembly (unless customizing the WPF functionality of the platform), and should just use the UI controls from the Eto assembly. +You do not need to use any of the classes of this assembly (unless customizing the WPF functionality of the platform), and should just use the UI controls from the Eto assembly. - Copyright 2014 by Curtis Wensley + $copyright$ cross platform gui ui framework desktop wpf eto.forms - + - - + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.XamMac.nuspec b/Resources/nuspec/Eto.Platform.XamMac.nuspec index a8670b0187..3dc51217a6 100644 --- a/Resources/nuspec/Eto.Platform.XamMac.nuspec +++ b/Resources/nuspec/Eto.Platform.XamMac.nuspec @@ -1,7 +1,7 @@ - $id$ + Eto.Platform.XamMac $version$ $title$ $author$ @@ -11,26 +11,27 @@ false $description$ - This is the Xamarin.Mac platform for Eto.Forms UI Framework. +This is the Xamarin.Mac platform for Eto.Forms UI Framework. - Include this along with your Eto.Forms application to provide an OS X interface for Mac users. +Include this along with your Eto.Forms application to provide an OS X interface for Mac users. - * Note: You should only use this package from an Xamarin.Mac project created with Xamarin Studio on OS X. Xamarin.Mac allows you to bundle mono inside your .app, however it requires purchasing Xamarin.Mac. +* Note: You should only use this package from an Xamarin.Mac project created with Xamarin Studio on OS X. Xamarin.Mac allows you to bundle mono inside your .app, however it requires purchasing Xamarin.Mac. - Using Eto.Platform.Mac instead uses the open source MonoMac, which allows you to create OS X Applications with no cost. However, it does require mono to be installed for the app to run. +Using Eto.Platform.Mac instead uses the open source MonoMac, which allows you to create OS X Applications with no cost. However, it does require mono to be installed for the app to run. - You do not need to use any of the classes of this assembly (unless customizing the Xamarin.Mac functionality of the platform), and should just use the UI controls from the Eto assembly. +You do not need to use any of the classes of this assembly (unless customizing the Xamarin.Mac functionality of the platform), and should just use the UI controls from the Eto assembly. - Copyright 2014 by Curtis Wensley + $copyright$ cross platform gui ui framework desktop osx xamarin.mac mac eto.forms - + - - + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.XamMac2.nuspec b/Resources/nuspec/Eto.Platform.XamMac2.nuspec new file mode 100644 index 0000000000..ccd62eac43 --- /dev/null +++ b/Resources/nuspec/Eto.Platform.XamMac2.nuspec @@ -0,0 +1,36 @@ + + + + Eto.Platform.XamMac2 + $version$ + $title$ + $author$ + $author$ + https://github.com/picoe/Eto/raw/master/LICENSE + https://github.com/picoe/Eto + false + $description$ + +This is the Xamarin.Mac2 (unified) platform for Eto.Forms UI Framework. + +Include this along with your Eto.Forms application to provide an OS X interface for Mac users using the 64-bit compatible Xamarin.Mac. + +* Note: You should only use this package from an Xamarin.Mac project created with Xamarin Studio on OS X. Xamarin.Mac allows you to bundle mono inside your .app, however it requires purchasing Xamarin.Mac. + +Using Eto.Platform.Mac instead uses the open source MonoMac, which allows you to create OS X Applications with no cost. However, it does require mono to be installed for the app to run. + + You do not need to use any of the classes of this assembly (unless customizing the Xamarin.Mac functionality of the platform), and should just use the UI controls from the Eto assembly. + + $copyright$ + cross platform gui ui framework desktop osx xamarin.mac mac eto.forms + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Platform.iOS.nuspec b/Resources/nuspec/Eto.Platform.iOS.nuspec new file mode 100644 index 0000000000..6379227570 --- /dev/null +++ b/Resources/nuspec/Eto.Platform.iOS.nuspec @@ -0,0 +1,32 @@ + + + + Eto.Platform.iOS + $version$ + $title$ + $author$ + $author$ + https://github.com/picoe/Eto/raw/master/LICENSE + https://github.com/picoe/Eto + false + $description$ + +This is the iOS mobile platform for Eto.Forms UI Framework. + +Include this along with your Eto.Forms application to provide an iOS interface for iPhone/iPad/iPod touch users using Xamarin.iOS. + +You do not need to use any of the classes of this assembly (unless customizing the iOS functionality of the platform), and should just use the UI controls from the Eto assembly. + + $copyright$ + cross platform gui ui framework desktop ios eto.forms + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Serialization.Json.nuspec b/Resources/nuspec/Eto.Serialization.Json.nuspec new file mode 100644 index 0000000000..0c0259b49e --- /dev/null +++ b/Resources/nuspec/Eto.Serialization.Json.nuspec @@ -0,0 +1,35 @@ + + + + Eto.Serialization.Json + $version$ + $title$ + $author$ + $author$ + https://github.com/picoe/Eto/raw/master/LICENSE + https://github.com/picoe/Eto + false + $description$ + +Eto.Json allows you to load json UI definitions for the Eto.Forms framework + +To get more information about how to get started, read the wiki: + +https://github.com/picoe/Eto/wiki + + $copyright$ + cross platform gui ui framework desktop json eto.forms + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Serialization.Xaml.nuspec b/Resources/nuspec/Eto.Serialization.Xaml.nuspec new file mode 100644 index 0000000000..476ffecda7 --- /dev/null +++ b/Resources/nuspec/Eto.Serialization.Xaml.nuspec @@ -0,0 +1,36 @@ + + + + Eto.Serialization.Xaml + $version$ + $title$ + $author$ + $author$ + https://github.com/picoe/Eto/raw/master/LICENSE + https://github.com/picoe/Eto + false + $description$ + +Eto.Xaml allows you to load xaml UI definitions for the Eto.Forms framework + +To get more information about how to get started, read the wiki: + +https://github.com/picoe/Eto/wiki + + $copyright$ + cross platform gui ui framework desktop xaml eto.forms + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/nuspec/Eto.Xaml.nuspec b/Resources/nuspec/Eto.Xaml.nuspec deleted file mode 100644 index f1493e44fd..0000000000 --- a/Resources/nuspec/Eto.Xaml.nuspec +++ /dev/null @@ -1,30 +0,0 @@ - - - - Eto.Forms.Xaml - $version$ - $title$ - $author$ - $author$ - https://github.com/picoe/Eto/raw/master/LICENSE - https://github.com/picoe/Eto - false - $description$ - - Eto.Xaml allows you to load xaml UI definitions for the Eto.Forms framework - - To get more information about how to get started, read the wiki: - - https://github.com/picoe/Eto/wiki - - Copyright 2014 by Curtis Wensley - cross platform gui ui framework desktop xaml eto.forms - - - - - - - - - \ No newline at end of file diff --git a/Resources/nuspec/Eto.nuspec b/Resources/nuspec/Eto.nuspec index 3a76d583a9..2806403cfd 100644 --- a/Resources/nuspec/Eto.nuspec +++ b/Resources/nuspec/Eto.nuspec @@ -11,34 +11,41 @@ false Eto.Forms UI Framework - Eto.Forms is a cross platform desktop user interface framework. +Eto.Forms is a cross platform desktop user interface framework. - This framework is built so that you can target multiple platforms with one UI codebase. +This framework is built so that you can target multiple platforms with one UI codebase. - The overall goal of this framework is to expose a common API that can be used to build functional applications that run across platforms using their native toolkit. This will make your applications look and work as if it were a native application on all platforms. +The goal of this framework is to expose a common API that can be used to build functional applications that run across platforms using their native toolkit. This will make your applications look and work as if it were a native application on all platforms. - For advanced scenarios, you can take advantage of each platform's capabilities by wrapping your common UI in a larger application, or even create your own high-level controls with a custom implementations per platform. +For advanced scenarios, you can take advantage of each platform's capabilities by wrapping your common UI in a larger application, or even create your own high-level controls with a custom implementations per platform. - This framework currently supports creating Desktop applications that work across Windows Forms, WPF, MonoMac/Xamarin.Mac, and GTK#. +This framework currently supports creating Desktop applications that work across Windows Forms, WPF, MonoMac/Xamarin.Mac, and GTK#. - In order to run your Eto.Forms based application, you must also install one (or more) of the following packages: +In order to run your Eto.Forms based application, you must also install one (or more) of the following packages: - - Eto.Platform.Wpf - - Eto.Platform.Windows - - Eto.Platform.Gtk - - Eto.Platform.Mac - - Eto.Platform.XamMac * requires Xamarin Studio on OS X. +- Eto.Platform.Wpf +- Eto.Platform.Windows +- Eto.Platform.Direct2D +- Eto.Platform.Gtk +- Eto.Platform.Gtk3 +- Eto.Platform.Mac +- Eto.Platform.XamMac * requires Xamarin Studio on OS X. +- Eto.Platform.XamMac2 * requires Xamarin Studio on OS X. - To get more information about how to get started, read the wiki: +To get more information about how to get started, read the wiki: - https://github.com/picoe/Eto/wiki +https://github.com/picoe/Eto/wiki - Copyright 2014 by Curtis Wensley + $copyright$ cross platform gui ui framework desktop winforms wpf mac osx gtk eto.forms - - - + + + + + + + \ No newline at end of file diff --git a/Resources/package.cmd b/Resources/package.cmd index acf3f9e699..19636aeae1 100644 --- a/Resources/package.cmd +++ b/Resources/package.cmd @@ -1,7 +1,8 @@ echo off -set MSBUILD=c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe +rem set MSBUILD=c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe +set MSBUILD="%ProgramFiles(x86)%\MSBuild\12.0\bin\MSBuild.exe" -%MSBUILD% -t:Package Publish.targets +%MSBUILD% -t:Package -p:BuildVersion=%1 Publish.targets pause \ No newline at end of file diff --git a/Resources/package.sh b/Resources/package.sh new file mode 100755 index 0000000000..b68eb9b886 --- /dev/null +++ b/Resources/package.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +xbuild /t:Package /p:BuildVersion=$1 /p:Platform=Mac Publish.targets diff --git a/Resources/prepare.sh b/Resources/prepare.sh deleted file mode 100755 index 1b5516ef26..0000000000 --- a/Resources/prepare.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -xbuild /t:PrepareMac Publish.targets diff --git a/Samples/Gtk/EmbedEtoInGtk/EmbedEtoInGtk.csproj b/Samples/Gtk/EmbedEtoInGtk/EmbedEtoInGtk.csproj new file mode 100644 index 0000000000..3aaeb00f9b --- /dev/null +++ b/Samples/Gtk/EmbedEtoInGtk/EmbedEtoInGtk.csproj @@ -0,0 +1,76 @@ + + + + Debug + AnyCPU + {27E7436C-0B29-430C-9A21-A5812FC72311} + WinExe + EmbedEtoInGtk + EmbedEtoInGtk + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + False + + + False + + + False + + + False + + + False + + + False + + + + + + gui.stetic + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + {80915A80-CA54-11E3-9C1A-0800200C9A66} + Eto.Gtk2 - Pcl + + + \ No newline at end of file diff --git a/Samples/Gtk/EmbedEtoInGtk/MainWindow.cs b/Samples/Gtk/EmbedEtoInGtk/MainWindow.cs new file mode 100644 index 0000000000..180ce01b50 --- /dev/null +++ b/Samples/Gtk/EmbedEtoInGtk/MainWindow.cs @@ -0,0 +1,25 @@ +using System; +using Gtk; +using Eto.Forms; + +namespace EmbedEtoInGtk +{ + public partial class MainWindow: Gtk.Window + { + public MainWindow() : base(Gtk.WindowType.Toplevel) + { + Build(); + + var nativeWidget = new MyEtoPanel().ToNative(true); + + this.Child = nativeWidget; + } + + protected void OnDeleteEvent(object sender, DeleteEventArgs a) + { + Gtk.Application.Quit(); + a.RetVal = true; + } + } + +} \ No newline at end of file diff --git a/Samples/Gtk/EmbedEtoInGtk/MyEtoPanel.cs b/Samples/Gtk/EmbedEtoInGtk/MyEtoPanel.cs new file mode 100644 index 0000000000..dbb6527247 --- /dev/null +++ b/Samples/Gtk/EmbedEtoInGtk/MyEtoPanel.cs @@ -0,0 +1,27 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace EmbedEtoInGtk +{ + /// + /// Eto.Forms panel to embed in an existing WinForms app + /// + public class MyEtoPanel : Panel + { + public MyEtoPanel() + { + Content = new TableLayout + { + Spacing = new Size(5, 5), + Rows = + { + new TableRow(new Label { Text = "An Eto.Forms control" }), + new TableRow(new TextBox()), + new TableRow(new ComboBox { Items = { "Item 1", "Item 2", "Item 3" } }), + null + } + }; + } + } +} diff --git a/Samples/Gtk/EmbedEtoInGtk/Program.cs b/Samples/Gtk/EmbedEtoInGtk/Program.cs new file mode 100644 index 0000000000..214c6205b7 --- /dev/null +++ b/Samples/Gtk/EmbedEtoInGtk/Program.cs @@ -0,0 +1,20 @@ +using System; +using Gtk; + +namespace EmbedEtoInGtk +{ + static class Program + { + public static MainWindow MainWindow { get; set; } + + [STAThread] + public static void Main(string[] args) + { + Application.Init(); + new Eto.Forms.Application(new Eto.GtkSharp.Platform()).Attach(); + MainWindow = new MainWindow(); + MainWindow.Show(); + Application.Run(); + } + } +} diff --git a/Samples/Gtk/EmbedEtoInGtk/Properties/AssemblyInfo.cs b/Samples/Gtk/EmbedEtoInGtk/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..5a8cddd4f0 --- /dev/null +++ b/Samples/Gtk/EmbedEtoInGtk/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("EmbedEtoInGtk")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Picoe Software Solutions Inc.")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Curtis Wensley")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Samples/Gtk/EmbedEtoInGtk/gtk-gui/EmbedEtoInGtk.MainWindow.cs b/Samples/Gtk/EmbedEtoInGtk/gtk-gui/EmbedEtoInGtk.MainWindow.cs new file mode 100644 index 0000000000..67ca5ceacc --- /dev/null +++ b/Samples/Gtk/EmbedEtoInGtk/gtk-gui/EmbedEtoInGtk.MainWindow.cs @@ -0,0 +1,23 @@ + +// This file has been generated by the GUI designer. Do not modify. +namespace EmbedEtoInGtk +{ + public partial class MainWindow + { + protected virtual void Build () + { + global::Stetic.Gui.Initialize (this); + // Widget EmbedEtoInGtk.MainWindow + this.Name = "EmbedEtoInGtk.MainWindow"; + this.Title = global::Mono.Unix.Catalog.GetString ("MainWindow"); + this.WindowPosition = ((global::Gtk.WindowPosition)(4)); + if ((this.Child != null)) { + this.Child.ShowAll (); + } + this.DefaultWidth = 423; + this.DefaultHeight = 312; + this.Show (); + this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent); + } + } +} diff --git a/Samples/Gtk/EmbedEtoInGtk/gtk-gui/generated.cs b/Samples/Gtk/EmbedEtoInGtk/gtk-gui/generated.cs new file mode 100644 index 0000000000..9ef3363981 --- /dev/null +++ b/Samples/Gtk/EmbedEtoInGtk/gtk-gui/generated.cs @@ -0,0 +1,29 @@ + +// This file has been generated by the GUI designer. Do not modify. +namespace Stetic +{ + internal class Gui + { + private static bool initialized; + + internal static void Initialize (Gtk.Widget iconRenderer) + { + if ((Stetic.Gui.initialized == false)) { + Stetic.Gui.initialized = true; + } + } + } + + internal class ActionGroups + { + public static Gtk.ActionGroup GetActionGroup (System.Type type) + { + return Stetic.ActionGroups.GetActionGroup (type.FullName); + } + + public static Gtk.ActionGroup GetActionGroup (string name) + { + return null; + } + } +} diff --git a/Samples/Gtk/EmbedEtoInGtk/gtk-gui/gui.stetic b/Samples/Gtk/EmbedEtoInGtk/gtk-gui/gui.stetic new file mode 100644 index 0000000000..3cb5fcaf78 --- /dev/null +++ b/Samples/Gtk/EmbedEtoInGtk/gtk-gui/gui.stetic @@ -0,0 +1,20 @@ + + + + .. + + + + + + + + + MainWindow + CenterOnParent + + + + + + \ No newline at end of file diff --git a/Samples/Gtk/EmbedGtkInEto/EmbedGtkInEto.csproj b/Samples/Gtk/EmbedGtkInEto/EmbedGtkInEto.csproj new file mode 100644 index 0000000000..aa17964d0d --- /dev/null +++ b/Samples/Gtk/EmbedGtkInEto/EmbedGtkInEto.csproj @@ -0,0 +1,63 @@ + + + + Debug + AnyCPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772} + WinExe + EmbedGtkInEto + EmbedGtkInEto + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + true + + + + + + + + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + {80915A80-CA54-11E3-9C1A-0800200C9A66} + Eto.Gtk2 - Pcl + + + + + gui.stetic + + + \ No newline at end of file diff --git a/Samples/Gtk/EmbedGtkInEto/MainForm.cs b/Samples/Gtk/EmbedGtkInEto/MainForm.cs new file mode 100644 index 0000000000..5e0454d512 --- /dev/null +++ b/Samples/Gtk/EmbedGtkInEto/MainForm.cs @@ -0,0 +1,30 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace EmbedGtkInEto +{ + public class MainForm : Form + { + public MainForm() + { + Menu = new MenuBar(); + + // create a new native MonoMac view and wrap it in an eto control + var nativeControl = new MyNativeWidget().ToEto(); + + Content = new TableLayout + { + Padding = new Padding(10), + Spacing = new Size(5, 5), + Rows = + { + nativeControl, + null, + new TableLayout(new TableRow(null, new Button { Text = "An Eto.Forms button" })), + } + }; + } + } +} + diff --git a/Samples/Gtk/EmbedGtkInEto/MyNativeWidget.cs b/Samples/Gtk/EmbedGtkInEto/MyNativeWidget.cs new file mode 100644 index 0000000000..d9fad0d96e --- /dev/null +++ b/Samples/Gtk/EmbedGtkInEto/MyNativeWidget.cs @@ -0,0 +1,14 @@ +using System; + +namespace EmbedGtkInEto +{ + [System.ComponentModel.ToolboxItem(true)] + public partial class MyNativeWidget : Gtk.Bin + { + public MyNativeWidget() + { + this.Build(); + } + } +} + diff --git a/Samples/Gtk/EmbedGtkInEto/Program.cs b/Samples/Gtk/EmbedGtkInEto/Program.cs new file mode 100644 index 0000000000..f2e5609164 --- /dev/null +++ b/Samples/Gtk/EmbedGtkInEto/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace EmbedGtkInEto +{ + static class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(new Eto.GtkSharp.Platform()).Run(new MainForm()); + } + } +} + diff --git a/Samples/Gtk/EmbedGtkInEto/Properties/AssemblyInfo.cs b/Samples/Gtk/EmbedGtkInEto/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..f3990e7983 --- /dev/null +++ b/Samples/Gtk/EmbedGtkInEto/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("EmbedGtkInEto")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Picoe Software Solutions Inc.")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Curtis Wensley")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Samples/Gtk/EmbedGtkInEto/gtk-gui/EmbedGtkInEto.MyNativeWidget.cs b/Samples/Gtk/EmbedGtkInEto/gtk-gui/EmbedGtkInEto.MyNativeWidget.cs new file mode 100644 index 0000000000..fb9b351d33 --- /dev/null +++ b/Samples/Gtk/EmbedGtkInEto/gtk-gui/EmbedGtkInEto.MyNativeWidget.cs @@ -0,0 +1,60 @@ + +// This file has been generated by the GUI designer. Do not modify. +namespace EmbedGtkInEto +{ + public partial class MyNativeWidget + { + private global::Gtk.VBox vbox1; + + private global::Gtk.Label label1; + + private global::Gtk.Entry entry2; + + private global::Gtk.ComboBox combobox1; + + protected virtual void Build () + { + global::Stetic.Gui.Initialize (this); + // Widget EmbedGtkInEto.MyNativeWidget + global::Stetic.BinContainer.Attach (this); + this.Name = "EmbedGtkInEto.MyNativeWidget"; + // Container child EmbedGtkInEto.MyNativeWidget.Gtk.Container+ContainerChild + this.vbox1 = new global::Gtk.VBox (); + this.vbox1.Name = "vbox1"; + this.vbox1.Spacing = 6; + // Container child vbox1.Gtk.Box+BoxChild + this.label1 = new global::Gtk.Label (); + this.label1.Name = "label1"; + this.label1.LabelProp = global::Mono.Unix.Catalog.GetString ("A GtkSharp Control"); + this.vbox1.Add (this.label1); + global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.label1])); + w1.Position = 0; + w1.Expand = false; + w1.Fill = false; + // Container child vbox1.Gtk.Box+BoxChild + this.entry2 = new global::Gtk.Entry (); + this.entry2.CanFocus = true; + this.entry2.Name = "entry2"; + this.entry2.IsEditable = true; + this.entry2.InvisibleChar = '●'; + this.vbox1.Add (this.entry2); + global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.entry2])); + w2.Position = 1; + w2.Expand = false; + w2.Fill = false; + // Container child vbox1.Gtk.Box+BoxChild + this.combobox1 = global::Gtk.ComboBox.NewText (); + this.combobox1.Name = "combobox1"; + this.vbox1.Add (this.combobox1); + global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.combobox1])); + w3.Position = 2; + w3.Expand = false; + w3.Fill = false; + this.Add (this.vbox1); + if ((this.Child != null)) { + this.Child.ShowAll (); + } + this.Hide (); + } + } +} diff --git a/Samples/Gtk/EmbedGtkInEto/gtk-gui/generated.cs b/Samples/Gtk/EmbedGtkInEto/gtk-gui/generated.cs new file mode 100644 index 0000000000..3285e87c05 --- /dev/null +++ b/Samples/Gtk/EmbedGtkInEto/gtk-gui/generated.cs @@ -0,0 +1,82 @@ + +// This file has been generated by the GUI designer. Do not modify. +namespace Stetic +{ + internal class Gui + { + private static bool initialized; + + internal static void Initialize (Gtk.Widget iconRenderer) + { + if ((Stetic.Gui.initialized == false)) { + Stetic.Gui.initialized = true; + } + } + } + + internal class BinContainer + { + private Gtk.Widget child; + + private Gtk.UIManager uimanager; + + public static BinContainer Attach (Gtk.Bin bin) + { + BinContainer bc = new BinContainer (); + bin.SizeRequested += new Gtk.SizeRequestedHandler (bc.OnSizeRequested); + bin.SizeAllocated += new Gtk.SizeAllocatedHandler (bc.OnSizeAllocated); + bin.Added += new Gtk.AddedHandler (bc.OnAdded); + return bc; + } + + private void OnSizeRequested (object sender, Gtk.SizeRequestedArgs args) + { + if ((this.child != null)) { + args.Requisition = this.child.SizeRequest (); + } + } + + private void OnSizeAllocated (object sender, Gtk.SizeAllocatedArgs args) + { + if ((this.child != null)) { + this.child.Allocation = args.Allocation; + } + } + + private void OnAdded (object sender, Gtk.AddedArgs args) + { + this.child = args.Widget; + } + + public void SetUiManager (Gtk.UIManager uim) + { + this.uimanager = uim; + this.child.Realized += new System.EventHandler (this.OnRealized); + } + + private void OnRealized (object sender, System.EventArgs args) + { + if ((this.uimanager != null)) { + Gtk.Widget w; + w = this.child.Toplevel; + if (((w != null) && typeof(Gtk.Window).IsInstanceOfType (w))) { + ((Gtk.Window)(w)).AddAccelGroup (this.uimanager.AccelGroup); + this.uimanager = null; + } + } + } + } + + internal class ActionGroups + { + public static Gtk.ActionGroup GetActionGroup (System.Type type) + { + return Stetic.ActionGroups.GetActionGroup (type.FullName); + } + + public static Gtk.ActionGroup GetActionGroup (string name) + { + return null; + } + } +} diff --git a/Samples/Gtk/EmbedGtkInEto/gtk-gui/gui.stetic b/Samples/Gtk/EmbedGtkInEto/gtk-gui/gui.stetic new file mode 100644 index 0000000000..c8f8e48f94 --- /dev/null +++ b/Samples/Gtk/EmbedGtkInEto/gtk-gui/gui.stetic @@ -0,0 +1,63 @@ + + + + .. + 2.12 + + + + + + + + False + + + + 6 + + + + A GtkSharp Control + + + 0 + True + False + False + + + + + + True + True + + + + 1 + True + False + False + + + + + + True + + + + 2 + True + False + False + + + + + + + + + \ No newline at end of file diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/AppDelegate.cs b/Samples/MonoMac/EmbedEtoInMonoMac/AppDelegate.cs new file mode 100644 index 0000000000..bdf0404a03 --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/AppDelegate.cs @@ -0,0 +1,24 @@ +using System; +using System.Drawing; +using MonoMac.Foundation; +using MonoMac.AppKit; +using MonoMac.ObjCRuntime; + +namespace EmbedEtoInMonoMac +{ + public partial class AppDelegate : NSApplicationDelegate + { + MainWindowController mainWindowController; + + public AppDelegate() + { + } + + public override void FinishedLaunching(NSObject notification) + { + mainWindowController = new MainWindowController(); + mainWindowController.Window.MakeKeyAndOrderFront(this); + } + } +} + diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/AppDelegate.designer.cs b/Samples/MonoMac/EmbedEtoInMonoMac/AppDelegate.designer.cs new file mode 100644 index 0000000000..60152bbd1d --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/AppDelegate.designer.cs @@ -0,0 +1,10 @@ + +namespace EmbedEtoInMonoMac +{ + // Should subclass MonoMac.AppKit.NSResponder + [MonoMac.Foundation.Register("AppDelegate")] + public partial class AppDelegate + { + } +} + diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/EmbedEtoInMonoMac.csproj b/Samples/MonoMac/EmbedEtoInMonoMac/EmbedEtoInMonoMac.csproj new file mode 100644 index 0000000000..b120fcf80f --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/EmbedEtoInMonoMac.csproj @@ -0,0 +1,104 @@ + + + + Debug + AnyCPU + {948B3504-5B70-4649-8FE4-BDE1FB46EC69};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {95B6E385-A0ED-4A49-99B5-19569156FCE6} + Exe + EmbedEtoInMonoMac + Resources + EmbedEtoInMonoMac + True + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + false + false + false + false + false + + + full + true + bin\Release + prompt + 4 + false + SdkOnly + false + true + false + Developer ID Application + true + true + + + full + true + bin\AppStore + prompt + 4 + false + SdkOnly + false + true + 3rd Party Mac Developer Installer + true + 3rd Party Mac Developer Application + true + true + + + + + + + + + ..\..\..\Libraries\MonoMac\MonoMac.dll + + + + + + + + + + MainWindow.cs + + + + AppDelegate.cs + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66} + Eto.Mac - Pcl + + + \ No newline at end of file diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/Info.plist b/Samples/MonoMac/EmbedEtoInMonoMac/Info.plist new file mode 100644 index 0000000000..ae59791408 --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDisplayName + EmbedEtoInMonoMac + CFBundleIdentifier + com.your-company.EmbedEtoInMonoMac + CFBundleName + EmbedEtoInMonoMac + CFBundleVersion + 1 + LSMinimumSystemVersion + 10.6 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/MainMenu.xib b/Samples/MonoMac/EmbedEtoInMonoMac/MainMenu.xib new file mode 100644 index 0000000000..bdd297a761 --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/MainMenu.xib @@ -0,0 +1,4074 @@ + + + + 1060 + 10D573 + 762 + 1038.29 + 460.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 762 + + + YES + + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + YES + + + YES + + + + YES + + NSApplication + + + FirstResponder + + + NSApplication + + + AMainMenu + + YES + + + EmbedEtoInMonoMac + + 1048576 + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + submenuAction: + + MacCocoaApp + + YES + + + About EmbedEtoInMonoMac + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Preferences… + , + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Services + + 1048576 + 2147483647 + + + submenuAction: + + Services + + YES + + _NSServicesMenu + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Hide EmbedEtoInMonoMac + h + 1048576 + 2147483647 + + + + + + Hide Others + h + 1572864 + 2147483647 + + + + + + Show All + + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Quit EmbedEtoInMonoMac + q + 1048576 + 2147483647 + + + + + _NSAppleMenu + + + + + File + + 1048576 + 2147483647 + + + submenuAction: + + File + + YES + + + New + n + 1048576 + 2147483647 + + + + + + Open… + o + 1048576 + 2147483647 + + + + + + Open Recent + + 1048576 + 2147483647 + + + submenuAction: + + Open Recent + + YES + + + Clear Menu + + 1048576 + 2147483647 + + + + + _NSRecentDocumentsMenu + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Close + w + 1048576 + 2147483647 + + + + + + Save + s + 1048576 + 2147483647 + + + + + + Save As… + S + 1179648 + 2147483647 + + + + + + Revert to Saved + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Page Setup... + P + 1179648 + 2147483647 + + + + + + + Print… + p + 1048576 + 2147483647 + + + + + + + + + Edit + + 1048576 + 2147483647 + + + submenuAction: + + Edit + + YES + + + Undo + z + 1048576 + 2147483647 + + + + + + Redo + Z + 1179648 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Cut + x + 1048576 + 2147483647 + + + + + + Copy + c + 1048576 + 2147483647 + + + + + + Paste + v + 1048576 + 2147483647 + + + + + + Paste and Match Style + V + 1572864 + 2147483647 + + + + + + Delete + + 1048576 + 2147483647 + + + + + + Select All + a + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Find + + 1048576 + 2147483647 + + + submenuAction: + + Find + + YES + + + Find… + f + 1048576 + 2147483647 + + + 1 + + + + Find Next + g + 1048576 + 2147483647 + + + 2 + + + + Find Previous + G + 1179648 + 2147483647 + + + 3 + + + + Use Selection for Find + e + 1048576 + 2147483647 + + + 7 + + + + Jump to Selection + j + 1048576 + 2147483647 + + + + + + + + + Spelling and Grammar + + 1048576 + 2147483647 + + + submenuAction: + + Spelling and Grammar + + YES + + + Show Spelling and Grammar + : + 1048576 + 2147483647 + + + + + + Check Document Now + ; + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Check Spelling While Typing + + 1048576 + 2147483647 + + + + + + Check Grammar With Spelling + + 1048576 + 2147483647 + + + + + + Correct Spelling Automatically + + 2147483647 + + + + + + + + + Substitutions + + 1048576 + 2147483647 + + + submenuAction: + + Substitutions + + YES + + + Show Substitutions + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Smart Copy/Paste + f + 1048576 + 2147483647 + + + 1 + + + + Smart Quotes + g + 1048576 + 2147483647 + + + 2 + + + + Smart Dashes + + 2147483647 + + + + + + Smart Links + G + 1179648 + 2147483647 + + + 3 + + + + Text Replacement + + 2147483647 + + + + + + + + + Transformations + + 2147483647 + + + submenuAction: + + Transformations + + YES + + + Make Upper Case + + 2147483647 + + + + + + Make Lower Case + + 2147483647 + + + + + + Capitalize + + 2147483647 + + + + + + + + + Speech + + 1048576 + 2147483647 + + + submenuAction: + + Speech + + YES + + + Start Speaking + + 1048576 + 2147483647 + + + + + + Stop Speaking + + 1048576 + 2147483647 + + + + + + + + + + + + Format + + 2147483647 + + + submenuAction: + + Format + + YES + + + Font + + 2147483647 + + + submenuAction: + + Font + + YES + + + Show Fonts + t + 1048576 + 2147483647 + + + + + + Bold + b + 1048576 + 2147483647 + + + 2 + + + + Italic + i + 1048576 + 2147483647 + + + 1 + + + + Underline + u + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Bigger + + + 1048576 + 2147483647 + + + 3 + + + + Smaller + - + 1048576 + 2147483647 + + + 4 + + + + YES + YES + + + 2147483647 + + + + + + Kern + + 2147483647 + + + submenuAction: + + Kern + + YES + + + Use Default + + 2147483647 + + + + + + Use None + + 2147483647 + + + + + + Tighten + + 2147483647 + + + + + + Loosen + + 2147483647 + + + + + + + + + Ligature + + 2147483647 + + + submenuAction: + + Ligature + + YES + + + Use Default + + 2147483647 + + + + + + Use None + + 2147483647 + + + + + + Use All + + 2147483647 + + + + + + + + + Baseline + + 2147483647 + + + submenuAction: + + Baseline + + YES + + + Use Default + + 2147483647 + + + + + + Superscript + + 2147483647 + + + + + + Subscript + + 2147483647 + + + + + + Raise + + 2147483647 + + + + + + Lower + + 2147483647 + + + + + + + + + YES + YES + + + 2147483647 + + + + + + Show Colors + C + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Copy Style + c + 1572864 + 2147483647 + + + + + + Paste Style + v + 1572864 + 2147483647 + + + + + _NSFontMenu + + + + + Text + + 2147483647 + + + submenuAction: + + Text + + YES + + + Align Left + { + 1048576 + 2147483647 + + + + + + Center + | + 1048576 + 2147483647 + + + + + + Justify + + 2147483647 + + + + + + Align Right + } + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Writing Direction + + 2147483647 + + + submenuAction: + + Writing Direction + + YES + + + YES + Paragraph + + 2147483647 + + + + + + CURlZmF1bHQ + + 2147483647 + + + + + + CUxlZnQgdG8gUmlnaHQ + + 2147483647 + + + + + + CVJpZ2h0IHRvIExlZnQ + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + YES + Selection + + 2147483647 + + + + + + CURlZmF1bHQ + + 2147483647 + + + + + + CUxlZnQgdG8gUmlnaHQ + + 2147483647 + + + + + + CVJpZ2h0IHRvIExlZnQ + + 2147483647 + + + + + + + + + YES + YES + + + 2147483647 + + + + + + Show Ruler + + 2147483647 + + + + + + Copy Ruler + c + 1310720 + 2147483647 + + + + + + Paste Ruler + v + 1310720 + 2147483647 + + + + + + + + + + + + View + + 1048576 + 2147483647 + + + submenuAction: + + View + + YES + + + Show Toolbar + t + 1572864 + 2147483647 + + + + + + Customize Toolbar… + + 1048576 + 2147483647 + + + + + + + + + Window + + 1048576 + 2147483647 + + + submenuAction: + + Window + + YES + + + Minimize + m + 1048576 + 2147483647 + + + + + + Zoom + + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Bring All to Front + + 1048576 + 2147483647 + + + + + _NSWindowsMenu + + + + + Help + + 2147483647 + + + submenuAction: + + Help + + YES + + + EmbedEtoInMonoMac Help + ? + 1048576 + 2147483647 + + + + + _NSHelpMenu + + + + _NSMainMenu + + + NSFontManager + + + AppDelegate + + + + + YES + + + performMiniaturize: + + + + 37 + + + + arrangeInFront: + + + + 39 + + + + print: + + + + 86 + + + + runPageLayout: + + + + 87 + + + + clearRecentDocuments: + + + + 127 + + + + orderFrontStandardAboutPanel: + + + + 142 + + + + performClose: + + + + 193 + + + + toggleContinuousSpellChecking: + + + + 222 + + + + undo: + + + + 223 + + + + copy: + + + + 224 + + + + checkSpelling: + + + + 225 + + + + paste: + + + + 226 + + + + stopSpeaking: + + + + 227 + + + + cut: + + + + 228 + + + + showGuessPanel: + + + + 230 + + + + redo: + + + + 231 + + + + selectAll: + + + + 232 + + + + startSpeaking: + + + + 233 + + + + delete: + + + + 235 + + + + performZoom: + + + + 240 + + + + performFindPanelAction: + + + + 241 + + + + centerSelectionInVisibleArea: + + + + 245 + + + + toggleGrammarChecking: + + + + 347 + + + + toggleSmartInsertDelete: + + + + 355 + + + + toggleAutomaticQuoteSubstitution: + + + + 356 + + + + toggleAutomaticLinkDetection: + + + + 357 + + + + saveDocument: + + + + 362 + + + + saveDocumentAs: + + + + 363 + + + + revertDocumentToSaved: + + + + 364 + + + + runToolbarCustomizationPalette: + + + + 365 + + + + toggleToolbarShown: + + + + 366 + + + + hide: + + + + 367 + + + + hideOtherApplications: + + + + 368 + + + + unhideAllApplications: + + + + 370 + + + + newDocument: + + + + 373 + + + + openDocument: + + + + 374 + + + + addFontTrait: + + + + 421 + + + + addFontTrait: + + + + 422 + + + + modifyFont: + + + + 423 + + + + orderFrontFontPanel: + + + + 424 + + + + modifyFont: + + + + 425 + + + + raiseBaseline: + + + + 426 + + + + lowerBaseline: + + + + 427 + + + + copyFont: + + + + 428 + + + + subscript: + + + + 429 + + + + superscript: + + + + 430 + + + + tightenKerning: + + + + 431 + + + + underline: + + + + 432 + + + + orderFrontColorPanel: + + + + 433 + + + + useAllLigatures: + + + + 434 + + + + loosenKerning: + + + + 435 + + + + pasteFont: + + + + 436 + + + + unscript: + + + + 437 + + + + useStandardKerning: + + + + 438 + + + + useStandardLigatures: + + + + 439 + + + + turnOffLigatures: + + + + 440 + + + + turnOffKerning: + + + + 441 + + + + terminate: + + + + 449 + + + + toggleAutomaticSpellingCorrection: + + + + 456 + + + + orderFrontSubstitutionsPanel: + + + + 458 + + + + toggleAutomaticDashSubstitution: + + + + 461 + + + + toggleAutomaticTextReplacement: + + + + 463 + + + + uppercaseWord: + + + + 464 + + + + capitalizeWord: + + + + 467 + + + + lowercaseWord: + + + + 468 + + + + pasteAsPlainText: + + + + 486 + + + + performFindPanelAction: + + + + 487 + + + + performFindPanelAction: + + + + 488 + + + + performFindPanelAction: + + + + 489 + + + + showHelp: + + + + 493 + + + + alignCenter: + + + + 518 + + + + pasteRuler: + + + + 519 + + + + toggleRuler: + + + + 520 + + + + alignRight: + + + + 521 + + + + copyRuler: + + + + 522 + + + + alignJustified: + + + + 523 + + + + alignLeft: + + + + 524 + + + + makeBaseWritingDirectionNatural: + + + + 525 + + + + makeBaseWritingDirectionLeftToRight: + + + + 526 + + + + makeBaseWritingDirectionRightToLeft: + + + + 527 + + + + makeTextWritingDirectionNatural: + + + + 528 + + + + makeTextWritingDirectionLeftToRight: + + + + 529 + + + + makeTextWritingDirectionRightToLeft: + + + + 530 + + + + delegate + + + + 534 + + + + + YES + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 29 + + + YES + + + + + + + + + + + + 19 + + + YES + + + + + + 56 + + + YES + + + + + + 217 + + + YES + + + + + + 83 + + + YES + + + + + + 81 + + + YES + + + + + + + + + + + + + + + + 75 + + + + + 80 + + + + + 78 + + + + + 72 + + + + + 82 + + + + + 124 + + + YES + + + + + + 77 + + + + + 73 + + + + + 79 + + + + + 112 + + + + + 74 + + + + + 125 + + + YES + + + + + + 126 + + + + + 205 + + + YES + + + + + + + + + + + + + + + + + + + + 202 + + + + + 198 + + + + + 207 + + + + + 214 + + + + + 199 + + + + + 203 + + + + + 197 + + + + + 206 + + + + + 215 + + + + + 218 + + + YES + + + + + + 216 + + + YES + + + + + + 200 + + + YES + + + + + + + + + + + 219 + + + + + 201 + + + + + 204 + + + + + 220 + + + YES + + + + + + + + + + 213 + + + + + 210 + + + + + 221 + + + + + 208 + + + + + 209 + + + + + 57 + + + YES + + + + + + + + + + + + + + + + 58 + + + + + 134 + + + + + 150 + + + + + 136 + + + + + 144 + + + + + 129 + + + + + 143 + + + + + 236 + + + + + 131 + + + YES + + + + + + 149 + + + + + 145 + + + + + 130 + + + + + 24 + + + YES + + + + + + + + + 92 + + + + + 5 + + + + + 239 + + + + + 23 + + + + + 295 + + + YES + + + + + + 296 + + + YES + + + + + + + 297 + + + + + 298 + + + + + 211 + + + YES + + + + + + 212 + + + YES + + + + + + + 195 + + + + + 196 + + + + + 346 + + + + + 348 + + + YES + + + + + + 349 + + + YES + + + + + + + + + + + + 350 + + + + + 351 + + + + + 354 + + + + + 375 + + + YES + + + + + + 376 + + + YES + + + + + + + 377 + + + YES + + + + + + 388 + + + YES + + + + + + + + + + + + + + + + + + + + + 389 + + + + + 390 + + + + + 391 + + + + + 392 + + + + + 393 + + + + + 394 + + + + + 395 + + + + + 396 + + + + + 397 + + + YES + + + + + + 398 + + + YES + + + + + + 399 + + + YES + + + + + + 400 + + + + + 401 + + + + + 402 + + + + + 403 + + + + + 404 + + + + + 405 + + + YES + + + + + + + + + + 406 + + + + + 407 + + + + + 408 + + + + + 409 + + + + + 410 + + + + + 411 + + + YES + + + + + + + + 412 + + + + + 413 + + + + + 414 + + + + + 415 + + + YES + + + + + + + + + 416 + + + + + 417 + + + + + 418 + + + + + 419 + + + + + 420 + + + + + 450 + + + YES + + + + + + 451 + + + YES + + + + + + + + 452 + + + + + 453 + + + + + 454 + + + + + 457 + + + + + 459 + + + + + 460 + + + + + 462 + + + + + 465 + + + + + 466 + + + + + 485 + + + + + 490 + + + YES + + + + + + 491 + + + YES + + + + + + 492 + + + + + 496 + + + YES + + + + + + 497 + + + YES + + + + + + + + + + + + + + + 498 + + + + + 499 + + + + + 500 + + + + + 501 + + + + + 502 + + + + + 503 + + + YES + + + + + + 504 + + + + + 505 + + + + + 506 + + + + + 507 + + + + + 508 + + + YES + + + + + + + + + + + + + + 509 + + + + + 510 + + + + + 511 + + + + + 512 + + + + + 513 + + + + + 514 + + + + + 515 + + + + + 516 + + + + + 517 + + + + + 533 + + + + + + + YES + + YES + -3.IBPluginDependency + 112.IBPluginDependency + 112.ImportedFromIB2 + 124.IBPluginDependency + 124.ImportedFromIB2 + 125.IBPluginDependency + 125.ImportedFromIB2 + 125.editorWindowContentRectSynchronizationRect + 126.IBPluginDependency + 126.ImportedFromIB2 + 129.IBPluginDependency + 129.ImportedFromIB2 + 130.IBPluginDependency + 130.ImportedFromIB2 + 130.editorWindowContentRectSynchronizationRect + 131.IBPluginDependency + 131.ImportedFromIB2 + 134.IBPluginDependency + 134.ImportedFromIB2 + 136.IBPluginDependency + 136.ImportedFromIB2 + 143.IBPluginDependency + 143.ImportedFromIB2 + 144.IBPluginDependency + 144.ImportedFromIB2 + 145.IBPluginDependency + 145.ImportedFromIB2 + 149.IBPluginDependency + 149.ImportedFromIB2 + 150.IBPluginDependency + 150.ImportedFromIB2 + 19.IBPluginDependency + 19.ImportedFromIB2 + 195.IBPluginDependency + 195.ImportedFromIB2 + 196.IBPluginDependency + 196.ImportedFromIB2 + 197.IBPluginDependency + 197.ImportedFromIB2 + 198.IBPluginDependency + 198.ImportedFromIB2 + 199.IBPluginDependency + 199.ImportedFromIB2 + 200.IBEditorWindowLastContentRect + 200.IBPluginDependency + 200.ImportedFromIB2 + 200.editorWindowContentRectSynchronizationRect + 201.IBPluginDependency + 201.ImportedFromIB2 + 202.IBPluginDependency + 202.ImportedFromIB2 + 203.IBPluginDependency + 203.ImportedFromIB2 + 204.IBPluginDependency + 204.ImportedFromIB2 + 205.IBEditorWindowLastContentRect + 205.IBPluginDependency + 205.ImportedFromIB2 + 205.editorWindowContentRectSynchronizationRect + 206.IBPluginDependency + 206.ImportedFromIB2 + 207.IBPluginDependency + 207.ImportedFromIB2 + 208.IBPluginDependency + 208.ImportedFromIB2 + 209.IBPluginDependency + 209.ImportedFromIB2 + 210.IBPluginDependency + 210.ImportedFromIB2 + 211.IBPluginDependency + 211.ImportedFromIB2 + 212.IBPluginDependency + 212.ImportedFromIB2 + 212.editorWindowContentRectSynchronizationRect + 213.IBPluginDependency + 213.ImportedFromIB2 + 214.IBPluginDependency + 214.ImportedFromIB2 + 215.IBPluginDependency + 215.ImportedFromIB2 + 216.IBPluginDependency + 216.ImportedFromIB2 + 217.IBPluginDependency + 217.ImportedFromIB2 + 218.IBPluginDependency + 218.ImportedFromIB2 + 219.IBPluginDependency + 219.ImportedFromIB2 + 220.IBEditorWindowLastContentRect + 220.IBPluginDependency + 220.ImportedFromIB2 + 220.editorWindowContentRectSynchronizationRect + 221.IBPluginDependency + 221.ImportedFromIB2 + 23.IBPluginDependency + 23.ImportedFromIB2 + 236.IBPluginDependency + 236.ImportedFromIB2 + 239.IBPluginDependency + 239.ImportedFromIB2 + 24.IBEditorWindowLastContentRect + 24.IBPluginDependency + 24.ImportedFromIB2 + 24.editorWindowContentRectSynchronizationRect + 29.IBEditorWindowLastContentRect + 29.IBPluginDependency + 29.ImportedFromIB2 + 29.WindowOrigin + 29.editorWindowContentRectSynchronizationRect + 295.IBPluginDependency + 296.IBEditorWindowLastContentRect + 296.IBPluginDependency + 296.editorWindowContentRectSynchronizationRect + 297.IBPluginDependency + 298.IBPluginDependency + 346.IBPluginDependency + 346.ImportedFromIB2 + 348.IBPluginDependency + 348.ImportedFromIB2 + 349.IBEditorWindowLastContentRect + 349.IBPluginDependency + 349.ImportedFromIB2 + 349.editorWindowContentRectSynchronizationRect + 350.IBPluginDependency + 350.ImportedFromIB2 + 351.IBPluginDependency + 351.ImportedFromIB2 + 354.IBPluginDependency + 354.ImportedFromIB2 + 375.IBPluginDependency + 376.IBEditorWindowLastContentRect + 376.IBPluginDependency + 377.IBPluginDependency + 388.IBEditorWindowLastContentRect + 388.IBPluginDependency + 389.IBPluginDependency + 390.IBPluginDependency + 391.IBPluginDependency + 392.IBPluginDependency + 393.IBPluginDependency + 394.IBPluginDependency + 395.IBPluginDependency + 396.IBPluginDependency + 397.IBPluginDependency + 398.IBPluginDependency + 399.IBPluginDependency + 400.IBPluginDependency + 401.IBPluginDependency + 402.IBPluginDependency + 403.IBPluginDependency + 404.IBPluginDependency + 405.IBPluginDependency + 406.IBPluginDependency + 407.IBPluginDependency + 408.IBPluginDependency + 409.IBPluginDependency + 410.IBPluginDependency + 411.IBPluginDependency + 412.IBPluginDependency + 413.IBPluginDependency + 414.IBPluginDependency + 415.IBPluginDependency + 416.IBPluginDependency + 417.IBPluginDependency + 418.IBPluginDependency + 419.IBPluginDependency + 450.IBPluginDependency + 451.IBEditorWindowLastContentRect + 451.IBPluginDependency + 452.IBPluginDependency + 453.IBPluginDependency + 454.IBPluginDependency + 457.IBPluginDependency + 459.IBPluginDependency + 460.IBPluginDependency + 462.IBPluginDependency + 465.IBPluginDependency + 466.IBPluginDependency + 485.IBPluginDependency + 490.IBPluginDependency + 491.IBEditorWindowLastContentRect + 491.IBPluginDependency + 492.IBPluginDependency + 496.IBPluginDependency + 497.IBEditorWindowLastContentRect + 497.IBPluginDependency + 498.IBPluginDependency + 499.IBPluginDependency + 5.IBPluginDependency + 5.ImportedFromIB2 + 500.IBPluginDependency + 501.IBPluginDependency + 502.IBPluginDependency + 503.IBPluginDependency + 504.IBPluginDependency + 505.IBPluginDependency + 506.IBPluginDependency + 507.IBPluginDependency + 508.IBEditorWindowLastContentRect + 508.IBPluginDependency + 509.IBPluginDependency + 510.IBPluginDependency + 511.IBPluginDependency + 512.IBPluginDependency + 513.IBPluginDependency + 514.IBPluginDependency + 515.IBPluginDependency + 516.IBPluginDependency + 517.IBPluginDependency + 56.IBPluginDependency + 56.ImportedFromIB2 + 57.IBEditorWindowLastContentRect + 57.IBPluginDependency + 57.ImportedFromIB2 + 57.editorWindowContentRectSynchronizationRect + 58.IBPluginDependency + 58.ImportedFromIB2 + 72.IBPluginDependency + 72.ImportedFromIB2 + 73.IBPluginDependency + 73.ImportedFromIB2 + 74.IBPluginDependency + 74.ImportedFromIB2 + 75.IBPluginDependency + 75.ImportedFromIB2 + 77.IBPluginDependency + 77.ImportedFromIB2 + 78.IBPluginDependency + 78.ImportedFromIB2 + 79.IBPluginDependency + 79.ImportedFromIB2 + 80.IBPluginDependency + 80.ImportedFromIB2 + 81.IBEditorWindowLastContentRect + 81.IBPluginDependency + 81.ImportedFromIB2 + 81.editorWindowContentRectSynchronizationRect + 82.IBPluginDependency + 82.ImportedFromIB2 + 83.IBPluginDependency + 83.ImportedFromIB2 + 92.IBPluginDependency + 92.ImportedFromIB2 + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{522, 812}, {146, 23}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{436, 809}, {64, 6}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{753, 187}, {275, 113}} + com.apple.InterfaceBuilder.CocoaPlugin + + {{608, 612}, {275, 83}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{453, 408}, {254, 283}} + com.apple.InterfaceBuilder.CocoaPlugin + + {{187, 434}, {243, 243}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{608, 612}, {167, 43}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{753, 217}, {238, 103}} + com.apple.InterfaceBuilder.CocoaPlugin + + {{608, 612}, {241, 103}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{613, 618}, {194, 73}} + com.apple.InterfaceBuilder.CocoaPlugin + + {{525, 802}, {197, 73}} + {{346, 722}, {402, 20}} + com.apple.InterfaceBuilder.CocoaPlugin + + {74, 862} + {{6, 978}, {478, 20}} + com.apple.InterfaceBuilder.CocoaPlugin + {{563, 648}, {231, 43}} + com.apple.InterfaceBuilder.CocoaPlugin + {{475, 832}, {234, 43}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{746, 287}, {220, 133}} + com.apple.InterfaceBuilder.CocoaPlugin + + {{608, 612}, {215, 63}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + {{497, 648}, {83, 43}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{580, 408}, {175, 283}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{753, 197}, {170, 63}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{684, 668}, {142, 23}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{674, 260}, {204, 183}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{878, 180}, {164, 173}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + {{355, 508}, {183, 183}} + com.apple.InterfaceBuilder.CocoaPlugin + + {{23, 794}, {245, 183}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{411, 488}, {196, 203}} + com.apple.InterfaceBuilder.CocoaPlugin + + {{145, 474}, {199, 203}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + + + + YES + + + YES + + + + + YES + + + YES + + + + 534 + + + + YES + + AppDelegate + NSResponder + + IBUserSource + + + + + + YES + + NSApplication + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSApplication.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSApplicationScripting.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSColorPanel.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSHelpManager.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSPageLayout.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSUserInterfaceItemSearching.h + + + + NSBrowser + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSBrowser.h + + + + NSControl + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSControl.h + + + + NSDocument + NSObject + + YES + + YES + printDocument: + revertDocumentToSaved: + runPageLayout: + saveDocument: + saveDocumentAs: + saveDocumentTo: + + + YES + id + id + id + id + id + id + + + + IBFrameworkSource + AppKit.framework/Headers/NSDocument.h + + + + NSDocument + + IBFrameworkSource + AppKit.framework/Headers/NSDocumentScripting.h + + + + NSDocumentController + NSObject + + YES + + YES + clearRecentDocuments: + newDocument: + openDocument: + saveAllDocuments: + + + YES + id + id + id + id + + + + IBFrameworkSource + AppKit.framework/Headers/NSDocumentController.h + + + + NSFontManager + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSFontManager.h + + + + NSFormatter + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFormatter.h + + + + NSMatrix + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSMatrix.h + + + + NSMenu + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSMenu.h + + + + NSMenuItem + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSMenuItem.h + + + + NSMovieView + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSMovieView.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSAccessibility.h + + + + NSObject + + + + NSObject + + + + NSObject + + + + NSObject + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSDictionaryController.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSDragging.h + + + + NSObject + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSFontPanel.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSKeyValueBinding.h + + + + NSObject + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSNibLoading.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSOutlineView.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSPasteboard.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSSavePanel.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSTableView.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSToolbarItem.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSView.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSClassDescription.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObjectScripting.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSPortCoder.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptClassDescription.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptObjectSpecifiers.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptWhoseTests.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLDownload.h + + + + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSInterfaceStyle.h + + + + NSResponder + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSResponder.h + + + + NSTableView + NSControl + + + + NSText + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSText.h + + + + NSTextView + NSText + + IBFrameworkSource + AppKit.framework/Headers/NSTextView.h + + + + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSClipView.h + + + + NSView + + + + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSRulerView.h + + + + NSView + NSResponder + + + + NSWindow + + IBFrameworkSource + AppKit.framework/Headers/NSDrawer.h + + + + NSWindow + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSWindow.h + + + + NSWindow + + IBFrameworkSource + AppKit.framework/Headers/NSWindowScripting.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + ../MacCocoaApp.xcodeproj + 3 + + YES + + YES + NSMenuCheckmark + NSMenuMixedState + + + YES + {9, 8} + {7, 2} + + + + diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.cs b/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.cs new file mode 100644 index 0000000000..9ef47a13c4 --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.cs @@ -0,0 +1,35 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using MonoMac.Foundation; +using MonoMac.AppKit; + +namespace EmbedEtoInMonoMac +{ + public partial class MainWindow : MonoMac.AppKit.NSWindow + { + #region Constructors + + // Called when created from unmanaged code + public MainWindow(IntPtr handle) : base(handle) + { + Initialize(); + } + + // Called when created directly from a XIB file + [Export("initWithCoder:")] + public MainWindow(NSCoder coder) : base(coder) + { + Initialize(); + } + + // Shared initialization code + void Initialize() + { + } + + #endregion + } +} + diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.designer.cs b/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.designer.cs new file mode 100644 index 0000000000..eb9b60cb6c --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.designer.cs @@ -0,0 +1,29 @@ +// WARNING +// +// This file has been generated automatically by Xamarin Studio to store outlets and +// actions made in the UI designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using MonoMac.Foundation; +using System.CodeDom.Compiler; + +namespace EmbedEtoInMonoMac +{ + [Register ("MainWindowController")] + partial class MainWindowController + { + + void ReleaseDesignerOutlets () + { + } + } + + [Register ("MainWindow")] + partial class MainWindow + { + + void ReleaseDesignerOutlets () + { + } + } +} diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.xib b/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.xib new file mode 100644 index 0000000000..a21b4db2ee --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/MainWindow.xib @@ -0,0 +1,154 @@ + + + + 1090 + 13F34 + 6245 + 1265.21 + 698.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 6245 + + + NSCustomObject + NSView + NSWindowTemplate + + + com.apple.InterfaceBuilder.CocoaPlugin + + + + + MainWindowController + + + FirstResponder + + + NSApplication + + + 15 + 2 + {{131, 74}, {606, 354}} + 611844096 + Window + MainWindow + + + + + 256 + + {606, 354} + + + + + {{0, 0}, {1440, 878}} + {10000000000000, 10000000000000} + YES + + + + + + + window + + + + 6 + + + + + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 2 + + + + + + + + 3 + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{319, 371}, {606, 354}} + + + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + 9 + + + + + MainWindow + NSWindow + + IBProjectSource + ../MainWindow.h + + + + MainWindowController + NSWindowController + + IBProjectSource + ../MainWindowController.h + + + + + 0 + IBCocoaFramework + NO + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/MainWindowController.cs b/Samples/MonoMac/EmbedEtoInMonoMac/MainWindowController.cs new file mode 100644 index 0000000000..1533732e26 --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/MainWindowController.cs @@ -0,0 +1,66 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using MonoMac.Foundation; +using MonoMac.AppKit; +using Eto.Forms; +using System.Drawing; + +namespace EmbedEtoInMonoMac +{ + public partial class MainWindowController : MonoMac.AppKit.NSWindowController + { + #region Constructors + + // Called when created from unmanaged code + public MainWindowController(IntPtr handle) : base(handle) + { + Initialize(); + } + + // Called when created directly from a XIB file + [Export("initWithCoder:")] + public MainWindowController(NSCoder coder) : base(coder) + { + Initialize(); + } + + // Call to load from the XIB/NIB file + public MainWindowController() : base("MainWindow") + { + Initialize(); + } + + // Shared initialization code + void Initialize() + { + } + + #endregion + + //strongly typed window accessor + public new MainWindow Window + { + get { return (MainWindow)base.Window; } + } + + + public override void AwakeFromNib() + { + base.AwakeFromNib(); + + // Get native view for the panel + // passing true so that we can embed, otherwise we just get a reference to the control + var nativeView = new MyEtoPanel().ToNative(true); + + nativeView.AutoresizingMask = NSViewResizingMask.MinYMargin; // anchor to top left + + // position control, keeping auto size of control + var contentFrame = Window.ContentView.Frame; + nativeView.SetFrameOrigin(new PointF(100, contentFrame.Height - nativeView.Frame.Height - 100)); + + Window.ContentView.AddSubview(nativeView); + } + } +} \ No newline at end of file diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/MyEtoPanel.cs b/Samples/MonoMac/EmbedEtoInMonoMac/MyEtoPanel.cs new file mode 100644 index 0000000000..dd5c37882a --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/MyEtoPanel.cs @@ -0,0 +1,31 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace EmbedEtoInMonoMac +{ + /// + /// Eto.Forms panel to embed in an existing MonoMac app + /// + /// + /// This is used in to add to the existing native app. + /// + public class MyEtoPanel : Panel + { + public MyEtoPanel() + { + Content = new TableLayout + { + Spacing = new Size(5, 5), + Rows = + { + new TableRow(new Label { Text = "An Eto.Forms control" }), + new TableRow(new TextBox()), + new TableRow(new ComboBox { Items = { "Item 1", "Item 2", "Item 3" } }), + null + } + }; + } + } +} + diff --git a/Samples/MonoMac/EmbedEtoInMonoMac/Program.cs b/Samples/MonoMac/EmbedEtoInMonoMac/Program.cs new file mode 100644 index 0000000000..7ad5854650 --- /dev/null +++ b/Samples/MonoMac/EmbedEtoInMonoMac/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Drawing; +using MonoMac.Foundation; +using MonoMac.AppKit; +using MonoMac.ObjCRuntime; + +namespace EmbedEtoInMonoMac +{ + static class Program + { + static void Main(string[] args) + { + NSApplication.Init(); + + // initialize eto forms after native app is initialized + new Eto.Forms.Application(new Eto.Mac.Platform()).Attach(); + + NSApplication.Main(args); + } + } +} + diff --git a/Samples/MonoMac/EmbedMonoMacInEto/EmbedMonoMacInEto.csproj b/Samples/MonoMac/EmbedMonoMacInEto/EmbedMonoMacInEto.csproj new file mode 100644 index 0000000000..2c9cbd7831 --- /dev/null +++ b/Samples/MonoMac/EmbedMonoMacInEto/EmbedMonoMacInEto.csproj @@ -0,0 +1,99 @@ + + + + Debug + AnyCPU + {948B3504-5B70-4649-8FE4-BDE1FB46EC69};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF} + Exe + EmbedMonoMacInEto + Resources + EmbedMonoMacInEto + True + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + false + false + false + false + false + + + full + true + bin\Release + prompt + 4 + false + SdkOnly + false + true + false + Developer ID Application + true + true + + + full + true + bin\AppStore + prompt + 4 + false + SdkOnly + false + true + 3rd Party Mac Developer Installer + true + 3rd Party Mac Developer Application + true + true + + + + + + + + + ..\..\..\Libraries\MonoMac\MonoMac.dll + + + + + + + + + + + + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66} + Eto.Mac - Pcl + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + + + + + + MyNativeView.cs + + + + + + \ No newline at end of file diff --git a/Samples/MonoMac/EmbedMonoMacInEto/Info.plist b/Samples/MonoMac/EmbedMonoMacInEto/Info.plist new file mode 100644 index 0000000000..3399fd2d77 --- /dev/null +++ b/Samples/MonoMac/EmbedMonoMacInEto/Info.plist @@ -0,0 +1,18 @@ + + + + + CFBundleDisplayName + EmbedMonoMacInEto + CFBundleIdentifier + com.your-company.EmbedMonoMacInEto + CFBundleName + EmbedMonoMacInEto + CFBundleVersion + 1 + LSMinimumSystemVersion + 10.6 + NSPrincipalClass + NSApplication + + diff --git a/Samples/MonoMac/EmbedMonoMacInEto/MainForm.cs b/Samples/MonoMac/EmbedMonoMacInEto/MainForm.cs new file mode 100644 index 0000000000..030ff6f3ae --- /dev/null +++ b/Samples/MonoMac/EmbedMonoMacInEto/MainForm.cs @@ -0,0 +1,30 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace EmbedMonoMacInEto +{ + public class MainForm : Form + { + public MainForm() + { + Menu = new MenuBar(); + + // create a new native MonoMac view and wrap it in an eto control + var nativeControl = new MyNativeViewController().ToEto(); + + Content = new TableLayout + { + Padding = new Padding(10), + Spacing = new Size(5, 5), + Rows = + { + nativeControl, + null, + new TableLayout(new TableRow(null, new Button { Text = "An Eto.Forms button" })), + } + }; + } + } +} + diff --git a/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.cs b/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.cs new file mode 100644 index 0000000000..ba9ed03c8c --- /dev/null +++ b/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.cs @@ -0,0 +1,35 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using MonoMac.Foundation; +using MonoMac.AppKit; + +namespace EmbedMonoMacInEto +{ + public partial class MyNativeView : MonoMac.AppKit.NSView + { + #region Constructors + + // Called when created from unmanaged code + public MyNativeView(IntPtr handle) : base(handle) + { + Initialize(); + } + + // Called when created directly from a XIB file + [Export("initWithCoder:")] + public MyNativeView(NSCoder coder) : base(coder) + { + Initialize(); + } + + // Shared initialization code + void Initialize() + { + } + + #endregion + } +} + diff --git a/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.designer.cs b/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.designer.cs new file mode 100644 index 0000000000..203e002934 --- /dev/null +++ b/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.designer.cs @@ -0,0 +1,17 @@ + +namespace EmbedMonoMacInEto +{ + + // Should subclass MonoMac.AppKit.NSView + [MonoMac.Foundation.Register("MyNativeView")] + public partial class MyNativeView + { + } + + // Should subclass MonoMac.AppKit.NSViewController + [MonoMac.Foundation.Register("MyNativeViewController")] + public partial class MyNativeViewController + { + } +} + diff --git a/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.xib b/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.xib new file mode 100644 index 0000000000..fe398afcd9 --- /dev/null +++ b/Samples/MonoMac/EmbedMonoMacInEto/MyNativeView.xib @@ -0,0 +1,385 @@ + + + + 1090 + 13F34 + 6245 + 1265.21 + 698.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 6245 + + + NSComboBox + NSComboBoxCell + NSCustomObject + NSCustomView + NSTextField + NSTextFieldCell + + + com.apple.InterfaceBuilder.CocoaPlugin + + + + + MyNativeViewController + + + FirstResponder + + + NSApplication + + + + 268 + + + + 266 + {{45, 45}, {353, 26}} + + + _NS:9 + YES + + 342884417 + 272630784 + + + YES + 13 + 1044 + + _NS:9 + + YES + + 6 + System + textBackgroundColor + + 3 + MQA + + + + 6 + System + controlTextColor + + 3 + MAA + + + 5 + YES + + Item 1 + Item 2 + Item 3 + + + + + 274 + {13, 63} + + + _NS:29 + YES + NO + YES + + + 0 + 10 + 10 + 3.4028234663852886e+38 + + 67108928 + 2048 + + + YES + 11 + 3100 + + + 6 + System + headerColor + + + + 6 + System + headerTextColor + + + + + 337641536 + 268437504 + Item 3 + + + + 6 + System + controlBackgroundColor + + 3 + MC42NjY2NjY2NjY3AA + + + + + 3 + YES + + + + 3 + 2 + + + 6 + System + gridColor + + 3 + MC41AA + + + 19 + tableViewAction: + -765427712 + + + + 1 + -1 + 0 + YES + 0 + 1 + + + NO + 1 + + + + 268 + {{43, 156}, {237, 17}} + + + + _NS:526 + {251, 750} + YES + + 68157504 + 272630784 + A Cocoa Label + + _NS:526 + + + 6 + System + controlColor + + + + + NO + 1 + + + + 266 + {{45, 103}, {350, 22}} + + + + _NS:9 + YES + + -1804599231 + 272630784 + + + _NS:9 + + YES + + + 6 + System + textColor + + + + NO + 1 + + + {420, 202} + + + + MyNativeView + + + + + + + view + + + + 17 + + + + + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 4 + + + + + + + + + + 18 + + + + + + + + 19 + + + + + 20 + + + + + + + + 21 + + + + + 22 + + + + + + + + 23 + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {302, 329} + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + 23 + + + + + MyNativeView + NSView + + IBProjectSource + ../MyNativeView.h + + + + MyNativeViewController + NSViewController + + IBProjectSource + ../MyNativeViewController.h + + + + + + NSFormatter + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFormatter.h + + + + + 0 + IBCocoaFramework + NO + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + diff --git a/Samples/MonoMac/EmbedMonoMacInEto/MyNativeViewController.cs b/Samples/MonoMac/EmbedMonoMacInEto/MyNativeViewController.cs new file mode 100644 index 0000000000..b3d59a1993 --- /dev/null +++ b/Samples/MonoMac/EmbedMonoMacInEto/MyNativeViewController.cs @@ -0,0 +1,50 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using MonoMac.Foundation; +using MonoMac.AppKit; + +namespace EmbedMonoMacInEto +{ + public partial class MyNativeViewController : MonoMac.AppKit.NSViewController + { + #region Constructors + + // Called when created from unmanaged code + public MyNativeViewController(IntPtr handle) : base(handle) + { + Initialize(); + } + + // Called when created directly from a XIB file + [Export("initWithCoder:")] + public MyNativeViewController(NSCoder coder) : base(coder) + { + Initialize(); + } + + // Call to load from the XIB/NIB file + public MyNativeViewController() : base("MyNativeView", NSBundle.MainBundle) + { + Initialize(); + } + + // Shared initialization code + void Initialize() + { + } + + #endregion + + //strongly typed view accessor + public new MyNativeView View + { + get + { + return (MyNativeView)base.View; + } + } + } +} + diff --git a/Samples/MonoMac/EmbedMonoMacInEto/Program.cs b/Samples/MonoMac/EmbedMonoMacInEto/Program.cs new file mode 100644 index 0000000000..8f24d4b772 --- /dev/null +++ b/Samples/MonoMac/EmbedMonoMacInEto/Program.cs @@ -0,0 +1,14 @@ +using System; +using Eto.Forms; + +namespace EmbedMonoMacInEto +{ + static class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(new Eto.Mac.Platform()).Run(new MainForm()); + } + } +} diff --git a/Samples/Samples.sln b/Samples/Samples.sln new file mode 100644 index 0000000000..fd23819032 --- /dev/null +++ b/Samples/Samples.sln @@ -0,0 +1,319 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MonoMac", "MonoMac", "{F65C2B2B-BE0E-4AF5-B65B-3F770F8D54CF}" + ProjectSection(MonoDevelopProperties) = preProject + BaseDirectory = MonoMac + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedEtoInMonoMac", "MonoMac\EmbedEtoInMonoMac\EmbedEtoInMonoMac.csproj", "{95B6E385-A0ED-4A49-99B5-19569156FCE6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedMonoMacInEto", "MonoMac\EmbedMonoMacInEto\EmbedMonoMacInEto.csproj", "{86A6EB85-7A64-4E9A-9C72-121A904D8EAF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Eto", "Eto", "{19A4EA01-CA9E-4390-B448-974152AB5706}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto - Pcl", "..\Source\Eto\Eto - Pcl.csproj", "{35EF0A4E-2A1A-492C-8BED-106774EA09F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Mac - Pcl", "..\Source\Eto.Mac\Eto.Mac - Pcl.csproj", "{3E7995E0-C9EB-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.WinForms - Pcl", "..\Source\Eto.WinForms\Eto.WinForms - Pcl.csproj", "{9F51798A-354C-47A1-9207-4BB7D7FC7FC4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Wpf - Pcl", "..\Source\Eto.Wpf\Eto.Wpf - Pcl.csproj", "{63137FA0-CA55-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Gtk2 - Pcl", "..\Source\Eto.Gtk\Eto.Gtk2 - Pcl.csproj", "{80915A80-CA54-11E3-9C1A-0800200C9A66}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WinForms", "WinForms", "{1A922E1B-12D1-4CAA-929C-A400BC875EAB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedWinFormsInEto", "WinForms\EmbedWinFormsInEto\EmbedWinFormsInEto.csproj", "{733C7D13-F676-4E41-BDB2-27696BD5AD15}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedEtoInWinForms", "WinForms\EmbedEtoInWinForms\EmbedEtoInWinForms.csproj", "{05323072-56A7-4CFE-9C64-2E7762D592EB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Wpf", "Wpf", "{F72787D2-13C7-4CBA-A383-5BFC74ACEFFB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedEtoInWpf", "Wpf\EmbedEtoInWpf\EmbedEtoInWpf.csproj", "{D528D241-8063-4732-B19D-6939838E516F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedWpfInEto", "Wpf\EmbedWpfInEto\EmbedWpfInEto.csproj", "{B19797BA-419B-4FD8-B306-A3C241C665EB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Gtk", "Gtk", "{B47C0BBE-0807-47D2-A3A1-A61CD28AC09D}" + ProjectSection(MonoDevelopProperties) = preProject + BaseDirectory = Gtk + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedGtkInEto", "Gtk\EmbedGtkInEto\EmbedGtkInEto.csproj", "{8096E21D-28E4-4A1B-973A-B60EC23C3772}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedEtoInGtk", "Gtk\EmbedEtoInGtk\EmbedEtoInGtk.csproj", "{27E7436C-0B29-430C-9A21-A5812FC72311}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tutorials", "Tutorials", "{16769B60-62AD-4D78-90A3-3138D29E072C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tutorial1 - Hello World", "Tutorials\Tutorial1\Tutorial1 - Hello World.csproj", "{7BE9E187-3FC4-49D2-A322-F4651C3AE256}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tutorial2 - Menus and Toolbars", "Tutorials\Tutorial2\Tutorial2 - Menus and Toolbars.csproj", "{0844A0AD-778A-4DB3-8332-03AC50A17D05}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tutorial3 - Table Layout", "Tutorials\Tutorial3\Tutorial3 - Table Layout.csproj", "{D51732E0-1E93-11E3-8224-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tutorial4 - Binding", "Tutorials\Tutorial4\Tutorial4 - Binding.csproj", "{DDC8A290-2F20-11E4-8C21-0800200C9A66}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Mac = Debug|Mac + Debug|Linux = Debug|Linux + Debug|Windows = Debug|Windows + Release|Mac = Release|Mac + Release|Linux = Release|Linux + Release|Windows = Release|Windows + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Debug|Linux.ActiveCfg = Debug|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Debug|Linux.Build.0 = Debug|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Debug|Mac.ActiveCfg = Debug|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Debug|Mac.Build.0 = Debug|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Debug|Windows.ActiveCfg = Debug|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Debug|Windows.Build.0 = Debug|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Release|Linux.ActiveCfg = Release|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Release|Linux.Build.0 = Release|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Release|Mac.ActiveCfg = Release|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Release|Mac.Build.0 = Release|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Release|Windows.ActiveCfg = Release|Any CPU + {05323072-56A7-4CFE-9C64-2E7762D592EB}.Release|Windows.Build.0 = Release|Any CPU + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Debug|Linux.ActiveCfg = Debug|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Debug|Linux.Build.0 = Debug|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Debug|Mac.ActiveCfg = Debug|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Debug|Mac.Build.0 = Debug|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Debug|Windows.ActiveCfg = Debug|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Debug|Windows.Build.0 = Debug|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Release|Linux.ActiveCfg = Release|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Release|Linux.Build.0 = Release|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Release|Mac.ActiveCfg = Release|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Release|Mac.Build.0 = Release|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Release|Windows.ActiveCfg = Release|x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05}.Release|Windows.Build.0 = Release|x86 + {27E7436C-0B29-430C-9A21-A5812FC72311}.Debug|Linux.ActiveCfg = Debug|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Debug|Linux.Build.0 = Debug|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Debug|Mac.ActiveCfg = Debug|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Debug|Mac.Build.0 = Debug|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Debug|Windows.ActiveCfg = Debug|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Debug|Windows.Build.0 = Debug|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Release|Linux.ActiveCfg = Release|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Release|Linux.Build.0 = Release|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Release|Mac.ActiveCfg = Release|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Release|Mac.Build.0 = Release|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Release|Windows.ActiveCfg = Release|Any CPU + {27E7436C-0B29-430C-9A21-A5812FC72311}.Release|Windows.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Linux.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Linux.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Mac.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Mac.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Windows.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Windows.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Linux.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Linux.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Mac.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Mac.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Windows.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Windows.Build.0 = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Debug|Linux.ActiveCfg = Debug|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Debug|Linux.Build.0 = Debug|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Debug|Mac.ActiveCfg = Debug|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Debug|Mac.Build.0 = Debug|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Debug|Windows.ActiveCfg = Debug|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Debug|Windows.Build.0 = Debug|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Release|Linux.ActiveCfg = Release|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Release|Linux.Build.0 = Release|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Release|Mac.ActiveCfg = Release|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Release|Mac.Build.0 = Release|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Release|Windows.ActiveCfg = Release|Any CPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15}.Release|Windows.Build.0 = Release|Any CPU + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Debug|Linux.ActiveCfg = Debug|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Debug|Linux.Build.0 = Debug|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Debug|Mac.ActiveCfg = Debug|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Debug|Mac.Build.0 = Debug|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Debug|Windows.ActiveCfg = Debug|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Debug|Windows.Build.0 = Debug|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Release|Linux.ActiveCfg = Release|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Release|Linux.Build.0 = Release|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Release|Mac.ActiveCfg = Release|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Release|Mac.Build.0 = Release|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Release|Windows.ActiveCfg = Release|x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256}.Release|Windows.Build.0 = Release|x86 + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Debug|Linux.ActiveCfg = Debug|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Debug|Linux.Build.0 = Debug|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Debug|Mac.ActiveCfg = Debug|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Debug|Mac.Build.0 = Debug|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Debug|Windows.ActiveCfg = Debug|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Debug|Windows.Build.0 = Debug|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Release|Linux.ActiveCfg = Release|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Release|Linux.Build.0 = Release|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Release|Mac.ActiveCfg = Release|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Release|Mac.Build.0 = Release|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Release|Windows.ActiveCfg = Release|Any CPU + {8096E21D-28E4-4A1B-973A-B60EC23C3772}.Release|Windows.Build.0 = Release|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Debug|Linux.ActiveCfg = Debug|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Debug|Linux.Build.0 = Debug|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Debug|Mac.ActiveCfg = Debug|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Debug|Mac.Build.0 = Debug|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Debug|Windows.ActiveCfg = Debug|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Debug|Windows.Build.0 = Debug|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Release|Linux.ActiveCfg = Release|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Release|Linux.Build.0 = Release|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Release|Mac.ActiveCfg = Release|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Release|Mac.Build.0 = Release|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Release|Windows.ActiveCfg = Release|Any CPU + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF}.Release|Windows.Build.0 = Release|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Debug|Linux.ActiveCfg = Debug|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Debug|Linux.Build.0 = Debug|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Debug|Mac.ActiveCfg = Debug|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Debug|Mac.Build.0 = Debug|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Debug|Windows.ActiveCfg = Debug|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Debug|Windows.Build.0 = Debug|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Release|Linux.ActiveCfg = Release|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Release|Linux.Build.0 = Release|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Release|Mac.ActiveCfg = Release|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Release|Mac.Build.0 = Release|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Release|Windows.ActiveCfg = Release|Any CPU + {95B6E385-A0ED-4A49-99B5-19569156FCE6}.Release|Windows.Build.0 = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Linux.ActiveCfg = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Linux.Build.0 = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Mac.ActiveCfg = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Mac.Build.0 = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Windows.ActiveCfg = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Windows.Build.0 = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Linux.ActiveCfg = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Linux.Build.0 = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Mac.ActiveCfg = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Mac.Build.0 = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Windows.ActiveCfg = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Windows.Build.0 = Release|Any CPU + {B19797BA-419B-4FD8-B306-A3C241C665EB}.Debug|Linux.ActiveCfg = Debug|Any CPU + {B19797BA-419B-4FD8-B306-A3C241C665EB}.Debug|Mac.ActiveCfg = Debug|Any CPU + {B19797BA-419B-4FD8-B306-A3C241C665EB}.Debug|Windows.ActiveCfg = Debug|Any CPU + {B19797BA-419B-4FD8-B306-A3C241C665EB}.Debug|Windows.Build.0 = Debug|Any CPU + {B19797BA-419B-4FD8-B306-A3C241C665EB}.Release|Linux.ActiveCfg = Release|Any CPU + {B19797BA-419B-4FD8-B306-A3C241C665EB}.Release|Mac.ActiveCfg = Release|Any CPU + {B19797BA-419B-4FD8-B306-A3C241C665EB}.Release|Windows.ActiveCfg = Release|Any CPU + {B19797BA-419B-4FD8-B306-A3C241C665EB}.Release|Windows.Build.0 = Release|Any CPU + {D51732E0-1E93-11E3-8224-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Debug|Linux.Build.0 = Debug|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Debug|Mac.Build.0 = Debug|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Debug|Windows.Build.0 = Debug|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Release|Linux.ActiveCfg = Release|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Release|Linux.Build.0 = Release|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Release|Mac.ActiveCfg = Release|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Release|Mac.Build.0 = Release|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Release|Windows.ActiveCfg = Release|x86 + {D51732E0-1E93-11E3-8224-0800200C9A66}.Release|Windows.Build.0 = Release|x86 + {D528D241-8063-4732-B19D-6939838E516F}.Debug|Linux.ActiveCfg = Debug|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Debug|Linux.Build.0 = Debug|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Debug|Mac.ActiveCfg = Debug|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Debug|Mac.Build.0 = Debug|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Debug|Windows.ActiveCfg = Debug|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Debug|Windows.Build.0 = Debug|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Release|Linux.ActiveCfg = Release|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Release|Linux.Build.0 = Release|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Release|Mac.ActiveCfg = Release|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Release|Mac.Build.0 = Release|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Release|Windows.ActiveCfg = Release|Any CPU + {D528D241-8063-4732-B19D-6939838E516F}.Release|Windows.Build.0 = Release|Any CPU + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Debug|Linux.Build.0 = Debug|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Debug|Mac.Build.0 = Debug|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Debug|Windows.Build.0 = Debug|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Release|Linux.ActiveCfg = Release|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Release|Linux.Build.0 = Release|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Release|Mac.ActiveCfg = Release|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Release|Mac.Build.0 = Release|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Release|Windows.ActiveCfg = Release|x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66}.Release|Windows.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {95B6E385-A0ED-4A49-99B5-19569156FCE6} = {F65C2B2B-BE0E-4AF5-B65B-3F770F8D54CF} + {86A6EB85-7A64-4E9A-9C72-121A904D8EAF} = {F65C2B2B-BE0E-4AF5-B65B-3F770F8D54CF} + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} = {19A4EA01-CA9E-4390-B448-974152AB5706} + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66} = {19A4EA01-CA9E-4390-B448-974152AB5706} + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4} = {19A4EA01-CA9E-4390-B448-974152AB5706} + {63137FA0-CA55-11E3-9C1A-0800200C9A66} = {19A4EA01-CA9E-4390-B448-974152AB5706} + {80915A80-CA54-11E3-9C1A-0800200C9A66} = {19A4EA01-CA9E-4390-B448-974152AB5706} + {733C7D13-F676-4E41-BDB2-27696BD5AD15} = {1A922E1B-12D1-4CAA-929C-A400BC875EAB} + {05323072-56A7-4CFE-9C64-2E7762D592EB} = {1A922E1B-12D1-4CAA-929C-A400BC875EAB} + {D528D241-8063-4732-B19D-6939838E516F} = {F72787D2-13C7-4CBA-A383-5BFC74ACEFFB} + {B19797BA-419B-4FD8-B306-A3C241C665EB} = {F72787D2-13C7-4CBA-A383-5BFC74ACEFFB} + {8096E21D-28E4-4A1B-973A-B60EC23C3772} = {B47C0BBE-0807-47D2-A3A1-A61CD28AC09D} + {27E7436C-0B29-430C-9A21-A5812FC72311} = {B47C0BBE-0807-47D2-A3A1-A61CD28AC09D} + {7BE9E187-3FC4-49D2-A322-F4651C3AE256} = {16769B60-62AD-4D78-90A3-3138D29E072C} + {0844A0AD-778A-4DB3-8332-03AC50A17D05} = {16769B60-62AD-4D78-90A3-3138D29E072C} + {D51732E0-1E93-11E3-8224-0800200C9A66} = {16769B60-62AD-4D78-90A3-3138D29E072C} + {DDC8A290-2F20-11E4-8C21-0800200C9A66} = {16769B60-62AD-4D78-90A3-3138D29E072C} + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Tutorials\Tutorial1\Tutorial1 - Hello World.csproj + Policies = $0 + $0.TextStylePolicy = $1 + $1.inheritsSet = null + $1.scope = text/x-csharp + $0.CSharpFormattingPolicy = $2 + $2.IndentSwitchBody = True + $2.AnonymousMethodBraceStyle = NextLine + $2.PropertyBraceStyle = NextLine + $2.PropertyGetBraceStyle = NextLine + $2.PropertySetBraceStyle = NextLine + $2.EventBraceStyle = NextLine + $2.EventAddBraceStyle = NextLine + $2.EventRemoveBraceStyle = NextLine + $2.StatementBraceStyle = NextLine + $2.ElseNewLinePlacement = NewLine + $2.CatchNewLinePlacement = NewLine + $2.FinallyNewLinePlacement = NewLine + $2.WhileNewLinePlacement = DoNotCare + $2.ArrayInitializerWrapping = DoNotChange + $2.ArrayInitializerBraceStyle = NextLine + $2.BeforeMethodDeclarationParentheses = False + $2.BeforeMethodCallParentheses = False + $2.BeforeConstructorDeclarationParentheses = False + $2.BeforeDelegateDeclarationParentheses = False + $2.NewParentheses = False + $2.SpacesBeforeBrackets = False + $2.inheritsSet = Mono + $2.inheritsScope = text/x-csharp + $2.scope = text/x-csharp + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Samples/Tutorials/README.md b/Samples/Tutorials/README.md new file mode 100644 index 0000000000..5cb598ebd2 --- /dev/null +++ b/Samples/Tutorials/README.md @@ -0,0 +1,20 @@ +Eto.Forms Tutorials +=================== + +How to Build +------------ + +These tutorials use a script to copy the required platform dependencies: + +- buildapp.sh is used for OS X or Linux +- buildapp.cmd is used for Windows + + +How to Run +---------- + +You can run from the IDE, though on OS X an .app bundle is created in the output directory that you must run separately, +otherwise it will run the GTK platform on OS X. + +To run the MonoMac platform directly in MonoDevelop for OS X, you must create a MonoMac project separate from your GUI +executable project. See the Eto.Test.Mac application as an example of how this looks. \ No newline at end of file diff --git a/Samples/Tutorials/Tutorial.targets b/Samples/Tutorials/Tutorial.targets new file mode 100644 index 0000000000..4ab0c1e9f5 --- /dev/null +++ b/Samples/Tutorials/Tutorial.targets @@ -0,0 +1,66 @@ + + + + + $(BuildDependsOn); + _CreateAppBundle + + + + + $(MSBuildProjectName) + $(MSBuildThisFileDirectory)\..\..\Resources\MacAppTemplate.app + + + + + + + $(OutputAppPath)\Contents\MonoBundle + $(OutputAppPath)\Contents\MacOS\Launcher.exec + + + + + + + + + + + + + + + + + $(PListContents.Replace('>MyApp.exe</', '>$(TargetFileName)</')) + $(PListContents.Replace('>MacAppTemplate</', '>$(AppBundleName)</')) + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Tutorials/Tutorial1/Main.cs b/Samples/Tutorials/Tutorial1/Main.cs new file mode 100644 index 0000000000..58c13ad6c5 --- /dev/null +++ b/Samples/Tutorials/Tutorial1/Main.cs @@ -0,0 +1,30 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Tutorial1 +{ + public class MyForm : Form + { + public MyForm() + { + // Set ClientSize instead of Size, as each platform has different window border sizes + ClientSize = new Size(600, 400); + + // Title to show in the title bar + Title = "Hello, Eto.Forms"; + + // Content of the form + Content = new Label { Text = "Some content", VerticalAlign = VerticalAlign.Middle, HorizontalAlign = HorizontalAlign.Center }; + } + } + + class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application().Run(new MyForm()); + } + } +} diff --git a/Samples/Tutorials/Tutorial1/Tutorial1 - Hello World.csproj b/Samples/Tutorials/Tutorial1/Tutorial1 - Hello World.csproj new file mode 100644 index 0000000000..493af582d2 --- /dev/null +++ b/Samples/Tutorials/Tutorial1/Tutorial1 - Hello World.csproj @@ -0,0 +1,58 @@ + + + + Debug + x86 + {7BE9E187-3FC4-49D2-A322-F4651C3AE256} + WinExe + Tutorial1 + Tutorial1 + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + false + + + none + false + bin\Release + prompt + 4 + x86 + false + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + {80915A80-CA54-11E3-9C1A-0800200C9A66} + Eto.Gtk2 - Pcl + + + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66} + Eto.Mac - Pcl + + + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4} + Eto.WinForms - Pcl + + + \ No newline at end of file diff --git a/Samples/Tutorials/Tutorial2/Main.cs b/Samples/Tutorials/Tutorial2/Main.cs new file mode 100644 index 0000000000..0b7507956e --- /dev/null +++ b/Samples/Tutorials/Tutorial2/Main.cs @@ -0,0 +1,93 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto; + +namespace Tutorial2 +{ + /// + /// Custom command + /// + /// + /// You can create your own command subclasses, or create instances of Command directly. + /// Commands can be used for either the menu or toolbar. + /// Otherwise, you can use MenuItem or ToolItem classes directly. + /// + public class MyCommand : Command + { + public MyCommand() + { + MenuText = "C&lick Me, Command"; + ToolBarText = "Click Me"; + ToolTip = "This shows a dialog for no reason"; + //Image = Icon.FromResource ("MyResourceName.ico"); + //Image = Bitmap.FromResource ("MyResourceName.png"); + Shortcut = Application.Instance.CommonModifier | Keys.M; // control+M or cmd+M + } + + protected override void OnExecuted(EventArgs e) + { + base.OnExecuted(e); + + MessageBox.Show(Application.Instance.MainForm, "You clicked me!", "Tutorial 2", MessageBoxButtons.OK); + } + } + + public class MyForm : Form + { + public MyForm() + { + ClientSize = new Size(600, 400); + Title = "Menus and Toolbars"; + + // create menu + Menu = new MenuBar + { + Items = + { + new ButtonMenuItem + { + Text = "&File", + Items = + { + // you can add commands or menu items + new MyCommand(), + new ButtonMenuItem { Text = "Click Me, MenuItem" } + } + } + }, + // quit item (goes in Application menu on OS X, File menu for others) + QuitItem = new Command((sender, e) => Application.Instance.Quit()) + { + MenuText = "Quit", + Shortcut = Application.Instance.CommonModifier | Keys.Q + }, + // about command (goes in Application menu on OS X, Help menu for others) + AboutItem = new Command((sender, e) => new Dialog { Content = new Label { Text = "About my app..." }, ClientSize = new Size(200, 200) }.ShowModal(this)) + { + MenuText = "About my app" + } + }; + + // create toolbar + ToolBar = new ToolBar + { + Items = + { + new MyCommand(), + new SeparatorToolItem(), + new ButtonToolItem { Text = "Click Me, ToolItem" } + } + }; + } + } + + class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application().Run(new MyForm()); + } + } +} diff --git a/Samples/Tutorials/Tutorial2/Tutorial2 - Menus and Toolbars.csproj b/Samples/Tutorials/Tutorial2/Tutorial2 - Menus and Toolbars.csproj new file mode 100644 index 0000000000..3ae446661f --- /dev/null +++ b/Samples/Tutorials/Tutorial2/Tutorial2 - Menus and Toolbars.csproj @@ -0,0 +1,58 @@ + + + + Debug + x86 + {0844A0AD-778A-4DB3-8332-03AC50A17D05} + WinExe + Tutorial2 + Tutorial2 + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + false + + + none + false + bin\Release + prompt + 4 + x86 + false + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + {80915A80-CA54-11E3-9C1A-0800200C9A66} + Eto.Gtk2 - Pcl + + + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66} + Eto.Mac - Pcl + + + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4} + Eto.WinForms - Pcl + + + \ No newline at end of file diff --git a/Samples/Tutorials/Tutorial3/Main.cs b/Samples/Tutorials/Tutorial3/Main.cs new file mode 100644 index 0000000000..4251581606 --- /dev/null +++ b/Samples/Tutorials/Tutorial3/Main.cs @@ -0,0 +1,75 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Tutorial3 +{ + public class MyForm : Form + { + public MyForm() + { + ClientSize = new Size(600, 400); + Title = "Table Layout"; + + // The main layout mechanism for Eto.Forms is a TableLayout. + // This is recommended to allow controls to keep their natural platform-specific size. + // You can layout your controls declaratively using rows and columns as below, or add to the TableLayout.Rows and TableRow.Cell directly. + + Content = new TableLayout( + new TableRow( + new TableCell { Control = new Label { Text = "First Column" }, ScaleWidth = true }, // Scale width to share space among all columns + new TableCell { Control = new Label { Text = "Second Column" }, ScaleWidth = true }, + new TableCell { Control = new Label { Text = "Third Column" }, ScaleWidth = true } + ), + new TableRow( + // A Control can be implicitly converted to a TableCell or TableRow, so we can omit creating a TableCell when we don't have to set scaling + new TextBox { Text = "Second Row, First Column" }, + new ComboBox { DataStore = new ListItemCollection { new ListItem { Text = "Second Row, Second Column" } } }, + new CheckBox { Text = "Second Row, Third Column" } + ), + // by default, the last row & column will get scaled. This adds a row at the end to take the extra space of the form. + // otherwise, the above row will get scaled and stretch the TextBox/ComboBox/CheckBox to fill the remaining height. + new TableRow { ScaleHeight = true } + ) + { + Spacing = new Size(5, 5), // space between each cell + Padding = new Padding(10, 10, 10, 10) // space around the table's sides + }; + + // This creates the following layout: + // -------------------------------- + // |First |Second |Third | + // -------------------------------- + // | ||| + // -------------------------------- + // | | | | + // | | | | + // -------------------------------- + // + // Some notes: + // 1. When scaling the width of a cell, it applies to all cells in the same column. + // 2. When scaling the height of a row, it applies to the entire row. + // 3. Scaling a row/column makes it share all remaining space with other scaled rows/columns. + // 4. If a row/column is not scaled, it will be the size of the largest control in that row/column. + // 5. A Control can be implicitly converted to a TableCell or TableRow to make the layout more concise. + + Menu = new MenuBar + { + QuitItem = new Command((sender, e) => Application.Instance.Quit()) + { + MenuText = "Quit", + Shortcut = Application.Instance.CommonModifier | Keys.Q + } + }; + } + } + + class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application().Run(new MyForm()); + } + } +} diff --git a/Samples/Tutorials/Tutorial3/Tutorial3 - Table Layout.csproj b/Samples/Tutorials/Tutorial3/Tutorial3 - Table Layout.csproj new file mode 100644 index 0000000000..d92b1ff7a4 --- /dev/null +++ b/Samples/Tutorials/Tutorial3/Tutorial3 - Table Layout.csproj @@ -0,0 +1,58 @@ + + + + Debug + x86 + {D51732E0-1E93-11E3-8224-0800200C9A66} + WinExe + Tutorial3 + Tutorial3 + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + false + + + none + false + bin\Release + prompt + 4 + x86 + false + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + {80915A80-CA54-11E3-9C1A-0800200C9A66} + Eto.Gtk2 - Pcl + + + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66} + Eto.Mac - Pcl + + + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4} + Eto.WinForms - Pcl + + + \ No newline at end of file diff --git a/Samples/Tutorials/Tutorial4/Main.cs b/Samples/Tutorials/Tutorial4/Main.cs new file mode 100644 index 0000000000..2fd228f1d9 --- /dev/null +++ b/Samples/Tutorials/Tutorial4/Main.cs @@ -0,0 +1,90 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto; +using System.Diagnostics; + +namespace Tutorial4 +{ + public class MyObject + { + string textProperty; + public string TextProperty + { + get { return textProperty; } + set + { + textProperty = value; + Debug.WriteLine(string.Format("Set TextProperty to {0}", value)); + } + } + } + + public class MyForm : Form + { + public MyForm() + { + ClientSize = new Size(600, 400); + Title = "Table Layout"; + + + Content = new TableLayout( + new TableRow(new Label { Text = "DataContext Binding" }, DataContextBinding()), + new TableRow(new Label { Text = "Object Binding" }, ObjectBinding()), + new TableRow(new Label { Text = "Direct Binding" }, DirectBinding()), + null // same as creating a row with ScaleHeight = true + ) { Spacing = new Size(5, 5), Padding = new Padding(10) }; + + // Set data context so it propegates to all child controls + DataContext = new MyObject { TextProperty = "Initial value 1" }; + + Menu = new MenuBar + { + QuitItem = new Command((sender, e) => Application.Instance.Quit()) + { + MenuText = "Quit", + Shortcut = Application.Instance.CommonModifier | Keys.Q + } + }; + } + + TextBox DataContextBinding() + { + var textBox = new TextBox(); + // bind to the text property using delegates + textBox.TextBinding.BindDataContext(r => r.TextProperty, (r, val) => r.TextProperty = val); + // You can also bind using reflection, if the data context type is unknown: + // textBox.TextBinding.BindDataContext(new PropertyBinding("TextProperty")); + return textBox; + } + + TextBox ObjectBinding() + { + // object instance we want to bind to + var obj = new MyObject { TextProperty = "Initial value 2" }; + + var textBox = new TextBox(); + // bind to the text property using delegates + textBox.TextBinding.Bind(obj, r => r.TextProperty, (r, val) => r.TextProperty = val); + return textBox; + } + + TextBox DirectBinding() + { + var textBox = new TextBox(); + + // bind to the text property using delegates + textBox.TextBinding.Bind(() => "some value", val => Debug.WriteLine(string.Format("Set value to {0} directly", val))); + return textBox; + } + } + + class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application().Run(new MyForm()); + } + } +} diff --git a/Samples/Tutorials/Tutorial4/Tutorial4 - Binding.csproj b/Samples/Tutorials/Tutorial4/Tutorial4 - Binding.csproj new file mode 100644 index 0000000000..6618381413 --- /dev/null +++ b/Samples/Tutorials/Tutorial4/Tutorial4 - Binding.csproj @@ -0,0 +1,60 @@ + + + + Debug + x86 + {DDC8A290-2F20-11E4-8C21-0800200C9A66} + WinExe + Tutorial4 + Tutorial4 + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + false + + + none + false + bin\Release + prompt + 4 + x86 + false + + + + + + + Eto.Forms + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + {80915A80-CA54-11E3-9C1A-0800200C9A66} + Eto.Gtk2 - Pcl + + + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66} + Eto.Mac - Pcl + + + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4} + Eto.WinForms - Pcl + + + \ No newline at end of file diff --git a/Samples/WinForms/EmbedEtoInWinForms/App.config b/Samples/WinForms/EmbedEtoInWinForms/App.config new file mode 100644 index 0000000000..8e15646352 --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Samples/WinForms/EmbedEtoInWinForms/EmbedEtoInWinForms.csproj b/Samples/WinForms/EmbedEtoInWinForms/EmbedEtoInWinForms.csproj new file mode 100644 index 0000000000..a6a7503756 --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/EmbedEtoInWinForms.csproj @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {05323072-56A7-4CFE-9C64-2E7762D592EB} + WinExe + Properties + EmbedEtoInWinForms + EmbedEtoInWinForms + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4} + Eto.WinForms - Pcl + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + + \ No newline at end of file diff --git a/Samples/WinForms/EmbedEtoInWinForms/Form1.Designer.cs b/Samples/WinForms/EmbedEtoInWinForms/Form1.Designer.cs new file mode 100644 index 0000000000..59393e7aa8 --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Form1.Designer.cs @@ -0,0 +1,47 @@ +namespace EmbedEtoInWinForms +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(440, 317); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + + } + + #endregion + } +} + diff --git a/Samples/WinForms/EmbedEtoInWinForms/Form1.cs b/Samples/WinForms/EmbedEtoInWinForms/Form1.cs new file mode 100644 index 0000000000..202396e536 --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Form1.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Eto.Forms; + +namespace EmbedEtoInWinForms +{ + public partial class Form1 : System.Windows.Forms.Form + { + public Form1() + { + InitializeComponent(); + + // Get native control for the panel + // passing true so that we can embed, otherwise we just get a reference to the control + var nativeView = new MyEtoPanel().ToNative(true); + // set where we want it, size, dock attributes, etc. + nativeView.Location = new Point(100, 100); + //nativeView.Dock = DockStyle.Fill; + + Controls.Add(nativeView); + } + } +} diff --git a/Samples/WinForms/EmbedEtoInWinForms/Form1.resx b/Samples/WinForms/EmbedEtoInWinForms/Form1.resx new file mode 100644 index 0000000000..1af7de150c --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Samples/WinForms/EmbedEtoInWinForms/MyEtoPanel.cs b/Samples/WinForms/EmbedEtoInWinForms/MyEtoPanel.cs new file mode 100644 index 0000000000..08218813ae --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/MyEtoPanel.cs @@ -0,0 +1,30 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace EmbedEtoInWinForms +{ + /// + /// Eto.Forms panel to embed in an existing WinForms app + /// + public class MyEtoPanel : Panel + { + public MyEtoPanel() + { + var button = new Button { Text = "Show Dialog" }; + + Content = new TableLayout + { + Spacing = new Size(5, 5), + Rows = + { + new TableRow(new Label { Text = "An Eto.Forms control" }), + new TableRow(new TextBox()), + new TableRow(new ComboBox { Items = { "Item 1", "Item 2", "Item 3" } }), + button, + null + } + }; + } + } +} diff --git a/Samples/WinForms/EmbedEtoInWinForms/Program.cs b/Samples/WinForms/EmbedEtoInWinForms/Program.cs new file mode 100644 index 0000000000..1ec75495a4 --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace EmbedEtoInWinForms +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + // initialize eto forms after native app is initialized + new Eto.Forms.Application(new Eto.WinForms.Platform()).Attach(); + + Application.Run(new Form1()); + } + } +} diff --git a/Samples/WinForms/EmbedEtoInWinForms/Properties/AssemblyInfo.cs b/Samples/WinForms/EmbedEtoInWinForms/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..fd5a86f31e --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EmbedEtoInWinForms")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EmbedEtoInWinForms")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e7258e63-ea64-4659-95ee-6e0a93c4517f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/WinForms/EmbedEtoInWinForms/Properties/Resources.Designer.cs b/Samples/WinForms/EmbedEtoInWinForms/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..4c90a1951b --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace EmbedEtoInWinForms.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("EmbedEtoInWinForms.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Samples/WinForms/EmbedEtoInWinForms/Properties/Resources.resx b/Samples/WinForms/EmbedEtoInWinForms/Properties/Resources.resx new file mode 100644 index 0000000000..af7dbebbac --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Samples/WinForms/EmbedEtoInWinForms/Properties/Settings.Designer.cs b/Samples/WinForms/EmbedEtoInWinForms/Properties/Settings.Designer.cs new file mode 100644 index 0000000000..be0cabd286 --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace EmbedEtoInWinForms.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Samples/WinForms/EmbedEtoInWinForms/Properties/Settings.settings b/Samples/WinForms/EmbedEtoInWinForms/Properties/Settings.settings new file mode 100644 index 0000000000..39645652af --- /dev/null +++ b/Samples/WinForms/EmbedEtoInWinForms/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Samples/WinForms/EmbedWinFormsInEto/EmbedWinFormsInEto.csproj b/Samples/WinForms/EmbedWinFormsInEto/EmbedWinFormsInEto.csproj new file mode 100644 index 0000000000..5bfb0a7ec7 --- /dev/null +++ b/Samples/WinForms/EmbedWinFormsInEto/EmbedWinFormsInEto.csproj @@ -0,0 +1,64 @@ + + + + Debug + AnyCPU + {733C7D13-F676-4E41-BDB2-27696BD5AD15} + WinExe + EmbedWinFormsInEto + EmbedWinFormsInEto + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + + + full + true + bin\Release + prompt + 4 + true + + + + + + + + + + + UserControl + + + MyNativeControl.cs + + + + + + + + + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4} + Eto.WinForms - Pcl + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + + MyNativeControl.cs + + + \ No newline at end of file diff --git a/Samples/WinForms/EmbedWinFormsInEto/MainForm.cs b/Samples/WinForms/EmbedWinFormsInEto/MainForm.cs new file mode 100644 index 0000000000..17e8265e4d --- /dev/null +++ b/Samples/WinForms/EmbedWinFormsInEto/MainForm.cs @@ -0,0 +1,30 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace EmbedWinFormsInEto +{ + public class MainForm : Form + { + public MainForm() + { + Menu = new MenuBar(); + + // create a new native WinForms control and wrap it in an eto control + var nativeControl = new MyNativeControl().ToEto(); + + Content = new TableLayout + { + Padding = new Padding(10), + Spacing = new Size(5, 5), + Rows = + { + nativeControl, + null, + new TableLayout(new TableRow(null, new Button { Text = "An Eto.Forms button" })), + } + }; + } + } +} + diff --git a/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.Designer.cs b/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.Designer.cs new file mode 100644 index 0000000000..d0b28166e3 --- /dev/null +++ b/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.Designer.cs @@ -0,0 +1,84 @@ +namespace EmbedWinFormsInEto +{ + partial class MyNativeControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(28, 33); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(93, 13); + this.label1.TabIndex = 0; + this.label1.Text = "A WinForms Label"; + // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.Location = new System.Drawing.Point(31, 78); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(171, 20); + this.textBox1.TabIndex = 1; + // + // comboBox1 + // + this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(31, 121); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(171, 21); + this.comboBox1.TabIndex = 2; + // + // MyNativeControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Name = "MyNativeControl"; + this.Size = new System.Drawing.Size(250, 224); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.ComboBox comboBox1; + } +} diff --git a/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.cs b/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.cs new file mode 100644 index 0000000000..f11c73aecb --- /dev/null +++ b/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace EmbedWinFormsInEto +{ + public partial class MyNativeControl : UserControl + { + public MyNativeControl() + { + InitializeComponent(); + } + } +} diff --git a/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.resx b/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.resx new file mode 100644 index 0000000000..1af7de150c --- /dev/null +++ b/Samples/WinForms/EmbedWinFormsInEto/MyNativeControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Samples/WinForms/EmbedWinFormsInEto/Program.cs b/Samples/WinForms/EmbedWinFormsInEto/Program.cs new file mode 100644 index 0000000000..2292417abe --- /dev/null +++ b/Samples/WinForms/EmbedWinFormsInEto/Program.cs @@ -0,0 +1,14 @@ +using Eto.Forms; +using System; + +namespace EmbedWinFormsInEto +{ + static class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(new Eto.WinForms.Platform()).Run(new MainForm()); + } + } +} diff --git a/Samples/WinForms/EmbedWinFormsInEto/Properties/AssemblyInfo.cs b/Samples/WinForms/EmbedWinFormsInEto/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..a76f599fda --- /dev/null +++ b/Samples/WinForms/EmbedWinFormsInEto/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("EmbedWinFormsInEto")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Picoe Software Solutions Inc.")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Curtis Wensley")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Samples/Wpf/EmbedEtoInWpf/App.config b/Samples/Wpf/EmbedEtoInWpf/App.config new file mode 100644 index 0000000000..8e15646352 --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Samples/Wpf/EmbedEtoInWpf/App.xaml b/Samples/Wpf/EmbedEtoInWpf/App.xaml new file mode 100644 index 0000000000..3471c777d0 --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/Samples/Wpf/EmbedEtoInWpf/App.xaml.cs b/Samples/Wpf/EmbedEtoInWpf/App.xaml.cs new file mode 100644 index 0000000000..5e6e909f26 --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/App.xaml.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace EmbedEtoInWpf +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + + new Eto.Forms.Application(new Eto.Wpf.Platform()).Attach(); + } + } +} diff --git a/Samples/Wpf/EmbedEtoInWpf/EmbedEtoInWpf.csproj b/Samples/Wpf/EmbedEtoInWpf/EmbedEtoInWpf.csproj new file mode 100644 index 0000000000..ca4ee17efb --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/EmbedEtoInWpf.csproj @@ -0,0 +1,113 @@ + + + + + Debug + AnyCPU + {D528D241-8063-4732-B19D-6939838E516F} + WinExe + Properties + EmbedEtoInWpf + EmbedEtoInWpf + v4.5 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + {63137fa0-ca55-11e3-9c1a-0800200c9a66} + Eto.Wpf - Pcl + + + {35ef0a4e-2a1a-492c-8bed-106774ea09f2} + Eto - Pcl + + + + + \ No newline at end of file diff --git a/Samples/Wpf/EmbedEtoInWpf/MainWindow.xaml b/Samples/Wpf/EmbedEtoInWpf/MainWindow.xaml new file mode 100644 index 0000000000..04b7787784 --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/MainWindow.xaml @@ -0,0 +1,9 @@ + + + + + + diff --git a/Samples/Wpf/EmbedEtoInWpf/MainWindow.xaml.cs b/Samples/Wpf/EmbedEtoInWpf/MainWindow.xaml.cs new file mode 100644 index 0000000000..57eb56c812 --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/MainWindow.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Eto.Forms; + +namespace EmbedEtoInWpf +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : System.Windows.Window + { + public FrameworkElement EtoControl { get; set; } + + public MainWindow() + { + InitializeComponent(); + + // Get native control for the panel + // passing true so that we can embed, otherwise we just get a reference to the control + var nativeControl = new MyEtoPanel().ToNative(true); + + stackPanel.Children.Add(nativeControl); + + + } + } +} diff --git a/Samples/Wpf/EmbedEtoInWpf/MyEtoPanel.cs b/Samples/Wpf/EmbedEtoInWpf/MyEtoPanel.cs new file mode 100644 index 0000000000..988cb5d92c --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/MyEtoPanel.cs @@ -0,0 +1,27 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace EmbedEtoInWpf +{ + /// + /// Eto.Forms panel to embed in an existing Wpf app + /// + public class MyEtoPanel : Panel + { + public MyEtoPanel() + { + Content = new TableLayout + { + Spacing = new Size(5, 5), + Rows = + { + new TableRow(new Label { Text = "An Eto.Forms control" }), + new TableRow(new TextBox()), + new TableRow(new ComboBox { Items = { "Item 1", "Item 2", "Item 3" } }), + null + } + }; + } + } +} diff --git a/Samples/Wpf/EmbedEtoInWpf/Properties/AssemblyInfo.cs b/Samples/Wpf/EmbedEtoInWpf/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..d3fdc04d78 --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EmbedEtoInWpf")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EmbedEtoInWpf")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/Wpf/EmbedEtoInWpf/Properties/Resources.Designer.cs b/Samples/Wpf/EmbedEtoInWpf/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..503405f3fa --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace EmbedEtoInWpf.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("EmbedEtoInWpf.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Samples/Wpf/EmbedEtoInWpf/Properties/Resources.resx b/Samples/Wpf/EmbedEtoInWpf/Properties/Resources.resx new file mode 100644 index 0000000000..af7dbebbac --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Samples/Wpf/EmbedEtoInWpf/Properties/Settings.Designer.cs b/Samples/Wpf/EmbedEtoInWpf/Properties/Settings.Designer.cs new file mode 100644 index 0000000000..cc02d5cd4d --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace EmbedEtoInWpf.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Samples/Wpf/EmbedEtoInWpf/Properties/Settings.settings b/Samples/Wpf/EmbedEtoInWpf/Properties/Settings.settings new file mode 100644 index 0000000000..033d7a5e9e --- /dev/null +++ b/Samples/Wpf/EmbedEtoInWpf/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Samples/Wpf/EmbedWpfInEto/App.config b/Samples/Wpf/EmbedWpfInEto/App.config new file mode 100644 index 0000000000..8e15646352 --- /dev/null +++ b/Samples/Wpf/EmbedWpfInEto/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Samples/Wpf/EmbedWpfInEto/EmbedWpfInEto.csproj b/Samples/Wpf/EmbedWpfInEto/EmbedWpfInEto.csproj new file mode 100644 index 0000000000..eae031c758 --- /dev/null +++ b/Samples/Wpf/EmbedWpfInEto/EmbedWpfInEto.csproj @@ -0,0 +1,82 @@ + + + + + Debug + AnyCPU + {B19797BA-419B-4FD8-B306-A3C241C665EB} + WinExe + Properties + EmbedWpfInEto + EmbedWpfInEto + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + MyNativeControl.xaml + + + + + + + + + + Designer + MSBuild:Compile + + + + + {63137FA0-CA55-11E3-9C1A-0800200C9A66} + Eto.Wpf - Pcl + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + + \ No newline at end of file diff --git a/Samples/Wpf/EmbedWpfInEto/MainForm.cs b/Samples/Wpf/EmbedWpfInEto/MainForm.cs new file mode 100644 index 0000000000..72224a6d65 --- /dev/null +++ b/Samples/Wpf/EmbedWpfInEto/MainForm.cs @@ -0,0 +1,30 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace EmbedWpfInEto +{ + public class MainForm : Form + { + public MainForm() + { + Menu = new MenuBar(); + + // create a new native Wpf control and wrap it in an eto control + var nativeControl = new MyNativeControl().ToEto(); + + Content = new TableLayout + { + Padding = new Padding(10), + Spacing = new Size(5, 5), + Rows = + { + nativeControl, + null, + new TableLayout(new TableRow(null, new Button { Text = "An Eto.Forms button" })), + } + }; + } + } +} + diff --git a/Samples/Wpf/EmbedWpfInEto/MyNativeControl.xaml b/Samples/Wpf/EmbedWpfInEto/MyNativeControl.xaml new file mode 100644 index 0000000000..e873a0e4a2 --- /dev/null +++ b/Samples/Wpf/EmbedWpfInEto/MyNativeControl.xaml @@ -0,0 +1,13 @@ + + + + diff --git a/Samples/Wpf/EmbedWpfInEto/MyNativeControl.xaml.cs b/Samples/Wpf/EmbedWpfInEto/MyNativeControl.xaml.cs new file mode 100644 index 0000000000..cd28f62262 --- /dev/null +++ b/Samples/Wpf/EmbedWpfInEto/MyNativeControl.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace EmbedWpfInEto +{ + /// + /// Interaction logic for MyNativeControl.xaml + /// + public partial class MyNativeControl : UserControl + { + public MyNativeControl() + { + InitializeComponent(); + } + } +} diff --git a/Samples/Wpf/EmbedWpfInEto/Program.cs b/Samples/Wpf/EmbedWpfInEto/Program.cs new file mode 100644 index 0000000000..2d271146fe --- /dev/null +++ b/Samples/Wpf/EmbedWpfInEto/Program.cs @@ -0,0 +1,18 @@ +using Eto.Forms; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmbedWpfInEto +{ + static class Program + { + [STAThread] + static void Main(string[] args) + { + new Application(new Eto.Wpf.Platform()).Run(new MainForm()); + } + } +} diff --git a/Samples/Wpf/EmbedWpfInEto/Properties/AssemblyInfo.cs b/Samples/Wpf/EmbedWpfInEto/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..a159ef2860 --- /dev/null +++ b/Samples/Wpf/EmbedWpfInEto/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EmbedWpfInEto")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EmbedWpfInEto")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cc142bb6-30f8-48f4-80db-2dd6d5ce4c07")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/.editorconfig b/Source/.editorconfig new file mode 100644 index 0000000000..6780a46f58 --- /dev/null +++ b/Source/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# use tabs by default for everything +[*.cs] +indent_style = tab +indent_size = 4 +tab_size = 4 +charset=utf-8 + +# packages.config uses spaces +[**\packages.config] +indent_style = space +indent_size = 2 diff --git a/Source/.nuget/NuGet.Config b/Source/.nuget/NuGet.Config index 0be0a9e918..87c3a33a6d 100644 --- a/Source/.nuget/NuGet.Config +++ b/Source/.nuget/NuGet.Config @@ -4,6 +4,6 @@ - + \ No newline at end of file diff --git a/Source/.nuget/NuGet.exe b/Source/.nuget/NuGet.exe index 2c9369842a..c41a0d0deb 100644 Binary files a/Source/.nuget/NuGet.exe and b/Source/.nuget/NuGet.exe differ diff --git a/Source/.nuget/NuGet.targets b/Source/.nuget/NuGet.targets index 7a7e148be8..9b25062f0f 100644 --- a/Source/.nuget/NuGet.targets +++ b/Source/.nuget/NuGet.targets @@ -14,10 +14,14 @@ false - $(ProjectDir).. + $(ProjectDir).. + $(PackagesDir) + $(PackagesDir)\packages + + @@ -29,26 +33,26 @@ - $([System.IO.Path]::Combine("$(BaseDir)", ".nuget")) + $([System.IO.Path]::Combine("$(NugetDir)", ".nuget")) $([System.IO.Path]::Combine("$(ProjectDir)", "packages.config")) - "$(BaseDir) " + "$(PackagesDir) " - $(BaseDir)/.nuget + $(NugetDir)/.nuget packages.config - "$(BaseDir)" + "$(PackagesDir)" - + - + Title=$(AssemblyTitle);Description=$(AssemblyDescription);Author=$(AssemblyCompany);Copyright=$(AssemblyCopyright);Id=$(AssemblyName) -Version $(AssemblyInformationalVersion) @@ -111,7 +115,7 @@ - $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform);$(NugetBuildProperties)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" $(NugetBuildOptions) + $(NuGetCommand) pack "$(ProjectFile)" -BasePath "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform);$(NugetBuildProperties)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" $(NugetBuildOptions) @@ -122,9 +126,9 @@ - + - + $(AssemblyName).$(AssemblyInformationalVersion).nupkg @@ -139,61 +143,6 @@ Condition=" '$(OS)' == 'Windows_NT' " /> - - - - - - - - - - - - - - - - - - - - - (); - if (informationalVersion != null) - AssemblyInformationalVersion = informationalVersion.InformationalVersion; - var title = assembly.GetCustomAttribute(); - if (title != null) - AssemblyTitle = title.Title; - var description = assembly.GetCustomAttribute(); - if (description != null) - AssemblyDescription = description.Description; - var copyright = assembly.GetCustomAttribute(); - if (copyright != null) - AssemblyCopyright = copyright.Copyright; - var company = assembly.GetCustomAttribute(); - if (company != null) - AssemblyCompany = company.Company; - AssemblyName = assembly.GetName().Name; - Log.LogMessage(" ver: {0}", AssemblyInformationalVersion); - return true; - } - catch (Exception ex) { - Log.LogErrorFromException(ex); - return false; - } - ]]> - - - diff --git a/Source/.nuget/packages.config b/Source/.nuget/packages.config index 7025a729de..6b8deb9c96 100644 --- a/Source/.nuget/packages.config +++ b/Source/.nuget/packages.config @@ -1,4 +1,3 @@  - \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/.gitattributes b/Source/Addins/Eto.Addin.VisualStudio/.gitattributes new file mode 100644 index 0000000000..96041c6ee3 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/.gitattributes @@ -0,0 +1,3 @@ +*.cs eol=crlf +*.csproj eol=crlf +*.vstemplate eol=crlf diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.sln b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.sln new file mode 100644 index 0000000000..da126375b3 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.sln @@ -0,0 +1,76 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Addin.VisualStudio", "Eto.Addin.VisualStudio\Eto.Addin.VisualStudio.csproj", "{4A50E311-097A-403F-BEE5-8A4EC3A8230B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.PCL.Combined", "Eto.PCL.Combined\Eto.PCL.Combined.csproj", "{6DFD6441-5A61-4376-9D95-B1C5A3E3B5F4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.PCL.Separate", "Eto.PCL.Separate\Eto.PCL.Separate.csproj", "{165F3320-D5D6-477E-8CEA-96C5D44B2CA7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.VisualStudioTemplates", "Eto.VisualStudioTemplates\Eto.VisualStudioTemplates.csproj", "{64060642-4897-4645-85D4-547EFA4C4FC2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.SAL.Combined", "Eto.SAL.Combined\Eto.SAL.Combined.csproj", "{DF219523-46E9-497C-A24C-3BAE40D6B41B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.SAL.Separate", "Eto.SAL.Separate\Eto.SAL.Separate.csproj", "{C670014C-BAE0-4608-A52F-CDBDC617EB80}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Library", "Eto.Library\Eto.Library.csproj", "{C2B7F6AC-A8C3-4338-874B-906BB61E3162}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.File.Form", "Eto.File.Form\Eto.File.Form.csproj", "{9F943483-CFEC-489A-AB1C-91659B63EFB8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.File.Dialog", "Eto.File.Dialog\Eto.File.Dialog.csproj", "{28F3D96A-A688-4172-B9E5-4CD3129A9BA1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.File.Panel", "Eto.File.Panel\Eto.File.Panel.csproj", "{77F0EC4C-6CD7-415E-8F3D-D55D17C219A4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4A50E311-097A-403F-BEE5-8A4EC3A8230B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A50E311-097A-403F-BEE5-8A4EC3A8230B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A50E311-097A-403F-BEE5-8A4EC3A8230B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A50E311-097A-403F-BEE5-8A4EC3A8230B}.Release|Any CPU.Build.0 = Release|Any CPU + {6DFD6441-5A61-4376-9D95-B1C5A3E3B5F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6DFD6441-5A61-4376-9D95-B1C5A3E3B5F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6DFD6441-5A61-4376-9D95-B1C5A3E3B5F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6DFD6441-5A61-4376-9D95-B1C5A3E3B5F4}.Release|Any CPU.Build.0 = Release|Any CPU + {165F3320-D5D6-477E-8CEA-96C5D44B2CA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {165F3320-D5D6-477E-8CEA-96C5D44B2CA7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {165F3320-D5D6-477E-8CEA-96C5D44B2CA7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {165F3320-D5D6-477E-8CEA-96C5D44B2CA7}.Release|Any CPU.Build.0 = Release|Any CPU + {64060642-4897-4645-85D4-547EFA4C4FC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64060642-4897-4645-85D4-547EFA4C4FC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64060642-4897-4645-85D4-547EFA4C4FC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64060642-4897-4645-85D4-547EFA4C4FC2}.Release|Any CPU.Build.0 = Release|Any CPU + {DF219523-46E9-497C-A24C-3BAE40D6B41B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF219523-46E9-497C-A24C-3BAE40D6B41B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF219523-46E9-497C-A24C-3BAE40D6B41B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF219523-46E9-497C-A24C-3BAE40D6B41B}.Release|Any CPU.Build.0 = Release|Any CPU + {C670014C-BAE0-4608-A52F-CDBDC617EB80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C670014C-BAE0-4608-A52F-CDBDC617EB80}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C670014C-BAE0-4608-A52F-CDBDC617EB80}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C670014C-BAE0-4608-A52F-CDBDC617EB80}.Release|Any CPU.Build.0 = Release|Any CPU + {C2B7F6AC-A8C3-4338-874B-906BB61E3162}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2B7F6AC-A8C3-4338-874B-906BB61E3162}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2B7F6AC-A8C3-4338-874B-906BB61E3162}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2B7F6AC-A8C3-4338-874B-906BB61E3162}.Release|Any CPU.Build.0 = Release|Any CPU + {9F943483-CFEC-489A-AB1C-91659B63EFB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F943483-CFEC-489A-AB1C-91659B63EFB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F943483-CFEC-489A-AB1C-91659B63EFB8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F943483-CFEC-489A-AB1C-91659B63EFB8}.Release|Any CPU.Build.0 = Release|Any CPU + {28F3D96A-A688-4172-B9E5-4CD3129A9BA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28F3D96A-A688-4172-B9E5-4CD3129A9BA1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28F3D96A-A688-4172-B9E5-4CD3129A9BA1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28F3D96A-A688-4172-B9E5-4CD3129A9BA1}.Release|Any CPU.Build.0 = Release|Any CPU + {77F0EC4C-6CD7-415E-8F3D-D55D17C219A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {77F0EC4C-6CD7-415E-8F3D-D55D17C219A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {77F0EC4C-6CD7-415E-8F3D-D55D17C219A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {77F0EC4C-6CD7-415E-8F3D-D55D17C219A4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.csproj new file mode 100644 index 0000000000..7c3a7f4066 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.csproj @@ -0,0 +1,167 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + 2.0 + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {4A50E311-097A-403F-BEE5-8A4EC3A8230B} + Library + Properties + Eto.Addin.VisualStudio + Eto.Addin.VisualStudio + v4.5 + false + false + false + false + false + false + + + true + full + false + ..\..\..\..\BuildOutput\Addins\Debug\VisualStudio\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\BuildOutput\Addins\Release\VisualStudio\ + TRACE + prompt + 4 + + + + + + + Packages\%(Filename)%(Extension) + true + + + Designer + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + {28F3D96A-A688-4172-B9E5-4CD3129A9BA1} + Eto.File.Dialog + ItemTemplates + false + TemplateProjectOutputGroup%3b + + + {9F943483-CFEC-489A-AB1C-91659B63EFB8} + Eto.File.Form + ItemTemplates + false + TemplateProjectOutputGroup%3b + + + {77F0EC4C-6CD7-415E-8F3D-D55D17C219A4} + Eto.File.Panel + ItemTemplates + false + TemplateProjectOutputGroup%3b + + + {C2B7F6AC-A8C3-4338-874B-906BB61E3162} + Eto.Library + ProjectTemplates + false + TemplateProjectOutputGroup%3b + + + {165F3320-D5D6-477E-8CEA-96C5D44B2CA7} + Eto.PCL.Separate + ProjectTemplates + false + TemplateProjectOutputGroup%3b + + + {6DFD6441-5A61-4376-9D95-B1C5A3E3B5F4} + Eto.PCL.Combined + ProjectTemplates + TemplateProjectOutputGroup%3b + false + + + {DF219523-46E9-497C-A24C-3BAE40D6B41B} + Eto.SAL.Combined + ProjectTemplates + false + TemplateProjectOutputGroup%3b + + + {C670014C-BAE0-4608-A52F-CDBDC617EB80} + Eto.SAL.Separate + ProjectTemplates + false + TemplateProjectOutputGroup%3b + + + {64060642-4897-4645-85D4-547EFA4C4FC2} + Eto.VisualStudioTemplates + ProjectTemplates + BuiltProjectOutputGroup%3bBuiltProjectOutputGroupDependencies%3bGetCopyToOutputDirectoryItems%3bSatelliteDllsProjectOutputGroup%3b + DebugSymbolsProjectOutputGroup%3b + False + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.csproj.user b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.csproj.user new file mode 100644 index 0000000000..0d97e2f834 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio.csproj.user @@ -0,0 +1,20 @@ + + + + ProjectFiles + + + Program + C:\Program Files %28x86%29\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe + /rootsuffix Exp + + + + + Program + C:\Program Files %28x86%29\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe + /rootsuffix Exp + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..a7fd0c5ade --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.VisualStudio")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.VisualStudio")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/source.extension.vsixmanifest b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/source.extension.vsixmanifest new file mode 100644 index 0000000000..17135a7e76 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Addin.VisualStudio/source.extension.vsixmanifest @@ -0,0 +1,27 @@ + + + + + Eto.Forms Visual Studio Addin + Eto.Forms Support for Visual Studio. Eto.Forms is a cross platform GUI framework for desktop and mobile applications in .NET that can target Wpf, WinForms, Direct2D, MonoMac, Xamarin.Mac, Gtk2, Gtk3, and iOS with a single set of code. + https://github.com/picoe/Eto + eto wpf mac osx gtk xamarin mono + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto-Dialog.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto-Dialog.cs new file mode 100644 index 0000000000..0a1300b3b7 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto-Dialog.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using Eto.Forms; +using Eto.Drawing; + +namespace $rootnamespace$ +{ + public class $safeitemname$ : Dialog + { + public $safeitemname$() + { + Title = "My $itemname$ dialog"; + + // buttons + DefaultButton = new Button { Text = "OK" }; + + AbortButton = new Button { Text = "C&ancel" }; + AbortButton.Click += (sender, e) => Close(); + + var buttons = new TableLayout { Rows = { new TableRow(null, DefaultButton, AbortButton) }, Spacing = new Size(5, 5) }; + + Content = new TableLayout + { + Padding = new Padding(10), + Rows = + { + new Label { Text = "Some content" }, + buttons + } + }; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.csproj new file mode 100644 index 0000000000..d96bcfda17 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.csproj @@ -0,0 +1,114 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {28F3D96A-A688-4172-B9E5-4CD3129A9BA1} + Library + Properties + Eto.File.Dialog + Eto.File.Dialog + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + Eto.Forms + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.vstemplate new file mode 100644 index 0000000000..61c1f4a794 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Eto.File.Dialog.vstemplate @@ -0,0 +1,24 @@ + + + + Eto.Forms Modal Dialog + + + + Eto.File.Dialog.ico + 2a8fde10-1d14-4271-a661-44105733faa8 + CSharp + CSharp + MultiTarget + 4.0 + 1 + EtoDialog.cs + + + + + System + + + Eto-Dialog.cs + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..5a52499102 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Dialog/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.File.Dialog")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.File.Dialog")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7f98d1bb-fbd2-4760-ad0e-e178993a62ba")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto-Form.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto-Form.cs new file mode 100644 index 0000000000..c9d0e1c3a9 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto-Form.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using Eto.Forms; +using Eto.Drawing; + +namespace $rootnamespace$ +{ + public class $safeitemname$ : Form + { + public $safeitemname$() + { + Title = "My $itemname$ form"; + + Content = new Label { Text = "Some content" }; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.csproj new file mode 100644 index 0000000000..0ba11da5b3 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.csproj @@ -0,0 +1,114 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {9F943483-CFEC-489A-AB1C-91659B63EFB8} + Library + Properties + Eto.File.Form + Eto.File.Form + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + Eto.Forms + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.vstemplate new file mode 100644 index 0000000000..9463855613 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Eto.File.Form.vstemplate @@ -0,0 +1,24 @@ + + + + Eto.Forms Modeless Form + + + + Eto.File.Form.ico + 3ff2b395-1bdf-4197-8bd0-7d37feb93584 + CSharp + CSharp + MultiTarget + 4.0 + 1 + EtoForm.cs + + + + + System + + + Eto-Form.cs + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..672440922d --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Form/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.File.Form")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.File.Form")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a85aff48-6ebd-4c7e-98e4-c15371d0df6a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto-Panel.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto-Panel.cs new file mode 100644 index 0000000000..110902e9b7 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto-Panel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using Eto.Forms; +using Eto.Drawing; + +namespace $rootnamespace$ +{ + public class $safeitemname$ : Panel + { + public $safeitemname$() + { + Content = new Label { Text = "Some Content" }; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.csproj new file mode 100644 index 0000000000..5c7d7cf39a --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.csproj @@ -0,0 +1,114 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {77F0EC4C-6CD7-415E-8F3D-D55D17C219A4} + Library + Properties + Eto.File.Panel + Eto.File.Panel + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + Eto.Forms + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.vstemplate new file mode 100644 index 0000000000..8f994394fc --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Eto.File.Panel.vstemplate @@ -0,0 +1,24 @@ + + + + Eto.Forms Custom Panel + + + + Eto.File.Panel.ico + a6a67004-a348-4f86-95db-3ec5260a7c29 + CSharp + CSharp + MultiTarget + 2.0 + 1 + EtoPanel.cs + + + + + System + + + Eto-Panel.cs + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..6a1bcfd1a9 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.File.Panel/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.File.Panel")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.File.Panel")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cf7c674e-de19-41d5-83c2-9fcc0e16cdde")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Class.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Class.cs new file mode 100644 index 0000000000..2ef7b003e8 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Class.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +$if$ ($targetframeworkversion$ >= 3.5)using System.Linq; +$endif$using System.Text; + +namespace $rootnamespace$ +{ + class $safeitemrootname$ + { + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.csproj new file mode 100644 index 0000000000..3dff28fded --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.csproj @@ -0,0 +1,80 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 997874de-aeb3-487c-aa9b-86507f53a7f2 + Library + Properties + Eto.Files + Eto.Files + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.vstemplate new file mode 100644 index 0000000000..528679f427 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Eto.Files.vstemplate @@ -0,0 +1,21 @@ + + + + Eto.Files + Eto.Files + Eto.Files.ico + 1a8a6408-926e-4c42-aae7-2b706aef6695 + CSharp + 2.0 + 1 + Class.cs + + + + + System + + + Class.cs + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..b24c6bcda4 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Files/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.Files")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.Files")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("997874de-aeb3-487c-aa9b-86507f53a7f2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/AssemblyInfo.cs new file mode 100644 index 0000000000..1d2eb4428c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("$safeprojectname$")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("$registeredorganization$")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright © $registeredorganization$ $year$")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.csproj new file mode 100644 index 0000000000..f6d5bb4db0 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.csproj @@ -0,0 +1,118 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {C2B7F6AC-A8C3-4338-874B-906BB61E3162} + Library + Properties + Eto.Library + Eto.Library + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + + Eto.Forms + + + + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.vstemplate new file mode 100644 index 0000000000..d5536e0e9b --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.Library.vstemplate @@ -0,0 +1,32 @@ + + + + Eto.Forms Library (portable) + A portable library project to build Eto.Forms UI and logic. + Eto.Library.ico + CSharp + 4.0 + 1000 + 187e19a3-8db1-4f37-9aa7-6cf1a3f5c985 + true + EtoLibrary + true + + + + MyPanel.cs + + AssemblyInfo.cs + + + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.csproj new file mode 100644 index 0000000000..7c2b87c505 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Eto.csproj @@ -0,0 +1,35 @@ + + + + Debug + AnyCPU + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {$guid1$} + Library + $safeprojectname$ + $safeprojectname$ + v4.5 + Profile259 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + + + full + true + bin\Release + prompt + 4 + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/MyPanel.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/MyPanel.cs new file mode 100644 index 0000000000..1dbf4882f2 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/MyPanel.cs @@ -0,0 +1,18 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace $safeprojectname$ +{ + /// + /// A custom panel + /// + public class MyPanel : Panel + { + public MyPanel() + { + // set your content and other properties here + Content = new Label { Text = "Some Content" }; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..3de52484b2 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.Library/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.Library")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.Library")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d5b42fd2-769f-4c9b-8bb8-1c5e8ef72bab")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/AssemblyInfo.cs new file mode 100644 index 0000000000..1d2eb4428c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("$safeprojectname$")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("$registeredorganization$")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright © $registeredorganization$ $year$")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Eto.Desktop.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Eto.Desktop.csproj new file mode 100644 index 0000000000..b460d34c4b --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Eto.Desktop.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {$guid2$} + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + {$root.guid1$} + $root.safeprojectname$ + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Eto.Desktop.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Eto.Desktop.vstemplate new file mode 100644 index 0000000000..77a635976f --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Eto.Desktop.vstemplate @@ -0,0 +1,37 @@ + + + Eto.Desktop + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Program.cs new file mode 100644 index 0000000000..eb119d6a3d --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.Desktop/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platform.Detect).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.csproj new file mode 100644 index 0000000000..00f6b5289e --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.csproj @@ -0,0 +1,131 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {6DFD6441-5A61-4376-9D95-B1C5A3E3B5F4} + Library + Properties + Eto.PCL.Shared + Eto.PCL.Shared + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + False + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + + Eto.Forms + + + + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + Designer + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.vstemplate new file mode 100644 index 0000000000..b5c0efbd7e --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto.PCL.Combined.vstemplate @@ -0,0 +1,43 @@ + + + + Eto.Forms App (portable, combined platforms) + + + + Eto.PCL.Combined.ico + CSharp + 4.0 + 1000 + a1848891-012f-4b0c-9917-eaf183fcb6b1 + true + EtoApp + true + 1 + + + AssemblyInfo.cs + Eto\Eto.vstemplate + Eto\Eto.csproj + Eto\MainForm.cs + Eto.Desktop\Eto.Desktop.vstemplate + Eto.Desktop\Eto.Desktop.csproj + Eto.Desktop\Program.cs + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.RootWizard + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.MultiProjectWizard + + + + Eto\Eto.vstemplate + Eto.Desktop\Eto.Desktop.vstemplate + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/Eto.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/Eto.csproj new file mode 100644 index 0000000000..b216ac059c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/Eto.csproj @@ -0,0 +1,35 @@ + + + + Debug + AnyCPU + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {$root.guid1$} + Library + $safeprojectname$ + $safeprojectname$ + v4.5 + Profile259 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + + + full + true + bin\Release + prompt + 4 + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/Eto.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/Eto.vstemplate new file mode 100644 index 0000000000..cf4b561844 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/Eto.vstemplate @@ -0,0 +1,32 @@ + + + Eto + + CSharp + + + 1000 + + + + + MainForm.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/MainForm.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/MainForm.cs new file mode 100644 index 0000000000..606ab59839 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Eto/MainForm.cs @@ -0,0 +1,62 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace $safeprojectname$ +{ + /// + /// Your application's main form + /// + public class MainForm : Form + { + public MainForm() + { + Title = "My Eto Form"; + ClientSize = new Size(400, 350); + + // scrollable region as the main content + Content = new Scrollable + { + // table with three rows + Content = new TableLayout( + null, + // row with three columns + new TableRow(null, new Label { Text = "Hello World!" }, null), + null + ) + }; + + // create a few commands that can be used for the menu and toolbar + var clickMe = new Command { MenuText = "Click Me!", ToolBarText = "Click Me!" }; + clickMe.Executed += (sender, e) => MessageBox.Show(this, "I was clicked!"); + + var quitCommand = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q }; + quitCommand.Executed += (sender, e) => Application.Instance.Quit(); + + var aboutCommand = new Command { MenuText = "About..." }; + aboutCommand.Executed += (sender, e) => MessageBox.Show(this, "About my app..."); + + // create menu + Menu = new MenuBar + { + Items = + { + // File submenu + new ButtonMenuItem { Text = "&File", Items = { clickMe } }, + // new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } }, + // new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } }, + }, + ApplicationItems = + { + // application (OS X) or file menu (others) + new ButtonMenuItem { Text = "&Preferences..." }, + }, + QuitItem = quitCommand, + AboutItem = aboutCommand + }; + + // create toolbar + ToolBar = new ToolBar { Items = { clickMe } }; + } + } +} \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..a9f8e82ea2 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Combined/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.PCL.Combined")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.PCL.Combined")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("add24157-e2fb-4fea-8b79-c5a886e1d92a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/AssemblyInfo.cs new file mode 100644 index 0000000000..1d2eb4428c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("$safeprojectname$")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("$registeredorganization$")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright © $registeredorganization$ $year$")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Eto.Gtk2.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Eto.Gtk2.csproj new file mode 100644 index 0000000000..b460d34c4b --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Eto.Gtk2.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {$guid2$} + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + {$root.guid1$} + $root.safeprojectname$ + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Eto.Gtk2.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Eto.Gtk2.vstemplate new file mode 100644 index 0000000000..2e9c4af165 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Eto.Gtk2.vstemplate @@ -0,0 +1,32 @@ + + + Eto.Gtk2 + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Program.cs new file mode 100644 index 0000000000..3665b70371 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk2/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.Gtk2).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Eto.Gtk3.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Eto.Gtk3.csproj new file mode 100644 index 0000000000..11b5b1d96e --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Eto.Gtk3.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {$guid3$} + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + {$root.guid1$} + $root.safeprojectname$ + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Eto.Gtk3.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Eto.Gtk3.vstemplate new file mode 100644 index 0000000000..5c4869a1f1 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Eto.Gtk3.vstemplate @@ -0,0 +1,32 @@ + + + Eto.Gtk3 + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Program.cs new file mode 100644 index 0000000000..eac2471c34 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Gtk3/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.Gtk3).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Eto.Mac.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Eto.Mac.csproj new file mode 100644 index 0000000000..957a8a8ee1 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Eto.Mac.csproj @@ -0,0 +1,45 @@ + + + + Debug + AnyCPU + $globalguid1$ + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + {$root.guid1$} + $root.safeprojectname$ + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Eto.Mac.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Eto.Mac.vstemplate new file mode 100644 index 0000000000..3161831c18 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Eto.Mac.vstemplate @@ -0,0 +1,33 @@ + + + Eto.Mac + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Program.cs new file mode 100644 index 0000000000..28f41cab6a --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Mac/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.Mac).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.csproj new file mode 100644 index 0000000000..07f0b18697 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.csproj @@ -0,0 +1,144 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {165F3320-D5D6-477E-8CEA-96C5D44B2CA7} + Library + Properties + Eto.PCL.Separate + Eto.PCL.Separate + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + + + + + + + + + Eto.Forms + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.vstemplate new file mode 100644 index 0000000000..f0adfe0c23 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.PCL.Separate.vstemplate @@ -0,0 +1,63 @@ + + + + Eto.Forms App (portable, separate platforms) + + + + Eto.PCL.Separate.ico + CSharp + 4.0 + 1000 + 8af0b680-f3ff-4094-92cb-a91c45a4d7fe + EtoApp + true + true + 1 + + + AssemblyInfo.cs + Eto\Eto.vstemplate + Eto\Eto.csproj + Eto\MainForm.cs + Eto.Gtk2\Eto.Gtk2.vstemplate + Eto.Gtk2\Eto.Gtk2.csproj + Eto.Gtk2\Program.cs + Eto.Gtk3\Eto.Gtk3.vstemplate + Eto.Gtk3\Eto.Gtk3.csproj + Eto.Gtk3\Program.cs + Eto.Wpf\Eto.Wpf.vstemplate + Eto.Wpf\Eto.Wpf.csproj + Eto.Wpf\Program.cs + Eto.WinForms\Eto.WinForms.vstemplate + Eto.WinForms\Eto.WinForms.csproj + Eto.WinForms\Program.cs + Eto.Mac\Eto.Mac.vstemplate + Eto.Mac\Eto.Mac.csproj + Eto.Mac\Program.cs + Eto.XamMac2\Eto.XamMac2.vstemplate + Eto.XamMac2\Eto.XamMac2.csproj + Eto.XamMac2\Program.cs + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.RootWizard + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.MultiProjectWizard + + + + Eto\Eto.vstemplate + Eto.Gtk2\Eto.Gtk2.vstemplate + Eto.Gtk3\Eto.Gtk3.vstemplate + Eto.Wpf\Eto.Wpf.vstemplate + Eto.WinForms\Eto.WinForms.vstemplate + Eto.Mac\Eto.Mac.vstemplate + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Eto.WinForms.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Eto.WinForms.csproj new file mode 100644 index 0000000000..833fdd38af --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Eto.WinForms.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + $guid5$ + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + {$root.guid1$} + $root.safeprojectname$ + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Eto.WinForms.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Eto.WinForms.vstemplate new file mode 100644 index 0000000000..a7e4089b62 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Eto.WinForms.vstemplate @@ -0,0 +1,32 @@ + + + Eto.WinForms + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Program.cs new file mode 100644 index 0000000000..2e39b20e91 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.WinForms/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.WinForms).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Eto.Wpf.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Eto.Wpf.csproj new file mode 100644 index 0000000000..46b0c347af --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Eto.Wpf.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + $guid6$ + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + {$root.guid1$} + $root.safeprojectname$ + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Eto.Wpf.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Eto.Wpf.vstemplate new file mode 100644 index 0000000000..f6f606c774 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Eto.Wpf.vstemplate @@ -0,0 +1,32 @@ + + + Eto.Wpf + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Program.cs new file mode 100644 index 0000000000..8fc871268c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.Wpf/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.Wpf).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Eto.XamMac2.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Eto.XamMac2.csproj new file mode 100644 index 0000000000..4c79eda360 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Eto.XamMac2.csproj @@ -0,0 +1,80 @@ + + + + Debug + AnyCPU + {A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $guid7$ + Exe + $safeprojectname$ + $safeprojectname$ + Resources + v2.0 + Xamarin.Mac + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + false + false + Mac Developer + false + false + + + full + true + bin\Release + prompt + 4 + SdkOnly + false + true + false + Developer ID Application + true + true + + + full + true + bin\AppStore + prompt + 4 + SdkOnly + false + true + 3rd Party Mac Developer Installer + true + 3rd Party Mac Developer Application + true + true + + + + + + + + {$root.guid1$} + $root.safeprojectname$ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Eto.XamMac2.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Eto.XamMac2.vstemplate new file mode 100644 index 0000000000..95db75aa03 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Eto.XamMac2.vstemplate @@ -0,0 +1,33 @@ + + + Eto.XamMac2 + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + Info.plist + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Info.plist b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Info.plist new file mode 100644 index 0000000000..4715e66d08 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Info.plist @@ -0,0 +1,19 @@ + + + + + CFBundleIconFile + TestIcon.icns + CFBundleIdentifier + com.yourcompany.$safeprojectname$ + CFBundleName + $safeprojectname$ + CFBundleVersion + 1 + LSMinimumSystemVersion + 10.6 + NSPrincipalClass + NSApplication + + + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Program.cs new file mode 100644 index 0000000000..b20c3d62dd --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto.XamMac2/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.XamMac2).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/Eto.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/Eto.csproj new file mode 100644 index 0000000000..b216ac059c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/Eto.csproj @@ -0,0 +1,35 @@ + + + + Debug + AnyCPU + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {$root.guid1$} + Library + $safeprojectname$ + $safeprojectname$ + v4.5 + Profile259 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + + + full + true + bin\Release + prompt + 4 + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/Eto.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/Eto.vstemplate new file mode 100644 index 0000000000..cf4b561844 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/Eto.vstemplate @@ -0,0 +1,32 @@ + + + Eto + + CSharp + + + 1000 + + + + + MainForm.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/MainForm.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/MainForm.cs new file mode 100644 index 0000000000..bbc1bcd4e0 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Eto/MainForm.cs @@ -0,0 +1,62 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace $safeprojectname$ +{ + /// + /// Your application's main form + /// + public class MainForm : Form + { + public MainForm() + { + Title = "My Eto Form"; + ClientSize = new Size(400, 350); + + // scrollable region as the main content + Content = new Scrollable + { + // table with three rows + Content = new TableLayout( + null, + // row with three columns + new TableRow(null, new Label { Text = "Hello World!" }, null), + null + ) + }; + + // create a few commands that can be used for the menu and toolbar + var clickMe = new Command { MenuText = "Click Me!", ToolBarText = "Click Me!" }; + clickMe.Executed += (sender, e) => MessageBox.Show(this, "I was clicked!"); + + var quitCommand = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q }; + quitCommand.Executed += (sender, e) => Application.Instance.Quit(); + + var aboutCommand = new Command { MenuText = "About..." }; + aboutCommand.Executed += (sender, e) => MessageBox.Show(this, "About my app..."); + + // create menu + Menu = new MenuBar + { + Items = + { + // File submenu + new ButtonMenuItem { Text = "&File", Items = { clickMe } }, + // new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } }, + // new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } }, + }, + ApplicationItems = + { + // application (OS X) or file menu (others) + new ButtonMenuItem { Text = "&Preferences..." }, + }, + QuitItem = quitCommand, + AboutItem = aboutCommand + }; + + // create toolbar + ToolBar = new ToolBar { Items = { clickMe } }; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..c81b972663 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.PCL.Separate/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.PCL.Separate")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.PCL.Separate")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("add24157-e2fb-4fea-8b79-c5a886e1d92a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/AssemblyInfo.cs new file mode 100644 index 0000000000..1d2eb4428c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("$safeprojectname$")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("$registeredorganization$")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright © $registeredorganization$ $year$")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Eto.Desktop.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Eto.Desktop.csproj new file mode 100644 index 0000000000..2503b349cd --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Eto.Desktop.csproj @@ -0,0 +1,40 @@ + + + + Debug + x86 + $guid2$ + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Eto.Desktop.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Eto.Desktop.vstemplate new file mode 100644 index 0000000000..77a635976f --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Eto.Desktop.vstemplate @@ -0,0 +1,37 @@ + + + Eto.Desktop + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Program.cs new file mode 100644 index 0000000000..eb119d6a3d --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.Desktop/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platform.Detect).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.csproj new file mode 100644 index 0000000000..3c02272dce --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.csproj @@ -0,0 +1,129 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {DF219523-46E9-497C-A24C-3BAE40D6B41B} + Library + Properties + Eto.SAL.Combined + Eto.SAL.Combined + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + + + + + Eto.Forms + + + + + Designer + + + + + + + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.vstemplate new file mode 100644 index 0000000000..8ab13252c4 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto.SAL.Combined.vstemplate @@ -0,0 +1,44 @@ + + + + Eto.Forms App (shared, combined platforms) + + + + Eto.SAL.Combined.ico + CSharp + 4.0 + 1000 + ab894672-fec4-431e-b55a-f578a8d41ced + true + EtoApp + true + 1 + + + AssemblyInfo.cs + Eto\Eto.vstemplate + Eto\Eto.shproj + Eto\Eto.projitems + Eto\MainForm.cs + Eto.Desktop\Eto.Desktop.vstemplate + Eto.Desktop\Eto.Desktop.csproj + Eto.Desktop\Program.cs + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.RootWizard + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.MultiProjectWizard + + + + Eto\Eto.vstemplate + Eto.Desktop\Eto.Desktop.vstemplate + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.projitems b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.projitems new file mode 100644 index 0000000000..aaf3b3adee --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.projitems @@ -0,0 +1,14 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + {$root.guid1$} + + + $safeprojectname$ + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.shproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.shproj new file mode 100644 index 0000000000..22611b3980 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.shproj @@ -0,0 +1,12 @@ + + + + {$root.guid1$} + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.vstemplate new file mode 100644 index 0000000000..a3f28714d3 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/Eto.vstemplate @@ -0,0 +1,22 @@ + + + Eto + + CSharp + + + 1000 + + true + + + + Eto.projitems + MainForm.cs + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/MainForm.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/MainForm.cs new file mode 100644 index 0000000000..bbc1bcd4e0 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Eto/MainForm.cs @@ -0,0 +1,62 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace $safeprojectname$ +{ + /// + /// Your application's main form + /// + public class MainForm : Form + { + public MainForm() + { + Title = "My Eto Form"; + ClientSize = new Size(400, 350); + + // scrollable region as the main content + Content = new Scrollable + { + // table with three rows + Content = new TableLayout( + null, + // row with three columns + new TableRow(null, new Label { Text = "Hello World!" }, null), + null + ) + }; + + // create a few commands that can be used for the menu and toolbar + var clickMe = new Command { MenuText = "Click Me!", ToolBarText = "Click Me!" }; + clickMe.Executed += (sender, e) => MessageBox.Show(this, "I was clicked!"); + + var quitCommand = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q }; + quitCommand.Executed += (sender, e) => Application.Instance.Quit(); + + var aboutCommand = new Command { MenuText = "About..." }; + aboutCommand.Executed += (sender, e) => MessageBox.Show(this, "About my app..."); + + // create menu + Menu = new MenuBar + { + Items = + { + // File submenu + new ButtonMenuItem { Text = "&File", Items = { clickMe } }, + // new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } }, + // new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } }, + }, + ApplicationItems = + { + // application (OS X) or file menu (others) + new ButtonMenuItem { Text = "&Preferences..." }, + }, + QuitItem = quitCommand, + AboutItem = aboutCommand + }; + + // create toolbar + ToolBar = new ToolBar { Items = { clickMe } }; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..b46761a915 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Combined/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.SAL.Combined")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.SAL.Combined")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5183bea5-b186-4e0f-b8ce-5664d068295e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/AssemblyInfo.cs new file mode 100644 index 0000000000..1d2eb4428c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("$safeprojectname$")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("$registeredorganization$")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright © $registeredorganization$ $year$")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Eto.Gtk2.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Eto.Gtk2.csproj new file mode 100644 index 0000000000..6d9128c152 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Eto.Gtk2.csproj @@ -0,0 +1,40 @@ + + + + Debug + x86 + {$guid2$} + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Eto.Gtk2.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Eto.Gtk2.vstemplate new file mode 100644 index 0000000000..2e9c4af165 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Eto.Gtk2.vstemplate @@ -0,0 +1,32 @@ + + + Eto.Gtk2 + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Program.cs new file mode 100644 index 0000000000..3665b70371 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk2/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.Gtk2).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Eto.Gtk3.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Eto.Gtk3.csproj new file mode 100644 index 0000000000..de1d21f9b3 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Eto.Gtk3.csproj @@ -0,0 +1,40 @@ + + + + Debug + x86 + {$guid3$} + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Eto.Gtk3.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Eto.Gtk3.vstemplate new file mode 100644 index 0000000000..5c4869a1f1 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Eto.Gtk3.vstemplate @@ -0,0 +1,32 @@ + + + Eto.Gtk3 + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Program.cs new file mode 100644 index 0000000000..eac2471c34 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Gtk3/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.Gtk3).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Eto.Mac.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Eto.Mac.csproj new file mode 100644 index 0000000000..abcbdcb962 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Eto.Mac.csproj @@ -0,0 +1,40 @@ + + + + Debug + AnyCPU + {$guid4$} + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Eto.Mac.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Eto.Mac.vstemplate new file mode 100644 index 0000000000..3161831c18 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Eto.Mac.vstemplate @@ -0,0 +1,33 @@ + + + Eto.Mac + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Program.cs new file mode 100644 index 0000000000..28f41cab6a --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Mac/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.Mac).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.csproj new file mode 100644 index 0000000000..f687cb0d0c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.csproj @@ -0,0 +1,145 @@ + + + + 12.0 + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + 12.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + Debug + AnyCPU + {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {C670014C-BAE0-4608-A52F-CDBDC617EB80} + Library + Properties + Eto.SAL.Separate + Eto.SAL.Separate + v4.5 + 512 + false + false + false + false + false + false + false + false + false + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + Eto.Forms + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + Designer + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.ico b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.ico new file mode 100644 index 0000000000..7d638b1d60 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.ico differ diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.vstemplate new file mode 100644 index 0000000000..6865825222 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.SAL.Separate.vstemplate @@ -0,0 +1,64 @@ + + + + Eto.Forms App (shared, separate platforms) + + + + Eto.SAL.Separate.ico + CSharp + 4.0 + 1000 + 653fba3d-cf63-4fab-9d86-b6b765b32aab + true + EtoApp + true + 1 + + + AssemblyInfo.cs + Eto\Eto.vstemplate + Eto\Eto.shproj + Eto\Eto.projitems + Eto\MainForm.cs + Eto.Gtk2\Eto.Gtk2.vstemplate + Eto.Gtk2\Eto.Gtk2.csproj + Eto.Gtk2\Program.cs + Eto.Gtk3\Eto.Gtk3.vstemplate + Eto.Gtk3\Eto.Gtk3.csproj + Eto.Gtk3\Program.cs + Eto.Wpf\Eto.Wpf.vstemplate + Eto.Wpf\Eto.Wpf.csproj + Eto.Wpf\Program.cs + Eto.WinForms\Eto.WinForms.vstemplate + Eto.WinForms\Eto.WinForms.csproj + Eto.WinForms\Program.cs + Eto.Mac\Eto.Mac.vstemplate + Eto.Mac\Eto.Mac.csproj + Eto.Mac\Program.cs + Eto.XamMac2\Eto.XamMac2.vstemplate + Eto.XamMac2\Eto.XamMac2.csproj + Eto.XamMac2\Program.cs + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.RootWizard + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.MultiProjectWizard + + + + Eto\Eto.vstemplate + Eto.Gtk2\Eto.Gtk2.vstemplate + Eto.Gtk3\Eto.Gtk3.vstemplate + Eto.Wpf\Eto.Wpf.vstemplate + Eto.WinForms\Eto.WinForms.vstemplate + Eto.Mac\Eto.Mac.vstemplate + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Eto.WinForms.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Eto.WinForms.csproj new file mode 100644 index 0000000000..bbd6ebf7d7 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Eto.WinForms.csproj @@ -0,0 +1,40 @@ + + + + Debug + x86 + {$guid5$} + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Eto.WinForms.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Eto.WinForms.vstemplate new file mode 100644 index 0000000000..a7e4089b62 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Eto.WinForms.vstemplate @@ -0,0 +1,32 @@ + + + Eto.WinForms + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Program.cs new file mode 100644 index 0000000000..2e39b20e91 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.WinForms/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.WinForms).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Eto.Wpf.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Eto.Wpf.csproj new file mode 100644 index 0000000000..ec65b8f265 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Eto.Wpf.csproj @@ -0,0 +1,40 @@ + + + + Debug + x86 + {$guid6$} + WinExe + $safeprojectname$ + $safeprojectname$ + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + full + true + bin\Release + prompt + 4 + x86 + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Eto.Wpf.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Eto.Wpf.vstemplate new file mode 100644 index 0000000000..f6f606c774 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Eto.Wpf.vstemplate @@ -0,0 +1,32 @@ + + + Eto.Wpf + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Program.cs new file mode 100644 index 0000000000..8fc871268c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.Wpf/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.Wpf).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Eto.XamMac2.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Eto.XamMac2.csproj new file mode 100644 index 0000000000..f1cec8d184 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Eto.XamMac2.csproj @@ -0,0 +1,75 @@ + + + + Debug + AnyCPU + {A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {$guid7$} + Exe + $safeprojectname$ + $safeprojectname$ + Resources + v2.0 + Xamarin.Mac + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + false + false + Mac Developer + false + false + + + full + true + bin\Release + prompt + 4 + SdkOnly + false + true + false + Developer ID Application + true + true + + + full + true + bin\AppStore + prompt + 4 + SdkOnly + false + true + 3rd Party Mac Developer Installer + true + 3rd Party Mac Developer Application + true + true + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Eto.XamMac2.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Eto.XamMac2.vstemplate new file mode 100644 index 0000000000..95db75aa03 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Eto.XamMac2.vstemplate @@ -0,0 +1,33 @@ + + + Eto.XamMac2 + + CSharp + + + + + + + Program.cs + + AssemblyInfo.cs + + Info.plist + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + + NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + NuGet.VisualStudio.TemplateWizard + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Info.plist b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Info.plist new file mode 100644 index 0000000000..4715e66d08 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Info.plist @@ -0,0 +1,19 @@ + + + + + CFBundleIconFile + TestIcon.icns + CFBundleIdentifier + com.yourcompany.$safeprojectname$ + CFBundleName + $safeprojectname$ + CFBundleVersion + 1 + LSMinimumSystemVersion + 10.6 + NSPrincipalClass + NSApplication + + + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Program.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Program.cs new file mode 100644 index 0000000000..b20c3d62dd --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto.XamMac2/Program.cs @@ -0,0 +1,15 @@ +using System; +using Eto.Forms; + +namespace $safeprojectname$ +{ + public class Program + { + [STAThread] + public static void Main(string[] args) + { + new Application(Eto.Platforms.XamMac2).Run(new MainForm()); + } + } +} + diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.projitems b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.projitems new file mode 100644 index 0000000000..aaf3b3adee --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.projitems @@ -0,0 +1,14 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + {$root.guid1$} + + + $safeprojectname$ + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.shproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.shproj new file mode 100644 index 0000000000..22611b3980 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.shproj @@ -0,0 +1,12 @@ + + + + {$root.guid1$} + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.vstemplate b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.vstemplate new file mode 100644 index 0000000000..a3f28714d3 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/Eto.vstemplate @@ -0,0 +1,22 @@ + + + Eto + + CSharp + + + 1000 + + true + + + + Eto.projitems + MainForm.cs + + + + Eto.VisualStudioTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46172bb98be483 + Eto.VisualStudioTemplates.ChildWizard + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/MainForm.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/MainForm.cs new file mode 100644 index 0000000000..bbc1bcd4e0 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Eto/MainForm.cs @@ -0,0 +1,62 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace $safeprojectname$ +{ + /// + /// Your application's main form + /// + public class MainForm : Form + { + public MainForm() + { + Title = "My Eto Form"; + ClientSize = new Size(400, 350); + + // scrollable region as the main content + Content = new Scrollable + { + // table with three rows + Content = new TableLayout( + null, + // row with three columns + new TableRow(null, new Label { Text = "Hello World!" }, null), + null + ) + }; + + // create a few commands that can be used for the menu and toolbar + var clickMe = new Command { MenuText = "Click Me!", ToolBarText = "Click Me!" }; + clickMe.Executed += (sender, e) => MessageBox.Show(this, "I was clicked!"); + + var quitCommand = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q }; + quitCommand.Executed += (sender, e) => Application.Instance.Quit(); + + var aboutCommand = new Command { MenuText = "About..." }; + aboutCommand.Executed += (sender, e) => MessageBox.Show(this, "About my app..."); + + // create menu + Menu = new MenuBar + { + Items = + { + // File submenu + new ButtonMenuItem { Text = "&File", Items = { clickMe } }, + // new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } }, + // new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } }, + }, + ApplicationItems = + { + // application (OS X) or file menu (others) + new ButtonMenuItem { Text = "&Preferences..." }, + }, + QuitItem = quitCommand, + AboutItem = aboutCommand + }; + + // create toolbar + ToolBar = new ToolBar { Items = { clickMe } }; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..3421815c0c --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.SAL.Separate/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.SAL.Separate")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.SAL.Separate")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("001e0483-1479-4285-80f8-a787e7964bdd")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/ChildWizard.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/ChildWizard.cs new file mode 100644 index 0000000000..855aedd07a --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/ChildWizard.cs @@ -0,0 +1,39 @@ +using Microsoft.VisualStudio.TemplateWizard; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Eto.VisualStudioTemplates +{ + public class ChildWizard : IWizard + { + public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) + { + foreach (var replacement in RootWizard.Globals) + replacementsDictionary["$root." + replacement.Key.TrimStart('$')] = replacement.Value; + } + + public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem) + { + } + + public void ProjectFinishedGenerating(EnvDTE.Project project) + { + } + + public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) + { + } + + public void RunFinished() + { + } + + public bool ShouldAddProjectItem(string filePath) + { + return true; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/Eto.VisualStudioTemplates.csproj b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/Eto.VisualStudioTemplates.csproj new file mode 100644 index 0000000000..cf40edb7bb --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/Eto.VisualStudioTemplates.csproj @@ -0,0 +1,68 @@ + + + + + Debug + AnyCPU + {64060642-4897-4645-85D4-547EFA4C4FC2} + Library + Properties + Eto.VisualStudioTemplates + Eto.VisualStudioTemplates + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + VisualStudioTemplates.snk + + + + False + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/MultiProjectWizard.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/MultiProjectWizard.cs new file mode 100644 index 0000000000..a3fd5397fe --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/MultiProjectWizard.cs @@ -0,0 +1,95 @@ +using Microsoft.VisualStudio.TemplateWizard; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Xml; + +namespace Eto.VisualStudioTemplates +{ + /// + /// Wizard to create projects at the root folder instead of in a subfolder + /// + /// + /// Also, supports setting the startup project + /// + public class MultiProjectWizard : IWizard + { + string defaultDestinationFolder; + string basePath; + string safeProjectName; + EnvDTE.DTE dte; + List definitions = new List(); + + static readonly Regex propertyRegex = new Regex(@"\$\w+\$", RegexOptions.Compiled); + + public class ProjectDefinition + { + public string Name { get; set; } + public string Path { get; set; } + public bool Startup { get; set; } + } + + public void RunFinished() + { + Directory.Delete(defaultDestinationFolder, true); + foreach (var definition in definitions) + { + AddProject(definition.Path, definition.Name); + } + var startupProject = definitions.FirstOrDefault(r => r.Startup); + if (startupProject != null) + dte.Solution.Properties.Item("StartupProject").Value = startupProject.Name; + } + + public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) + { + dte = automationObject as EnvDTE.DTE; + defaultDestinationFolder = replacementsDictionary["$destinationdirectory$"]; + basePath = Path.GetDirectoryName((string)customParams[0]); + + safeProjectName = replacementsDictionary["$safeprojectname$"]; + + var wizardData = "" + replacementsDictionary["$wizarddata$"] + ""; + var doc = new XmlDocument(); + doc.LoadXml(wizardData); + var nsmgr = new XmlNamespaceManager(doc.NameTable); + nsmgr.AddNamespace("vs", "http://schemas.microsoft.com/developer/vstemplate/2005"); + foreach (var element in doc.SelectNodes("//vs:Projects/vs:Project", nsmgr).OfType()) + { + var name = propertyRegex.Replace(element.GetAttribute("Name"), match => replacementsDictionary[match.Value]); + var startup = string.Equals(element.GetAttribute("Startup"), "true", StringComparison.InvariantCultureIgnoreCase); + definitions.Add(new ProjectDefinition { Name = name, Path = element.InnerText, Startup = startup }); + } + } + + public bool ShouldAddProjectItem(string filePath) + { + return true; + } + + public void AddProject(string templatePath, string name) + { + var solution = dte.Solution; + + string destinationPath = Path.Combine(Path.GetDirectoryName(defaultDestinationFolder), name); + + solution.AddFromTemplate(Path.Combine(basePath, templatePath), destinationPath, name, false); + } + + public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem) + { + } + + public void ProjectFinishedGenerating(EnvDTE.Project project) + { + } + + public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) + { + } + } +} \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..720ab34c04 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Eto.VisualStudioTemplates")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Eto.VisualStudioTemplates")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("712ffee0-1d08-4e97-aa57-40efbc3e4735")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/RootWizard.cs b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/RootWizard.cs new file mode 100644 index 0000000000..70d3c5aa14 --- /dev/null +++ b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/RootWizard.cs @@ -0,0 +1,41 @@ +using Microsoft.VisualStudio.TemplateWizard; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Eto.VisualStudioTemplates +{ + public class RootWizard : IWizard + { + public static Dictionary Globals = new Dictionary(); + + public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) + { + foreach (var replacement in replacementsDictionary) + Globals[replacement.Key] = replacement.Value; + } + + public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem) + { + } + + public void ProjectFinishedGenerating(EnvDTE.Project project) + { + } + + public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) + { + } + + public void RunFinished() + { + } + + public bool ShouldAddProjectItem(string filePath) + { + return true; + } + } +} diff --git a/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/VisualStudioTemplates.snk b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/VisualStudioTemplates.snk new file mode 100644 index 0000000000..84c11dcf94 Binary files /dev/null and b/Source/Addins/Eto.Addin.VisualStudio/Eto.VisualStudioTemplates/VisualStudioTemplates.snk differ diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Eto.Addin.XamarinStudio.csproj b/Source/Addins/Eto.Addin.XamarinStudio/Eto.Addin.XamarinStudio.csproj new file mode 100644 index 0000000000..b43aa4b44e --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Eto.Addin.XamarinStudio.csproj @@ -0,0 +1,189 @@ + + + + Debug + AnyCPU + {7DBEB09D-BB9F-4D92-A141-A009135475EF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {54A88D77-39C6-49E5-971E-05451209F2A9} + Library + Eto.Addin.XamarinStudio + Eto.Addin.XamarinStudio + True + ..\.. + . + + + true + full + false + ..\..\..\BuildOutput\Addins\Debug\XamarinStudio + DEBUG; + prompt + 4 + false + + + full + true + ..\..\..\BuildOutput\Addins\Release\XamarinStudio + prompt + 4 + false + + + + + + + /Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/Mono.Addins.dll + False + + + /Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/MonoDevelop.Core.dll + False + + + /Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/MonoDevelop.Ide.dll + False + + + /Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/Mono.TextEditor.dll + False + + + /Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/ICSharpCode.NRefactory.dll + False + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + Packages\Eto.Forms.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Forms.Sample.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.Direct2D.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.Gtk.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.Gtk3.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.iOS.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.Mac.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.Mac.Template.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.Mac64.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.Windows.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.WinRT.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.Wpf.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.XamMac.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Platform.XamMac2.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Serialization.Json.2.0.1.nupkg + PreserveNewest + + + Packages\Eto.Serialization.Xaml.2.0.1.nupkg + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Eto.Addin.XamarinStudio.sln b/Source/Addins/Eto.Addin.XamarinStudio/Eto.Addin.XamarinStudio.sln new file mode 100644 index 0000000000..6f069798ec --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Eto.Addin.XamarinStudio.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Addin.XamarinStudio", "Eto.Addin.XamarinStudio.csproj", "{54A88D77-39C6-49E5-971E-05451209F2A9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {54A88D77-39C6-49E5-971E-05451209F2A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {54A88D77-39C6-49E5-971E-05451209F2A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {54A88D77-39C6-49E5-971E-05451209F2A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {54A88D77-39C6-49E5-971E-05451209F2A9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Eto.Forms.XamarinStudio.csproj + EndGlobalSection +EndGlobal diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Properties/AddinInfo.cs b/Source/Addins/Eto.Addin.XamarinStudio/Properties/AddinInfo.cs new file mode 100644 index 0000000000..d6ac0be089 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Properties/AddinInfo.cs @@ -0,0 +1,17 @@ +using System; +using Mono.Addins; +using Mono.Addins.Description; + +[assembly:Addin( + "Eto.Addin.XamarinStudio", + Namespace = "Eto.Addin.XamarinStudio", + Version = "1.0" +)] + +[assembly:AddinName("Eto.Forms")] +[assembly:AddinCategory("Eto.Forms")] +[assembly:AddinDescription("Addin to easily start developing with Eto.Forms using project and file templates.")] +[assembly:AddinAuthor("Curtis Wensley")] + +[assembly:AddinDependency("::MonoDevelop.Core", MonoDevelop.BuildInfo.Version)] +[assembly:AddinDependency("::MonoDevelop.Ide", MonoDevelop.BuildInfo.Version)] diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Properties/AssemblyInfo.cs b/Source/Addins/Eto.Addin.XamarinStudio/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..367eb38713 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Eto.Addin.XamarinStudio")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Picoe Software Solutions Inc.")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Curtis Wensley")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Properties/Manifest.addin.xml b/Source/Addins/Eto.Addin.XamarinStudio/Properties/Manifest.addin.xml new file mode 100644 index 0000000000..0e503ec8d4 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Properties/Manifest.addin.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Dialog.cs b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Dialog.cs new file mode 100644 index 0000000000..d2386ece03 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Dialog.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using Eto.Forms; +using Eto.Drawing; + +namespace ${Namespace} +{ + public class ${EscapedIdentifier} : Dialog + { + public ${EscapedIdentifier}() + { + Title = "My ${EscapedIdentifier} dialog"; + + // buttons + DefaultButton = new Button { Text = "OK" }; + + AbortButton = new Button { Text = "C&ancel" }; + AbortButton.Click += (sender, e) => Close(); + + var buttons = new TableLayout { Rows = { new TableRow(null, DefaultButton, AbortButton) }, Spacing = new Size(5, 5) }; + + Content = new TableLayout + { + Padding = new Padding(10), + Rows = + { + new Label { Text = "Some content" }, + buttons + } + }; + } + } +} diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Dialog.xft.xml b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Dialog.xft.xml new file mode 100644 index 0000000000..76443d6809 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Dialog.xft.xml @@ -0,0 +1,16 @@ + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Form.cs b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Form.cs new file mode 100644 index 0000000000..b850949bb8 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Form.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using Eto.Forms; +using Eto.Drawing; + +namespace ${Namespace} +{ + public class ${EscapedIdentifier} : Form + { + public ${EscapedIdentifier}() + { + Title = "My ${EscapedIdentifier} form"; + + Content = new Label { Text = "Some content" }; + } + } +} diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Form.xft.xml b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Form.xft.xml new file mode 100644 index 0000000000..a80c95a7ad --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Form.xft.xml @@ -0,0 +1,16 @@ + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Panel.cs b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Panel.cs new file mode 100644 index 0000000000..2f6a765e01 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Panel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using Eto.Forms; +using Eto.Drawing; + +namespace ${Namespace} +{ + public class ${EscapedIdentifier} : Panel + { + public ${EscapedIdentifier}() + { + Content = new Label { Text = "Some Content" }; + } + } +} diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Panel.xft.xml b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Panel.xft.xml new file mode 100644 index 0000000000..97a128787d --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Files/Eto-Panel.xft.xml @@ -0,0 +1,16 @@ + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-Library.xpt.xml b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-Library.xpt.xml new file mode 100644 index 0000000000..1d8b460565 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-Library.xpt.xml @@ -0,0 +1,24 @@ + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-PCL-Combined.xpt.xml b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-PCL-Combined.xpt.xml new file mode 100644 index 0000000000..d6ceb6e4e8 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-PCL-Combined.xpt.xml @@ -0,0 +1,133 @@ + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-PCL-Separate.xpt.xml b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-PCL-Separate.xpt.xml new file mode 100644 index 0000000000..fc2820790a --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-PCL-Separate.xpt.xml @@ -0,0 +1,227 @@ + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-SAL-Combined.xpt.xml b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-SAL-Combined.xpt.xml new file mode 100644 index 0000000000..e178a83a92 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-SAL-Combined.xpt.xml @@ -0,0 +1,128 @@ + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-SAL-Separate.xpt.xml b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-SAL-Separate.xpt.xml new file mode 100644 index 0000000000..e15034b962 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Eto-SAL-Separate.xpt.xml @@ -0,0 +1,222 @@ + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Mac/Info.plist b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Mac/Info.plist new file mode 100644 index 0000000000..0549c2254e --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Mac/Info.plist @@ -0,0 +1,18 @@ + + + + + CFBundleIconFile + TestIcon.icns + CFBundleIdentifier + com.yourcompany.${ProjectName} + CFBundleName + ${ProjectName} + CFBundleVersion + 1 + LSMinimumSystemVersion + 10.6 + NSPrincipalClass + NSApplication + + diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Shared/MainForm.cs b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Shared/MainForm.cs new file mode 100644 index 0000000000..3b1b62d389 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Shared/MainForm.cs @@ -0,0 +1,60 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace ${Namespace} +{ + /// + /// Your application's main form + /// + public class MainForm : Form + { + public MainForm() + { + Title = "My Eto Form"; + ClientSize = new Size(400, 350); + + // scrollable region as the main content + Content = new Scrollable + { + // table with three rows + Content = new TableLayout( + null, + // row with three columns + new TableRow(null, new Label { Text = "Hello World!" }, null), + null + ) + }; + + // create a few commands that can be used for the menu and toolbar + var clickMe = new Command { MenuText = "Click Me!", ToolBarText = "Click Me!" }; + clickMe.Executed += (sender, e) => MessageBox.Show(this, "I was clicked!"); + + var quitCommand = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q }; + quitCommand.Executed += (sender, e) => Application.Instance.Quit(); + + var aboutCommand = new Command { MenuText = "About..." }; + aboutCommand.Executed += (sender, e) => MessageBox.Show(this, "About my app..."); + + // create menu + Menu = new MenuBar + { + Items = { + // File submenu + new ButtonMenuItem { Text = "&File", Items = { clickMe } }, + // new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } }, + // new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } }, + }, + ApplicationItems = { + // application (OS X) or file menu (others) + new ButtonMenuItem { Text = "&Preferences..." }, + }, + QuitItem = quitCommand, + AboutItem = aboutCommand + }; + + // create toolbar + ToolBar = new ToolBar { Items = { clickMe } }; + } + } +} \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Shared/MyPanel.cs b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Shared/MyPanel.cs new file mode 100644 index 0000000000..376b2f6c37 --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/Templates/Projects/Shared/MyPanel.cs @@ -0,0 +1,18 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace ${Namespace} +{ + /// + /// A custom panel + /// + public class MyPanel : Panel + { + public MyPanel() + { + // set your content and other properties here + Content = new Label { Text = "Some Content" }; + } + } +} diff --git a/Source/Addins/Eto.Addin.XamarinStudio/addin-project.xml b/Source/Addins/Eto.Addin.XamarinStudio/addin-project.xml new file mode 100644 index 0000000000..4e115c839f --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/addin-project.xml @@ -0,0 +1,7 @@ + + + ../../../BuildOutput/Addins/Release/XamarinStudio/Eto.Addin.XamarinStudio.dll + ../../../Resources/Publish.targets + Release + + \ No newline at end of file diff --git a/Source/Addins/Eto.Addin.XamarinStudio/packages.config b/Source/Addins/Eto.Addin.XamarinStudio/packages.config new file mode 100644 index 0000000000..e90e91c23f --- /dev/null +++ b/Source/Addins/Eto.Addin.XamarinStudio/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Source/Eto - Android.sln b/Source/Eto - Android.sln index 2ca9455e4e..15c640804c 100644 --- a/Source/Eto - Android.sln +++ b/Source/Eto - Android.sln @@ -3,15 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Android", "Eto.Test\Eto.Test.Android\Eto.Test.Android.csproj", "{22BE7E21-76D0-4C29-9D0A-6D6D432CC952}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Platform.Android", "Eto.Platform.Android\Eto.Platform.Android.csproj", "{7A02E771-D30B-41A1-8A35-C78D3940FC33}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Android", "Eto.Android\Eto.Android.csproj", "{7A02E771-D30B-41A1-8A35-C78D3940FC33}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto - Android", "Eto\Eto - Android.csproj", "{73A5AD74-68BC-448C-A38C-CFBAF014A311}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto - Pcl", "Eto\Eto - Pcl.csproj", "{35EF0A4E-2A1A-492C-8BED-106774EA09F2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test - Android", "Eto.Test\Eto.Test\Eto.Test - Android.csproj", "{BA9DB2EC-C210-4EB9-8A44-4351A1958E85}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Serialization.Json - Pcl", "Eto.Serialization.Json\Eto.Serialization.Json - Pcl.csproj", "{3F8178EF-0710-43F7-92E2-130B9BE2212D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Json - Android", "Eto.Json\Eto.Json - Android.csproj", "{757FCF9A-E2D0-4031-9A11-82A2A49FA892}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{0DFC22F9-1B35-4B43-A57C-89A173576D01}" + ProjectSection(SolutionItems) = preProject + .nuget\packages.config = .nuget\packages.config + EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.UnitTest - Android", "Eto.UnitTest\Eto.UnitTest - Android.csproj", "{D7161F60-B4AD-11E3-A5E2-0800200C9A66}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test - Pcl", "Eto.Test\Eto.Test\Eto.Test - Pcl.csproj", "{EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -23,28 +26,29 @@ Global {22BE7E21-76D0-4C29-9D0A-6D6D432CC952}.Debug|Any CPU.Build.0 = Debug|Any CPU {22BE7E21-76D0-4C29-9D0A-6D6D432CC952}.Release|Any CPU.ActiveCfg = Release|Any CPU {22BE7E21-76D0-4C29-9D0A-6D6D432CC952}.Release|Any CPU.Build.0 = Release|Any CPU - {73A5AD74-68BC-448C-A38C-CFBAF014A311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {73A5AD74-68BC-448C-A38C-CFBAF014A311}.Debug|Any CPU.Build.0 = Debug|Any CPU - {73A5AD74-68BC-448C-A38C-CFBAF014A311}.Release|Any CPU.ActiveCfg = Release|Any CPU - {73A5AD74-68BC-448C-A38C-CFBAF014A311}.Release|Any CPU.Build.0 = Release|Any CPU - {757FCF9A-E2D0-4031-9A11-82A2A49FA892}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {757FCF9A-E2D0-4031-9A11-82A2A49FA892}.Debug|Any CPU.Build.0 = Debug|Any CPU - {757FCF9A-E2D0-4031-9A11-82A2A49FA892}.Release|Any CPU.ActiveCfg = Release|Any CPU - {757FCF9A-E2D0-4031-9A11-82A2A49FA892}.Release|Any CPU.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Any CPU.Build.0 = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|Any CPU.Build.0 = Release|Any CPU {7A02E771-D30B-41A1-8A35-C78D3940FC33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7A02E771-D30B-41A1-8A35-C78D3940FC33}.Debug|Any CPU.Build.0 = Debug|Any CPU {7A02E771-D30B-41A1-8A35-C78D3940FC33}.Release|Any CPU.ActiveCfg = Release|Any CPU {7A02E771-D30B-41A1-8A35-C78D3940FC33}.Release|Any CPU.Build.0 = Release|Any CPU - {BA9DB2EC-C210-4EB9-8A44-4351A1958E85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BA9DB2EC-C210-4EB9-8A44-4351A1958E85}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BA9DB2EC-C210-4EB9-8A44-4351A1958E85}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BA9DB2EC-C210-4EB9-8A44-4351A1958E85}.Release|Any CPU.Build.0 = Release|Any CPU - {D7161F60-B4AD-11E3-A5E2-0800200C9A66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D7161F60-B4AD-11E3-A5E2-0800200C9A66}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D7161F60-B4AD-11E3-A5E2-0800200C9A66}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D7161F60-B4AD-11E3-A5E2-0800200C9A66}.Release|Any CPU.Build.0 = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = Eto.Test\Eto.Test.Android\Eto.Test.Android.csproj EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection EndGlobal diff --git a/Source/Eto - Free.sln b/Source/Eto - Free.sln index 3ea4c2be17..720e135498 100644 --- a/Source/Eto - Free.sln +++ b/Source/Eto - Free.sln @@ -5,11 +5,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Mac", "Eto.Test\Et EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto", "Eto\Eto.csproj", "{16289D2F-044C-49EF-83E9-9391AFF8FD2B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Platform.Gtk", "Eto.Platform.Gtk\Eto.Platform.Gtk.csproj", "{1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Gtk2", "Eto.Gtk\Eto.Gtk2.csproj", "{1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Platform.Mac", "Eto.Platform.Mac\Eto.Platform.Mac.csproj", "{9DD10DFF-5AB3-4E66-B798-CA17911A61E4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Mac", "Eto.Mac\Eto.Mac.csproj", "{9DD10DFF-5AB3-4E66-B798-CA17911A61E4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Platform.Windows", "Eto.Platform.Windows\Eto.Platform.Windows.csproj", "{69D38C57-AD4B-4A16-A7B1-49BCFBE71491}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.WinForms", "Eto.WinForms\Eto.WinForms.csproj", "{69D38C57-AD4B-4A16-A7B1-49BCFBE71491}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test", "Eto.Test\Eto.Test\Eto.Test.csproj", "{F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}" EndProject @@ -17,15 +17,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.WinForms", "Eto.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Direct2D", "Eto.Test\Eto.Test.Direct2D\Eto.Test.Direct2D.csproj", "{74328428-C412-4BC3-BD0C-E1DBC43FB479}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Gtk", "Eto.Test\Eto.Test.Gtk\Eto.Test.Gtk.csproj", "{DD350D2E-149A-4EF1-8AAE-CBA9740B5735}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Gtk2", "Eto.Test\Eto.Test.Gtk2\Eto.Test.Gtk2.csproj", "{DD350D2E-149A-4EF1-8AAE-CBA9740B5735}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Json", "Eto.Json\Eto.Json.csproj", "{2F2C45E0-4142-44D0-8A0C-7264C0F925B2}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Serialization.Json", "Eto.Serialization.Json\Eto.Serialization.Json.csproj", "{2F2C45E0-4142-44D0-8A0C-7264C0F925B2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Platform.Wpf", "Eto.Platform.Wpf\Eto.Platform.Wpf.csproj", "{E3524178-5A24-47C0-B155-92314FE4B2B6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Wpf", "Eto.Wpf\Eto.Wpf.csproj", "{E3524178-5A24-47C0-B155-92314FE4B2B6}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Wpf", "Eto.Test\Eto.Test.Wpf\Eto.Test.Wpf.csproj", "{DBAEAD48-6540-43FA-B86A-114ECCB15C7A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Platform.Gtk3", "Eto.Platform.Gtk\Eto.Platform.Gtk3.csproj", "{EECFE22F-A544-4498-AE2D-90C81BD2931A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Gtk3", "Eto.Gtk\Eto.Gtk3.csproj", "{EECFE22F-A544-4498-AE2D-90C81BD2931A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Gtk3", "Eto.Test\Eto.Test.Gtk3\Eto.Test.Gtk3.csproj", "{B2148BDC-7D98-419B-B329-FF580FB481DE}" EndProject @@ -36,200 +36,192 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{9D5A60 .nuget\NuGet.targets = .nuget\NuGet.targets EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Platform.Direct2D", "Eto.Platform.Direct2D\Eto.Platform.Direct2D.csproj", "{3C1B77D5-6C93-4366-A487-3D307FC29FFB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Direct2D", "Eto.Direct2D\Eto.Direct2D.csproj", "{3C1B77D5-6C93-4366-A487-3D307FC29FFB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.UnitTest", "Eto.UnitTest\Eto.UnitTest.csproj", "{65F2B3D9-8611-4872-B7BE-6582FB428297}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Serialization.Xaml", "Eto.Serialization.Xaml\Eto.Serialization.Xaml.csproj", "{FA4BC167-9909-45D2-B86A-D4AE4062A524}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Linux Debug|Any CPU = Linux Debug|Any CPU - Linux Release|Any CPU = Linux Release|Any CPU - Mac Debug|Any CPU = Mac Debug|Any CPU - Mac Release|Any CPU = Mac Release|Any CPU - Windows Debug|Any CPU = Windows Debug|Any CPU - Windows Release|Any CPU = Windows Release|Any CPU + Debug|Linux = Debug|Linux + Release|Linux = Release|Linux + Debug|Mac = Debug|Mac + Release|Mac = Release|Mac + Debug|Windows = Debug|Windows + Release|Windows = Release|Windows EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Linux Debug|Any CPU.Build.0 = Debug|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Linux Release|Any CPU.Build.0 = Release|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Linux Debug|Any CPU.Build.0 = Debug|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Linux Release|Any CPU.Build.0 = Release|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Linux Debug|Any CPU.Build.0 = Debug|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Linux Release|Any CPU.Build.0 = Release|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Linux Debug|Any CPU.Build.0 = Debug|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Linux Release|Any CPU.Build.0 = Release|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {65F2B3D9-8611-4872-B7BE-6582FB428297}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Linux Debug|Any CPU.Build.0 = Debug|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Linux Release|Any CPU.Build.0 = Release|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Linux Debug|Any CPU.Build.0 = Debug|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Linux Release|Any CPU.Build.0 = Release|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {B2148BDC-7D98-419B-B329-FF580FB481DE}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Linux Debug|Any CPU.ActiveCfg = Debug|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Linux Debug|Any CPU.Build.0 = Debug|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Linux Release|Any CPU.ActiveCfg = Release|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Linux Release|Any CPU.Build.0 = Release|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Mac Debug|Any CPU.ActiveCfg = Debug|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Mac Debug|Any CPU.Build.0 = Debug|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Mac Release|Any CPU.ActiveCfg = Release|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Mac Release|Any CPU.Build.0 = Release|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Windows Debug|Any CPU.ActiveCfg = Debug|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Windows Debug|Any CPU.Build.0 = Debug|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Windows Release|Any CPU.ActiveCfg = Release|x86 - {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Windows Release|Any CPU.Build.0 = Release|x86 - {E3524178-5A24-47C0-B155-92314FE4B2B6}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E3524178-5A24-47C0-B155-92314FE4B2B6}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {E3524178-5A24-47C0-B155-92314FE4B2B6}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E3524178-5A24-47C0-B155-92314FE4B2B6}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {E3524178-5A24-47C0-B155-92314FE4B2B6}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E3524178-5A24-47C0-B155-92314FE4B2B6}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {E3524178-5A24-47C0-B155-92314FE4B2B6}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {E3524178-5A24-47C0-B155-92314FE4B2B6}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Linux Debug|Any CPU.Build.0 = Debug|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Linux Release|Any CPU.Build.0 = Release|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Linux Debug|Any CPU.Build.0 = Debug|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Linux Release|Any CPU.Build.0 = Release|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Windows Debug|Any CPU.Build.0 = Debug|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Windows Release|Any CPU.Build.0 = Release|Any CPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU - {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Linux Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Linux Release|Any CPU.ActiveCfg = Release|Any CPU - {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Mac Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Mac Debug|Any CPU.Build.0 = Debug|Any CPU - {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Mac Release|Any CPU.ActiveCfg = Release|Any CPU - {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Mac Release|Any CPU.Build.0 = Release|Any CPU - {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Windows Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Windows Release|Any CPU.ActiveCfg = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Linux.ActiveCfg = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Linux.Build.0 = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Mac.ActiveCfg = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Mac.Build.0 = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.ActiveCfg = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.Build.0 = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Linux.ActiveCfg = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Linux.Build.0 = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Mac.ActiveCfg = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Mac.Build.0 = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.ActiveCfg = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.Build.0 = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Linux.ActiveCfg = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Linux.Build.0 = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Mac.ActiveCfg = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Mac.Build.0 = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Windows.ActiveCfg = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Windows.Build.0 = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Linux.ActiveCfg = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Linux.Build.0 = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Mac.ActiveCfg = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Mac.Build.0 = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Windows.ActiveCfg = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Windows.Build.0 = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Linux.ActiveCfg = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Linux.Build.0 = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Mac.ActiveCfg = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Mac.Build.0 = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Windows.ActiveCfg = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Windows.Build.0 = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Linux.ActiveCfg = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Linux.Build.0 = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Mac.ActiveCfg = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Mac.Build.0 = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Windows.ActiveCfg = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Windows.Build.0 = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Linux.ActiveCfg = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Linux.Build.0 = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Mac.ActiveCfg = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Mac.Build.0 = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Windows.ActiveCfg = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Windows.Build.0 = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Linux.ActiveCfg = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Linux.Build.0 = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Mac.ActiveCfg = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Mac.Build.0 = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Windows.ActiveCfg = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Windows.Build.0 = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Debug|Linux.ActiveCfg = Debug|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Debug|Mac.ActiveCfg = Debug|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Debug|Windows.ActiveCfg = Debug|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Debug|Windows.Build.0 = Debug|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Linux.ActiveCfg = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Mac.ActiveCfg = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Windows.ActiveCfg = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Windows.Build.0 = Release|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Debug|Linux.ActiveCfg = Debug|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Debug|Mac.ActiveCfg = Debug|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Debug|Mac.Build.0 = Debug|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Debug|Windows.ActiveCfg = Debug|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Release|Linux.ActiveCfg = Release|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Release|Mac.ActiveCfg = Release|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Release|Mac.Build.0 = Release|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Release|Windows.ActiveCfg = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Linux.ActiveCfg = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Linux.Build.0 = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Mac.ActiveCfg = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Mac.Build.0 = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Windows.ActiveCfg = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Windows.Build.0 = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Linux.ActiveCfg = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Linux.Build.0 = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Mac.ActiveCfg = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Mac.Build.0 = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Windows.ActiveCfg = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Windows.Build.0 = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Linux.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Mac.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.Build.0 = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Linux.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Mac.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.Build.0 = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Linux.ActiveCfg = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Linux.Build.0 = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Mac.ActiveCfg = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Mac.Build.0 = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Windows.ActiveCfg = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Windows.Build.0 = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Linux.ActiveCfg = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Linux.Build.0 = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Mac.ActiveCfg = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Mac.Build.0 = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Windows.ActiveCfg = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Windows.Build.0 = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Linux.ActiveCfg = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Linux.Build.0 = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Mac.ActiveCfg = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Mac.Build.0 = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Windows.ActiveCfg = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Windows.Build.0 = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Linux.ActiveCfg = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Linux.Build.0 = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Mac.ActiveCfg = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Mac.Build.0 = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Windows.ActiveCfg = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Windows.Build.0 = Release|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Debug|Linux.ActiveCfg = Debug|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Debug|Mac.ActiveCfg = Debug|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Debug|Windows.ActiveCfg = Debug|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Debug|Windows.Build.0 = Debug|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Release|Linux.ActiveCfg = Release|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Release|Mac.ActiveCfg = Release|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Release|Windows.ActiveCfg = Release|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Release|Windows.Build.0 = Release|Any CPU + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Linux.ActiveCfg = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Linux.Build.0 = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Mac.ActiveCfg = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Mac.Build.0 = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Windows.ActiveCfg = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Windows.Build.0 = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Linux.ActiveCfg = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Linux.Build.0 = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Mac.ActiveCfg = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Mac.Build.0 = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Windows.ActiveCfg = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Windows.Build.0 = Release|x86 + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Debug|Linux.ActiveCfg = Debug|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Debug|Mac.ActiveCfg = Debug|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Debug|Windows.ActiveCfg = Debug|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Debug|Windows.Build.0 = Debug|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Release|Linux.ActiveCfg = Release|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Release|Mac.ActiveCfg = Release|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Release|Windows.ActiveCfg = Release|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Release|Windows.Build.0 = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Linux.ActiveCfg = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Linux.Build.0 = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Mac.ActiveCfg = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Mac.Build.0 = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Windows.ActiveCfg = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Windows.Build.0 = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Linux.ActiveCfg = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Linux.Build.0 = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Mac.ActiveCfg = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Mac.Build.0 = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Windows.ActiveCfg = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Windows.Build.0 = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Linux.ActiveCfg = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Linux.Build.0 = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Mac.ActiveCfg = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Mac.Build.0 = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Windows.ActiveCfg = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Windows.Build.0 = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Linux.ActiveCfg = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Linux.Build.0 = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Mac.ActiveCfg = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Mac.Build.0 = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Windows.ActiveCfg = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Windows.Build.0 = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Linux.ActiveCfg = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Linux.Build.0 = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Mac.ActiveCfg = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Mac.Build.0 = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Windows.ActiveCfg = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Windows.Build.0 = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Linux.ActiveCfg = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Linux.Build.0 = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Mac.ActiveCfg = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Mac.Build.0 = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Windows.ActiveCfg = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Windows.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution EndGlobalSection diff --git a/Source/Eto - iOS.sln b/Source/Eto - iOS.sln index 2ea5d207e1..05fa7fe9cd 100644 --- a/Source/Eto - iOS.sln +++ b/Source/Eto - iOS.sln @@ -1,143 +1,97 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto - iOS", "Eto\Eto - iOS.csproj", "{83452633-C37C-490F-852A-3ADE0A2CF0D4}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Platform.iOS", "Eto.Platform.iOS\Eto.Platform.iOS.csproj", "{E711B298-D141-4EC5-9BFD-84962B264F90}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test - iOS", "Eto.Test\Eto.Test\Eto.Test - iOS.csproj", "{97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.iOS", "Eto.Test\Eto.Test.iOS\Eto.Test.iOS.csproj", "{AB42209E-E87F-4749-96CF-8CAE83981808}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Json - iOS", "Eto.Json\Eto.Json - iOS.csproj", "{5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.UnitTest - iOS", "Eto.UnitTest\Eto.UnitTest - iOS.csproj", "{CB40A480-B4AD-11E3-A5E2-0800200C9A66}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|iPhoneSimulator = Debug|iPhoneSimulator - Release|iPhoneSimulator = Release|iPhoneSimulator - Debug|iPhone = Debug|iPhone - Release|iPhone = Release|iPhone - Ad-Hoc|iPhone = Ad-Hoc|iPhone - AppStore|iPhone = AppStore|iPhone - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.AppStore|iPhone.ActiveCfg = Release|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.AppStore|iPhone.Build.0 = Release|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Debug|iPhone.Build.0 = Debug|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Release|iPhone.ActiveCfg = Release|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Release|iPhone.Build.0 = Release|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.AppStore|iPhone.ActiveCfg = Release|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.AppStore|iPhone.Build.0 = Release|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Debug|iPhone.Build.0 = Debug|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Release|iPhone.ActiveCfg = Release|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Release|iPhone.Build.0 = Release|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {83452633-C37C-490F-852A-3ADE0A2CF0D4}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.AppStore|iPhone.ActiveCfg = Release|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.AppStore|iPhone.Build.0 = Release|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Debug|iPhone.Build.0 = Debug|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Release|iPhone.ActiveCfg = Release|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Release|iPhone.Build.0 = Release|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {97DEC3D5-5E7C-493D-AB7E-C0001AF7085F}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {AB42209E-E87F-4749-96CF-8CAE83981808}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone - {AB42209E-E87F-4749-96CF-8CAE83981808}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone - {AB42209E-E87F-4749-96CF-8CAE83981808}.AppStore|iPhone.ActiveCfg = AppStore|iPhone - {AB42209E-E87F-4749-96CF-8CAE83981808}.AppStore|iPhone.Build.0 = AppStore|iPhone - {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhone.ActiveCfg = Debug|iPhone - {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhone.Build.0 = Debug|iPhone - {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator - {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator - {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhone.ActiveCfg = Release|iPhone - {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhone.Build.0 = Release|iPhone - {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator - {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.AppStore|iPhone.ActiveCfg = Release|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.AppStore|iPhone.Build.0 = Release|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Debug|iPhone.Build.0 = Debug|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Release|iPhone.ActiveCfg = Release|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Release|iPhone.Build.0 = Release|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {CB40A480-B4AD-11E3-A5E2-0800200C9A66}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.AppStore|iPhone.ActiveCfg = Release|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.AppStore|iPhone.Build.0 = Release|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Debug|iPhone.Build.0 = Debug|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Release|iPhone.ActiveCfg = Release|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Release|iPhone.Build.0 = Release|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {E711B298-D141-4EC5-9BFD-84962B264F90}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = Eto.Test\Eto.Test.iOS\Eto.Test.iOS.csproj - Policies = $0 - $0.DotNetNamingPolicy = $1 - $1.DirectoryNamespaceAssociation = PrefixedHierarchical - $1.ResourceNamePolicy = MSBuild - $0.TextStylePolicy = $2 - $2.inheritsSet = null - $2.scope = text/x-csharp - $0.CSharpFormattingPolicy = $3 - $3.IndentSwitchBody = True - $3.AnonymousMethodBraceStyle = NextLine - $3.PropertyBraceStyle = NextLine - $3.PropertyGetBraceStyle = NextLine - $3.PropertySetBraceStyle = NextLine - $3.EventBraceStyle = NextLine - $3.EventAddBraceStyle = NextLine - $3.EventRemoveBraceStyle = NextLine - $3.StatementBraceStyle = NextLine - $3.ElseNewLinePlacement = NewLine - $3.CatchNewLinePlacement = NewLine - $3.FinallyNewLinePlacement = NewLine - $3.WhileNewLinePlacement = DoNotCare - $3.ArrayInitializerWrapping = DoNotChange - $3.ArrayInitializerBraceStyle = NextLine - $3.BeforeMethodDeclarationParentheses = False - $3.BeforeMethodCallParentheses = False - $3.BeforeConstructorDeclarationParentheses = False - $3.BeforeDelegateDeclarationParentheses = False - $3.NewParentheses = False - $3.SpacesBeforeBrackets = False - $3.inheritsSet = Mono - $3.inheritsScope = text/x-csharp - $3.scope = text/x-csharp - $0.TextStylePolicy = $4 - $4.FileWidth = 120 - $4.TabsToSpaces = False - $4.inheritsSet = VisualStudio - $4.inheritsScope = text/plain - $4.scope = text/plain - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.iOS", "Eto.iOS\Eto.iOS.csproj", "{E711B298-D141-4EC5-9BFD-84962B264F90}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.iOS", "Eto.Test\Eto.Test.iOS\Eto.Test.iOS.csproj", "{AB42209E-E87F-4749-96CF-8CAE83981808}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto - Pcl", "Eto\Eto - Pcl.csproj", "{35EF0A4E-2A1A-492C-8BED-106774EA09F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Serialization.Json - Pcl", "Eto.Serialization.Json\Eto.Serialization.Json - Pcl.csproj", "{3F8178EF-0710-43F7-92E2-130B9BE2212D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test - Pcl", "Eto.Test\Eto.Test\Eto.Test - Pcl.csproj", "{EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Ad-Hoc|iPhone = Ad-Hoc|iPhone + AppStore|iPhone = AppStore|iPhone + Debug|iPhone = Debug|iPhone + Debug|iPhoneSimulator = Debug|iPhoneSimulator + Release|iPhone = Release|iPhone + Release|iPhoneSimulator = Release|iPhoneSimulator + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.AppStore|iPhone.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.AppStore|iPhone.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|iPhone.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|iPhone.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|iPhone.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.AppStore|iPhone.ActiveCfg = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.AppStore|iPhone.Build.0 = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|iPhone.Build.0 = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|iPhone.ActiveCfg = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|iPhone.Build.0 = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {AB42209E-E87F-4749-96CF-8CAE83981808}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Ad-Hoc|iPhone.Deploy.0 = Ad-Hoc|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.AppStore|iPhone.ActiveCfg = AppStore|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.AppStore|iPhone.Build.0 = AppStore|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.AppStore|iPhone.Deploy.0 = AppStore|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhone.ActiveCfg = Debug|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhone.Build.0 = Debug|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhone.Deploy.0 = Debug|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator + {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator + {AB42209E-E87F-4749-96CF-8CAE83981808}.Debug|iPhoneSimulator.Deploy.0 = Debug|iPhoneSimulator + {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhone.ActiveCfg = Release|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhone.Build.0 = Release|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhone.Deploy.0 = Release|iPhone + {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator + {AB42209E-E87F-4749-96CF-8CAE83981808}.Release|iPhoneSimulator.Deploy.0 = Release|iPhoneSimulator + {E711B298-D141-4EC5-9BFD-84962B264F90}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.AppStore|iPhone.ActiveCfg = Release|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.AppStore|iPhone.Build.0 = Release|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Debug|iPhone.Build.0 = Debug|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Release|iPhone.ActiveCfg = Release|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Release|iPhone.Build.0 = Release|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {E711B298-D141-4EC5-9BFD-84962B264F90}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.AppStore|iPhone.ActiveCfg = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.AppStore|iPhone.Build.0 = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|iPhone.Build.0 = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|iPhone.ActiveCfg = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|iPhone.Build.0 = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Eto.Test\Eto.Test.iOS\Eto.Test.iOS.csproj + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Source/Eto - net40.sln b/Source/Eto - net40.sln new file mode 100644 index 0000000000..1f6adb8c75 --- /dev/null +++ b/Source/Eto - net40.sln @@ -0,0 +1,290 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +VisualStudioVersion = 12.0.30324.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto", "Eto\Eto.csproj", "{16289D2F-044C-49EF-83E9-9391AFF8FD2B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Gtk2", "Eto.Gtk\Eto.Gtk2.csproj", "{1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Mac", "Eto.Mac\Eto.Mac.csproj", "{9DD10DFF-5AB3-4E66-B798-CA17911A61E4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.WinForms", "Eto.WinForms\Eto.WinForms.csproj", "{69D38C57-AD4B-4A16-A7B1-49BCFBE71491}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Serialization.Json", "Eto.Serialization.Json\Eto.Serialization.Json.csproj", "{2F2C45E0-4142-44D0-8A0C-7264C0F925B2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Wpf", "Eto.Wpf\Eto.Wpf.csproj", "{E3524178-5A24-47C0-B155-92314FE4B2B6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.XamMac", "Eto.Mac\Eto.XamMac.csproj", "{15490F6C-C579-4A86-AD16-8D9B5B41EB87}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Gtk3", "Eto.Gtk\Eto.Gtk3.csproj", "{EECFE22F-A544-4498-AE2D-90C81BD2931A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{9D5A6006-2595-4E8E-8F54-9A4216E00370}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Direct2D", "Eto.Direct2D\Eto.Direct2D.csproj", "{3C1B77D5-6C93-4366-A487-3D307FC29FFB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Serialization.Xaml", "Eto.Serialization.Xaml\Eto.Serialization.Xaml.csproj", "{FA4BC167-9909-45D2-B86A-D4AE4062A524}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Mac", "Eto.Test\Eto.Test.Mac\Eto.Test.Mac.csproj", "{57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test", "Eto.Test\Eto.Test\Eto.Test.csproj", "{F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.WinForms", "Eto.Test\Eto.Test.WinForms\Eto.Test.WinForms.csproj", "{01118427-C412-4BC3-BD0C-E1DBC43FB479}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Direct2D", "Eto.Test\Eto.Test.Direct2D\Eto.Test.Direct2D.csproj", "{74328428-C412-4BC3-BD0C-E1DBC43FB479}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Gtk2", "Eto.Test\Eto.Test.Gtk2\Eto.Test.Gtk2.csproj", "{DD350D2E-149A-4EF1-8AAE-CBA9740B5735}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Wpf", "Eto.Test\Eto.Test.Wpf\Eto.Test.Wpf.csproj", "{DBAEAD48-6540-43FA-B86A-114ECCB15C7A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.XamMac", "Eto.Test\Eto.Test.Mac\Eto.Test.XamMac.csproj", "{5CFF5206-278B-4DE2-93AF-571B2121B5A7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Gtk3", "Eto.Test\Eto.Test.Gtk3\Eto.Test.Gtk3.csproj", "{B2148BDC-7D98-419B-B329-FF580FB481DE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Mac64", "Eto.Mac\Eto.Mac64.csproj", "{75EADBA0-15B4-11E4-8C21-0800200C9A66}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Linux = Debug|Linux + Debug|Mac = Debug|Mac + Debug|Windows = Debug|Windows + Release|Linux = Release|Linux + Release|Mac = Release|Mac + Release|Windows = Release|Windows + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Linux.ActiveCfg = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Linux.Build.0 = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Mac.ActiveCfg = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Mac.Build.0 = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.ActiveCfg = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.Build.0 = Debug|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Linux.ActiveCfg = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Linux.Build.0 = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Mac.ActiveCfg = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Mac.Build.0 = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.ActiveCfg = Release|Any CPU + {01118427-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.Build.0 = Release|Any CPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Debug|Linux.ActiveCfg = Debug|Any CPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Debug|Mac.ActiveCfg = Debug|Any CPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Debug|Mac.Build.0 = Debug|Any CPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Debug|Windows.ActiveCfg = Debug|Any CPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Release|Linux.ActiveCfg = Release|Any CPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Release|Mac.ActiveCfg = Release|Any CPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Release|Mac.Build.0 = Release|Any CPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87}.Release|Windows.ActiveCfg = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Linux.ActiveCfg = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Linux.Build.0 = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Mac.ActiveCfg = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Mac.Build.0 = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Windows.ActiveCfg = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Debug|Windows.Build.0 = Debug|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Linux.ActiveCfg = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Linux.Build.0 = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Mac.ActiveCfg = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Mac.Build.0 = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Windows.ActiveCfg = Release|Any CPU + {16289D2F-044C-49EF-83E9-9391AFF8FD2B}.Release|Windows.Build.0 = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Linux.ActiveCfg = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Linux.Build.0 = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Mac.ActiveCfg = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Mac.Build.0 = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Windows.ActiveCfg = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Debug|Windows.Build.0 = Debug|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Linux.ActiveCfg = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Linux.Build.0 = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Mac.ActiveCfg = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Mac.Build.0 = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Windows.ActiveCfg = Release|Any CPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1}.Release|Windows.Build.0 = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Linux.ActiveCfg = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Linux.Build.0 = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Mac.ActiveCfg = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Mac.Build.0 = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Windows.ActiveCfg = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Debug|Windows.Build.0 = Debug|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Linux.ActiveCfg = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Linux.Build.0 = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Mac.ActiveCfg = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Mac.Build.0 = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Windows.ActiveCfg = Release|Any CPU + {2F2C45E0-4142-44D0-8A0C-7264C0F925B2}.Release|Windows.Build.0 = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Debug|Linux.ActiveCfg = Debug|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Debug|Mac.ActiveCfg = Debug|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Debug|Windows.ActiveCfg = Debug|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Debug|Windows.Build.0 = Debug|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Linux.ActiveCfg = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Mac.ActiveCfg = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Mac.Build.0 = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Windows.ActiveCfg = Release|Any CPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB}.Release|Windows.Build.0 = Release|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Debug|Linux.ActiveCfg = Debug|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Debug|Mac.ActiveCfg = Debug|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Debug|Mac.Build.0 = Debug|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Debug|Windows.ActiveCfg = Debug|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Release|Linux.ActiveCfg = Release|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Release|Mac.ActiveCfg = Release|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Release|Mac.Build.0 = Release|Any CPU + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB}.Release|Windows.ActiveCfg = Release|Any CPU + {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Debug|Linux.ActiveCfg = Debug|Any CPU + {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Debug|Mac.ActiveCfg = Debug|Any CPU + {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Debug|Mac.Build.0 = Debug|Any CPU + {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Debug|Windows.ActiveCfg = Debug|Any CPU + {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Release|Linux.ActiveCfg = Release|Any CPU + {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Release|Mac.ActiveCfg = Release|Any CPU + {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Release|Mac.Build.0 = Release|Any CPU + {5CFF5206-278B-4DE2-93AF-571B2121B5A7}.Release|Windows.ActiveCfg = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Linux.ActiveCfg = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Linux.Build.0 = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Mac.ActiveCfg = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Mac.Build.0 = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Windows.ActiveCfg = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Debug|Windows.Build.0 = Debug|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Linux.ActiveCfg = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Linux.Build.0 = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Mac.ActiveCfg = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Mac.Build.0 = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Windows.ActiveCfg = Release|Any CPU + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491}.Release|Windows.Build.0 = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Linux.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Mac.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.Build.0 = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Linux.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Mac.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.Build.0 = Release|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Linux.ActiveCfg = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Linux.Build.0 = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Mac.ActiveCfg = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Mac.Build.0 = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Windows.ActiveCfg = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Debug|Windows.Build.0 = Debug|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Linux.ActiveCfg = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Linux.Build.0 = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Mac.ActiveCfg = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Mac.Build.0 = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Windows.ActiveCfg = Release|Any CPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4}.Release|Windows.Build.0 = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Linux.ActiveCfg = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Linux.Build.0 = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Mac.ActiveCfg = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Mac.Build.0 = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Windows.ActiveCfg = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Debug|Windows.Build.0 = Debug|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Linux.ActiveCfg = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Linux.Build.0 = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Mac.ActiveCfg = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Mac.Build.0 = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Windows.ActiveCfg = Release|Any CPU + {B2148BDC-7D98-419B-B329-FF580FB481DE}.Release|Windows.Build.0 = Release|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Debug|Linux.ActiveCfg = Debug|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Debug|Mac.ActiveCfg = Debug|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Debug|Windows.ActiveCfg = Debug|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Debug|Windows.Build.0 = Debug|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Release|Linux.ActiveCfg = Release|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Release|Mac.ActiveCfg = Release|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Release|Windows.ActiveCfg = Release|Any CPU + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A}.Release|Windows.Build.0 = Release|Any CPU + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Linux.ActiveCfg = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Linux.Build.0 = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Mac.ActiveCfg = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Mac.Build.0 = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Windows.ActiveCfg = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Debug|Windows.Build.0 = Debug|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Linux.ActiveCfg = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Linux.Build.0 = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Mac.ActiveCfg = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Mac.Build.0 = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Windows.ActiveCfg = Release|x86 + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735}.Release|Windows.Build.0 = Release|x86 + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Debug|Linux.ActiveCfg = Debug|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Debug|Mac.ActiveCfg = Debug|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Debug|Windows.ActiveCfg = Debug|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Debug|Windows.Build.0 = Debug|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Release|Linux.ActiveCfg = Release|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Release|Mac.ActiveCfg = Release|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Release|Windows.ActiveCfg = Release|Any CPU + {E3524178-5A24-47C0-B155-92314FE4B2B6}.Release|Windows.Build.0 = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Linux.ActiveCfg = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Linux.Build.0 = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Mac.ActiveCfg = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Mac.Build.0 = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Windows.ActiveCfg = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Debug|Windows.Build.0 = Debug|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Linux.ActiveCfg = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Linux.Build.0 = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Mac.ActiveCfg = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Mac.Build.0 = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Windows.ActiveCfg = Release|Any CPU + {EECFE22F-A544-4498-AE2D-90C81BD2931A}.Release|Windows.Build.0 = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Linux.ActiveCfg = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Linux.Build.0 = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Mac.ActiveCfg = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Mac.Build.0 = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Windows.ActiveCfg = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Debug|Windows.Build.0 = Debug|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Linux.ActiveCfg = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Linux.Build.0 = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Mac.ActiveCfg = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Mac.Build.0 = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Windows.ActiveCfg = Release|Any CPU + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5}.Release|Windows.Build.0 = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Linux.ActiveCfg = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Linux.Build.0 = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Mac.ActiveCfg = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Mac.Build.0 = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Windows.ActiveCfg = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Debug|Windows.Build.0 = Debug|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Linux.ActiveCfg = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Linux.Build.0 = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Mac.ActiveCfg = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Mac.Build.0 = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Windows.ActiveCfg = Release|Any CPU + {FA4BC167-9909-45D2-B86A-D4AE4062A524}.Release|Windows.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {57BCCF63-1D05-4AD6-9BBB-E2CE4E2451AB} = {D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8} + {F8F400B8-A2F6-4342-82F6-D6D8B544A7E5} = {D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8} + {01118427-C412-4BC3-BD0C-E1DBC43FB479} = {D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8} + {74328428-C412-4BC3-BD0C-E1DBC43FB479} = {D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8} + {DD350D2E-149A-4EF1-8AAE-CBA9740B5735} = {D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8} + {DBAEAD48-6540-43FA-B86A-114ECCB15C7A} = {D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8} + {5CFF5206-278B-4DE2-93AF-571B2121B5A7} = {D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8} + {B2148BDC-7D98-419B-B329-FF580FB481DE} = {D5AF5792-1085-4EC1-8C5D-B5A5FF98C8D8} + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Eto.Test\Eto.Test.Mac\Eto.Test.Mac.csproj + Policies = $0 + $0.DotNetNamingPolicy = $1 + $1.DirectoryNamespaceAssociation = PrefixedHierarchical + $1.ResourceNamePolicy = MSBuild + $0.TextStylePolicy = $2 + $2.FileWidth = 120 + $2.TabsToSpaces = False + $2.inheritsSet = VisualStudio + $2.inheritsScope = text/plain + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Source/Eto - net45.sln b/Source/Eto - net45.sln new file mode 100644 index 0000000000..f55f1f6754 --- /dev/null +++ b/Source/Eto - net45.sln @@ -0,0 +1,340 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto - Pcl", "Eto\Eto - Pcl.csproj", "{35EF0A4E-2A1A-492C-8BED-106774EA09F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Serialization.Json - Pcl", "Eto.Serialization.Json\Eto.Serialization.Json - Pcl.csproj", "{3F8178EF-0710-43F7-92E2-130B9BE2212D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Direct2D - Pcl", "Eto.Direct2D\Eto.Direct2D - Pcl.csproj", "{330EF9FD-5947-4AC9-9796-950C7633695F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.WinForms - Pcl", "Eto.WinForms\Eto.WinForms - Pcl.csproj", "{9F51798A-354C-47A1-9207-4BB7D7FC7FC4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Mac - Pcl", "Eto.Mac\Eto.Mac - Pcl.csproj", "{3E7995E0-C9EB-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Gtk2 - Pcl", "Eto.Gtk\Eto.Gtk2 - Pcl.csproj", "{80915A80-CA54-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Wpf - Pcl", "Eto.Wpf\Eto.Wpf - Pcl.csproj", "{63137FA0-CA55-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Gtk3 - Pcl", "Eto.Gtk\Eto.Gtk3 - Pcl.csproj", "{543B2F90-CA56-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.XamMac - Pcl", "Eto.Mac\Eto.XamMac - Pcl.csproj", "{BF405A10-C9EB-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Serialization.Xaml - Pcl", "Eto.Serialization.Xaml\Eto.Serialization.Xaml - Pcl.csproj", "{231FB3B0-CB71-11E3-9C1A-0800200C9A66}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{E121B009-AB4B-4585-B3FB-D70E3DF8D3CC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test - Pcl", "Eto.Test\Eto.Test\Eto.Test - Pcl.csproj", "{EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Gtk2 - Pcl", "Eto.Test\Eto.Test.Gtk2\Eto.Test.Gtk2 - Pcl.csproj", "{CC33FE70-CA54-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Gtk3 - Pcl", "Eto.Test\Eto.Test.Gtk3\Eto.Test.Gtk3 - Pcl.csproj", "{D70E9E90-CA54-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.WinForms - Pcl", "Eto.Test\Eto.Test.WinForms\Eto.Test.WinForms - Pcl.csproj", "{CF18B0BB-2C60-437F-8AA3-711ABAE11A91}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Wpf - Pcl", "Eto.Test\Eto.Test.Wpf\Eto.Test.Wpf - Pcl.csproj", "{DD0C2B40-CA55-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Mac - Pcl", "Eto.Test\Eto.Test.Mac\Eto.Test.Mac - Pcl.csproj", "{A4267C50-C9EB-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.XamMac - Pcl", "Eto.Test\Eto.Test.Mac\Eto.Test.XamMac - Pcl.csproj", "{9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Direct2D - Pcl", "Eto.Test\Eto.Test.Direct2D\Eto.Test.Direct2D - Pcl.csproj", "{74328428-C412-4BC3-BD0C-E1DBC43FB479}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.XamMac2", "Eto.Test\Eto.Test.Mac\Eto.Test.XamMac2.csproj", "{689E4C20-2702-11E4-8C21-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.Mac64 - Pcl", "Eto.Test\Eto.Test.Mac\Eto.Test.Mac64 - Pcl.csproj", "{B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.WinRT", "Eto.Test\Eto.Test.WinRT\Eto.Test.WinRT.csproj", "{DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{451A0C58-A0FE-4DAE-9B57-FB1450C2071B}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Mac64 - Pcl", "Eto.Mac\Eto.Mac64 - Pcl.csproj", "{55DAB390-1CFC-11E4-8C21-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.XamMac2 - Pcl", "Eto.Mac\Eto.XamMac2 - Pcl.csproj", "{856E8C70-2702-11E4-8C21-0800200C9A66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.WinRT", "Eto.WinRT\Eto.WinRT.csproj", "{4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Linux = Debug|Linux + Debug|Mac = Debug|Mac + Debug|Windows = Debug|Windows + Release|Linux = Release|Linux + Release|Mac = Release|Mac + Release|Windows = Release|Windows + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {231FB3B0-CB71-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Debug|Linux.ActiveCfg = Debug|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Debug|Mac.ActiveCfg = Debug|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Debug|Windows.ActiveCfg = Debug|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Debug|Windows.Build.0 = Debug|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Release|Linux.ActiveCfg = Release|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Release|Mac.ActiveCfg = Release|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Release|Mac.Build.0 = Release|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Release|Windows.ActiveCfg = Release|Any CPU + {330EF9FD-5947-4AC9-9796-950C7633695F}.Release|Windows.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Linux.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Linux.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Mac.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Mac.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Windows.ActiveCfg = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Debug|Windows.Build.0 = Debug|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Linux.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Linux.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Mac.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Mac.Build.0 = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Windows.ActiveCfg = Release|Any CPU + {35EF0A4E-2A1A-492C-8BED-106774EA09F2}.Release|Windows.Build.0 = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|Linux.ActiveCfg = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|Linux.Build.0 = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|Mac.ActiveCfg = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|Mac.Build.0 = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|Windows.ActiveCfg = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Debug|Windows.Build.0 = Debug|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|Linux.ActiveCfg = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|Linux.Build.0 = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|Mac.ActiveCfg = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|Mac.Build.0 = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|Windows.ActiveCfg = Release|Any CPU + {3F8178EF-0710-43F7-92E2-130B9BE2212D}.Release|Windows.Build.0 = Release|Any CPU + {4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}.Debug|Linux.ActiveCfg = Debug|Any CPU + {4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}.Debug|Mac.ActiveCfg = Debug|Any CPU + {4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}.Debug|Windows.ActiveCfg = Debug|Any CPU + {4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}.Debug|Windows.Build.0 = Debug|Any CPU + {4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}.Release|Linux.ActiveCfg = Release|Any CPU + {4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}.Release|Mac.ActiveCfg = Release|Any CPU + {4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}.Release|Windows.ActiveCfg = Release|Any CPU + {4C2B4FA7-5C94-4582-82CB-FC856BEBFE75}.Release|Windows.Build.0 = Release|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {543B2F90-CA56-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {63137FA0-CA55-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {689E4C20-2702-11E4-8C21-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {689E4C20-2702-11E4-8C21-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {689E4C20-2702-11E4-8C21-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {689E4C20-2702-11E4-8C21-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {689E4C20-2702-11E4-8C21-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {689E4C20-2702-11E4-8C21-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {689E4C20-2702-11E4-8C21-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {689E4C20-2702-11E4-8C21-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Linux.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Mac.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.ActiveCfg = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Debug|Windows.Build.0 = Debug|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Linux.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Mac.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.ActiveCfg = Release|Any CPU + {74328428-C412-4BC3-BD0C-E1DBC43FB479}.Release|Windows.Build.0 = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {80915A80-CA54-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {856E8C70-2702-11E4-8C21-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {856E8C70-2702-11E4-8C21-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {856E8C70-2702-11E4-8C21-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {856E8C70-2702-11E4-8C21-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {856E8C70-2702-11E4-8C21-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {856E8C70-2702-11E4-8C21-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {856E8C70-2702-11E4-8C21-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {856E8C70-2702-11E4-8C21-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Linux.ActiveCfg = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Linux.Build.0 = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Mac.ActiveCfg = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Mac.Build.0 = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Windows.ActiveCfg = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Debug|Windows.Build.0 = Debug|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Linux.ActiveCfg = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Linux.Build.0 = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Mac.ActiveCfg = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Mac.Build.0 = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Windows.ActiveCfg = Release|Any CPU + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4}.Release|Windows.Build.0 = Release|Any CPU + {A4267C50-C9EB-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {A4267C50-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {A4267C50-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {A4267C50-C9EB-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {A4267C50-C9EB-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {A4267C50-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {A4267C50-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {A4267C50-C9EB-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Debug|Linux.ActiveCfg = Debug|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Debug|Linux.Build.0 = Debug|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Debug|Mac.ActiveCfg = Debug|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Debug|Mac.Build.0 = Debug|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Debug|Windows.ActiveCfg = Debug|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Debug|Windows.Build.0 = Debug|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Release|Linux.ActiveCfg = Release|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Release|Linux.Build.0 = Release|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Release|Mac.ActiveCfg = Release|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Release|Mac.Build.0 = Release|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Release|Windows.ActiveCfg = Release|Any CPU + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689}.Release|Windows.Build.0 = Release|Any CPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Debug|Linux.Build.0 = Debug|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Release|Linux.Build.0 = Release|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|x86 + {CC33FE70-CA54-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|x86 + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Debug|Linux.ActiveCfg = Debug|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Debug|Linux.Build.0 = Debug|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Debug|Mac.ActiveCfg = Debug|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Debug|Mac.Build.0 = Debug|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Debug|Windows.ActiveCfg = Debug|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Debug|Windows.Build.0 = Debug|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Release|Linux.ActiveCfg = Release|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Release|Linux.Build.0 = Release|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Release|Mac.ActiveCfg = Release|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Release|Mac.Build.0 = Release|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Release|Windows.ActiveCfg = Release|Any CPU + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91}.Release|Windows.Build.0 = Release|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Debug|Linux.Build.0 = Debug|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Debug|Mac.Build.0 = Debug|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Release|Linux.Build.0 = Release|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Release|Mac.Build.0 = Release|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {D70E9E90-CA54-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66}.Debug|Linux.ActiveCfg = Debug|Any CPU + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66}.Debug|Mac.ActiveCfg = Debug|Any CPU + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66}.Debug|Windows.ActiveCfg = Debug|Any CPU + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66}.Debug|Windows.Build.0 = Debug|Any CPU + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66}.Release|Linux.ActiveCfg = Release|Any CPU + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66}.Release|Mac.ActiveCfg = Release|Any CPU + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66}.Release|Windows.ActiveCfg = Release|Any CPU + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66}.Release|Windows.Build.0 = Release|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Debug|Linux.ActiveCfg = Debug|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Debug|Mac.ActiveCfg = Debug|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Debug|Windows.ActiveCfg = Debug|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Debug|Windows.Build.0 = Debug|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Debug|Windows.Deploy.0 = Debug|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Release|Linux.ActiveCfg = Release|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Release|Mac.ActiveCfg = Release|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Release|Windows.ActiveCfg = Release|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Release|Windows.Build.0 = Release|Any CPU + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F}.Release|Windows.Deploy.0 = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|Linux.ActiveCfg = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|Linux.Build.0 = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|Mac.ActiveCfg = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|Mac.Build.0 = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|Windows.ActiveCfg = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Debug|Windows.Build.0 = Debug|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|Linux.ActiveCfg = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|Linux.Build.0 = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|Mac.ActiveCfg = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|Mac.Build.0 = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|Windows.ActiveCfg = Release|Any CPU + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1}.Release|Windows.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {EB9C0A22-6644-46E4-948C-F7C95E1F8CE1} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {CC33FE70-CA54-11E3-9C1A-0800200C9A66} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {D70E9E90-CA54-11E3-9C1A-0800200C9A66} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {CF18B0BB-2C60-437F-8AA3-711ABAE11A91} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {DD0C2B40-CA55-11E3-9C1A-0800200C9A66} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {A4267C50-C9EB-11E3-9C1A-0800200C9A66} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {9CEE7E60-C9EB-11E3-9C1A-0800200C9A66} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {74328428-C412-4BC3-BD0C-E1DBC43FB479} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {689E4C20-2702-11E4-8C21-0800200C9A66} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {B5BC1D10-24ED-441C-A4D6-1F3AB9FF3689} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + {DFAC63ED-7563-4F09-97E0-9FC3F0FD552F} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC} + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Eto.Test\Eto.Test.Mac\Eto.Test.Mac - Pcl.csproj + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Source/Eto.Android/Conversions.cs b/Source/Eto.Android/Conversions.cs new file mode 100644 index 0000000000..a9ea1701c9 --- /dev/null +++ b/Source/Eto.Android/Conversions.cs @@ -0,0 +1,329 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; +using Eto.Android.Drawing; + +namespace Eto.Android +{ + public static class Conversions + { + public static Padding GetPadding(this av.View view) + { + return new Padding(view.PaddingLeft, view.PaddingTop, view.PaddingRight, view.PaddingBottom); + } + + public static void SetPadding(this av.View view, Padding padding) + { + view.SetPadding(padding.Left, padding.Top, padding.Right, padding.Bottom); + } + + public static Color ToEto(this global::Android.Content.Res.ColorStateList colors) + { + return Color.FromArgb(colors.DefaultColor); + } + + public static Color ToEto(this ag.Color color) + { + return Color.FromArgb(color.R, color.G, color.B, color.A); + } + + public static ag.Color ToAndroid(this Color color) + { + return new ag.Color((int)color.ToArgb()); + } + + public static ag.Paint ToAndroid(this Pen pen) + { + return (ag.Paint)pen.ControlObject; + } + + public static ag.Paint ToAndroid(this Brush brush) + { + return ((BrushHandler)brush.Handler).GetPaint(brush); + } + + public static MouseEventArgs ToEto(av.MotionEvent e) + { + if (e.Action == av.MotionEventActions.Down) + { + return new MouseEventArgs(MouseButtons.Primary, Keys.None, new PointF(e.GetX(), e.GetY())); + } + // Is this correct? It generates a mouse event for pointer-up and cancel actions + // See the iOS handler as well, which does something similar + return new MouseEventArgs(MouseButtons.Primary, Keys.None, Point.Empty); + } + + public static ag.Paint.Join ToAndroid(this PenLineJoin value) + { + switch (value) + { + case PenLineJoin.Miter: + return ag.Paint.Join.Miter; + case PenLineJoin.Bevel: + return ag.Paint.Join.Bevel; + case PenLineJoin.Round: + return ag.Paint.Join.Round; + default: + throw new NotSupportedException(); + } + } + + public static PenLineJoin ToEto(this ag.Paint.Join value) + { + if (object.ReferenceEquals(value, ag.Paint.Join.Bevel)) + return PenLineJoin.Bevel; + if (object.ReferenceEquals(value, ag.Paint.Join.Miter)) + return PenLineJoin.Miter; + if (object.ReferenceEquals(value, ag.Paint.Join.Round)) + return PenLineJoin.Round; + throw new NotSupportedException(); + } + + public static ag.Paint.Cap ToSD(this PenLineCap value) + { + switch (value) + { + case PenLineCap.Butt: + return ag.Paint.Cap.Butt; + case PenLineCap.Round: + return ag.Paint.Cap.Round; + case PenLineCap.Square: + return ag.Paint.Cap.Square; + default: + throw new NotSupportedException(); + } + } + + public static PenLineCap ToEto(this ag.Paint.Cap value) + { + if (object.ReferenceEquals(value, ag.Paint.Cap.Butt)) + return PenLineCap.Butt; + if (object.ReferenceEquals(value, ag.Paint.Cap.Round)) + return PenLineCap.Round; + if (object.ReferenceEquals(value, ag.Paint.Cap.Square)) + return PenLineCap.Square; + throw new NotSupportedException(); + } + + public static ag.Matrix ToAndroid(this IMatrix m) + { + return (ag.Matrix)m.ControlObject; + } + + public static Point ToEto(this ag.Point point) + { + return new Point(point.X, point.Y); + } + + public static PointF ToEto(this ag.PointF point) + { + return new PointF(point.X, point.Y); + } + + public static ag.PointF ToAndroid(this PointF point) + { + return new ag.PointF(point.X, point.Y); + } + + public static ag.Point ToAndroidPoint(this PointF point) + { + return new ag.Point((int)point.X, (int)point.Y); + } + + public static Rectangle ToEto(this ag.Rect rect) + { + return new Rectangle(rect.Left, rect.Top, rect.Width(), rect.Height()); + } + + public static RectangleF ToEto(this ag.RectF rect) + { + return new RectangleF(rect.Left, rect.Top, rect.Width(), rect.Height()); + } + + public static ag.Rect ToAndroid(this Rectangle rect) + { + return new ag.Rect(rect.X, rect.Y, rect.Width, rect.Height); + } + + public static ag.RectF ToAndroid(this RectangleF rect) + { + return new ag.RectF(rect.X, rect.Y, rect.Width, rect.Height); + } + + public static ag.Rect ToAndroidRectangle(this RectangleF rect) + { + return new ag.Rect((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height); + } + + internal static ag.Point[] ToAndroid(this Point[] points) + { + var result = + new ag.Point[points.Length]; + + for (var i = 0; + i < points.Length; + ++i) + { + var p = points[i]; + result[i] = + new ag.Point(p.X, p.Y); + } + + return result; + } + + internal static ag.PointF[] ToAndroid(this PointF[] points) + { + var result = + new ag.PointF[points.Length]; + + for (var i = 0; + i < points.Length; + ++i) + { + var p = points[i]; + result[i] = + new ag.PointF(p.X, p.Y); + } + + return result; + } + + internal static PointF[] ToEto(this ag.PointF[] points) + { + var result = + new PointF[points.Length]; + + for (var i = 0; + i < points.Length; + ++i) + { + var p = points[i]; + result[i] = + new PointF(p.X, p.Y); + } + + return result; + } + + public static GraphicsPathHandler ToHandler(this IGraphicsPath path) + { + return ((GraphicsPathHandler)path.ControlObject); + } + + public static ag.Path ToAndroid(this IGraphicsPath path) + { + return ((GraphicsPathHandler)path.ControlObject).Control; + } + + public static ag.TypefaceStyle ToAndroid(this FontStyle style) + { + var ret = ag.TypefaceStyle.Normal; + if ((style & FontStyle.Bold) != 0) + ret = ag.TypefaceStyle.Bold; + if ((style & FontStyle.Italic) != 0) + ret = ag.TypefaceStyle.Italic; + return ret; + } + + public static FontStyle ToEto(this ag.TypefaceStyle style) + { + var ret = FontStyle.None; + if (style == ag.TypefaceStyle.Normal) + ret = FontStyle.None; + else if (style == ag.TypefaceStyle.Bold) + ret = FontStyle.Bold; + else if (style == ag.TypefaceStyle.Italic) + ret = FontStyle.Italic; + return ret; + } + + public static HorizontalAlign ToEtoHorizontal(this av.GravityFlags gravity) + { + switch (gravity & av.GravityFlags.HorizontalGravityMask) + { + case av.GravityFlags.CenterHorizontal: + return HorizontalAlign.Center; + case av.GravityFlags.Left: + return HorizontalAlign.Left; + case av.GravityFlags.Right: + return HorizontalAlign.Right; + default: + throw new NotSupportedException(); + } + } + + public static av.GravityFlags ToAndroid(this HorizontalAlign value) + { + switch (value) + { + case HorizontalAlign.Center: + return av.GravityFlags.CenterHorizontal; + case HorizontalAlign.Right: + return av.GravityFlags.Right; + case HorizontalAlign.Left: + return av.GravityFlags.Left; + default: + throw new NotSupportedException(); + } + } + + public static VerticalAlign ToEtoVertical(this av.GravityFlags gravity) + { + switch (gravity & av.GravityFlags.VerticalGravityMask) + { + case av.GravityFlags.CenterVertical: + return VerticalAlign.Middle; + case av.GravityFlags.Top: + return VerticalAlign.Top; + case av.GravityFlags.Bottom: + return VerticalAlign.Bottom; + default: + throw new NotSupportedException(); + } + } + + public static av.GravityFlags ToAndroid(this VerticalAlign value) + { + switch (value) + { + case VerticalAlign.Middle: + return av.GravityFlags.CenterVertical; + case VerticalAlign.Top: + return av.GravityFlags.Top; + case VerticalAlign.Bottom: + return av.GravityFlags.Bottom; + default: + throw new NotSupportedException(); + } + } + + public static ag.Bitmap ToAndroid(this Image image) + { + var handler = (IAndroidImage)image.Handler; + return handler.GetImageWithSize(null); + } + public static ag.Drawables.BitmapDrawable ToAndroidDrawable(this Image image) + { + var bmp = image.ToAndroid(); + return bmp != null ? new ag.Drawables.BitmapDrawable(aa.Application.Context.Resources, bmp) : null; + } + + public static ag.Typeface ToAndroid(this Font font) + { + return FontHandler.GetControl(font); + } + + public static Font ToEto(this ag.Typeface typeface) + { + return new Font(new FontHandler(typeface)); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/BitmapHandler.cs b/Source/Eto.Android/Drawing/BitmapHandler.cs new file mode 100644 index 0000000000..9e111184ee --- /dev/null +++ b/Source/Eto.Android/Drawing/BitmapHandler.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + /// + /// Interface for all Android images + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public interface IAndroidImage + { + ag.Bitmap GetImageWithSize(int? size); + + void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination); + + void DrawImage(GraphicsHandler graphics, float x, float y); + + void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height); + } + + + /// + /// Bitmap handler. + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + class BitmapHandler : WidgetHandler, Bitmap.IHandler, IAndroidImage + { + public BitmapHandler() + { + } + + public BitmapHandler(ag.Bitmap image) + { + Control = image; + } + + public void Create(string fileName) + { + Control = ag.BitmapFactory.DecodeFile(fileName); + } + + public void Create(System.IO.Stream stream) + { + Control = ag.BitmapFactory.DecodeStream(stream); + } + + public void Create(int width, int height, PixelFormat pixelFormat) + { + ag.Bitmap.Config config = ag.Bitmap.Config.Argb8888; + switch(pixelFormat) + { + /*case PixelFormat.Format24bppRgb: + config = ag.Bitmap.Config.Argb8888; + break;*/ + case PixelFormat.Format32bppRgb: + case PixelFormat.Format32bppRgba: + config = ag.Bitmap.Config.Argb8888; + break; + default: + throw new ArgumentOutOfRangeException("pixelFormat", pixelFormat, "Not supported"); + } + + Control = ag.Bitmap.CreateBitmap(width, height, config); + } + + public void Create(int width, int height, Graphics graphics) + { + throw new NotImplementedException(); + } + + public void Create(Image image, int width, int height, ImageInterpolation interpolation) + { + Control = ag.Bitmap.CreateScaledBitmap(image.ToAndroid(), width, height, false); + } + + public void Save(System.IO.Stream stream, ImageFormat format) + { + ag.Bitmap.CompressFormat compressFormat; + if(format == ImageFormat.Jpeg) + compressFormat =ag.Bitmap.CompressFormat.Jpeg; + else if(format == ImageFormat.Png) + compressFormat = ag.Bitmap.CompressFormat.Png; + else + throw new ArgumentException("ImageFormat must be Jpeg or Png"); + Control.Compress(compressFormat, 100, stream); // 100 means maximum quality. Png ignores this since it is lossless. + } + + public Bitmap Clone(Rectangle? rectangle = null) + { + if (rectangle != null) + { + var r = rectangle.Value; + return new Bitmap(new BitmapHandler( + ag.Bitmap.CreateBitmap(this.Control, r.X, r.Y, r.Width, r.Height))); + } + else + return new Bitmap(new BitmapHandler(ag.Bitmap.CreateBitmap(this.Control))); + } + + public Color GetPixel(int x, int y) + { + return new ag.Color(Control.GetPixel(x, y)).ToEto(); + } + + public Size Size + { + get { return new Size(Control.Width, Control.Height); } + } + + public BitmapData Lock() + { + throw new NotImplementedException(); + } + + public void Unlock(BitmapData bitmapData) + { + throw new NotImplementedException(); + } + + public ag.Bitmap GetImageWithSize(int? size) + { + return Control; + } + + public void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) + { + graphics.Control.DrawBitmap(Control, new Rectangle(source).ToAndroid(), destination.ToAndroid(), paint: null); + } + + public void DrawImage(GraphicsHandler graphics, float x, float y) + { + graphics.Control.DrawBitmap(Control, x, y, paint: null); + } + + public void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height) + { + graphics.Control.DrawBitmap(Control, null, new RectangleF(x, y, width, height).ToAndroid(), paint: null); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/BrushHandler.cs b/Source/Eto.Android/Drawing/BrushHandler.cs new file mode 100644 index 0000000000..6af7436641 --- /dev/null +++ b/Source/Eto.Android/Drawing/BrushHandler.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + public abstract class BrushHandler + { + public abstract ag.Paint GetPaint(Brush brush); + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/FontFamilyHandler.cs b/Source/Eto.Android/Drawing/FontFamilyHandler.cs new file mode 100644 index 0000000000..41460d7568 --- /dev/null +++ b/Source/Eto.Android/Drawing/FontFamilyHandler.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + public class FontFamilyHandler : WidgetHandler, FontFamily.IHandler + { + public string Name + { + get { return Control.Class.Name; } + } + + public IEnumerable Typefaces + { + get { throw new NotImplementedException(); } + } + + public void Create(string familyName) + { + Control = ag.Typeface.Create(familyName, ag.TypefaceStyle.Normal); // the style doesn't matter + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/FontHandler.cs b/Source/Eto.Android/Drawing/FontHandler.cs new file mode 100644 index 0000000000..5414340c80 --- /dev/null +++ b/Source/Eto.Android/Drawing/FontHandler.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class FontHandler : WidgetHandler, Font.IHandler + { + float size; + /// + /// Used by GraphicsHandler.MeasureText + /// + ag.Paint paint; + public ag.Paint Paint + { + get + { + if (paint == null) + { + paint = new ag.Paint(); + paint.SetTypeface(this.Control); + } + return paint; + } + } + + ag.Paint.FontMetrics fontMetrics; + ag.Paint.FontMetrics FontMetrics { get { return fontMetrics = fontMetrics ?? Paint.GetFontMetrics(); } } + + public FontHandler() + { + } + + public FontHandler(ag.Typeface typeface) + { + Control = typeface; + } + + public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) + { + this.size = size; + this.Control = ag.Typeface.Create(family.ControlObject as ag.Typeface, style.ToAndroid()); + } + + // TODO: + public void Create(SystemFont systemFont, float? size, FontDecoration decoration) + { + var style = ag.TypefaceStyle.Normal; + switch (systemFont) + { + case SystemFont.Default: + break; + case SystemFont.Bold: + break; + case SystemFont.Label: + break; + case SystemFont.TitleBar: + break; + case SystemFont.ToolTip: + break; + case SystemFont.MenuBar: + break; + case SystemFont.Menu: + break; + case SystemFont.Message: + break; + case SystemFont.Palette: + break; + case SystemFont.StatusBar: + break; + default: + break; + } + + Control = ag.Typeface.Create(ag.Typeface.Default, style); + } + + public void Create(FontTypeface typeface, float size, FontDecoration decoration) + { + this.size = size; + this.Control = ag.Typeface.Create(typeface.Family.Name, typeface.FontStyle.ToAndroid()); + } + + public float XHeight + { + get { throw new NotImplementedException(); } + } + + public float Ascent + { + get { return Math.Abs(FontMetrics.Ascent); } // TODO: does this need to be scaled? + } + + public float Descent + { + get { return Math.Abs(FontMetrics.Descent); } // TODO: does this need to be scaled? + } + + public float LineHeight + { + get { throw new NotImplementedException(); } + } + + public float Leading + { + get { return Math.Abs(FontMetrics.Leading); } // TODO: does this need to be scaled? + } + + public float Baseline + { + get { throw new NotImplementedException(); } + } + + public float Size + { + get { throw new NotImplementedException(); } + } + + public string FamilyName + { + get { throw new NotImplementedException(); } + } + + public FontStyle FontStyle + { + get { throw new NotImplementedException(); } + } + + public FontDecoration FontDecoration + { + get { throw new NotImplementedException(); } + } + + public FontFamily Family + { + get { throw new NotImplementedException(); } + } + + public FontTypeface Typeface + { + get { throw new NotImplementedException(); } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/FontTypefaceHandler.cs b/Source/Eto.Android/Drawing/FontTypefaceHandler.cs new file mode 100644 index 0000000000..8fbbf64b37 --- /dev/null +++ b/Source/Eto.Android/Drawing/FontTypefaceHandler.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + class FontTypefaceHandler : WidgetHandler, FontTypeface.IHandler + { + public FontTypefaceHandler(ag.TypefaceStyle style) + { + this.Control = style; + Name = this.FontStyle.ToString().Replace(',', ' '); + } + + public string Name { get; set; } + + public FontStyle FontStyle + { + get { return Control.ToEto(); } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/FontsHandler.cs b/Source/Eto.Android/Drawing/FontsHandler.cs new file mode 100644 index 0000000000..0387ecb20a --- /dev/null +++ b/Source/Eto.Android/Drawing/FontsHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + class FontsHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/GraphicsHandler.cs b/Source/Eto.Android/Drawing/GraphicsHandler.cs new file mode 100644 index 0000000000..d3545635c5 --- /dev/null +++ b/Source/Eto.Android/Drawing/GraphicsHandler.cs @@ -0,0 +1,209 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class GraphicsHandler : WidgetHandler, Graphics.IHandler + { + public GraphicsHandler() + { + } + + public float PointsPerPixel { get { return 1f; } } // TODO + + public PixelOffsetMode PixelOffsetMode { get; set; } // TODO + + public void CreateFromImage(Bitmap image) + { + Control = new ag.Canvas((ag.Bitmap)image.ControlObject); + } + + public void DrawLine(Pen pen, float startx, float starty, float endx, float endy) + { + Control.DrawLine(startx, starty, endx, endy, pen.ToAndroid()); + } + + public void DrawRectangle(Pen pen, float x, float y, float width, float height) + { + Control.DrawRect(new RectangleF(x, y, width, height).ToAndroid(), pen.ToAndroid()); + } + + public void FillRectangle(Brush brush, float x, float y, float width, float height) + { + Control.DrawRect(new RectangleF(x, y, width, height).ToAndroid(), brush.ToAndroid()); + } + + public void FillEllipse(Brush brush, float x, float y, float width, float height) + { + Control.DrawOval(new RectangleF(x, y, width, height).ToAndroid(), brush.ToAndroid()); + } + + public void DrawEllipse(Pen pen, float x, float y, float width, float height) + { + Control.DrawOval(new RectangleF(x, y, width, height).ToAndroid(), pen.ToAndroid()); + } + + public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) + { + Control.DrawArc(new RectangleF(x, y, width, height).ToAndroid(), startAngle, sweepAngle, false, pen.ToAndroid()); + } + + public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) + { + Control.DrawArc(new RectangleF(x, y, width, height).ToAndroid(), startAngle, sweepAngle, true, brush.ToAndroid()); + } + + public void FillPath(Brush brush, IGraphicsPath path) + { + Control.DrawPath(path.ToAndroid(), brush.ToAndroid()); + } + + public void DrawPath(Pen pen, IGraphicsPath path) + { + Control.DrawPath(path.ToAndroid(), pen.ToAndroid()); + } + + public void DrawImage(Image image, float x, float y) + { + var handler = image.Handler as IAndroidImage; + handler.DrawImage(this, x, y); + } + + public void DrawImage(Image image, float x, float y, float width, float height) + { + var handler = image.Handler as IAndroidImage; + handler.DrawImage(this, x, y, width, height); + } + + public void DrawImage(Image image, RectangleF source, RectangleF destination) + { + var handler = image.Handler as IAndroidImage; + handler.DrawImage(this, source, destination); + } + + + public void DrawText(Font font, SolidBrush brush, float x, float y, string text) + { + var paint = GetTextPaint(font); + paint.Color = brush.ToAndroid().Color; // this overwrites the color on the cached paint, but that's ok since it is only used here. + Control.DrawText(text, x, y, paint); + } + + public SizeF MeasureString(Font font, string text) + { + if(string.IsNullOrEmpty(text)) // needed to avoid exception + return SizeF.Empty; + var paint = GetTextPaint(font); + + // See http://stackoverflow.com/questions/7549182/android-paint-measuretext-vs-gettextbounds + var bounds = new ag.Rect(); + paint.GetTextBounds(text, 0, text.Length, bounds); + + // TODO: see the above article; the width may be truncated to the nearest integer. + return new SizeF(bounds.Width(), bounds.Height()); + } + + /// + /// Returns a Paint that is cached on the font. + /// This is used by all font operations (across all Canvases) that use the same font. + /// + private ag.Paint GetTextPaint(Font font) + { + var paint = (font.Handler as FontHandler).Paint; + paint.AntiAlias = AntiAlias; + return paint; + } + + public void Flush() + { + } + + // The ANTI_ALIAS flag on Paint (not Canvas) causes it to render antialiased. + // SUBPIXEL_TEXT_FLAG is currently unsupported on Android. + // See http://stackoverflow.com/questions/4740565/meaning-of-some-paint-constants-in-android + public bool AntiAlias { get; set; } + + // TODO: setting the FILTER_BITMAP_FLAG on Paint (not Canvas) + // causes it to do a bilinear interpolation. + public ImageInterpolation ImageInterpolation { get; set; } + + public bool IsRetained + { + get { return false; } + } + + public void TranslateTransform(float offsetX, float offsetY) + { + Control.Translate(offsetX, offsetY); + } + + public void RotateTransform(float angle) + { + Control.Rotate(angle); + } + + public void ScaleTransform(float scaleX, float scaleY) + { + Control.Scale(scaleX, scaleY); + } + + public void MultiplyTransform(IMatrix matrix) + { + Control.Concat(matrix.ToAndroid()); + } + + public void SaveTransform() + { + Control.Save(ag.SaveFlags.Matrix); + } + + public void RestoreTransform() + { + Control.Restore(); + } + + public RectangleF ClipBounds + { + get { return Control.ClipBounds.ToEto(); } + } + + public void SetClip(RectangleF rectangle) + { + Control.ClipRect(rectangle.ToAndroid(), ag.Region.Op.Replace); + } + + public void SetClip(IGraphicsPath path) + { + // NOTE: This may not work with hardware acceleration. + // See http://developer.android.com/guide/topics/graphics/hardware-accel.html#drawing-support + // See http://stackoverflow.com/questions/16889815/canvas-clippath-only-works-on-android-emulator + Control.ClipPath(path.ToAndroid(), ag.Region.Op.Replace); + } + + public void ResetClip() + { + Control.ClipRect(new ag.Rect(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue)); + } + + public void Clear(SolidBrush brush) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/GraphicsPathHandler.cs b/Source/Eto.Android/Drawing/GraphicsPathHandler.cs new file mode 100644 index 0000000000..aa0fed1720 --- /dev/null +++ b/Source/Eto.Android/Drawing/GraphicsPathHandler.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class GraphicsPathHandler : GraphicsPath.IHandler + { + public ag.Path Control { get; private set; } + ag.PointF position; + + public GraphicsPathHandler() + { + Control = new ag.Path(); + } + + public GraphicsPathHandler(ag.Path control) + { + Control = control; + } + + public RectangleF Bounds + { + get { throw new NotImplementedException(); } + } + + public FillMode FillMode + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool IsEmpty + { + get { return Control.IsEmpty; } + } + + public PointF CurrentPoint + { + get { throw new NotImplementedException(); } + } + + public void AddLine(float startX, float startY, float endX, float endY) + { + this.Control.MoveTo(startX, startY); + this.Control.LineTo(endX, endY); + position = new ag.PointF(endX, endY); + } + + public void AddLines(IEnumerable points) + { + throw new NotImplementedException(); + } + + public void LineTo(float x, float y) + { + throw new NotImplementedException(); + } + + public void MoveTo(float x, float y) + { + throw new NotImplementedException(); + } + + public void AddArc(float x, float y, float width, float height, float startAngle, float sweepAngle) + { + throw new NotImplementedException(); + } + + public void AddBezier(PointF start, PointF control1, PointF control2, PointF end) + { + throw new NotImplementedException(); + } + + public void AddCurve(IEnumerable points, float tension = 0.5f) + { + throw new NotImplementedException(); + } + + public void AddEllipse(float x, float y, float width, float height) + { + throw new NotImplementedException(); + } + + public void AddRectangle(float x, float y, float width, float height) + { + throw new NotImplementedException(); + } + + public void AddPath(IGraphicsPath path, bool connect = false) + { + throw new NotImplementedException(); + } + + public void Transform(IMatrix matrix) + { + throw new NotImplementedException(); + } + + public void StartFigure() + { + throw new NotImplementedException(); + } + + public void CloseFigure() + { + throw new NotImplementedException(); + } + + public IGraphicsPath Clone() + { + return new GraphicsPathHandler(new ag.Path(this.Control)); + } + + public void Dispose() + { + Control.Dispose(); + } + + public object ControlObject + { + get { return this; } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/IconHandler.cs b/Source/Eto.Android/Drawing/IconHandler.cs new file mode 100644 index 0000000000..20befc98e6 --- /dev/null +++ b/Source/Eto.Android/Drawing/IconHandler.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + class IconHandler : WidgetHandler, Icon.IHandler, IAndroidImage + { + public void Create(System.IO.Stream stream) + { + Control = ag.BitmapFactory.DecodeStream(stream); + } + + public void Create(string fileName) + { + Control = ag.BitmapFactory.DecodeFile(fileName); + } + public Size Size + { + get { return new Size(Control.Width, Control.Height); } + } + + public ag.Bitmap GetImageWithSize(int? size) + { + throw new NotImplementedException(); + } + + public void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) + { + graphics.Control.DrawBitmap(Control, new Rectangle(source).ToAndroid(), destination.ToAndroid(), paint: null); + } + + public void DrawImage(GraphicsHandler graphics, float x, float y) + { + graphics.Control.DrawBitmap(Control, x, y, paint: null); + } + + public void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height) + { + graphics.Control.DrawBitmap(Control, null, new RectangleF(x, y, width, height).ToAndroid(), paint: null); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Android/Drawing/IndexedBitmapHandler.cs new file mode 100644 index 0000000000..f23988d4f4 --- /dev/null +++ b/Source/Eto.Android/Drawing/IndexedBitmapHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + class IndexedBitmapHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/LinearGradientBrushHandler.cs b/Source/Eto.Android/Drawing/LinearGradientBrushHandler.cs new file mode 100644 index 0000000000..c78c3ce5dd --- /dev/null +++ b/Source/Eto.Android/Drawing/LinearGradientBrushHandler.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + public class LinearGradientBrushHandler : BrushHandler, LinearGradientBrush.IHandler + { + // TODO: Android does not have the concept of a linear + class BrushObject + { + public ag.Paint Paint { get; set; } + public ag.Matrix InitialMatrix { get; set; } + public IMatrix Matrix { get; set; } + } + + public override ag.Paint GetPaint(Brush brush) + { + return ((BrushObject)brush.ControlObject).Paint; + } + + public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint) + { + var shader = new ag.LinearGradient(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, startColor.ToAndroid(), endColor.ToAndroid(), + // is this correct? + ag.Shader.TileMode.Clamp); + var paint = new ag.Paint(); + paint.SetShader(shader); + return new BrushObject { Paint = paint }; // TODO: initial matrix + } + + public object Create(RectangleF rectangle, Color startColor, Color endColor, float angle) + { + throw new NotImplementedException(); + } + + public IMatrix GetTransform(LinearGradientBrush widget) + { + throw new NotImplementedException(); + } + + public void SetTransform(LinearGradientBrush widget, IMatrix transform) + { + throw new NotImplementedException(); + } + + public GradientWrapMode GetGradientWrap(LinearGradientBrush widget) + { + throw new NotImplementedException(); + } + + public void SetGradientWrap(LinearGradientBrush widget, GradientWrapMode gradientWrap) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/MatrixHandler.cs b/Source/Eto.Android/Drawing/MatrixHandler.cs new file mode 100644 index 0000000000..53a26bb93b --- /dev/null +++ b/Source/Eto.Android/Drawing/MatrixHandler.cs @@ -0,0 +1,232 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class MatrixHandler : Matrix.IHandler, IDisposable + { + ag.Matrix control; + + public ag.Matrix Control { get { return control; } } + + object IControlObjectSource.ControlObject { get { return control; } } + + public MatrixHandler() + { + } + + public MatrixHandler(ag.Matrix matrix) + { + control = matrix; + } + + public float[] Elements + { + get + { + var nineValues = NineValues; + var result = new float[6] + { + nineValues[0], nineValues[1], // array[2] not copied as it is always 1 + nineValues[3], nineValues[4], // array[5] not copied as it is always 1 + nineValues[6], nineValues[7] // array[8] not copied as it is always 1 + }; + + return result; + } + } + + private float[] NineValues + { + get + { + var nineValues = new float[9]; + control.GetValues(nineValues); + return nineValues; + } + } + + private void SetValue(int indexInNineValues, float value) + { + var nineValues = new float[9]; + control.GetValues(nineValues); + nineValues[indexInNineValues] = value; + control.SetValues(nineValues); + } + + public float Xx + { + get { return NineValues[0]; } + set { SetValue(0, value); } + } + + public float Xy + { + get { return NineValues[1]; } + set { SetValue(1, value); } + } + + public float Yx + { + get { return NineValues[3]; } + set { SetValue(3, value); } + } + + public float Yy + { + get { return NineValues[4]; } + set { SetValue(4, value); } + } + + public float X0 + { + get { return NineValues[6]; } + set { SetValue(6, value); } + } + + public float Y0 + { + get { return NineValues[7]; } + set { SetValue(7, value); } + } + + public void Rotate(float angle) + { + this.Control.PreRotate(angle); + } + + public void RotateAt(float angle, float centerX, float centerY) + { +#if TODO + this.Control.RotateAt(angle, new ag.PointF(centerX, centerY), ag.MatrixOrder.Prepend); +#else + throw new NotImplementedException(); +#endif + } + + public void Translate(float x, float y) + { + this.Control.PreTranslate(x, y); + } + + public void Scale(float scaleX, float scaleY) + { + this.Control.PreScale(scaleX, scaleY); + } + + public void ScaleAt(float scaleX, float scaleY, float centerX, float centerY) + { +#if TODO + var m = new ag.Matrix(scaleX, 0, 0, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); + this.Control.Multiply(m, ag.MatrixOrder.Prepend); +#else + throw new NotImplementedException(); +#endif + } + + public void Skew(float skewX, float skewY) + { +#if TODO + var m = new ag.Matrix(1, (float)Math.Tan(Conversions.DegreesToRadians(skewX)), (float)Math.Tan(Conversions.DegreesToRadians(skewY)), 1, 0, 0); + this.Control.Multiply(m, ag.MatrixOrder.Prepend); +#else + throw new NotImplementedException(); +#endif + } + + public void Append(IMatrix matrix) + { + this.Control.PostConcat(matrix.ToAndroid()); + } + + public void Prepend(IMatrix matrix) + { + this.Control.PreConcat(matrix.ToAndroid()); + } + + public void Create() + { + control = new ag.Matrix(); + } + + public void Create(float xx, float yx, float xy, float yy, float dx, float dy) + { + control = new ag.Matrix(); + var values = new float[] + { + xx, yx, 1, + xy, yy, 1, + dx, dy, 1 + }; + control.SetValues(values); + } + + public void Invert() + { + var inverse = new ag.Matrix(); + this.Control.Invert(inverse); + this.control = inverse; + } + + public PointF TransformPoint(Point p) + { + var px = new ag.Point[] { Conversions.ToAndroidPoint(p) }; + +#if TODO + this.Control.TransformPoints(px); + + return Platform.Conversions.ToEto(px[0]); +#else + throw new NotImplementedException(); +#endif + } + + public PointF TransformPoint(PointF p) + { + var px = new ag.PointF[] { p.ToAndroid() }; + +#if TODO + this.Control.TransformPoints(px); +#else + throw new NotImplementedException(); +#endif + + + return px[0].ToEto(); + } + + public void Dispose() + { + if (control != null) + { + control.Dispose(); + control = null; + } + } + + public IMatrix Clone() + { +#if TODO + return new MatrixHandler(control.Clone()); +#else + throw new NotImplementedException(); +#endif + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/PenHandler.cs b/Source/Eto.Android/Drawing/PenHandler.cs new file mode 100644 index 0000000000..9815c2cfd3 --- /dev/null +++ b/Source/Eto.Android/Drawing/PenHandler.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class PenHandler : Pen.IHandler + { + public object Create(Color color, float thickness) + { + var paint = new ag.Paint + { + Color = color.ToAndroid(), + StrokeWidth = thickness, + StrokeCap = ag.Paint.Cap.Square, + StrokeMiter = 10f + }; + return paint; + } + + public Color GetColor(Pen widget) + { + return widget.ToAndroid().Color.ToEto(); + } + + public void SetColor(Pen widget, Color color) + { + widget.ToAndroid().Color = color.ToAndroid(); + } + + public float GetThickness(Pen widget) + { + return widget.ToAndroid().StrokeWidth; + } + + public void SetThickness(Pen widget, float thickness) + { + widget.ToAndroid().StrokeWidth = thickness; + } + + public PenLineJoin GetLineJoin(Pen widget) + { + return widget.ToAndroid().StrokeJoin.ToEto(); + } + + public void SetLineJoin(Pen widget, PenLineJoin lineJoin) + { + widget.ToAndroid().StrokeJoin = lineJoin.ToAndroid(); + } + + public PenLineCap GetLineCap(Pen widget) + { + return widget.ToAndroid().StrokeCap.ToEto(); + } + + public void SetLineCap(Pen widget, PenLineCap lineCap) + { + var pen = widget.ToAndroid(); + pen.StrokeCap = lineCap.ToSD(); + SetDashStyle(widget, widget.DashStyle); + } + + public float GetMiterLimit(Pen widget) + { + return widget.ToAndroid().StrokeMiter; + } + + public void SetMiterLimit(Pen widget, float miterLimit) + { + widget.ToAndroid().StrokeMiter = miterLimit; + } + + public void SetDashStyle(Pen widget, DashStyle dashStyle) + { + var pen = widget.ToAndroid(); + + if (dashStyle == null || dashStyle.IsSolid) + pen.SetPathEffect(null); + else + { + // TODO: create a new ag.DashPathEffect with the appropriate intervals + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/SolidBrushHandler.cs b/Source/Eto.Android/Drawing/SolidBrushHandler.cs new file mode 100644 index 0000000000..27b5ca3007 --- /dev/null +++ b/Source/Eto.Android/Drawing/SolidBrushHandler.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class SolidBrushHandler : BrushHandler, SolidBrush.IHandler + { + public object Create(Color color) + { + var result = new ag.Paint + { + Color = color.ToAndroid(), + }; + result.SetStyle(ag.Paint.Style.Fill); + return result; + } + + public Color GetColor(SolidBrush widget) + { + return ((ag.Paint)widget.ControlObject).Color.ToEto(); + } + + public void SetColor(SolidBrush widget, Color color) + { + throw new NotImplementedException(); + } + + public override ag.Paint GetPaint(Brush brush) + { + return (ag.Paint)brush.ControlObject; + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Drawing/TextureBrushHandler.cs b/Source/Eto.Android/Drawing/TextureBrushHandler.cs new file mode 100644 index 0000000000..f6dd8e0720 --- /dev/null +++ b/Source/Eto.Android/Drawing/TextureBrushHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Drawing +{ + class TextureBrushHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Eto.Android.csproj b/Source/Eto.Android/Eto.Android.csproj new file mode 100644 index 0000000000..1b68e4d3e8 --- /dev/null +++ b/Source/Eto.Android/Eto.Android.csproj @@ -0,0 +1,119 @@ + + + + Debug + AnyCPU + {7A02E771-D30B-41A1-8A35-C78D3940FC33} + {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Eto.Android + Assets + Resources + Eto.Android + Resources\Resource.designer.cs + Resource + True + v4.4 + + + true + full + false + ..\..\BuildOutput\Android\Debug + DEBUG; + 4 + false + None + + + full + true + ..\..\BuildOutput\Android\Release + 4 + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + \ No newline at end of file diff --git a/Source/Eto.Android/Forms/AndroidContainer.cs b/Source/Eto.Android/Forms/AndroidContainer.cs new file mode 100644 index 0000000000..ff208040db --- /dev/null +++ b/Source/Eto.Android/Forms/AndroidContainer.cs @@ -0,0 +1,28 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using a = Android; +using av = Android.Views; +using aw = Android.Widget; + +namespace Eto.Android.Forms +{ + /// + /// Base handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public abstract class AndroidContainer : AndroidControl, Container.IHandler + where TControl: av.View + where TWidget: Container + where TCallback: Container.ICallback + { + protected AndroidContainer() + { + } + + public virtual bool RecurseToChildren { get { return true; } } + + public virtual Size ClientSize { get { return Size; } set { Size = value; } } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/AndroidControl.cs b/Source/Eto.Android/Forms/AndroidControl.cs new file mode 100644 index 0000000000..cd50e4eddb --- /dev/null +++ b/Source/Eto.Android/Forms/AndroidControl.cs @@ -0,0 +1,165 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using a = Android; +using av = Android.Views; +using aw = Android.Widget; +using System.Collections.Generic; +using System.Linq; + +namespace Eto.Android.Forms +{ + public interface IAndroidControl + { + av.View ContainerControl { get; } + } + + /// + /// Base handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public abstract class AndroidControl : WidgetHandler, Control.IHandler, IAndroidControl + where TControl: av.View + where TWidget: Control + where TCallback: Control.ICallback + { + public abstract av.View ContainerControl { get; } + + public void Invalidate() + { + throw new NotImplementedException(); + } + + public void Invalidate(Rectangle rect) + { + throw new NotImplementedException(); + } + + public void SuspendLayout() + { + } + + public void ResumeLayout() + { + } + + public void Focus() + { + Control.RequestFocus(); + } + + public virtual void OnPreLoad(EventArgs e) + { + } + + public virtual void OnLoad(EventArgs e) + { + } + + public virtual void OnLoadComplete(EventArgs e) + { + } + + public virtual void OnUnLoad(EventArgs e) + { + } + + public virtual void SetParent(Container parent) + { + } + + public PointF PointFromScreen(PointF point) + { + throw new NotImplementedException(); + } + + public PointF PointToScreen(PointF point) + { + throw new NotImplementedException(); + } + + Color? backgroundColor; + + public Color BackgroundColor + { + get { return backgroundColor ?? Colors.Transparent; } + set + { + backgroundColor = value; + ContainerControl.SetBackgroundColor(value.ToAndroid()); + } + } + + public virtual Size Size + { + get { return new Size(ContainerControl.Width, ContainerControl.Height); } + set + { + Control.SetMinimumWidth(value.Width); + Control.SetMinimumHeight(value.Height); + } + } + + public virtual bool Enabled + { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + + public bool HasFocus + { + get { return Control.IsFocused; } + } + + public bool Visible + { + get { return Control.Visibility == av.ViewStates.Visible; } + set { Control.Visibility = value ? av.ViewStates.Visible : av.ViewStates.Invisible; } + } + + public virtual Point Location + { + get + { + throw new NotImplementedException(); + } + set { } + } + + public IEnumerable SupportedPlatformCommands + { + get { return Enumerable.Empty(); } + } + + public void MapPlatformCommand(string systemAction, Command action) + { + throw new NotImplementedException(); + } + + + public string ToolTip + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public Cursor Cursor + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/AndroidExtensions.cs b/Source/Eto.Android/Forms/AndroidExtensions.cs similarity index 96% rename from Source/Eto.Platform.Android/Forms/AndroidExtensions.cs rename to Source/Eto.Android/Forms/AndroidExtensions.cs index 1e9e772083..b7c0dd45ac 100644 --- a/Source/Eto.Platform.Android/Forms/AndroidExtensions.cs +++ b/Source/Eto.Android/Forms/AndroidExtensions.cs @@ -5,7 +5,7 @@ using av = Android.Views; using aw = Android.Widget; -namespace Eto.Platform.Android.Forms +namespace Eto.Android.Forms { public static class AndroidExtensions { diff --git a/Source/Eto.Android/Forms/AndroidPanel.cs b/Source/Eto.Android/Forms/AndroidPanel.cs new file mode 100644 index 0000000000..2e2be183fd --- /dev/null +++ b/Source/Eto.Android/Forms/AndroidPanel.cs @@ -0,0 +1,88 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using a = Android; +using av = Android.Views; +using aw = Android.Widget; + +namespace Eto.Android.Forms +{ + /// + /// Base handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public abstract class AndroidPanel : AndroidContainer, Panel.IHandler + where TControl: av.View + where TWidget: Panel + where TCallback: Panel.ICallback + { + readonly aw.FrameLayout frame; + Control content; + Size minimumSize; + + protected aw.FrameLayout InnerFrame { get { return frame; } } + + protected AndroidPanel() + { + frame = new aw.FrameLayout(a.App.Application.Context); + } + + protected override void Initialize() + { + base.Initialize(); + SetContent(frame); + } + + public Control Content + { + get { return content; } + set + { + if (content != null) + { + var view = content.GetContainerView(); + frame.RemoveView(view); + } + content = value; + if (content != null) + { + var view = content.GetContainerView(); + view.LayoutParameters = new av.ViewGroup.LayoutParams(av.ViewGroup.LayoutParams.MatchParent, av.ViewGroup.LayoutParams.MatchParent); + frame.AddView(view); + } + } + } + + protected abstract void SetContent(av.View content); + + public Padding Padding + { + get { return frame.GetPadding(); } + set { frame.SetPadding(value); } + } + + public Size MinimumSize + { + get { return minimumSize; } + set + { + minimumSize = value; + ContainerControl.SetMinimumWidth(value.Width); + ContainerControl.SetMinimumHeight(value.Height); + } + } + + public ContextMenu ContextMenu + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/AndroidWindow.cs b/Source/Eto.Android/Forms/AndroidWindow.cs new file mode 100644 index 0000000000..aa1e43a186 --- /dev/null +++ b/Source/Eto.Android/Forms/AndroidWindow.cs @@ -0,0 +1,183 @@ +using System; +using System.Threading.Tasks; +using Eto.Forms; +using Eto.Drawing; +using a = Android; +using av = Android.Views; +using aw = Android.Widget; + +namespace Eto.Android.Forms +{ + public interface IAndroidWindow + { + a.App.Activity Activity { get; set; } + } + + /// + /// Base handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public abstract class AndroidWindow : AndroidPanel, Window.IHandler, IAndroidWindow + where TWidget: Window + where TCallback: Window.ICallback + { + a.App.Activity activity; + public a.App.Activity Activity + { + get { return activity ?? (activity = CreateActivity()); } + set { activity = value; } + } + + protected virtual a.App.Activity CreateActivity() + { + return null; // todo + } + + protected AndroidWindow() + { + } + + public override av.View ContainerControl + { + get { return InnerFrame; } + } + + public void Close() + { + //a.App.Application.Context.Start + } + + protected override void SetContent(av.View content) + { + } + + public ToolBar ToolBar { get; set; } + + public double Opacity { get; set; } + + public string Title { get; set; } + + public Screen Screen + { + get + { + throw new NotImplementedException(); + } + } + + + public MenuBar Menu + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public Icon Icon { get { return null; } set { } } + + public bool Resizable + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool Maximizable + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool Minimizable + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool ShowInTaskbar + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool Topmost + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public WindowState WindowState + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public Rectangle? RestoreBounds + { + get { throw new NotImplementedException(); } + } + + public WindowStyle WindowStyle + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public void BringToFront() + { + throw new NotImplementedException(); + } + + public void SendToBack() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/ApplicationHandler.cs b/Source/Eto.Android/Forms/ApplicationHandler.cs new file mode 100644 index 0000000000..f3342c35bf --- /dev/null +++ b/Source/Eto.Android/Forms/ApplicationHandler.cs @@ -0,0 +1,122 @@ +using System; +using a = Android; +using Eto.Forms; +using System.Collections.Generic; +using System.Threading; + +namespace Eto.Android.Forms +{ + /// + /// Handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public class ApplicationHandler : WidgetHandler, Application.IHandler + { + public static ApplicationHandler Instance { get { return Application.Instance.Handler as ApplicationHandler; } } + + public a.App.Activity MainActivity { get; private set; } + + public ApplicationHandler() + { + Control = a.App.Application.Context as a.App.Application; + } + + public void OnMainFormChanged() + { + if (Widget.MainForm != null) + { + var window = Widget.MainForm.Handler as IAndroidWindow; + if (window != null) + window.Activity = MainActivity; + } + } + + public void Attach(object context) + { + var activity = context as a.App.Activity; + if (activity != null) + { + MainActivity = activity; + } + } + + public void Run() + { + Callback.OnInitialized(Widget, EventArgs.Empty); + } + + public void Quit() + { + throw new NotImplementedException(); + } + + public bool QuitIsSupported { get { return false; } } + + public void Open(string url) + { + throw new NotImplementedException(); + } + + public void Invoke(Action action) + { + if (MainActivity != null) + { + var ev = new ManualResetEvent(false); + MainActivity.RunOnUiThread(() => + { + try + { + action(); + } + finally + { + ev.Set(); + } + }); + ev.WaitOne(); + } + } + + public void AsyncInvoke(Action action) + { + if (MainActivity != null) + { + MainActivity.RunOnUiThread(action); + } + } + + public Keys CommonModifier + { + get { return Keys.Control; } + } + + public Keys AlternateModifier + { + get { return Keys.Alt; } + } + + public string BadgeLabel + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + + public void Restart() + { + throw new NotImplementedException(); + } + + public void RunIteration() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Cells/TextBoxCellHandler.cs b/Source/Eto.Android/Forms/Cells/TextBoxCellHandler.cs new file mode 100644 index 0000000000..1dd7ffd908 --- /dev/null +++ b/Source/Eto.Android/Forms/Cells/TextBoxCellHandler.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; +using Eto.Forms; + +namespace Eto.Android.Forms.Cells +{ + public interface ICellHandler + { + av.View CreateView(av.View view, object item); + } + + public abstract class CellHandler : WidgetHandler, Cell.IHandler, ICellHandler + where TWidget: Cell + { + public abstract av.View CreateView(av.View view, object item); + } + + public class TextBoxCellHandler : CellHandler, TextBoxCell.IHandler + { + public override av.View CreateView(av.View view, object item) + { + var tv = view as aw.TextView ?? new aw.TextView(aa.Application.Context); + + tv.Text = Widget.Binding != null ? Widget.Binding.GetValue(item) : null; + return tv; + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/AndroidCommonControl.cs b/Source/Eto.Android/Forms/Controls/AndroidCommonControl.cs new file mode 100644 index 0000000000..faae5d8e2d --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/AndroidCommonControl.cs @@ -0,0 +1,44 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using a = Android; +using av = Android.Views; +using aw = Android.Widget; + +namespace Eto.Android.Forms.Controls +{ + public abstract class AndroidCommonControl : AndroidControl, CommonControl.IHandler + where TWidget: CommonControl + where TControl: av.View + where TCallback: CommonControl.ICallback + { + public override av.View ContainerControl + { + get { return Control; } + } + + // TODO + public virtual Font Font + { + get; + set; + } + + public override Size Size + { + get { return new Size(Control.Width, Control.Height); } + set + { + // TODO: need to change to desired size, not min size.. e.g. if control is in a container + Control.SetMinimumWidth(value.Width); + Control.SetMinimumHeight(value.Height); + } + } + + public override bool Enabled + { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/ButtonHandler.cs b/Source/Eto.Android/Forms/Controls/ButtonHandler.cs new file mode 100644 index 0000000000..ffce31e09a --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/ButtonHandler.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; +using Eto.Drawing; + +namespace Eto.Android.Forms.Controls +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class ButtonHandler : AndroidCommonControl, Button.IHandler + { + public ButtonHandler() + { + Control = new aw.Button(aa.Application.Context); + Control.Click += (sender, e) => Callback.OnClick(Widget, EventArgs.Empty); + } + + Image image; + public Image Image + { + get { return image; } + set + { + image = value; + Control.SetCompoundDrawablesWithIntrinsicBounds(image.ToAndroidDrawable(), null, null, null); + } + } + + public ButtonImagePosition ImagePosition + { + get; + set; + } + + public string Text + { + get { return Control.Text; } + set { Control.Text = value; } + } + + public Color TextColor + { + get { return Control.TextColors.ToEto(); } + set { Control.SetTextColor(value.ToAndroid()); } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/CheckBoxHandler.cs b/Source/Eto.Android/Forms/Controls/CheckBoxHandler.cs new file mode 100644 index 0000000000..86e72ee5f2 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/CheckBoxHandler.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; +using Eto.Drawing; + +namespace Eto.Android.Forms.Controls +{ + public class CheckBoxHandler : AndroidCommonControl, CheckBox.IHandler + { + public CheckBoxHandler() + { + Control = new aw.CheckBox(aa.Application.Context); + } + + public bool? Checked + { + get { return Control.Checked; } + set { Control.Checked = value ?? false; } + } + + // TODO: + public bool ThreeState + { + get; + set; + } + + public string Text + { + get { return Control.Text; } + set { Control.Text = value; } + } + + public Color TextColor + { + get { return Control.TextColors.ToEto(); } + set { Control.SetTextColor(value.ToAndroid()); } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/ComboBoxHandler.cs b/Source/Eto.Android/Forms/Controls/ComboBoxHandler.cs new file mode 100644 index 0000000000..ac4806bfcf --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/ComboBoxHandler.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + public class ComboBoxHandler : AndroidControl, ComboBox.IHandler + { + public override av.View ContainerControl { get { return Control; } } + + public ComboBoxHandler() + { + Control = new aw.Spinner(aa.Application.Context); + } + + public IEnumerable DataStore + { + get; + set; + } + + public int SelectedIndex { get; set; } + + public Eto.Drawing.Font Font + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public Eto.Drawing.Color TextColor + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public string Text + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool ReadOnly + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool AutoComplete + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/DateTimePickerHandler.cs b/Source/Eto.Android/Forms/Controls/DateTimePickerHandler.cs new file mode 100644 index 0000000000..4834ce9164 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/DateTimePickerHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class DateTimePickerHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/DrawableHandler.cs b/Source/Eto.Android/Forms/Controls/DrawableHandler.cs new file mode 100644 index 0000000000..e5dd20315e --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/DrawableHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class DrawableHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/DropDownHandler.cs b/Source/Eto.Android/Forms/Controls/DropDownHandler.cs new file mode 100644 index 0000000000..8d220a98e5 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/DropDownHandler.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + public class DropDownHandler : AndroidControl, DropDown.IHandler + { + public override av.View ContainerControl { get { return Control; } } + + public DropDownHandler() + { + Control = new aw.Spinner(aa.Application.Context); + } + + public IEnumerable DataStore + { + get; + set; + } + + public int SelectedIndex { get; set; } + + public Eto.Drawing.Font Font + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public Eto.Drawing.Color TextColor + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/GridColumnHandler.cs b/Source/Eto.Android/Forms/Controls/GridColumnHandler.cs new file mode 100644 index 0000000000..89a8b262d4 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/GridColumnHandler.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + public class GridColumnHandler : WidgetHandler, GridColumn.IHandler + { + public string HeaderText { get; set; } + public bool Resizable { get; set; } + public bool Sortable { get; set; } + public bool AutoSize { get; set; } + public int Width { get; set; } + public Cell DataCell { get; set; } + public bool Editable { get; set; } + public bool Visible { get; set; } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/GridHandler.cs b/Source/Eto.Android/Forms/Controls/GridHandler.cs new file mode 100644 index 0000000000..987d58c9d5 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/GridHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class GridHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/GridViewHandler.cs b/Source/Eto.Android/Forms/Controls/GridViewHandler.cs new file mode 100644 index 0000000000..a2e5becf90 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/GridViewHandler.cs @@ -0,0 +1,292 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; +using Eto.Android.Forms.Cells; + +namespace Eto.Android.Forms.Controls +{ + public class GridViewHandler : AndroidControl, GridView.IHandler + { + ColumnsChangedHandler columns; + DataStoreHandler collection; + Adapter adapter; + + class ColumnsChangedHandler : EnumerableChangedHandler + { + public GridViewHandler Handler { get; set; } + + public override void AddRange(IEnumerable items) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void RemoveRange(int index, int count) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void AddItem(GridColumn item) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void InsertItem(int index, GridColumn item) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void RemoveItem(int index) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void RemoveAllItems() + { + Handler.adapter.NotifyDataSetChanged(); + } + } + + class DataStoreHandler : EnumerableChangedHandler + { + public GridViewHandler Handler { get; set; } + + public override void AddRange(IEnumerable items) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void InsertRange(int index, IEnumerable items) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void AddItem(object item) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void InsertItem(int index, object item) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void RemoveItem(int index) + { + Handler.adapter.NotifyDataSetChanged(); + } + + public override void RemoveAllItems() + { + Handler.adapter.NotifyDataSetChanged(); + } + } + + class Adapter : aw.BaseAdapter + { + public GridViewHandler Handler { get; set; } + + public override Java.Lang.Object GetItem(int position) + { + return null; + } + + public override long GetItemId(int position) + { + return position; + } + + public override int GetItemViewType(int position) + { + return position % ViewTypeCount; + } + + public override int ViewTypeCount + { + get { return Math.Max(Handler.columns.Count, 1); } + } + + public override av.View GetView(int position, av.View convertView, av.ViewGroup parent) + { + var colCount = Handler.columns.Count; + var row = position; + var view = convertView as aw.LinearLayout; + var item = Handler.collection.ElementAt(row); + if (view == null || view.ChildCount != Handler.columns.Count) + { + view = new aw.LinearLayout(aa.Application.Context); + + for (int i = 0; i < Handler.columns.Count; i++) + { + var column = Handler.columns.ElementAt(i); + var cell = column.DataCell; + av.View colView = null; + if (cell != null) + { + var cellHandler = cell.Handler as ICellHandler; + if (cellHandler != null) + { + colView = cellHandler.CreateView(null, item); + } + } + view.AddView(colView ?? new av.View(aa.Application.Context), new aw.LinearLayout.LayoutParams(av.ViewGroup.LayoutParams.MatchParent, av.ViewGroup.LayoutParams.MatchParent, 1f)); + } + } + else + { + for (int i = 0; i < Handler.columns.Count; i++) + { + var column = Handler.columns.ElementAt(i); + var cell = column.DataCell; + if (cell != null) + { + var cellHandler = cell.Handler as ICellHandler; + if (cellHandler != null) + { + var colView = view.GetChildAt(i); + cellHandler.CreateView(colView, item); + } + } + } + } + return view; + } + + public override int Count + { + get { return Handler.collection.Count; } + } + } + + public GridViewHandler() + { + columns = new ColumnsChangedHandler { Handler = this }; + collection = new DataStoreHandler { Handler = this }; + adapter = new Adapter { Handler = this }; + Control = new aw.ListView(aa.Application.Context) + { + Adapter = adapter, + ChoiceMode = aw.ChoiceMode.Single + }; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case GridView.SelectionChangedEvent: + Control.ItemClick += (sender, e) => + Callback.OnSelectionChanged(Widget, EventArgs.Empty); + break; + default: + base.AttachEvent(id); + break; + } + } + + protected override void Initialize() + { + base.Initialize(); + columns.Register(Widget.Columns); + } + + public IEnumerable DataStore + { + get { return collection.Collection; } + set { collection.Register(value); } + } + + public bool ShowCellBorders { get; set; } + + public bool ShowHeader { get; set; } + + public int RowHeight { get; set; } + + public bool AllowColumnReordering { get; set; } + + public bool AllowMultipleSelection + { + get { return Control.ChoiceMode == aw.ChoiceMode.Multiple; } + set { Control.ChoiceMode = value ? aw.ChoiceMode.Multiple : aw.ChoiceMode.Single; } + } + + public IEnumerable SelectedItems + { + get + { + foreach (var row in SelectedRows) + yield return collection.ElementAt(row); + } + } + + public IEnumerable SelectedRows + { + get + { + var c = Control.CheckedItemPositions; + for (int i = 0; i < c.Size(); i++) + yield return c.KeyAt(i); + } + set + { + var c = Control.CheckedItemPositions; + c.Clear(); + foreach (var row in value) + c.Append(row, true); + + } + } + + public void SelectRow(int row) + { + Control.SetItemChecked(row, true); + } + + public void UnselectRow(int row) + { + Control.SetItemChecked(row, false); + } + + public void SelectAll() + { + for (int i = 0; i < collection.Count; i++) + SelectRow(i); + } + + public void UnselectAll() + { + Control.ClearChoices(); + } + + public override av.View ContainerControl + { + get { return Control; } + } + + public ContextMenu ContextMenu + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public void BeginEdit(int row, int column) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/GroupBoxHandler.cs b/Source/Eto.Android/Forms/Controls/GroupBoxHandler.cs new file mode 100644 index 0000000000..b5597578d7 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/GroupBoxHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class GroupBoxHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/ImageViewHandler.cs b/Source/Eto.Android/Forms/Controls/ImageViewHandler.cs new file mode 100644 index 0000000000..6c6341961f --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/ImageViewHandler.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; +using Eto.Drawing; + +namespace Eto.Android.Forms.Controls +{ + public class ImageViewHandler : AndroidControl, ImageView.IHandler + { + public override av.View ContainerControl { get { return Control; } } + + public ImageViewHandler() + { + Control = new aw.ImageView(aa.Application.Context); + } + + Image image; + public Image Image + { + get { return image; } + set + { + image = value; + Control.SetImageBitmap(image.ToAndroid()); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/LabelHandler.cs b/Source/Eto.Android/Forms/Controls/LabelHandler.cs new file mode 100644 index 0000000000..79ddbe3c80 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/LabelHandler.cs @@ -0,0 +1,77 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using a = Android; +using av = Android.Views; +using aw = Android.Widget; + +namespace Eto.Android.Forms.Controls +{ + /// + /// Handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public class LabelHandler : AndroidCommonControl, Label.IHandler + { + const av.GravityFlags AlignmentMask = av.GravityFlags.HorizontalGravityMask | av.GravityFlags.VerticalGravityMask; + + public LabelHandler() + { + Control = new aw.TextView(a.App.Application.Context); + } + + public HorizontalAlign HorizontalAlign + { + get { return Control.Gravity.ToEtoHorizontal(); } + set + { + var gravity = value.ToAndroid(); + Control.Gravity = (Control.Gravity & ~av.GravityFlags.HorizontalGravityMask & AlignmentMask) | gravity; + } + } + + public VerticalAlign VerticalAlign + { + get { return Control.Gravity.ToEtoVertical(); } + set + { + var gravity = value.ToAndroid(); + Control.Gravity = (Control.Gravity & ~av.GravityFlags.VerticalGravityMask & AlignmentMask) | gravity; + } + } + + // TODO + public WrapMode Wrap + { + get; + set; + } + + Font font; + public override Font Font + { + get { return font ?? (font = Control.Typeface.ToEto()); } + set + { + if (font != value) + { + font = value; + Control.Typeface = font.ToAndroid(); + } + } + } + + public Color TextColor + { + get { return Color.FromArgb((int)Control.CurrentTextColor); } + set { Control.SetTextColor(value.ToAndroid()); } + } + + public string Text + { + get { return Control.Text; } + set { Control.Text = value; } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/ListBoxHandler.cs b/Source/Eto.Android/Forms/Controls/ListBoxHandler.cs new file mode 100644 index 0000000000..7e5420c6e5 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/ListBoxHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class ListBoxHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/NavigationHandler.cs b/Source/Eto.Android/Forms/Controls/NavigationHandler.cs new file mode 100644 index 0000000000..44618ee2cd --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/NavigationHandler.cs @@ -0,0 +1,88 @@ +using System; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; +using Eto.Forms; +using System.Collections.Generic; + +namespace Eto.Android.Forms.Controls +{ + [aa.Activity] + public class EtoNavigationActivity : aa.Activity + { + INavigationItem content; + + protected override void OnCreate(ao.Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + var key = Intent.GetStringExtra("item"); + + content = NavigationHandler.GetItem(key); + if (content != null && content.Content != null) + { + SetContentView(content.Content.GetContainerView()); + } + } + } + + public class NavigationHandler : AndroidContainer, Navigation.IHandler + { + static Dictionary itemsLookup = new Dictionary(); + + public static INavigationItem GetItem(string key) + { + INavigationItem item; + return itemsLookup.TryGetValue(key, out item) ? item : null; + } + + readonly Stack items = new Stack(); + + public override av.View ContainerControl { get { return Control; } } + + public NavigationHandler() + { + Control = new aw.FrameLayout(aa.Application.Context); + } + + public void Push(INavigationItem item) + { + if (items.Count > 0) + { + var intent = new ac.Intent(Control.Context, typeof(EtoNavigationActivity)); + var key = Guid.NewGuid().ToString(); + itemsLookup.Add(key, item); + intent.PutExtra("item", key); + intent.SetFlags(ac.ActivityFlags.NewTask); + aa.Application.Context.StartActivity(intent); + } + else + { + SetContent(item.Content); + } + items.Push(item); + } + + public void Pop() + { + var item = items.Pop(); + SetContent(item.Content); + } + + void SetContent(Control content) + { + Control.RemoveAllViews(); + + var view = content.GetContainerView(); + if (view != null) + { + view.LayoutParameters = new av.ViewGroup.LayoutParams(av.ViewGroup.LayoutParams.MatchParent, av.ViewGroup.LayoutParams.MatchParent); + Control.AddView(view); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/NumericUpDownHandler.cs b/Source/Eto.Android/Forms/Controls/NumericUpDownHandler.cs new file mode 100644 index 0000000000..c96c226aa5 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/NumericUpDownHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class NumericUpDownHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/PanelHandler.cs b/Source/Eto.Android/Forms/Controls/PanelHandler.cs new file mode 100644 index 0000000000..49f4742b5d --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/PanelHandler.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + /// + /// Handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public class PanelHandler : AndroidPanel, Panel.IHandler + { + public override av.View ContainerControl { get { return InnerFrame; } } + + protected override void SetContent(av.View content) + { + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/PasswordBoxHandler.cs b/Source/Eto.Android/Forms/Controls/PasswordBoxHandler.cs new file mode 100644 index 0000000000..0add33298f --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/PasswordBoxHandler.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; +using Eto.Drawing; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class PasswordBoxHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/ProgressBarHandler.cs b/Source/Eto.Android/Forms/Controls/ProgressBarHandler.cs new file mode 100644 index 0000000000..1e7a09b89b --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/ProgressBarHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class ProgressBarHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/RadioButtonHandler.cs b/Source/Eto.Android/Forms/Controls/RadioButtonHandler.cs new file mode 100644 index 0000000000..064b7df956 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/RadioButtonHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class RadioButtonHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/ScrollableHandler.cs b/Source/Eto.Android/Forms/Controls/ScrollableHandler.cs new file mode 100644 index 0000000000..2a4b7e69d6 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/ScrollableHandler.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; +using Eto.Drawing; +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + /// + /// Handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public class ScrollableHandler : AndroidPanel, Scrollable.IHandler + { + public ScrollableHandler() + { + Control = new aw.ScrollView(aa.Application.Context); + } + + public void UpdateScrollSizes() + { + } + + public override av.View ContainerControl + { + get { return Control; } + } + + protected override void SetContent(av.View content) + { + Control.AddView(content); + } + + public Point ScrollPosition + { + get { return new Point(Control.ScrollX, Control.ScrollY); } + set { Control.ScrollTo(value.X, value.Y); } + } + + public float MinimumZoom { get; set; } + + public float MaximumZoom { get; set; } + + public float Zoom { get; set; } + + public Size ScrollSize + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public BorderType Border + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public Rectangle VisibleRect + { + get + { + throw new NotImplementedException(); + } + } + + public bool ExpandContentWidth + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool ExpandContentHeight + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/SearchBoxHandler.cs b/Source/Eto.Android/Forms/Controls/SearchBoxHandler.cs new file mode 100644 index 0000000000..f4c999d06f --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/SearchBoxHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + public class SearchBoxHandler : TextBoxHandler, SearchBox.IHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/SliderHandler.cs b/Source/Eto.Android/Forms/Controls/SliderHandler.cs new file mode 100644 index 0000000000..d0f5d1a09d --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/SliderHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class SliderHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/SpinnerHandler.cs b/Source/Eto.Android/Forms/Controls/SpinnerHandler.cs new file mode 100644 index 0000000000..d8bfd1f991 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/SpinnerHandler.cs @@ -0,0 +1,43 @@ +using System; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + public class SpinnerHandler : AndroidControl, Spinner.IHandler + { + bool enabled; + + public override av.View ContainerControl { get { return Control; } } + + public SpinnerHandler() + { + Control = new aw.ProgressBar(aa.Application.Context); + Control.Indeterminate = true; + } + + public override bool Enabled + { + get { return enabled; } + set + { + if (enabled != value) + { + enabled = value; + if (enabled) + Control.Visibility = av.ViewStates.Visible; + else + Control.Visibility = av.ViewStates.Invisible; + } + } + } + } +} + diff --git a/Source/Eto.Android/Forms/Controls/SplitterHandler.cs b/Source/Eto.Android/Forms/Controls/SplitterHandler.cs new file mode 100644 index 0000000000..a3d4aea477 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/SplitterHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class SplitterHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/TabControlHandler.cs b/Source/Eto.Android/Forms/Controls/TabControlHandler.cs new file mode 100644 index 0000000000..baa981c96e --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/TabControlHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class TabControlHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/TabPageHandler.cs b/Source/Eto.Android/Forms/Controls/TabPageHandler.cs new file mode 100644 index 0000000000..a511528411 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/TabPageHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class TabPageHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/TextAreaHandler.cs b/Source/Eto.Android/Forms/Controls/TextAreaHandler.cs new file mode 100644 index 0000000000..7dfca7dd9e --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/TextAreaHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class TextAreaHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/TextBoxHandler.cs b/Source/Eto.Android/Forms/Controls/TextBoxHandler.cs new file mode 100644 index 0000000000..7c506619d6 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/TextBoxHandler.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; +using at = Android.Text; +using Eto.Drawing; +using Eto.Forms; + +namespace Eto.Android.Forms.Controls +{ + public class TextBoxHandler : AndroidControl, TextBox.IHandler + { + public override av.View ContainerControl { get { return Control; } } + + public TextBoxHandler() + { + Control = new aw.EditText(aa.Application.Context); + } + + public void SelectAll() + { + Control.SelectAll(); + } + + // TODO + public bool ReadOnly + { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + Control.TextChanged += (sender, e) => Callback.OnTextChanged(Widget, EventArgs.Empty); + break; + default: + base.AttachEvent(id); + break; + } + } + + int maxLength = int.MaxValue; + public int MaxLength + { + get { return maxLength; } + set + { + maxLength = value; + Control.SetFilters(new [] { new at.InputFilterLengthFilter(maxLength) }); + } + } + public string PlaceholderText + { + get { return Control.Hint; } + set { Control.Hint = value; } + } + public string Text + { + get { return Control.Text; } + set { Control.Text = value; } + } + + public Eto.Drawing.Font Font + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public Color TextColor + { + get { return Control.TextColors.ToEto(); } + set { Control.SetTextColor(value.ToAndroid()); } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/TreeGridViewHandler.cs b/Source/Eto.Android/Forms/Controls/TreeGridViewHandler.cs new file mode 100644 index 0000000000..89cc442b1a --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/TreeGridViewHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class TreeGridViewHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/TreeViewHandler.cs b/Source/Eto.Android/Forms/Controls/TreeViewHandler.cs new file mode 100644 index 0000000000..8c31c612cf --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/TreeViewHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class TreeViewHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/Controls/WebViewHandler.cs b/Source/Eto.Android/Forms/Controls/WebViewHandler.cs new file mode 100644 index 0000000000..fdab40eb90 --- /dev/null +++ b/Source/Eto.Android/Forms/Controls/WebViewHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms.Controls +{ + class WebViewHandler + { + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Forms/FormHandler.cs b/Source/Eto.Android/Forms/FormHandler.cs new file mode 100644 index 0000000000..e99cc266f8 --- /dev/null +++ b/Source/Eto.Android/Forms/FormHandler.cs @@ -0,0 +1,24 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using a = Android; +using av = Android.Views; +using aw = Android.Widget; + +namespace Eto.Android.Forms +{ + /// + /// Handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public class FormHandler : AndroidWindow, Form.IHandler + { + public void Show() + { + // TODO: create activity if it doesn't exist + Activity.SetContentView(ContainerControl); + } + } +} + diff --git a/Source/Eto.Android/Forms/TableLayoutHandler.cs b/Source/Eto.Android/Forms/TableLayoutHandler.cs new file mode 100644 index 0000000000..40ad9ed7eb --- /dev/null +++ b/Source/Eto.Android/Forms/TableLayoutHandler.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; +using Eto.Drawing; +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; +using ag = Android.Graphics; + +namespace Eto.Android.Forms +{ + /// + /// Handler for + /// + /// (c) 2013 by Curtis Wensley + /// See LICENSE for full terms + public class TableLayoutHandler : AndroidContainer, TableLayout.IHandler + { + int lastColumnScale; + bool[] columnScale; + int lastRowScale; + bool[] rowScale; + + public override av.View ContainerControl { get { return Control; } } + + public TableLayoutHandler() + { + Control = new aw.TableLayout(aa.Application.Context); + } + + public void CreateControl(int cols, int rows) + { + lastColumnScale = cols - 1; + columnScale = new bool[cols]; + lastRowScale = rows - 1; + rowScale = new bool[rows]; + for (int y = 0; y < rows; y++) + { + var row = new aw.TableRow(aa.Application.Context); + for (int x = 0; x < cols; x++) + { + row.AddView(new aw.FrameLayout(aa.Application.Context), new aw.TableRow.LayoutParams(x)); + } + Control.AddView(row, new aw.TableLayout.LayoutParams(av.ViewGroup.LayoutParams.MatchParent, av.ViewGroup.LayoutParams.MatchParent, y == lastRowScale ? 1f : 0f)); + } + Control.SetColumnStretchable(cols - 1, true); + } + + public bool GetColumnScale(int column) + { + return columnScale[column]; + } + + public void SetColumnScale(int column, bool scale) + { + var lastScale = lastColumnScale; + columnScale[column] = scale; + Control.SetColumnStretchable(column, scale); + lastColumnScale = columnScale.Any(r => r) ? -1 : columnScale.Length - 1; + if (lastScale != lastColumnScale) + { + Control.SetColumnStretchable(columnScale.Length - 1, column == lastColumnScale || columnScale[columnScale.Length - 1]); + } + } + + public bool GetRowScale(int row) + { + return rowScale[row]; + } + + public void SetRowScale(int row, bool scale) + { + var lastScale = lastRowScale; + rowScale[row] = scale; + var layout = Control.GetChildAt(row).LayoutParameters as aw.TableLayout.LayoutParams; + layout.Weight = scale ? 1f : 0f; + lastRowScale = rowScale.Any(r => r) ? -1 : rowScale.Length - 1; + if (lastScale != lastRowScale) + { + layout = Control.GetChildAt(rowScale.Length - 1).LayoutParameters as aw.TableLayout.LayoutParams; + layout.Weight = row == lastRowScale || rowScale[rowScale.Length - 1] ? 1f : 0f; + } + } + + public Size Spacing { get; set; } + + public Padding Padding + { + get { return Control.GetPadding(); } + set { Control.SetPadding(value); } + } + + public void Add(Control child, int x, int y) + { + var row = (aw.TableRow)Control.GetChildAt(y); + + var cell = (aw.FrameLayout)row.GetChildAt(x); + cell.RemoveAllViews(); + var control = child.GetContainerView(); + if (control != null) + { + control.LayoutParameters = new av.ViewGroup.LayoutParams(av.ViewGroup.LayoutParams.MatchParent, av.ViewGroup.LayoutParams.MatchParent); + cell.AddView(control); + } + } + + public void Move(Control child, int x, int y) + { + Remove(child); + Add(child, x, y); + } + + public void Remove(Control child) + { + var control = child.GetContainerView(); + var row = control.Parent as aw.TableRow; + if (row != null && object.ReferenceEquals(row.Parent, Control)) + { + var x = row.IndexOfChild(control); + row.RemoveView(control); + row.AddView(new av.View(aa.Application.Context), new aw.TableRow.LayoutParams(av.ViewGroup.LayoutParams.MatchParent, av.ViewGroup.LayoutParams.MatchParent) { Column = x }); + } + } + + public void Update() + { + Control.ForceLayout(); + } + } +} + diff --git a/Source/Eto.Android/KeyMap.cs b/Source/Eto.Android/KeyMap.cs new file mode 100644 index 0000000000..83661a95b3 --- /dev/null +++ b/Source/Eto.Android/KeyMap.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Forms; + +using aa = Android.App; +using ac = Android.Content; +using ao = Android.OS; +using ar = Android.Runtime; +using av = Android.Views; +using aw = Android.Widget; + +namespace Eto.Android +{ + public static class KeyMap + { + static Dictionary keymap = new Dictionary(); + static Dictionary inverse = new Dictionary(); + + public static Keys ToEto(this av.Keycode keyData) + { + // convert the modifiers + Keys modifiers = Keys.None; + +#if TODO + // Shift + if ((keyData & av.Keycode.Shift) == av.Keycode.Shift) + modifiers |= Keys.Shift; + + // Control + if ((keyData & av.Keycode.Control) == av.Keycode.Control) + modifiers |= Keys.Control; + + // Alt + if ((keyData & av.Keycode.Alt) == av.Keycode.Alt) + modifiers |= Keys.Alt; + + var keyCode = + Find(keyData & ~(av.Keycode.Shift | av.Keycode.Control | av.Keycode.Alt)); +#else + var keyCode = Find(keyData); // This is incomplete; modifiers are not currently handled +#endif + + return keyCode | modifiers; + } + + private static Keys Find(av.Keycode key) + { + Keys mapped; + if (keymap.TryGetValue(key, out mapped)) return mapped; + else return Keys.None; + } + + public static av.Keycode Find(Keys key) + { + av.Keycode mapped; + if (inverse.TryGetValue(key, out mapped)) return mapped; + else return av.Keycode.Unknown; + } + + public static av.Keycode ToSWF(this Keys key) + { + var code = key & Keys.KeyMask; + av.Keycode modifiers = av.Keycode.Unknown; + +#if TODO + // convert the modifiers + // Shift + if ((key & Key.Shift) == Key.Shift) + modifiers |= av.Keycode.Shift; + + // Control + if ((key & Key.Control) == Key.Control) + modifiers |= av.Keycode.Control; + + // Alt + if ((key & Key.Alt) == Key.Alt) + modifiers |= av.Keycode.Alt; +#endif + + return Find (code) | modifiers; + } + + static KeyMap() + { + keymap.Add(av.Keycode.A, Keys.A); + keymap.Add(av.Keycode.B, Keys.B); + keymap.Add(av.Keycode.C, Keys.C); + keymap.Add(av.Keycode.D, Keys.D); + keymap.Add(av.Keycode.E, Keys.E); + keymap.Add(av.Keycode.F, Keys.F); + keymap.Add(av.Keycode.G, Keys.G); + keymap.Add(av.Keycode.H, Keys.H); + keymap.Add(av.Keycode.I, Keys.I); + keymap.Add(av.Keycode.J, Keys.J); + keymap.Add(av.Keycode.K, Keys.K); + keymap.Add(av.Keycode.L, Keys.L); + keymap.Add(av.Keycode.M, Keys.M); + keymap.Add(av.Keycode.N, Keys.N); + keymap.Add(av.Keycode.O, Keys.O); + keymap.Add(av.Keycode.P, Keys.P); + keymap.Add(av.Keycode.Q, Keys.Q); + keymap.Add(av.Keycode.R, Keys.R); + keymap.Add(av.Keycode.S, Keys.S); + keymap.Add(av.Keycode.T, Keys.T); + keymap.Add(av.Keycode.U, Keys.U); + keymap.Add(av.Keycode.V, Keys.V); + keymap.Add(av.Keycode.W, Keys.W); + keymap.Add(av.Keycode.X, Keys.X); + keymap.Add(av.Keycode.Y, Keys.Y); + keymap.Add(av.Keycode.Z, Keys.Z); + //keymap.Add(av.Keycode.F1, Keys.F1); + //keymap.Add(av.Keycode.F2, Keys.F2); + //keymap.Add(av.Keycode.F3, Keys.F3); + //keymap.Add(av.Keycode.F4, Keys.F4); + //keymap.Add(av.Keycode.F5, Keys.F5); + //keymap.Add(av.Keycode.F6, Keys.F6); + //keymap.Add(av.Keycode.F7, Keys.F7); + //keymap.Add(av.Keycode.F8, Keys.F8); + //keymap.Add(av.Keycode.F9, Keys.F9); + //keymap.Add(av.Keycode.F10, Keys.F10); + //keymap.Add(av.Keycode.F11, Keys.F11); + //keymap.Add(av.Keycode.F12, Keys.F12); + keymap.Add(av.Keycode.Num0, Keys.D0); + keymap.Add(av.Keycode.Num1, Keys.D1); + keymap.Add(av.Keycode.Num2, Keys.D2); + keymap.Add(av.Keycode.Num3, Keys.D3); + keymap.Add(av.Keycode.Num4, Keys.D4); + keymap.Add(av.Keycode.Num5, Keys.D5); + keymap.Add(av.Keycode.Num6, Keys.D6); + keymap.Add(av.Keycode.Num7, Keys.D7); + keymap.Add(av.Keycode.Num8, Keys.D8); + keymap.Add(av.Keycode.Num9, Keys.D9); + keymap.Add(av.Keycode.Space, Keys.Space); + //keymap.Add(av.Keycode.Up, Keys.Up); + //keymap.Add(av.Keycode.Down, Keys.Down); + //keymap.Add(av.Keycode.Left, Keys.Left); + //keymap.Add(av.Keycode.Right, Keys.Right); + //keymap.Add(av.Keycode.PageDown, Keys.PageDown); + //keymap.Add(av.Keycode.PageUp, Keys.PageUp); + keymap.Add(av.Keycode.Home, Keys.Home); + //keymap.Add(av.Keycode.End, Keys.End); + //keymap.Add(av.Keycode.Alt, Keys.Alt); + //keymap.Add(av.Keycode.Control, Keys.Control); + //keymap.Add(av.Keycode.Shift, Keys.Shift); + keymap.Add(av.Keycode.Menu, Keys.Menu); + //keymap.Add(av.Keycode.Escape, Keys.Escape); + keymap.Add(av.Keycode.Del, Keys.Delete); + keymap.Add(av.Keycode.Back, Keys.Backspace); + //keymap.Add(av.Keycode.Divide, Keys.Divide); + keymap.Add(av.Keycode.Enter, Keys.Enter); + //keymap.Add(av.Keycode.Insert, Keys.Insert); + keymap.Add(av.Keycode.Period, Keys.Period); + keymap.Add(av.Keycode.Tab, Keys.Tab); + //keymap.Add(av.Keycode.Apps, Keys.ContextMenu); + + foreach (var entry in keymap) + { + inverse.Add(entry.Value, entry.Key); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Android/Platform.cs b/Source/Eto.Android/Platform.cs new file mode 100644 index 0000000000..7620c69a8e --- /dev/null +++ b/Source/Eto.Android/Platform.cs @@ -0,0 +1,122 @@ +using System; +using Eto.Drawing; +using Eto.Forms; +using Eto.Android.Drawing; +using Eto.Android.Forms.Controls; +using Eto.Android.Forms; +using Eto.Android.Forms.Cells; + +namespace Eto.Android +{ + public class Platform : Eto.Platform + { + public override string ID { get { return "android"; } } + + public override bool IsMobile { get { return true; } } + + public override bool IsAndroid { get { return true; } } + + public Platform() + { + AddTo(this); + } + + public static void AddTo(Eto.Platform p) + { + // Drawing + p.Add(() => new BitmapHandler()); + p.Add(() => new FontFamilyHandler()); + p.Add(() => new FontHandler()); + //p.Add(() => new FontsHandler()); + p.Add(() => new GraphicsHandler()); + p.Add(() => new GraphicsPathHandler()); + p.Add(() => new IconHandler()); + //p.Add(() => new IndexedBitmapHandler()); + p.Add(() => new MatrixHandler()); + p.Add(() => new PenHandler()); + p.Add(() => new SolidBrushHandler()); + //p.Add(() => new TextureBrushHandler()); + p.Add(() => new LinearGradientBrushHandler()); + + // Forms.Cells + //p.Add(() => new CheckBoxCellHandler ()); + //p.Add(() => new ComboBoxCellHandler ()); + //p.Add(() => new ImageTextCellHandler()); + //p.Add(() => new ImageViewCellHandler ()); + p.Add(() => new TextBoxCellHandler()); + + // Forms.Controls + p.Add(() => new ButtonHandler()); + p.Add(() => new CheckBoxHandler()); + p.Add(() => new DropDownHandler()); + p.Add(() => new ComboBoxHandler()); + //p.Add(() => new DateTimePickerHandler ()); + //p.Add(() => new DrawableHandler()); + p.Add(() => new GridColumnHandler()); + p.Add(() => new GridViewHandler()); + //p.Add(() => new GroupBoxHandler ()); + p.Add(() => new ImageViewHandler()); + p.Add(() => new LabelHandler()); + //p.Add(() => new ListBoxHandler()); + //p.Add(() => new NumericUpDownHandler()); + p.Add(() => new PanelHandler()); + //p.Add(() => new PasswordBoxHandler()); + //p.Add(() => new ProgressBarHandler()); + //p.Add(() => new RadioButtonHandler()); + p.Add(() => new ScrollableHandler()); + p.Add(() => new SearchBoxHandler()); + //p.Add(() => new SliderHandler()); + p.Add(() => new SpinnerHandler()); + //p.Add(() => new SplitterHandler()); + //p.Add(() => new TabControlHandler ()); + //p.Add(() => new TabPageHandler ()); + //p.Add(() => new TextAreaHandler()); + p.Add(() => new TextBoxHandler()); + //p.Add(() => new TreeGridViewHandler()); + //p.Add(() => new TreeViewHandler ()); + //p.Add(() => new WebViewHandler()); + p.Add(() => new NavigationHandler()); + + // Forms.Menu + //p.Add(() => new CheckMenuItemHandler ()); + //p.Add(() => new ContextMenuHandler ()); + //p.Add(() => new ImageMenuItemHandler ()); + //p.Add(() => new MenuBarHandler ()); + //p.Add(() => new RadioMenuItemHandler ()); + //p.Add(() => new SeparatorMenuItemHandler ()); + + // Forms.Printing + //p.Add(() => new PrintDialogHandler ()); + //p.Add(() => new PrintDocumentHandler ()); + //p.Add(() => new PrintSettingsHandler ()); + + // Forms.ToolBar + //p.Add(() => new CheckToolBarButtonHandler ()); + //p.Add(() => new SeparatorToolBarItemHandler ()); + //p.Add(() => new ToolBarButtonHandler ()); + //p.Add(() => new ToolBarHandler ()); + + // Forms + p.Add(() => new ApplicationHandler()); + //p.Add(() => new ClipboardHandler ()); + //p.Add(() => new ColorDialogHandler ()); + //p.Add(() => new CursorHandler ()); + //p.Add(() => new DialogHandler()); + //p.Add(() => new FontDialogHandler ()); + p.Add(() => new FormHandler()); + //p.Add(() => new MessageBoxHandler()); + //p.Add(() => new OpenFileDialogHandler ()); + //p.Add(() => new PixelLayoutHandler()); + //p.Add(() => new SaveFileDialogHandler ()); + //p.Add(() => new SelectFolderDialogHandler ()); + p.Add(() => new TableLayoutHandler()); + //p.Add(() => new UITimerHandler()); + + // IO + //p.Add(() => new SystemIconsHandler ()); + + // General + //p.Add(() => new EtoEnvironmentHandler()); + } + } +} diff --git a/Source/Eto.Platform.Android/Resources/AboutResources.txt b/Source/Eto.Android/Resources/AboutResources.txt similarity index 100% rename from Source/Eto.Platform.Android/Resources/AboutResources.txt rename to Source/Eto.Android/Resources/AboutResources.txt diff --git a/Source/Eto.Android/Resources/Resource.designer.cs b/Source/Eto.Android/Resources/Resource.designer.cs new file mode 100644 index 0000000000..ae8bf24895 --- /dev/null +++ b/Source/Eto.Android/Resources/Resource.designer.cs @@ -0,0 +1,57 @@ +#pragma warning disable 1591 +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Mono Runtime Version: 4.0.30319.17020 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +[assembly: Android.Runtime.ResourceDesignerAttribute("Eto.Android.Resource", IsApplication=false)] + +namespace Eto.Android +{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] + public partial class Resource + { + + static Resource() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + public partial class Attribute + { + + static Attribute() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Attribute() + { + } + } + + public partial class String + { + + // aapt resource value: 0x7f020000 + public static int library_name = 2130837504; + + static String() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private String() + { + } + } + } +} +#pragma warning restore 1591 diff --git a/Source/Eto.Platform.Android/Resources/values/Strings.xml b/Source/Eto.Android/Resources/values/Strings.xml similarity index 100% rename from Source/Eto.Platform.Android/Resources/values/Strings.xml rename to Source/Eto.Android/Resources/values/Strings.xml diff --git a/Source/Eto.Direct2D/Conversions.cs b/Source/Eto.Direct2D/Conversions.cs new file mode 100644 index 0000000000..7bf4af8c23 --- /dev/null +++ b/Source/Eto.Direct2D/Conversions.cs @@ -0,0 +1,387 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using Eto.Direct2D.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.DirectWrite; + +namespace Eto.Direct2D +{ + /// + /// Direct2D conversions. This file is part of the Direct2D platform library + /// and is also linked into the Xaml platform library. + /// + /// (c) 2014 by Vivek Jhaveri + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public static class Conversions + { + public static s.Color4 ToDx(this Color color) + { + return new s.Color4(color.R, color.G, color.B, color.A); + } + + public static s.Color ToDxColor(this Color color) + { + return new s.Color(color.R, color.G, color.B, color.A); + } + + public static Color ToEto(this s.Color4 value) + { + return new Color { A = value.Alpha, R = value.Red, G = value.Green, B = value.Blue }; + } + + public static Rectangle ToEto(this s.RectangleF value) + { + return new Rectangle((int)value.X, (int)value.Y, (int)value.Width, (int)value.Height); + } + + public static RectangleF ToEtoF(this s.RectangleF value) + { + return new RectangleF((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height); + } + + public static s.RectangleF ToDxF(this Rectangle value) + { + return new s.RectangleF(value.X, value.Y, value.Width, value.Height); + } + + public static s.Rectangle ToDx(this Rectangle value) + { + return new s.Rectangle(value.X, value.Y, value.Width, value.Height); + } + + public static s.RectangleF ToDx(this RectangleF value) + { + return new s.RectangleF(value.X, value.Y, value.Width, value.Height); + } + + public static Size ToEto(this s.Size2 value) + { + return new Size(value.Width, value.Height); + } + + public static s.Size2 ToDx(this Size value) + { + return new s.Size2(value.Width, value.Height); + } + + public static SizeF ToEto(this s.Size2F value) + { + return new SizeF(value.Width, value.Height); + } + + public static s.Size2F ToDx(this SizeF value) + { + return new s.Size2F(value.Width, value.Height); + } + + public static Point ToEto(this s.Vector2 value) + { + return new Point((int)value.X, (int)value.Y); + } + + public static s.Vector2 ToDx(this PointF value) + { + return new s.Vector2(value.X, value.Y); + } + + public static string ToWpfMneumonic(this string value) + { + if (value == null) return null; + return value.Replace("_", "__").Replace("&", "_"); + } + + public static sd.BitmapInterpolationMode ToDx(this ImageInterpolation value) + { + switch (value) + { + case ImageInterpolation.None: + return sd.BitmapInterpolationMode.NearestNeighbor; + case ImageInterpolation.Default: + case ImageInterpolation.Low: + case ImageInterpolation.Medium: + case ImageInterpolation.High: + return sd.BitmapInterpolationMode.Linear; + default: + throw new NotSupportedException(); + } + } + + public static ImageInterpolation ToEto(this sd.BitmapInterpolationMode value) + { + switch (value) + { + case sd.BitmapInterpolationMode.Linear: + return ImageInterpolation.High; + case sd.BitmapInterpolationMode.NearestNeighbor: + return ImageInterpolation.None; + default: + throw new NotSupportedException(); + } + } + + public static sd.Bitmap ToDx(this Image image, sd.RenderTarget target) + { + var handler = (ID2DBitmapHandler)image.Handler; + return target != null ? handler.GetBitmap(target) : null; + } + + public static FontStyle ToEtoStyle(this sw.Font font) + { + var style = FontStyle.None; + if (font.Style == sw.FontStyle.Italic || font.Style == sw.FontStyle.Oblique) + style |= FontStyle.Italic; + + if (font.Weight.IsBold()) + style |= FontStyle.Bold; + return style; + } + + public static bool IsBold(this sw.FontWeight weight) + { + switch (weight) + { + case SharpDX.DirectWrite.FontWeight.Bold: + case SharpDX.DirectWrite.FontWeight.DemiBold: + case SharpDX.DirectWrite.FontWeight.ExtraBold: + case SharpDX.DirectWrite.FontWeight.Heavy: + return true; + case SharpDX.DirectWrite.FontWeight.ExtraBlack: + case SharpDX.DirectWrite.FontWeight.ExtraLight: + case SharpDX.DirectWrite.FontWeight.Light: + case SharpDX.DirectWrite.FontWeight.Medium: + case SharpDX.DirectWrite.FontWeight.Normal: + case SharpDX.DirectWrite.FontWeight.Thin: + default: + return false; + } + } + + public static void Convert(FontStyle value, out sw.FontStyle fontStyle, out sw.FontWeight fontWeight) + { + fontStyle = sw.FontStyle.Normal; + fontWeight = sw.FontWeight.Normal; + + if (value.HasFlag(FontStyle.Italic)) + fontStyle = sw.FontStyle.Italic; + + if (value.HasFlag(FontStyle.Bold)) + fontWeight = sw.FontWeight.Bold; + } + + public static sd.DashStyle ToDx(this DashStyle d) + { + if (d == DashStyles.Solid) + return sd.DashStyle.Solid; + else if (d == DashStyles.Dash) + return sd.DashStyle.Dash; + else if (d == DashStyles.DashDot) + return sd.DashStyle.DashDot; + else if (d == DashStyles.DashDotDot) + return sd.DashStyle.DashDotDot; + else if (d == DashStyles.Dot) + return sd.DashStyle.Dot; + else + { + return sd.DashStyle.Custom; + } + } + + public static sd.LineJoin ToDx(this PenLineJoin lineJoin) + { + switch (lineJoin) + { + case PenLineJoin.Miter: + return sd.LineJoin.MiterOrBevel; + case PenLineJoin.Bevel: + return sd.LineJoin.Bevel; + case PenLineJoin.Round: + return sd.LineJoin.Round; + default: + throw new NotSupportedException(); + } + } + + public static sd.CapStyle ToDx(this PenLineCap lineCap) + { + switch (lineCap) + { + case PenLineCap.Square: + return sd.CapStyle.Square; + case PenLineCap.Butt: + return sd.CapStyle.Flat; + case PenLineCap.Round: + return sd.CapStyle.Round; + default: + throw new NotSupportedException(); + } + } + + public static DashStyle ToEto(this sd.DashStyle d) + { + if (object.ReferenceEquals(d, sd.DashStyle.Dash)) + return DashStyles.Dash; + else if (object.ReferenceEquals(d, sd.DashStyle.DashDot)) + return DashStyles.DashDot; + else if (object.ReferenceEquals(d, sd.DashStyle.DashDotDot)) + return DashStyles.DashDotDot; + else if (object.ReferenceEquals(d, sd.DashStyle.Dot)) + return DashStyles.Dot; + else + return DashStyles.Solid; + } + + public static FillMode ToEto(this sd.FillMode f) + { + return + f == sd.FillMode.Alternate + ? FillMode.Alternate + : FillMode.Winding; + } + + public static sd.FillMode ToDx(this FillMode f) + { + return + f == FillMode.Alternate + ? sd.FillMode.Alternate + : sd.FillMode.Winding; + } + + public static s.Vector2[] ToDx(this PointF[] points) + { + var p = new s.Vector2[points.Length]; + for (var i = 0; i < points.Length; ++i) + p[i] = points[i].ToDx(); + return p; + } + + public static s.Matrix3x2 ToDx(this IMatrix m) + { + return m != null ? (s.Matrix3x2)m.ControlObject : s.Matrix3x2.Identity; + } + + public static float DegreesToRadians(float angle) + { + return (float)Math.PI * angle / 180.0f; + } + + public static PenData ToPenData(this Pen pen) + { + return (PenData)pen.ControlObject; + } + + public static sd.Brush ToDx(this Brush brush, sd.RenderTarget target) + { + var obj = (BrushData)brush.ControlObject; + return obj.Get(target); + } + + public static GraphicsPathHandler ToHandler(this IGraphicsPath path) + { + return path as GraphicsPathHandler ?? ((IHandlerSource)path).Handler as GraphicsPathHandler; + } + + public static sd.Geometry ToGeometry(this IGraphicsPath path) + { + var handler = path.ToHandler(); + handler.CloseSink(); + return handler.Control; + } + + public static sd.PixelFormat ToDx(this PixelFormat format) + { + switch (format) + { + case PixelFormat.Format32bppRgb: + return new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Ignore); + case PixelFormat.Format24bppRgb: + return new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Ignore); + case PixelFormat.Format32bppRgba: + return new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Premultiplied); + default: + throw new NotSupportedException(); + } + } + + public static Guid ToWic(this PixelFormat format) + { + switch (format) + { + case PixelFormat.Format32bppRgb: + return s.WIC.PixelFormat.Format32bppBGR; + case PixelFormat.Format24bppRgb: + return s.WIC.PixelFormat.Format24bppBGR; + case PixelFormat.Format32bppRgba: + return s.WIC.PixelFormat.Format32bppPBGRA; + default: + throw new NotSupportedException(); + } + } + +#if WINFORMS + public static System.Drawing.Imaging.PixelFormat ToSDPixelFormat(this Guid pixelFormat) + { + if (pixelFormat == s.WIC.PixelFormat.Format32bppBGR) + return System.Drawing.Imaging.PixelFormat.Format32bppRgb; + if (pixelFormat == s.WIC.PixelFormat.Format32bppPBGRA) + return System.Drawing.Imaging.PixelFormat.Format32bppPArgb; + if (pixelFormat == s.WIC.PixelFormat.Format24bppBGR) + return System.Drawing.Imaging.PixelFormat.Format24bppRgb; + if (pixelFormat == s.WIC.PixelFormat.Format8bppIndexed) + return System.Drawing.Imaging.PixelFormat.Format8bppIndexed; + throw new NotSupportedException(); + } +#endif + + public static Guid ToWic(this ImageFormat format) + { + switch (format) + { + case ImageFormat.Jpeg: + return s.WIC.ContainerFormatGuids.Jpeg; + case ImageFormat.Bitmap: + return s.WIC.ContainerFormatGuids.Bmp; + case ImageFormat.Tiff: + return s.WIC.ContainerFormatGuids.Tiff; + case ImageFormat.Png: + return s.WIC.ContainerFormatGuids.Png; + case ImageFormat.Gif: + return s.WIC.ContainerFormatGuids.Gif; + default: + throw new NotSupportedException(); + } + } + +#if WINFORMS + public static System.Drawing.Bitmap ToSD(this s.WIC.Bitmap bmp) + { + using (var bl = bmp.Lock(s.WIC.BitmapLockFlags.Read)) + { + var pixelFormat = bmp.PixelFormat.ToSDPixelFormat(); + + return new System.Drawing.Bitmap(bmp.Size.Width, bmp.Size.Height, bl.Data.Pitch, pixelFormat, bl.Data.DataPointer); + } + } +#endif + + public static s.WIC.Bitmap ToBitmap(this s.WIC.BitmapSource bmp, Guid? pixelFormat = null) + { + using (var converter = new s.WIC.FormatConverter(SDFactory.WicImagingFactory)) + { + converter.Initialize( + bmp, + pixelFormat ?? s.WIC.PixelFormat.Format32bppPBGRA, + s.WIC.BitmapDitherType.None, + null, + 0f, + s.WIC.BitmapPaletteType.Custom); + + return new s.WIC.Bitmap(SDFactory.WicImagingFactory, converter, s.WIC.BitmapCreateCacheOption.CacheOnLoad); + } + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/BitmapHandler.cs b/Source/Eto.Direct2D/Drawing/BitmapHandler.cs new file mode 100644 index 0000000000..4e73c715bd --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/BitmapHandler.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.WIC; +using System.IO; + +namespace Eto.Direct2D.Drawing +{ + public class WicBitmapData : BitmapData + { + public WicBitmapData(Image image, sw.BitmapLock bitmapLock, int bitsPerPixel) + : base(image, bitmapLock.Data.DataPointer, bitmapLock.Data.Pitch, bitsPerPixel, bitmapLock) + { + } + + public override int TranslateArgbToData(int argb) + { + return argb; + } + + public override int TranslateDataToArgb(int bitmapData) + { + return bitmapData; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + ((sw.BitmapLock)ControlObject).Dispose(); + } + base.Dispose(disposing); + } + } + + public class BitmapHandler : ImageHandler, Bitmap.IHandler + { + public BitmapData Lock() + { + var data = Control.Lock(sw.BitmapLockFlags.Write); + return new WicBitmapData(Widget, data, 32); + } + + public void Unlock(BitmapData bitmapData) + { + } + } +} diff --git a/Source/Eto.Platform.Direct2D/Drawing/BrushData.cs b/Source/Eto.Direct2D/Drawing/BrushData.cs similarity index 96% rename from Source/Eto.Platform.Direct2D/Drawing/BrushData.cs rename to Source/Eto.Direct2D/Drawing/BrushData.cs index a743c6edc3..4d0058ee40 100644 --- a/Source/Eto.Platform.Direct2D/Drawing/BrushData.cs +++ b/Source/Eto.Direct2D/Drawing/BrushData.cs @@ -2,7 +2,7 @@ using Eto.Drawing; using sd = SharpDX.Direct2D1; -namespace Eto.Platform.Direct2D.Drawing +namespace Eto.Direct2D.Drawing { public abstract class BrushData : IDisposable { diff --git a/Source/Eto.Direct2D/Drawing/FontFamilyHandler.cs b/Source/Eto.Direct2D/Drawing/FontFamilyHandler.cs new file mode 100644 index 0000000000..624fa296ff --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/FontFamilyHandler.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.DirectWrite; + +namespace Eto.Direct2D.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class FontFamilyHandler : WidgetHandler, FontFamily.IHandler + { + public string Name { get; private set; } + + FontTypeface[] typefaces; + public IEnumerable Typefaces + { + get { + return typefaces ?? (typefaces = Enumerable.Range(0, Control.FontCount) + .Select(r => Control.GetFont(r)) + .Select(r => new FontTypeface(Widget, new FontTypefaceHandler(r))) + .ToArray()); + } + } + + public FontFamilyHandler() + { + } + + public FontFamilyHandler(sw.FontFamily family) + { + Control = family; + } + + public void Create(string familyName) + { + string translatedName = Name = familyName; + + switch (familyName.ToUpperInvariant()) + { + case FontFamilies.MonospaceFamilyName: + translatedName = "Courier New"; + break; + case FontFamilies.SansFamilyName: + translatedName = "Microsoft Sans Serif"; + break; + case FontFamilies.SerifFamilyName: + translatedName = "Times New Roman"; + break; + case FontFamilies.CursiveFamilyName: + translatedName = "Comic Sans MS"; + break; + case FontFamilies.FantasyFamilyName: + translatedName = "Gabriola"; + break; + } + + Control = FontHandler.GetFontFamily(translatedName); + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/FontHandler.cs b/Source/Eto.Direct2D/Drawing/FontHandler.cs new file mode 100644 index 0000000000..79bba8615f --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/FontHandler.cs @@ -0,0 +1,221 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.DirectWrite; +#if WINFORMS +using Eto.WinForms.Drawing; +#else +using Windows.Globalization.Fonts; +#endif + +namespace Eto.Direct2D.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class FontHandler : WidgetHandler, Font.IHandler +#if WINFORMS + , IWindowsFontSource +#endif + { + sw.TextFormat textFormat; + public sw.TextFormat TextFormat + { + get + { + if (textFormat == null) + { + textFormat = new sw.TextFormat( + SDFactory.DirectWriteFactory, + Control.FontFamily.FamilyNames.GetString(0), + FontCollection, + Control.Weight, + Control.Style, + Control.Stretch, + Size * 96.0f / 72.0f // convert from points to pixels. (The documentation says device-independent pixels.) + ); + } + return textFormat; + } + } + + public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) + { + this.family = family; + Size = size; + FontStyle = style; + FontDecoration = decoration; + + sw.FontStyle fontStyle; + sw.FontWeight fontWeight; + Conversions.Convert(style, out fontStyle, out fontWeight); + + var familyHandler = (FontFamilyHandler)family.Handler; + Control = familyHandler.Control.GetFirstMatchingFont(fontWeight, sw.FontStretch.Normal, fontStyle); + } + +#if !WINFORMS + static LanguageFontGroup languageFontGroup = new LanguageFontGroup("en"); // TODO: add Eto support for other locales. +#endif + + public void Create(SystemFont systemFont, float? size, FontDecoration decoration) + { +#if WINFORMS + var sdfont = Eto.WinForms.Conversions.ToSD(systemFont); + Create(sdfont.Name, size ?? sdfont.SizeInPoints, FontStyle.None, decoration); +#else + var familyName = "Segoe UI"; + var sizeInPoints = size ?? 12f; + var fontStyle = FontStyle.None; + + // TODO: map the systemfont and default size to a family name and font size. + + // See: http://msdn.microsoft.com/en-us/library/windows/apps/hh700394.aspx + switch (systemFont) + { + case SystemFont.Default: + case SystemFont.Bold: + case SystemFont.TitleBar: + case SystemFont.ToolTip: + case SystemFont.Label: + case SystemFont.MenuBar: + case SystemFont.Menu: + case SystemFont.Message: + case SystemFont.Palette: + case SystemFont.StatusBar: + default: + break; + } + + Create(familyName, sizeInPoints, fontStyle, decoration); +#endif + } + + public void Create(FontTypeface typeface, float size, FontDecoration decoration) + { + family = typeface.Family; + this.typeface = typeface; + var typefaceHandler = (FontTypefaceHandler)typeface.Handler; + + Control = typefaceHandler.Font; + FontStyle = Control.ToEtoStyle(); + FontDecoration = decoration; + Size = size; + } + + void Create(string familyName, float sizeInPoints, FontStyle style, FontDecoration decoration) + { + Size = sizeInPoints; + FontStyle = style; + FontDecoration = decoration; + int index; + if (FontCollection.FindFamilyName(familyName, out index)) + { + sw.FontStyle fontStyle; + sw.FontWeight fontWeight; + Conversions.Convert(style, out fontStyle, out fontWeight); + Control = FontCollection.GetFontFamily(index).GetFirstMatchingFont(fontWeight, sw.FontStretch.Normal, fontStyle); + } + } + + static sw.FontCollection fontCollection; + public static sw.FontCollection FontCollection + { + get + { + return fontCollection = fontCollection ?? SDFactory.DirectWriteFactory.GetSystemFontCollection(checkForUpdates: false); + } + } + + public static sw.FontFamily GetFontFamily(string familyName) + { + sw.FontFamily result = null; + int index; + if (FontHandler.FontCollection.FindFamilyName(familyName, out index)) + result = FontHandler.FontCollection.GetFontFamily(index); + return result; + } + + protected override void Dispose(bool disposing) + { + if (textFormat != null) + { + textFormat.Dispose(); + textFormat = null; + } + + base.Dispose(disposing); + } + + FontFamily family; + public FontFamily Family + { + get { return family ?? (family = new FontFamily(new FontFamilyHandler(Control.FontFamily))); } + } + + public string FamilyName + { + get { return Family.Name; } + } + + public FontStyle FontStyle { get; private set; } + + public FontDecoration FontDecoration { get; private set; } + + /// + /// The size in points. + /// + public float Size { get; private set; } + + FontTypeface typeface; + public FontTypeface Typeface + { + get { return typeface ?? (typeface = new FontTypeface(Family, new FontTypefaceHandler(Control))); } + } + + public float XHeight + { + get { return Size * Control.Metrics.XHeight / Control.Metrics.DesignUnitsPerEm; } + } + + public float Ascent + { + get { return Size * Control.Metrics.Ascent / Control.Metrics.DesignUnitsPerEm; } + } + + public float Descent + { + get { return Size * Control.Metrics.Descent / Control.Metrics.DesignUnitsPerEm; } + } + + public float LineHeight + { + get { return Ascent + Descent + Size * Control.Metrics.LineGap / Control.Metrics.DesignUnitsPerEm; } + } + + public float Leading + { + get { return LineHeight - (Ascent + Descent);} + } + + public float Baseline + { + get { return Ascent; } + } + +#if WINFORMS + public System.Drawing.Font GetFont() + { + var familyName = Control.FontFamily.FamilyNames.GetString(0); + var style = Eto.WinForms.Conversions.ToSD(FontStyle) | Eto.WinForms.Conversions.ToSD(FontDecoration); + return new System.Drawing.Font(familyName, Size, style); + } +#endif + } +} diff --git a/Source/Eto.Direct2D/Drawing/FontTypefaceHandler.cs b/Source/Eto.Direct2D/Drawing/FontTypefaceHandler.cs new file mode 100644 index 0000000000..efb7425612 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/FontTypefaceHandler.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.DirectWrite; + +namespace Eto.Direct2D.Drawing +{ + public class FontTypefaceHandler : WidgetHandler, FontTypeface.IHandler + { + public sw.Font Font { get; private set; } + + public FontTypefaceHandler(sw.Font font) + { + Font = font; + Control = new sw.FontFace(font); + } + + public FontStyle FontStyle + { + get { return Font.ToEtoStyle(); } + } + + public string Name + { + get { return Font.FaceNames.GetString(0); } + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/FontsHandler.cs b/Source/Eto.Direct2D/Drawing/FontsHandler.cs new file mode 100644 index 0000000000..701cc2e619 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/FontsHandler.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.DirectWrite; + +namespace Eto.Direct2D.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class FontsHandler : WidgetHandler, Fonts.IHandler + { + FontFamily[] availableFontFamilies; + public IEnumerable AvailableFontFamilies + { + get + { + if (availableFontFamilies == null) + { + var fonts = FontHandler.FontCollection; + availableFontFamilies = Enumerable.Range(0, fonts.FontFamilyCount) + .Select(r => fonts.GetFontFamily(r).FamilyNames.GetString(0)) + .Distinct() + .Select(r => new FontFamily(r)) + .ToArray(); + } + return availableFontFamilies; + } + } + + public bool FontFamilyAvailable(string fontFamily) + { + return AvailableFontFamilies.Any(r => string.Equals(r.Name, fontFamily, StringComparison.OrdinalIgnoreCase)); + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/GraphicsHandler.cs b/Source/Eto.Direct2D/Drawing/GraphicsHandler.cs new file mode 100644 index 0000000000..2dd1768b6c --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/GraphicsHandler.cs @@ -0,0 +1,639 @@ +using System; +using System.Collections.Generic; +using Eto.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.DirectWrite; +using Eto.Forms; +using System.Diagnostics; +#if WINFORMS +using Eto.WinForms.Forms.Controls; +#endif + +namespace Eto.Direct2D.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public partial class GraphicsHandler : WidgetHandler, Graphics.IHandler + { + bool hasBegan; + bool rectClip; + bool disposeControl = true; + Bitmap image; + float offset = 0.5f; + float fillOffset; + sd.Layer helperLayer; + sd.Geometry clipGeometry; + sd.LayerParameters? clipParams; + RectangleF clipBounds; +#if WINFORMS + DrawableHandler drawable; +#endif + public float PointsPerPixel { get { return 72f / Control.DotsPerInch.Width; } } + + protected override bool DisposeControl { get { return disposeControl; } } + + protected sd.Layer HelperLayer + { + get { return helperLayer ?? (helperLayer = new sd.Layer(Control)); } + } + + public GraphicsHandler() + { + } + + public GraphicsHandler(GraphicsHandler other) + { + Control = other.Control; + disposeControl = false; + } + +#if WINFORMS + public GraphicsHandler(DrawableHandler drawable) + { + this.drawable = drawable; + CreateRenderTarget(); + + //set hwnd target properties (permit to attach Direct2D to window) + //target creation + drawable.Control.SizeChanged += HandleSizeChanged; + } +#endif + void CreateRenderTarget() + { +#if WINFORMS + if (drawable != null) + { + var renderProp = CreateRenderProperties(); + renderProp.PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Premultiplied); + var winProp = new sd.HwndRenderTargetProperties + { + Hwnd = drawable.Control.Handle, + PixelSize = drawable.ClientSize.ToDx(), + PresentOptions = sd.PresentOptions.Immediately + }; + + Control = new sd.WindowRenderTarget(SDFactory.D2D1Factory, renderProp, winProp); + return; + } +#endif + CreateWicTarget(); // this is executed in winforms if not created from a drawable, and always in Xaml. + } + + private void CreateWicTarget() + { + if (image != null) + { + var renderProp = CreateRenderProperties(); + var imageHandler = image.Handler as BitmapHandler; + renderProp.PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.Unknown, sd.AlphaMode.Unknown); + Control = new sd.WicRenderTarget(SDFactory.D2D1Factory, imageHandler.Control, renderProp); + } + } + + private static sd.RenderTargetProperties CreateRenderProperties() + { + var renderProp = new sd.RenderTargetProperties + { + DpiX = 0, + DpiY = 0, + MinLevel = sd.FeatureLevel.Level_DEFAULT, + Type = sd.RenderTargetType.Default, + Usage = sd.RenderTargetUsage.None + }; + + return renderProp; + } + + void HandleSizeChanged(object sender, EventArgs e) + { +#if WINFORMS + var target = Control as sd.WindowRenderTarget; + if (target == null) + return; + try + { + target.Resize(drawable.ClientSize.ToDx()); + drawable.Invalidate(); + } + catch (Exception ex) + { + Debug.WriteLine(string.Format("Could not resize: {0}", ex)); + } +#else + throw new NotImplementedException(); +#endif + } + + sd.Ellipse GetEllipse(float x, float y, float width, float height) + { + var rx = width / 2f; + var ry = height / 2f; + + return new sd.Ellipse(center: new s.Vector2(x + rx, y + ry), radiusX: rx, radiusY: ry); + } + + public bool AntiAlias + { + get { return Control != null && Control.AntialiasMode == sd.AntialiasMode.PerPrimitive; } + set + { + if (Control != null) + Control.AntialiasMode = value ? sd.AntialiasMode.PerPrimitive : sd.AntialiasMode.Aliased; + } + } + + public ImageInterpolation ImageInterpolation { get; set; } + + public bool IsRetained + { + get { return false; } + } + + public double DpiX + { + get { return Control.DotsPerInch.Width; } + } + + public double DpiY + { + get { return Control.DotsPerInch.Height; } + } + + public RectangleF ClipBounds + { + get + { + if (Control != null) + { + // not very efficient, but works + var transform = Control.Transform; + transform.Invert(); + var start = s.Matrix3x2.TransformPoint(transform, clipBounds.Location.ToDx()).ToEto(); + var end = s.Matrix3x2.TransformPoint(transform, clipBounds.EndLocation.ToDx()).ToEto(); + return new RectangleF(start, end); + } + else + return new RectangleF(); + } + } + + public void SetClip(RectangleF rect) + { + ResetClip(); + clipBounds = rect; + rectClip = true; + Control.PushAxisAlignedClip(rect.ToDx(), Control.AntialiasMode); + } + + public void SetClip(IGraphicsPath path) + { + ResetClip(); + clipBounds = path.Bounds; + var parameters = new sd.LayerParameters + { + ContentBounds = clipBounds.ToDx(), + GeometricMask = clipGeometry = path.ToGeometry(), + MaskAntialiasMode = Control.AntialiasMode, + MaskTransform = s.Matrix3x2.Identity, + Opacity = 1f + }; + clipParams = parameters; + Control.PushLayer(ref parameters, HelperLayer); + } + + public void ResetClip() + { + if (clipParams != null) + { + Control.PopLayer(); + clipBounds = new RectangleF(Control.Size.ToEto()); + clipParams = null; + } + if (rectClip) + { + Control.PopAxisAlignedClip(); + rectClip = false; + clipBounds = new RectangleF(Control.Size.ToEto()); + } + } + + public void TranslateTransform(float dx, float dy) + { + Control.Transform = s.Matrix3x2.Multiply(s.Matrix3x2.Translation(dx, dy), Control.Transform); + } + + public void RotateTransform(float angle) + { + Control.Transform = s.Matrix3x2.Multiply(s.Matrix3x2.Rotation((float)(Conversions.DegreesToRadians(angle))), Control.Transform); + } + + public void ScaleTransform(float sx, float sy) + { + Control.Transform = s.Matrix3x2.Multiply(s.Matrix3x2.Scaling(sx, sy), Control.Transform); + } + + public void MultiplyTransform(IMatrix matrix) + { + Control.Transform = s.Matrix3x2.Multiply((s.Matrix3x2)matrix.ControlObject, Control.Transform); + } + + Stack transformStack; + + public void SaveTransform() + { + if (transformStack == null) + transformStack = new Stack(); + transformStack.Push(Control.Transform); + } + + public void RestoreTransform() + { + Control.Transform = transformStack.Pop(); + } + + public void CreateFromImage(Bitmap image) + { + this.image = image; + CreateWicTarget(); + BeginDrawing(); + } + + public void DrawText(Font font, SolidBrush brush, float x, float y, string text) + { + using (var textLayout = GetTextLayout(font, text)) + { + Control.DrawTextLayout(new s.Vector2(x, y), textLayout, brush.ToDx(Control)); + } + } + + public SizeF MeasureString(Font font, string text) + { + using (var textLayout = GetTextLayout(font, text)) + { + var metrics = textLayout.Metrics; + return new SizeF(metrics.WidthIncludingTrailingWhitespace, metrics.Height); + } + } + + static sw.TextLayout GetTextLayout(Font font, string text) + { + var fontHandler = (FontHandler)font.Handler; + var textLayout = new sw.TextLayout(SDFactory.DirectWriteFactory, text, fontHandler.TextFormat, float.MaxValue, float.MaxValue); + return textLayout; + } + + public void Flush() + { + Control.Flush(); + } + + public PixelOffsetMode PixelOffsetMode + { + get { return offset == 0f ? PixelOffsetMode.None : PixelOffsetMode.Half; } + set + { + if (value == PixelOffsetMode.None) + { + offset = .5f; + fillOffset = 0f; + } + else + { + offset = 0f; + fillOffset = -.5f; + } + } + } + + public void DrawRectangle(Pen pen, float x, float y, float width, float height) + { + var pd = pen.ToPenData(); + Control.DrawRectangle(new s.RectangleF(x + offset, y + offset, width, height), pd.GetBrush(Control), pd.Width, pd.StrokeStyle); + } + + public void FillRectangle(Brush brush, float x, float y, float width, float height) + { + Control.FillRectangle(new s.RectangleF(x + fillOffset, y + fillOffset, width, height), brush.ToDx(Control)); + } + + public void DrawLine(Pen pen, float startx, float starty, float endx, float endy) + { + var pd = pen.ToPenData(); + Control.DrawLine( + new s.Vector2(startx + offset, starty + offset), + new s.Vector2(endx + offset, endy + offset), + pd.GetBrush(Control), + pd.Width, + pd.StrokeStyle); + } + + public void FillEllipse(Brush brush, float x, float y, float width, float height) + { + Control.FillEllipse(GetEllipse(x + fillOffset, y + fillOffset, width, height), brush.ToDx(Control)); + } + + public void DrawEllipse(Pen pen, float x, float y, float width, float height) + { + var pd = pen.ToPenData(); + Control.DrawEllipse(GetEllipse(x + offset, y + offset, width, height), pd.GetBrush(Control), pd.Width, pd.StrokeStyle); + } + + public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) + { + PointF start; + var arc = CreateArc(x + offset, y + offset, width, height, startAngle, sweepAngle, out start); + var path = new sd.PathGeometry(SDFactory.D2D1Factory); + var sink = path.Open(); + sink.BeginFigure(start.ToDx(), sd.FigureBegin.Hollow); + sink.AddArc(arc); + sink.EndFigure(sd.FigureEnd.Open); + sink.Close(); + sink.Dispose(); + var pd = pen.ToPenData(); + Control.DrawGeometry(path, pd.GetBrush(Control), pd.Width, pd.StrokeStyle); + } + + internal static sd.ArcSegment CreateArc(float x, float y, float width, float height, float startAngle, float sweepAngle, out PointF start) + { + // degrees to radians conversion + float startRadians = startAngle * (float)Math.PI / 180.0f; + float sweepRadians = sweepAngle * (float)Math.PI / 180.0f; + + // x and y radius + float dx = width / 2; + float dy = height / 2; + + // determine the start point + float xs = x + dx + ((float)Math.Cos(startRadians) * dx); + float ys = y + dy + ((float)Math.Sin(startRadians) * dy); + + // determine the end point + float xe = x + dx + ((float)Math.Cos(startRadians + sweepRadians) * dx); + float ye = y + dy + ((float)Math.Sin(startRadians + sweepRadians) * dy); + + bool isLargeArc = Math.Abs(sweepAngle) > 180; + bool isClockwise = sweepAngle >= 0 && Math.Abs(sweepAngle) < 360; + start = new PointF(xs, ys); + return new sd.ArcSegment + { + Point = new s.Vector2(xe, ye), + Size = new s.Size2F(dx, dy), + SweepDirection = isClockwise ? sd.SweepDirection.Clockwise : sd.SweepDirection.CounterClockwise, + ArcSize = isLargeArc ? sd.ArcSize.Large : sd.ArcSize.Small + }; + } + + + public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) + { + PointF start; + x += fillOffset; + y += fillOffset; + var arc = CreateArc(x, y, width, height, startAngle, sweepAngle, out start); + var path = new sd.PathGeometry(SDFactory.D2D1Factory); + var sink = path.Open(); + var center = new s.Vector2(x + width / 2, y + height / 2); + sink.BeginFigure(center, sd.FigureBegin.Filled); + sink.AddLine(start.ToDx()); + sink.AddArc(arc); + sink.AddLine(center); + sink.EndFigure(sd.FigureEnd.Open); + sink.Close(); + sink.Dispose(); + Control.FillGeometry(path, brush.ToDx(Control)); + } + + public void FillPath(Brush brush, IGraphicsPath path) + { + SaveTransform(); + TranslateTransform(-fillOffset, -fillOffset); + Control.FillGeometry(path.ToGeometry(), brush.ToDx(Control)); + RestoreTransform(); + } + + public void DrawPath(Pen pen, IGraphicsPath path) + { + var pd = pen.ToPenData(); + SaveTransform(); + TranslateTransform(offset, offset); + Control.DrawGeometry(path.ToGeometry(), pd.GetBrush(Control), pd.Width, pd.StrokeStyle); + RestoreTransform(); + } + + public void DrawImage(Image image, RectangleF source, RectangleF destination) + { + var bmp = image.ToDx(Control); + Control.DrawBitmap(bmp, destination.ToDx(), 1f, sd.BitmapInterpolationMode.Linear, source.ToDx()); + } + + public void DrawImage(Image image, float x, float y) + { + var bmp = image.ToDx(Control); + if (bmp != null) + Control.DrawBitmap(bmp, new s.RectangleF(x, y, bmp.Size.Width, bmp.Size.Height), 1f, ImageInterpolation.ToDx()); + } + + public void DrawImage(Image image, float x, float y, float width, float height) + { + var bmp = image.ToDx(Control); + Control.DrawBitmap(bmp, new s.RectangleF(x, y, width, height), 1f, ImageInterpolation.ToDx()); + } + + public object ControlObject + { + get { throw new NotImplementedException(); } + } + + public void Clear(SolidBrush brush) + { + if (Control != null) + { + var color = brush != null ? brush.Color : Colors.Transparent; + // drawing to an image, so we can clear to transparent + if (image != null) + { + if (clipParams != null) + { + // can't clear the current layer otherwise it will not be applied to main layer + // This creates a copy of the current context, inverses the current clip, and draws the image back clipping + // the cleared path. + + // end clip layer and current drawing session + Control.PopLayer(); + Control.EndDraw(); + + // create a copy of the current state + var copy = image.Clone(); + var bmp = copy.ToDx(Control); + + Control.BeginDraw(); + + // clear existing contents + Control.Clear(null); + var size = Control.Size; + + // create an inverse geometry + var inverse = new sd.PathGeometry(SDFactory.D2D1Factory); + var sink = inverse.Open(); + var bounds = new s.RectangleF(0, 0, size.Width, size.Height); + var geom = new sd.RectangleGeometry(SDFactory.D2D1Factory, bounds); + geom.Combine(clipGeometry, sd.CombineMode.Exclude, sink); + sink.Close(); + + // create a new mask layer with inverse geometry + var parameters = new sd.LayerParameters + { + ContentBounds = bounds, + GeometricMask = inverse, + MaskAntialiasMode = Control.AntialiasMode, + MaskTransform = s.Matrix3x2.Identity, + Opacity = 1f + }; + Control.PushLayer(ref parameters, HelperLayer); + + // draw bitmap of contents back, clipping to the inverse of the clip region + Control.DrawBitmap(bmp, 1f, sd.BitmapInterpolationMode.NearestNeighbor); + Control.PopLayer(); + + // restore our clip path + parameters = clipParams.Value; + Control.PushLayer(ref parameters, HelperLayer); + + copy.Dispose(); + } + } + else + { + // alpha is not supported on a drawable, so blend with black as the base color. + color = Color.Blend(Colors.Black, color); + } + + Control.Clear(color.ToDx()); + } + } + + static sd.RenderTarget globalRenderTarget; + /// + /// This is a HACK. + /// Brushes, bitmaps and other resources are associated with a specific + /// render target in D2D. Eto does not currently support this. + /// + public static sd.RenderTarget CurrentRenderTarget + { + get + { + if (globalRenderTarget == null) + { +#if WINFORMS + // hack for now, use a temporary control to get the current target + // ideally, each brush/etc will create itself when needed, not right away. + // though, this may be difficult for things like a bitmap + var ctl = new System.Windows.Forms.Control(); + var winProp = new sd.HwndRenderTargetProperties + { + Hwnd = ctl.Handle, + PixelSize = new s.Size2(2000, 2000), + PresentOptions = sd.PresentOptions.Immediately + }; + var renderProp = new sd.RenderTargetProperties + { + DpiX = 0, + DpiY = 0, + MinLevel = sd.FeatureLevel.Level_10, + PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Premultiplied), + Type = sd.RenderTargetType.Hardware, + Usage = sd.RenderTargetUsage.None + }; + globalRenderTarget = new sd.WindowRenderTarget(SDFactory.D2D1Factory, renderProp, winProp); +#else + throw new NotImplementedException(); +#endif + } + return currentRenderTarget ?? globalRenderTarget; + } + set + { + currentRenderTarget = value; + } + } + + static sd.RenderTarget currentRenderTarget; + + public void BeginDrawing(RectangleF? clipRect = null) + { + if (Control != null) + { + CurrentRenderTarget = Control; + Control.BeginDraw(); + Control.Transform = s.Matrix3x2.Identity; + if (transformStack != null) + transformStack.Clear(); + ResetClip(); + clipBounds = new RectangleF(Control.Size.ToEto()); + if (clipRect != null) + Control.PushAxisAlignedClip(clipRect.Value.ToDx(), SharpDX.Direct2D1.AntialiasMode.PerPrimitive); + hasBegan = true; + } + } + + public void EndDrawing(bool popClip = false) + { + if (hasBegan) + { + ResetClip(); + CurrentRenderTarget = null; + + if (popClip) + Control.PopAxisAlignedClip(); + + Control.EndDraw(); + hasBegan = false; + + if (image != null) + { + var imageHandler = image.Handler as BitmapHandler; + imageHandler.Reset(); + } + } + } + + public void PerformDrawing(RectangleF? clipRect, Action draw) + { + bool recreated = false; + do + { + try + { + recreated = false; + BeginDrawing(clipRect); + draw(); + EndDrawing(clipRect != null); + } + catch (s.SharpDXException ex) + { + if (ex.ResultCode == 0x8899000C) // D2DERR_RECREATE_TARGET + { + Debug.WriteLine("Recreating targets"); + // need to recreate render target + CreateRenderTarget(); + CurrentRenderTarget = Control; + globalRenderTarget = null; + recreated = true; + } + } + } + while (recreated); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + EndDrawing(); + base.Dispose(disposing); + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/GraphicsPathHandler.cs b/Source/Eto.Direct2D/Drawing/GraphicsPathHandler.cs new file mode 100644 index 0000000000..956fb2b3c2 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/GraphicsPathHandler.cs @@ -0,0 +1,241 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.DirectWrite; +using Eto.Drawing; + +namespace Eto.Direct2D.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class GraphicsPathHandler : GraphicsPath.IHandler + { + List geometries = new List(); + IMatrix transform; + sd.PathGeometry path; + bool isInFigure = false; + sd.FillMode fillMode; + sd.Geometry control; + + public PointF CurrentPoint { get; private set; } + public object ControlObject { get { return this.Control; } } + + public sd.Geometry Control + { + get + { + if (control == null) + { + if (geometries.Count > 0) + { + control = new sd.GeometryGroup(SDFactory.D2D1Factory, fillMode, geometries.ToArray()); + } + if (transform != null && control != null) + control = new sd.TransformedGeometry(SDFactory.D2D1Factory, control, transform.ToDx()); + } + return control; + } + } + public RectangleF Bounds + { + get + { + return Control.GetBounds().ToEto(); + } + } + + sd.GeometrySink sink; + public sd.GeometrySink Sink + { + get + { + if (sink == null) + { + geometries.Add(path = new sd.PathGeometry(SDFactory.D2D1Factory)); + control = null; + sink = path.Open(); + } + return sink; + } + } + + public GraphicsPathHandler() + { + } + + public void CloseSink() + { + // This must be called before rendering the path. + if (sink != null) + { + if (isInFigure) + sink.EndFigure(sd.FigureEnd.Open); + isInFigure = false; + sink.Close(); + sink.Dispose(); + sink = null; + } + } + + public void AddBezier(PointF pt1, PointF pt2, PointF pt3, PointF pt4) + { + ConnectTo(pt1); + AddBezier(pt2, pt3, pt4); + } + + void AddBezier(PointF pt2, PointF pt3, PointF pt4) + { + Sink.AddBezier(new sd.BezierSegment + { + Point1 = pt2.ToDx(), + Point2 = pt3.ToDx(), + Point3 = pt4.ToDx() + }); + + CurrentPoint = pt4; + } + + public IGraphicsPath Clone() + { + throw new NotImplementedException(); + } + + public FillMode FillMode + { + get { return fillMode.ToEto(); ; } + set { fillMode = value.ToDx(); } + } + + public bool IsEmpty + { + get { return geometries.Count == 0; } + } + + void ConnectTo(PointF p) + { + var pt = p.ToDx(); + if (isInFigure) + Sink.AddLine(pt); + else + { + isInFigure = true; + // create filled for when we fill with a brush + Sink.BeginFigure(pt, sd.FigureBegin.Filled); + } + + CurrentPoint = p; + } + + public void StartFigure() + { + if (isInFigure) + { + Sink.EndFigure(sd.FigureEnd.Open); + isInFigure = false; + } + } + + public void CloseFigure() + { + if (isInFigure) + { + Sink.EndFigure(sd.FigureEnd.Closed); + isInFigure = false; + } + } + + public void Transform(IMatrix matrix) + { + if (matrix != null) + { + if (transform != null) + transform.Prepend(matrix); + else + transform = matrix.Clone(); + } + else + transform = null; + control = null; + } + + public void AddLine(float startX, float startY, float endX, float endY) + { + ConnectTo(new PointF(startX, startY)); + ConnectTo(new PointF(endX, endY)); + } + + public void AddLines(IEnumerable points) + { + foreach (var p in points) + ConnectTo(p); + } + + public void LineTo(float x, float y) + { + ConnectTo(new PointF(x, y)); + } + + public void MoveTo(float x, float y) + { + StartFigure(); + ConnectTo(new PointF(x, y)); + } + + public void AddCurve(IEnumerable points, float tension = 0.5f) + { + var temp = SplineHelper.SplineCurve(points, tension); + SplineHelper.Draw(temp, ConnectTo, AddBezier); + } + + public void AddArc(float x, float y, float width, float height, float startAngle, float sweepAngle) + { + PointF start; + var arc = GraphicsHandler.CreateArc(x, y, width, height, startAngle, sweepAngle, out start); + ConnectTo(start); + Sink.AddArc(arc); + } + + public void AddEllipse(float x, float y, float width, float height) + { + CloseSink(); + var ellipse = new sd.Ellipse(new s.Vector2(x + width / 2, y + height / 2), width / 2, height / 2); + geometries.Add(new sd.EllipseGeometry(SDFactory.D2D1Factory, ellipse)); + control = null; + } + + public void AddPath(IGraphicsPath path, bool connect) + { + var inputGeometry = path.ToHandler(); + if (connect) + { + // TODO: how do we attach to the existing sink? throws an exception otherwise + StartFigure(); + inputGeometry.Control.Simplify(sd.GeometrySimplificationOption.CubicsAndLines, Sink); + } + else + { + CloseSink(); + geometries.Add(inputGeometry.Control); + } + control = null; + } + + public void AddRectangle(float x, float y, float width, float height) + { + CloseSink(); + geometries.Add(new sd.RectangleGeometry(SDFactory.D2D1Factory, new s.RectangleF(x, y, width, height))); + control = null; + } + + public void Dispose() + { + Control.Dispose(); + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/IconHandler.cs b/Source/Eto.Direct2D/Drawing/IconHandler.cs new file mode 100644 index 0000000000..787b53d669 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/IconHandler.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.WIC; +#if WINFORMS +using Eto.WinForms.Drawing; +#endif + +namespace Eto.Direct2D.Drawing +{ + public class IconHandler : ImageHandler, Icon.IHandler +#if WINFORMS + , IWindowsIconSource +#endif + { +#if WINFORMS + System.Drawing.Icon sdicon; + public System.Drawing.Icon GetIcon() + { + if (sdicon == null && Frames != null) + { + // TODO: Convert each bitmap in Frames to a single icon + sdicon = System.Drawing.Icon.FromHandle(Control.ToBitmap().ToSD().GetHicon()); + } + return sdicon; + } + + public override void Reset() + { + base.Reset(); + if (sdicon != null) + { + sdicon.Dispose(); + sdicon = null; + } + } +#endif + } +} diff --git a/Source/Eto.Direct2D/Drawing/ImageHandler.cs b/Source/Eto.Direct2D/Drawing/ImageHandler.cs new file mode 100644 index 0000000000..5a37df4f35 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/ImageHandler.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.WIC; +using System.IO; +using System.Diagnostics; +#if WINFORMS +using Eto.WinForms.Drawing; +#endif + +namespace Eto.Direct2D.Drawing +{ + public interface ID2DBitmapHandler + { + sd.Bitmap GetBitmap(sd.RenderTarget target); + } + + public class ImageHandler : WidgetHandler, Image.IHandler, ID2DBitmapHandler +#if WINFORMS + , IWindowsImageSource +#endif + where TWidget: Image + { + sd.Bitmap targetBitmap; + public sw.Bitmap[] Frames { get; private set; } + public sd.Bitmap GetBitmap(sd.RenderTarget target) + { + if (targetBitmap == null || !ReferenceEquals(targetBitmap.Tag, target)) + { + targetBitmap = CreateDrawableBitmap(target); + } + return targetBitmap; + } + + protected virtual sd.Bitmap CreateDrawableBitmap(sd.RenderTarget target) + { + return sd.Bitmap.FromWicBitmap(target, Control); + } + + void Initialize(s.WIC.BitmapDecoder decoder) + { + Frames = Enumerable.Range(0, decoder.FrameCount).Select(r => decoder.GetFrame(r).ToBitmap()).ToArray(); + // find largest frame (e.g. when loading icons) + Control = Frames.Aggregate((x,y) => x.Size.Width > y.Size.Width || x.Size.Height > y.Size.Height ? x : y); + } + + public void Create(string filename) + { + using (var decoder = new s.WIC.BitmapDecoder( + SDFactory.WicImagingFactory, + filename, + s.WIC.DecodeOptions.CacheOnDemand)) + Initialize(decoder); + } + + public void Create(System.IO.Stream stream) + { + using (var decoder = new s.WIC.BitmapDecoder( + SDFactory.WicImagingFactory, + stream, + s.WIC.DecodeOptions.CacheOnDemand)) + Initialize(decoder); + } + + public void Create(int width, int height, PixelFormat pixelFormat) + { + Control = new sw.Bitmap(SDFactory.WicImagingFactory, width, height, pixelFormat.ToWic(), sw.BitmapCreateCacheOption.CacheOnLoad); + } + + public void Create(int width, int height, Graphics graphics) + { + Create(width, height, PixelFormat.Format32bppRgba); + } + + public void Save(Stream stream, ImageFormat format) + { + using (var encoder = new s.WIC.BitmapEncoder( + SDFactory.WicImagingFactory, + format.ToWic())) + { + stream.Flush(); + encoder.Initialize(stream); + using (var frameEncoder = new s.WIC.BitmapFrameEncode(encoder)) + { + frameEncoder.Initialize(); + frameEncoder.SetSize(Control.Size.Width, Control.Size.Height); + frameEncoder.WriteSource(Control); + frameEncoder.Commit(); + } + encoder.Commit(); + } + } + + public Bitmap Clone(Rectangle? rectangle = null) + { + sw.Bitmap bmp = Control; + if (rectangle != null) + bmp = new sw.Bitmap(SDFactory.WicImagingFactory, bmp, rectangle.Value.ToDx()); + else + bmp = new sw.Bitmap(SDFactory.WicImagingFactory, bmp, sw.BitmapCreateCacheOption.CacheOnLoad); + + return new Bitmap(new BitmapHandler { Control = bmp }); + } + + public Color GetPixel(int x, int y) + { + try + { + var output = new uint[1]; + Control.CopyPixels(new s.Rectangle(x, y, 1, 1), output); + return new s.Color4(new s.ColorBGRA(output[0]).ToRgba()).ToEto(); + } + catch (s.SharpDXException ex) + { + Debug.WriteLine("GetPixel: {0}", ex.ToString()); + throw; + } + } + + public Size Size + { + get { return Control.Size.ToEto(); } + } + + public void Create(Image image, int width, int height, ImageInterpolation interpolation) + { + var imageHandler = (ImageHandler)image.Handler; + + Control = new sw.Bitmap(SDFactory.WicImagingFactory, width, height, imageHandler.Control.PixelFormat, sw.BitmapCreateCacheOption.CacheOnLoad); + using (var graphics = new Graphics(Widget as Bitmap)) + { + graphics.ImageInterpolation = interpolation; + var rect = new Rectangle(0, 0, width, height); + graphics.FillRectangle(Colors.Transparent, rect); + graphics.DrawImage(image, rect); + } + } + + public virtual void Reset() + { + if (targetBitmap != null) + { + targetBitmap.Dispose(); + targetBitmap = null; + } +#if WINFORMS + if (sdimage != null) + { + sdimage.Dispose(); + sdimage = null; + } +#endif + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + Reset(); + if (Frames != null) + { + foreach (var frame in Frames) + { + frame.Dispose(); + } + Control = null; + } + } + base.Dispose(disposing); + } + +#if WINFORMS + System.Drawing.Image sdimage; + + public virtual System.Drawing.Image GetImageWithSize(int? size) + { + if (size != null && Frames != null && Control.Size.Width > size.Value) + { + var src = Frames.Aggregate((x, y) => Math.Abs(x.Size.Width - size.Value) < Math.Abs(y.Size.Width - size.Value) ? x : y); + if (src != null) + { + return src.ToBitmap().ToSD(); + } + } + return sdimage ?? (sdimage = Control.ToSD()); + } +#endif + } +} diff --git a/Source/Eto.Direct2D/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Direct2D/Drawing/IndexedBitmapHandler.cs new file mode 100644 index 0000000000..0f5408e266 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/IndexedBitmapHandler.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.WIC; +using System.IO; + +namespace Eto.Direct2D.Drawing +{ + public class IndexedBitmapHandler : ImageHandler, IndexedBitmap.IHandler + { + public static Guid GetFormat(int bitsPerPixel) + { + switch (bitsPerPixel) + { + case 8: + return sw.PixelFormat.Format8bppIndexed; + case 4: + return sw.PixelFormat.Format4bppIndexed; + case 2: + return sw.PixelFormat.Format2bppIndexed; + case 1: + return sw.PixelFormat.Format1bppIndexed; + default: + throw new NotSupportedException(); + } + } + + protected override sd.Bitmap CreateDrawableBitmap(sd.RenderTarget target) + { + using (var converter = new sw.FormatConverter(SDFactory.WicImagingFactory)) + { + converter.Initialize(Control, sw.PixelFormat.Format32bppPBGRA); + var bmp = new sw.Bitmap(SDFactory.WicImagingFactory, converter, sw.BitmapCreateCacheOption.CacheOnLoad); + return sd.Bitmap.FromWicBitmap(target, bmp); + } + } + + public void Create(int width, int height, int bitsPerPixel) + { + Control = new sw.Bitmap(SDFactory.WicImagingFactory, width, height, GetFormat(bitsPerPixel), sw.BitmapCreateCacheOption.CacheOnLoad); + } + + public BitmapData Lock() + { + var data = Control.Lock(sw.BitmapLockFlags.Write); + return new WicBitmapData(Widget, data, Widget.BitsPerPixel); + } + + public void Unlock(BitmapData bitmapData) + { + Reset(); + } + + public void Resize(int width, int height) + { + throw new NotImplementedException(); + } + + Palette palette; + public Palette Palette + { + get { return palette; } + set + { + palette = value; + var pal = new sw.Palette(SDFactory.WicImagingFactory); + // for some reason, Red/Blue are swapped here when displaying the bitmap + pal.Initialize(palette.Select(r => new s.Color4(r.B, r.G, r.R, r.A)).ToArray()); + Control.Palette = pal; + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Direct2D/Drawing/LinearGradientBrushHandler.cs b/Source/Eto.Direct2D/Drawing/LinearGradientBrushHandler.cs new file mode 100644 index 0000000000..04cafb8cc2 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/LinearGradientBrushHandler.cs @@ -0,0 +1,85 @@ +using Eto.Drawing; +using sd = SharpDX.Direct2D1; +using s = SharpDX; + +namespace Eto.Direct2D.Drawing +{ + public class LinearGradientBrushHandler : LinearGradientBrush.IHandler + { + public class LinearBrushData : TransformBrushData + { + public PointF StartPoint { get; set; } + public PointF EndPoint { get; set; } + public Color StartColor { get; set; } + public Color EndColor { get; set; } + public GradientWrapMode WrapMode { get; set; } + + protected override sd.Brush Create(sd.RenderTarget target) + { + return new sd.LinearGradientBrush( + target, + new sd.LinearGradientBrushProperties + { + StartPoint = StartPoint.ToDx(), + EndPoint = EndPoint.ToDx() + }, + new sd.GradientStopCollection(GraphicsHandler.CurrentRenderTarget, new[] { + new sd.GradientStop { Color = StartColor.ToDx(), Position = 0f }, + new sd.GradientStop { Color = EndColor.ToDx(), Position = 1f } + }, WrapMode == GradientWrapMode.Reflect ? sd.ExtendMode.Mirror : sd.ExtendMode.Wrap) + ); + } + } + + public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint) + { + return new LinearBrushData + { + StartColor = startColor, + EndColor = endColor, + StartPoint = startPoint, + EndPoint = endPoint + }; + } + + public object Create(RectangleF rectangle, Color startColor, Color endColor, float angle) + { + var matrix = new MatrixHandler(); + var startPoint = rectangle.Location; + matrix.RotateAt(angle - 45, startPoint.X, startPoint.Y); + var endPoint = matrix.TransformPoint(rectangle.EndLocation); + return new LinearBrushData + { + StartColor = startColor, + EndColor = endColor, + StartPoint = startPoint, + EndPoint = endPoint + }; + } + + public IMatrix GetTransform(LinearGradientBrush widget) + { + var brush = (LinearBrushData)widget.ControlObject; + return brush.Transform; + } + + public void SetTransform(LinearGradientBrush widget, IMatrix transform) + { + var brush = (LinearBrushData)widget.ControlObject; + brush.Transform = transform; + } + + public GradientWrapMode GetGradientWrap(LinearGradientBrush widget) + { + var brush = (LinearBrushData)widget.ControlObject; + return brush.WrapMode; + } + + public void SetGradientWrap(LinearGradientBrush widget, GradientWrapMode gradientWrap) + { + var brush = (LinearBrushData)widget.ControlObject; + brush.WrapMode = gradientWrap; + brush.Reset(); + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/MatrixHandler.cs b/Source/Eto.Direct2D/Drawing/MatrixHandler.cs new file mode 100644 index 0000000000..c126198dbc --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/MatrixHandler.cs @@ -0,0 +1,174 @@ +using System; +using Eto.Drawing; +using s = SharpDX; + +namespace Eto.Direct2D.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class MatrixHandler : Matrix.IHandler + { + s.Matrix3x2 Control; + + public MatrixHandler() + { + this.Control = s.Matrix3x2.Identity; + } + + public MatrixHandler(ref s.Matrix3x2 m) + { + this.Control = m; // copied the value as Control is a struct + } + + public float[] Elements + { + get + { + return new float[] { + (float)Control.M11, + (float)Control.M12, + (float)Control.M21, + (float)Control.M22, + (float)Control.M31, + (float)Control.M32}; + } + } + + public float OffsetX + { + get { return (float)Control.M31; } + } + + public float OffsetY + { + get { return (float)Control.M32; } + } + + public void Rotate(float angle) + { + Control = s.Matrix3x2.Multiply(s.Matrix3x2.Rotation(Conversions.DegreesToRadians(angle)), Control); // premultiply + } + + public void RotateAt(float angle, float centerX, float centerY) + { + angle = Conversions.DegreesToRadians(angle); + var sina = (float)Math.Sin(angle); + var cosa = (float)Math.Cos(angle); + var matrix = new s.Matrix3x2(cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa); + Control = s.Matrix3x2.Multiply(matrix, Control); + } + + public void Translate(float x, float y) + { + Control = s.Matrix3x2.Multiply(s.Matrix3x2.Translation(x, y), Control); // premultiply + } + + public void Scale(float sx, float sy) + { + Control = s.Matrix3x2.Multiply(s.Matrix3x2.Scaling(sx, sy), Control); // premultiply + } + + public void Skew(float skewX, float skewY) + { + var matrix = new s.Matrix3x2(1, (float)Math.Tan(Conversions.DegreesToRadians(skewX)), (float)Math.Tan(Conversions.DegreesToRadians(skewY)), 1, 0, 0); + Control = s.Matrix3x2.Multiply(matrix, Control); + } + + public void ScaleAt(float scaleX, float scaleY, float centerX, float centerY) + { + var matrix = new s.Matrix3x2(scaleX, 0f, 0f, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); + Control = s.Matrix3x2.Multiply(matrix, Control); + } + + public void Prepend(IMatrix matrix) + { + Control = s.Matrix3x2.Multiply(matrix.ToDx(), this.Control); + } + + public void Append(IMatrix matrix) + { + Control = s.Matrix3x2.Multiply(this.Control, matrix.ToDx()); + } + + public void Create(float m11, float m12, float m21, float m22, float dx, float dy) + { + this.Control = new s.Matrix3x2(m11, m12, m21, m22, dx, dy); + } + + public void Create() + { + this.Control = s.Matrix3x2.Identity; + } + + public void Invert() + { + this.Control = s.Matrix3x2.Invert(this.Control); + } + + public PointF TransformPoint(Point p) + { + s.Vector2 v = s.Matrix3x2.TransformPoint(this.Control, new s.Vector2(p.X, p.Y)); // implicit conversion from Vector2 to Vector2 + return v.ToEto(); + } + + public PointF TransformPoint(PointF p) + { + s.Vector2 v = s.Matrix3x2.TransformPoint(this.Control, p.ToDx()); // implicit conversion from Vector2 to Vector2 + return v.ToEto(); + } + + public float Xx + { + get { return Control.M11; } + set { Control.M11 = value; } + } + + public float Xy + { + get { return Control.M21; } + set { Control.M21 = value; } + } + + public float Yx + { + get { return Control.M12; } + set { Control.M12 = value; } + } + + public float Yy + { + get { return Control.M22; } + set { Control.M22 = value; } + } + + public float X0 + { + get { return Control.M31; } + set { Control.M31 = value; } + } + + public float Y0 + { + get { return Control.M32; } + set { Control.M32 = value; } + } + + public object ControlObject + { + get { return Control; } + } + + public IMatrix Clone() + { + return new MatrixHandler(ref Control); + } + + public void Dispose() + { + // do nothing + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/PenHandler.cs b/Source/Eto.Direct2D/Drawing/PenHandler.cs new file mode 100644 index 0000000000..d1d23cf439 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/PenHandler.cs @@ -0,0 +1,189 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using Eto.Drawing; + +namespace Eto.Direct2D.Drawing +{ + /// + /// Combines a brush and a stroke style + /// + public class PenData : IDisposable + { + sd.Brush brush; + public sd.Brush GetBrush(sd.RenderTarget target) + { + if (brush == null || !ReferenceEquals(brush.Tag, target)) + { + if (brush != null) + brush.Dispose(); + brush = new sd.SolidColorBrush(target, Color.ToDx()) { Tag = target }; + } + return brush; + } + + sd.StrokeStyle strokeStyle; + public sd.StrokeStyle StrokeStyle + { + get + { + if (strokeStyle == null) + { + var properties = new sd.StrokeStyleProperties + { + DashStyle = dashStyle.ToDx(), + LineJoin = lineJoin.ToDx(), + MiterLimit = miterLimit, + DashCap = lineCap == PenLineCap.Round ? sd.CapStyle.Round : sd.CapStyle.Square, + DashOffset = lineCap == PenLineCap.Butt ? -.5f + dashStyle.Offset : dashStyle.Offset + }; + properties.StartCap = properties.EndCap = lineCap.ToDx(); + if (properties.DashStyle == sd.DashStyle.Custom) + strokeStyle = new sd.StrokeStyle(SDFactory.D2D1Factory, properties, dashStyle.Dashes); + else + strokeStyle = new sd.StrokeStyle(SDFactory.D2D1Factory, properties); + } + + return strokeStyle; + } + } + + void Reset() + { + if (strokeStyle != null) + { + strokeStyle.Dispose(); + strokeStyle = null; + } + } + + float miterLimit = 10f; + public float MiterLimit + { + get { return miterLimit; } + set + { + miterLimit = value; + Reset(); + } + } + + public Color Color { get; set; } + + public float Width { get; set; } + + DashStyle dashStyle = DashStyles.Solid; + public DashStyle DashStyle + { + get { return dashStyle; } + set + { + dashStyle = value ?? DashStyles.Solid; + Reset(); + } + } + + PenLineCap lineCap; + public PenLineCap LineCap + { + get { return lineCap; } + set + { + lineCap = value; + Reset(); + } + } + + PenLineJoin lineJoin; + public PenLineJoin LineJoin + { + get { return lineJoin; } + set + { + lineJoin = value; + Reset(); + } + } + + public void Dispose() + { + if (brush != null) + { + brush.Dispose(); + brush = null; + } + + if (strokeStyle != null) + { + strokeStyle.Dispose(); + strokeStyle = null; + } + } + } + + public class PenHandler : Pen.IHandler + { + public object Create(Color color, float thickness) + { + return new PenData { Color = color, Width = thickness }; + } + + public Color GetColor(Pen widget) + { + return widget.ToPenData().Color; + } + + public void SetColor(Pen widget, Color color) + { + widget.ToPenData().Color = color; + } + + public float GetThickness(Pen widget) + { + return widget.ToPenData().Width; + } + + public void SetThickness(Pen widget, float thickness) + { + widget.ToPenData().Width = thickness; + } + + public PenLineJoin GetLineJoin(Pen widget) + { + return widget.ToPenData().LineJoin; + } + + public void SetLineJoin(Pen widget, PenLineJoin lineJoin) + { + widget.ToPenData().LineJoin = lineJoin; + } + + public PenLineCap GetLineCap(Pen widget) + { + return widget.ToPenData().LineCap; + } + + public void SetLineCap(Pen widget, PenLineCap lineCap) + { + widget.ToPenData().LineCap = lineCap; + } + + public float GetMiterLimit(Pen widget) + { + return widget.ToPenData().MiterLimit; + } + + public void SetMiterLimit(Pen widget, float miterLimit) + { + widget.ToPenData().MiterLimit = miterLimit; + } + + public void SetDashStyle(Pen widget, DashStyle dashStyle) + { + widget.ToPenData().DashStyle = dashStyle; + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/SDFactory.cs b/Source/Eto.Direct2D/Drawing/SDFactory.cs new file mode 100644 index 0000000000..3172bf1d3f --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/SDFactory.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using s = SharpDX; +using sd = SharpDX.Direct2D1; +using sw = SharpDX.DirectWrite; + +namespace Eto.Direct2D.Drawing +{ + public static class SDFactory + { + static sd.Factory d2D1Factory; + public static sd.Factory D2D1Factory { get { return d2D1Factory ?? (d2D1Factory = new sd.Factory()); } } + + static s.WIC.ImagingFactory wicImagingFactory; + public static s.WIC.ImagingFactory WicImagingFactory { get { return wicImagingFactory ?? (wicImagingFactory = new s.WIC.ImagingFactory()); } } + + static sw.Factory directWriteFactory; + public static sw.Factory DirectWriteFactory { get { return directWriteFactory ?? (directWriteFactory = new sw.Factory()); } } + } +} diff --git a/Source/Eto.Direct2D/Drawing/SolidBrushHandler.cs b/Source/Eto.Direct2D/Drawing/SolidBrushHandler.cs new file mode 100644 index 0000000000..5069c2bf62 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/SolidBrushHandler.cs @@ -0,0 +1,40 @@ +using Eto.Drawing; +using sd = SharpDX.Direct2D1; + +namespace Eto.Direct2D.Drawing +{ + /// + /// Handler for + /// + /// (c) 2013 by Vivek Jhaveri + /// See LICENSE for full terms + public class SolidBrushHandler : SolidBrush.IHandler + { + public class SolidBrushData : BrushData + { + public Color Color { get; set; } + + protected override sd.Brush Create(sd.RenderTarget target) + { + return new sd.SolidColorBrush(target, Color.ToDx()); + } + } + + public object Create(Color color) + { + return new SolidBrushData { Color = color }; + } + + public Color GetColor(SolidBrush widget) + { + return ((SolidBrushData)widget.ControlObject).Color; + } + + public void SetColor(SolidBrush widget, Color color) + { + var brush = ((SolidBrushData)widget.ControlObject); + brush.Reset(); + brush.Color = color; + } + } +} diff --git a/Source/Eto.Direct2D/Drawing/TextureBrushHandler.cs b/Source/Eto.Direct2D/Drawing/TextureBrushHandler.cs new file mode 100644 index 0000000000..3e3728d268 --- /dev/null +++ b/Source/Eto.Direct2D/Drawing/TextureBrushHandler.cs @@ -0,0 +1,46 @@ +using Eto.Drawing; +using System; +using sd = SharpDX.Direct2D1; + +namespace Eto.Direct2D.Drawing +{ + public class TextureBrushHandler : TextureBrush.IHandler + { + public class TextureBrushData : TransformBrushData + { + public Image Image { get; set; } + + protected override sd.Brush Create(sd.RenderTarget target) + { + var brush = new sd.BitmapBrush(target, Image.ToDx(target)); + brush.ExtendModeX = brush.ExtendModeY = sd.ExtendMode.Wrap; + if (Transform != null) + brush.Transform = Transform.ToDx(); + return brush; + } + } + + public IMatrix GetTransform(TextureBrush widget) + { + var brush = (TextureBrushData)widget.ControlObject; + return brush.Transform; + } + + public void SetTransform(TextureBrush widget, IMatrix transform) + { + var brush = (TextureBrushData)widget.ControlObject; + brush.Transform = transform; + } + + public void SetOpacity(TextureBrush widget, float opacity) + { + var brush = (TextureBrushData)widget.ControlObject; + brush.Alpha = opacity; + } + + public object Create(Image image, float opacity) + { + return new TextureBrushData { Image = image, Alpha = opacity }; + } + } +} diff --git a/Source/Eto.Direct2D/Eto.Direct2D - Pcl.csproj b/Source/Eto.Direct2D/Eto.Direct2D - Pcl.csproj new file mode 100644 index 0000000000..976ce816ad --- /dev/null +++ b/Source/Eto.Direct2D/Eto.Direct2D - Pcl.csproj @@ -0,0 +1,109 @@ + + + + Debug + AnyCPU + {330EF9FD-5947-4AC9-9796-950C7633695F} + Library + Properties + Eto.Direct2D + 512 + ..\..\..\ + true + + v4.5 + Eto.Direct2D + + + true + full + false + ..\..\BuildOutput\Pcl\Debug + DEBUG;TRACE;WINFORMS + prompt + 4 + false + + + true + ..\..\BuildOutput\Pcl\Release + TRACE;WINFORMS + prompt + 4 + false + + + .. + + + + + + + + + + ..\packages\SharpDX.2.5.0\lib\net40\SharpDX.dll + + + ..\packages\SharpDX.Direct2D1.2.5.0\lib\net40\SharpDX.Direct2D1.dll + + + ..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + Drawing\SplineHelper.cs + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + {9F51798A-354C-47A1-9207-4BB7D7FC7FC4} + Eto.WinForms - Pcl + + + + \ No newline at end of file diff --git a/Source/Eto.Direct2D/Eto.Direct2D.csproj b/Source/Eto.Direct2D/Eto.Direct2D.csproj new file mode 100644 index 0000000000..3f09f06235 --- /dev/null +++ b/Source/Eto.Direct2D/Eto.Direct2D.csproj @@ -0,0 +1,108 @@ + + + + Debug + AnyCPU + {3C1B77D5-6C93-4366-A487-3D307FC29FFB} + Library + Properties + Eto.Direct2D + Eto.Direct2D + v4.0 + 512 + ..\..\..\ + true + WINFORMS + + + true + full + false + ..\..\BuildOutput\Debug\ + DEBUG;TRACE;WINFORMS + prompt + 4 + + + pdbonly + true + ..\..\BuildOutput\Release\ + TRACE;WINFORMS + prompt + 4 + + + .. + + + + + + + + + + ..\packages\SharpDX.2.5.0\lib\net40\SharpDX.dll + + + ..\packages\SharpDX.Direct2D1.2.5.0\lib\net40\SharpDX.Direct2D1.dll + + + ..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + Drawing\SplineHelper.cs + + + + + + {16289D2F-044C-49EF-83E9-9391AFF8FD2B} + Eto + + + {69D38C57-AD4B-4A16-A7B1-49BCFBE71491} + Eto.WinForms + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Eto.Direct2D/Forms/Controls/DrawableHandler.cs b/Source/Eto.Direct2D/Forms/Controls/DrawableHandler.cs new file mode 100644 index 0000000000..db8e7f4ebc --- /dev/null +++ b/Source/Eto.Direct2D/Forms/Controls/DrawableHandler.cs @@ -0,0 +1,78 @@ +using Eto.Drawing; +using Eto.Forms; +using Eto.Direct2D.Drawing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using swf = System.Windows.Forms; + +namespace Eto.Direct2D.Forms.Controls +{ + public class DrawableHandler : Eto.WinForms.Forms.Controls.DrawableHandler + { + Graphics graphics; + GraphicsHandler graphicsHandler; + SolidBrush backgroundColor; + + public override Color BackgroundColor + { + get { return backgroundColor != null ? backgroundColor.Color : base.BackgroundColor; } + set + { + backgroundColor = value.A > 0 ? new SolidBrush(value) : null; + if (Widget.Loaded) + Invalidate(); + } + } + + protected override void Initialize() + { + base.Initialize(); + Control.SetStyle(swf.ControlStyles.SupportsTransparentBackColor | swf.ControlStyles.DoubleBuffer, false); + Control.SetStyle(swf.ControlStyles.AllPaintingInWmPaint | swf.ControlStyles.Opaque, true); + Control.HandleCreated += (sender, e) => + { + graphics = new Graphics(new GraphicsHandler(this)); + graphicsHandler = (GraphicsHandler)graphics.Handler; + }; + } + + public override Graphics CreateGraphics() + { + if (graphics == null) + return null; + var handler = new GraphicsHandler((GraphicsHandler)graphics.Handler); + handler.BeginDrawing(); + return new Graphics(handler); + } + + public override void Update(Eto.Drawing.Rectangle rect) + { + if (graphics == null) + return; + graphicsHandler.PerformDrawing(null, () => + { + Callback.OnPaint(Widget, new PaintEventArgs(graphics, rect)); + }); + } + + protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) + { + if (graphics == null) + return; + var clipRect = e.ClipRectangle.ToEto(); + graphicsHandler.PerformDrawing(clipRect, () => + { + // clear to control's background color + if (backgroundColor == null) + backgroundColor = new SolidBrush(base.BackgroundColor); + graphics.Clear(backgroundColor); + + // perform user painting + Callback.OnPaint(Widget, new PaintEventArgs(graphics, clipRect)); + }); + } + } +} diff --git a/Source/Eto.Direct2D/Forms/Printing/PrintDocumentHandler.cs b/Source/Eto.Direct2D/Forms/Printing/PrintDocumentHandler.cs new file mode 100644 index 0000000000..6920179f1c --- /dev/null +++ b/Source/Eto.Direct2D/Forms/Printing/PrintDocumentHandler.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Eto.Direct2D.Forms.Printing +{ + public class PrintDocumentHandler : Eto.WinForms.Forms.Printing.PrintDocumentHandler + { + protected override void HandlePrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) + { + using (((Eto.Direct2D.Platform)Widget.Platform).BasePlatform.Context) + { + base.HandlePrintPage(sender, e); + } + } + } +} diff --git a/Source/Eto.Direct2D/Platform.cs b/Source/Eto.Direct2D/Platform.cs new file mode 100644 index 0000000000..624f636040 --- /dev/null +++ b/Source/Eto.Direct2D/Platform.cs @@ -0,0 +1,57 @@ +using Eto.Drawing; +using Eto.Forms; +using Eto.Direct2D.Drawing; +using Eto.Direct2D.Forms.Controls; +using Eto.Direct2D.Forms.Printing; + +namespace Eto.Direct2D +{ + public class Platform : Eto.WinForms.Platform + { + public override string ID + { + get { return Platforms.Direct2D; } + } + + public Platform() + { + // generator to use for scenarios where direct 2d doesn't work (e.g. printing) + BasePlatform = new Eto.WinForms.Platform(); + + Eto.WinForms.Platform.AddTo(this); + + // This is added after the base class's assembly + AddTo(this); + } + + public Eto.Platform BasePlatform + { + get; + set; + } + + public static new void AddTo(Eto.Platform p) + { + // Drawing + p.Add(() => new BitmapHandler()); + p.Add(() => new FontFamilyHandler()); + p.Add(() => new FontHandler()); + p.Add(() => new FontsHandler()); + p.Add(() => new GraphicsHandler()); + p.Add(() => new GraphicsPathHandler()); + p.Add(() => new IconHandler()); + p.Add(() => new IndexedBitmapHandler()); + p.Add(() => new MatrixHandler()); + p.Add(() => new PenHandler()); + p.Add(() => new SolidBrushHandler()); + p.Add(() => new TextureBrushHandler()); + p.Add(() => new LinearGradientBrushHandler()); + + // Forms.Cells + p.Add(() => new DrawableHandler()); + + // Forms.Printing + p.Add(() => new PrintDocumentHandler()); + } + } +} diff --git a/Source/Eto.Platform.Direct2D/Properties/AssemblyInfo.cs b/Source/Eto.Direct2D/Properties/AssemblyInfo.cs similarity index 100% rename from Source/Eto.Platform.Direct2D/Properties/AssemblyInfo.cs rename to Source/Eto.Direct2D/Properties/AssemblyInfo.cs diff --git a/Source/Eto.Platform.Direct2D/packages.config b/Source/Eto.Direct2D/packages.config similarity index 100% rename from Source/Eto.Platform.Direct2D/packages.config rename to Source/Eto.Direct2D/packages.config diff --git a/Source/Eto.FxCop b/Source/Eto.FxCop index 5ee753da89..e63cbc2af2 100644 --- a/Source/Eto.FxCop +++ b/Source/Eto.FxCop @@ -66,7 +66,6 @@ - @@ -117,29 +116,29 @@ - + - + - Eto.Threading + Eto.Forms.ThemedControls - + - + - Eto.Xaml + Eto.IO - + - + - Eto.Xaml.Extensions + Eto.Threading @@ -161,71 +160,30 @@ - - - - - 'BindingExtensions.Bind(this Control, IndirectBinding, object, IndirectBinding, DualBindingMode, object, object)' - object - 'objectValue' - - - - 'controlProperty' - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'Expression<Func<W, WP>>' + 'BindingExtensions.Bind<TWidget, TWidgetProperty, TSource, TSourceProperty>(this TWidget, Expression<Func<TWidget, TWidgetProperty>>, TSource, Expression<Func<TSource, TSourceProperty>>, DualBindingMode)' + 'Expression<Func<TWidget, TWidgetProperty>>' 'LambdaExpression' 'sourceProperty' - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'Expression<Func<S, SP>>' + 'BindingExtensions.Bind<TWidget, TWidgetProperty, TSource, TSourceProperty>(this TWidget, Expression<Func<TWidget, TWidgetProperty>>, TSource, Expression<Func<TSource, TSourceProperty>>, DualBindingMode)' + 'Expression<Func<TSource, TSourceProperty>>' 'LambdaExpression' - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'Expression<Func<S, SP>>' + 'BindingExtensions.Bind<TWidget, TWidgetProperty, TSource, TSourceProperty>(this TWidget, Expression<Func<TWidget, TWidgetProperty>>, TSource, Expression<Func<TSource, TSourceProperty>>, DualBindingMode)' + 'Expression<Func<TSource, TSourceProperty>>' - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'Expression<Func<W, WP>>' - - - - - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'S' - - - - - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'W' - - - - - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'S' - - - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'SP' - - - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'W' - - - 'BindingExtensions.Bind<W, WP, S, SP>(this W, Expression<Func<W, WP>>, S, Expression<Func<S, SP>>, DualBindingMode)' - 'WP' + 'BindingExtensions.Bind<TWidget, TWidgetProperty, TSource, TSourceProperty>(this TWidget, Expression<Func<TWidget, TWidgetProperty>>, TSource, Expression<Func<TSource, TSourceProperty>>, DualBindingMode)' + 'Expression<Func<TWidget, TWidgetProperty>>' @@ -235,49 +193,25 @@ 'controlProperty' - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'Expression<Func<W, WP>>' + 'BindingExtensions.Bind<TWidget, TWidgetProperty, TContextProperty, TContext>(this TWidget, Expression<Func<TWidget, TWidgetProperty>>, Expression<Func<TContext, TContextProperty>>, DualBindingMode, object, object)' + 'Expression<Func<TWidget, TWidgetProperty>>' 'LambdaExpression' 'sourceProperty' - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'Expression<Func<DC, SP>>' + 'BindingExtensions.Bind<TWidget, TWidgetProperty, TContextProperty, TContext>(this TWidget, Expression<Func<TWidget, TWidgetProperty>>, Expression<Func<TContext, TContextProperty>>, DualBindingMode, object, object)' + 'Expression<Func<TContext, TContextProperty>>' 'LambdaExpression' - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'Expression<Func<DC, SP>>' + 'BindingExtensions.Bind<TWidget, TWidgetProperty, TContextProperty, TContext>(this TWidget, Expression<Func<TWidget, TWidgetProperty>>, Expression<Func<TContext, TContextProperty>>, DualBindingMode, object, object)' + 'Expression<Func<TContext, TContextProperty>>' - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'Expression<Func<W, WP>>' - - - - - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'W' - - - - - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'DC' - - - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'SP' - - - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'W' - - - 'BindingExtensions.Bind<W, WP, SP, DC>(this W, Expression<Func<W, WP>>, Expression<Func<DC, SP>>, DualBindingMode, object, object)' - 'WP' + 'BindingExtensions.Bind<TWidget, TWidgetProperty, TContextProperty, TContext>(this TWidget, Expression<Func<TWidget, TWidgetProperty>>, Expression<Func<TContext, TContextProperty>>, DualBindingMode, object, object)' + 'Expression<Func<TWidget, TWidgetProperty>>' @@ -310,15 +244,15 @@ - + - + - 'DelegateBinding<T, TValue>.DelegateBinding(Func<T, TValue>, Action<T, TValue>, Action<T, EventHandler<EventArgs>>, Action<T, EventHandler<EventArgs>>)' + 'DelegateBinding<T, TValue>.DelegateBinding(Func<T, TValue>, Action<T, TValue>, Action<T, EventHandler<EventArgs>>, Action<T, EventHandler<EventArgs>>, TValue, TValue)' 'Action<T, EventHandler<EventArgs>>' - 'DelegateBinding<T, TValue>.DelegateBinding(Func<T, TValue>, Action<T, TValue>, Action<T, EventHandler<EventArgs>>, Action<T, EventHandler<EventArgs>>)' + 'DelegateBinding<T, TValue>.DelegateBinding(Func<T, TValue>, Action<T, TValue>, Action<T, EventHandler<EventArgs>>, Action<T, EventHandler<EventArgs>>, TValue, TValue)' 'Action<T, EventHandler<EventArgs>>' @@ -334,6 +268,19 @@ + + + + + 'Convert.ChangeType(object, Type)' + 'DelegateBinding<T, TValue>.ChangeType(object)' + 'Convert.ChangeType(object, Type, IFormatProvider)' + 'CultureInfo.CurrentCulture' + 'CultureInfo.InvariantCulture' + + + + @@ -361,63 +308,34 @@ - + - - - - - - - 'Generator.Current.get()' - 'EtoException' - - - - - - - - - - - - - 'Generator.Detect.get()' - 'EtoException' - - - - - - - - - - - 'Generator.ExecuteOnMainThread(Action)' - - - - - + - - - ID - 'Generator.ID' - Id + + + 'HandlerAttribute.Type' + 'object.GetType()' - + + + + + - + - 'Generator.Supports<T>()' - 'T' + 'type' + 'HandlerInfo.HandlerInfo(Type, bool, Func<object>)' + + + + + @@ -436,88 +354,6 @@ - - - - - - - ID - 'IInstanceWidget.ID' - Id - - - - - - - - - - - 'IInstanceWidget<T, W>' - 'W' - - - - - 'IInstanceWidget<T, W>' - 'W' - - - - - - - - - - - - - 'InstanceWidget.Handler.get()' - 'Widget' - - - - - - - - - - - ID - 'InstanceWidget.ID' - Id - - - - - - - - - - - 'IWeakEventHandler<E>' - 'E' - - - - - 'IWeakEventHandler<E>' - 'E' - - - - - 'IWeakEventHandler<E>' - EventHandler - - - - @@ -570,15 +406,15 @@ - + - + - 'ObjectBinding<T, TValue>.Bind<TObject>(TObject, Func<TObject, TValue>, Action<TObject, TValue>, Action<TObject, EventHandler<EventArgs>>, Action<TObject, EventHandler<EventArgs>>, DualBindingMode)' + 'ObjectBinding<T, TValue>.Bind<TObject>(TObject, Func<TObject, TValue>, Action<TObject, TValue>, Action<TObject, EventHandler<EventArgs>>, Action<TObject, EventHandler<EventArgs>>, DualBindingMode, TValue, TValue)' 'Action<TObject, EventHandler<EventArgs>>' - 'ObjectBinding<T, TValue>.Bind<TObject>(TObject, Func<TObject, TValue>, Action<TObject, TValue>, Action<TObject, EventHandler<EventArgs>>, Action<TObject, EventHandler<EventArgs>>, DualBindingMode)' + 'ObjectBinding<T, TValue>.Bind<TObject>(TObject, Func<TObject, TValue>, Action<TObject, TValue>, Action<TObject, EventHandler<EventArgs>>, Action<TObject, EventHandler<EventArgs>>, DualBindingMode, TValue, TValue)' 'Action<TObject, EventHandler<EventArgs>>' @@ -596,15 +432,15 @@ - + - + - 'ObjectBinding<T, TValue>.Bind<TObject>(Func<TObject, TValue>, Action<TObject, TValue>, Action<TObject, EventHandler<EventArgs>>, Action<TObject, EventHandler<EventArgs>>, DualBindingMode)' + 'ObjectBinding<T, TValue>.Bind<TObject>(Func<TObject, TValue>, Action<TObject, TValue>, Action<TObject, EventHandler<EventArgs>>, Action<TObject, EventHandler<EventArgs>>, DualBindingMode, TValue, TValue)' 'Action<TObject, EventHandler<EventArgs>>' - 'ObjectBinding<T, TValue>.Bind<TObject>(Func<TObject, TValue>, Action<TObject, TValue>, Action<TObject, EventHandler<EventArgs>>, Action<TObject, EventHandler<EventArgs>>, DualBindingMode)' + 'ObjectBinding<T, TValue>.Bind<TObject>(Func<TObject, TValue>, Action<TObject, TValue>, Action<TObject, EventHandler<EventArgs>>, Action<TObject, EventHandler<EventArgs>>, DualBindingMode, TValue, TValue)' 'Action<TObject, EventHandler<EventArgs>>' @@ -635,184 +471,357 @@ - - - - - 'PropertyStore' - - - - - + - + + + + + + + 'Platform.Detect.get()' + 'EtoException' + + + + + + + - - - 'Action<InstanceWidget>' - - - 'Action<InstanceWidget>' + + + ID + 'Platform.ID' + Id - + + + + + - 'Action<InstanceWidget>' - EventHandler + 'Platform.Supports<T>()' + 'T' - - - - - 'UnregisterCallback<E>' - 'E' - - - - - 'UnregisterCallback<E>' - 'E' - - - - - + - + - - - 'WeakEventExtensions.MakeWeak<E>(this EventHandler<E>, UnregisterCallback<E>)' - 'E' + + + 'PropertyBinding.AddValueChangedHandler(object, EventHandler<EventArgs>)' + 'object' - - - 'WeakEventExtensions.MakeWeak<E>(this EventHandler<E>, UnregisterCallback<E>)' - 'E' + + + + + + + 'PropertyBinding.RemoveValueChangedHandler(object, EventHandler<EventArgs>)' + 'object' - + - - - 'WeakEventHandler<T, E>' - 'E' - - - - - 'WeakEventHandler<T, E>' - 'E' - - - - - 'WeakEventHandler<T, E>' - EventHandler + + + 'PropertyStore' + + - + - - - 'WeakEventHandler<T, E>.implicit operator EventHandler<E>(WeakEventHandler<T, E>)' - weh - 'weh' + + + 'Action<Widget>' + + + 'Action<Widget>' - - - ToXXX - FromXXX - 'WeakEventHandler<T, E>.implicit operator EventHandler<E>(WeakEventHandler<T, E>)' + + + 'Action<Widget>' + EventHandler - - - - - - - - - 'WidgetHandler<TWidget>' - 'IWidget.Widget.set(Widget)' - - - - - - - - - + - - - - - - - 'WidgetHandler<T, TWidget>' - 'IInstanceWidget.ControlObject.get()' - - - - - - - + - + - 'WidgetHandler<T, TWidget>.GetControl(TWidget)' - 'WidgetHandler<T, TWidget>' + 'TypeHelper.CreateDelegate(this MethodInfo, Type, object)' - - - - - + - - - 'XmlExtensions.GetAttribute<T>(this XmlElement, string, XmlToValue<T>)' - 'XmlElement' + + + 'TypeHelper.GetAssembly(this Type)' - + - - - 'XmlExtensions.GetBoolAttribute(this XmlElement, string)' - 'XmlElement' + + + 'TypeHelper.GetBaseType(this Type)' - + + + + + 'TypeHelper.GetGetMethod(this PropertyInfo)' + + + + + + + + + 'TypeHelper.GetRuntimeEvents(this Type)' + + + + + + + + + 'TypeHelper.GetRuntimeField(this Type, string)' + + + + + + + + + 'TypeHelper.GetRuntimeFields(this Type)' + + + + + + + + + 'TypeHelper.GetRuntimeMethod(this Type, string, Type[])' + + + + + + + + + 'TypeHelper.GetRuntimeMethods(this Type)' + + + + + + + + + 'TypeHelper.GetRuntimeProperties(this Type)' + + + + + + + + + 'TypeHelper.GetRuntimeProperty(this Type, string)' + + + + + + + + + 'TypeHelper.GetSetMethod(this PropertyInfo)' + + + + + + + + + + + + + + + 'Widget' + 'ICallbackSource.Callback.get()' + + + + + + + + + + + 'Widget.GetCallback()' + + + + + + + + + + + + + + ID + 'Widget.ID' + Id + + + + + + + + + + + 'Widget.ICallback' + + + + + + + + + + + ID + 'Widget.IHandler.ID' + Id + + + + + + + + + + + + + + + 'WidgetHandler<TWidget>' + 'Widget.IHandler.Widget.set(Widget)' + + + + + + + + + + + + + + + + + 'WidgetHandler<T, TWidget>' + 'IControlObjectSource.ControlObject.get()' + + + + + + + + + + + 'WidgetHandler<T, TWidget>.GetControl(TWidget)' + 'WidgetHandler<T, TWidget>' + + + + + + + + + + + 'WidgetHandler<T, TWidget, TCallback>' + + + + + + + + + + + 'XmlExtensions.GetAttribute<T>(this XmlElement, string, XmlToValue<T>)' + 'XmlElement' + + + + + + + + + 'XmlExtensions.GetBoolAttribute(this XmlElement, string)' + 'XmlElement' + + + + + @@ -953,11 +962,11 @@ - + - + - 'Bitmap.Bitmap(byte[], Generator)' + 'Bitmap.Bitmap(byte[])' bytes 'bytes' @@ -997,35 +1006,49 @@ + + + + + 'Brush.IHandler' + + + + - + - - - Cornsilk - 'Brushes.Cornsilk(Generator)' + + + 'generator' + 'Brushes.Cached(Color, Generator)' - + - + - + + + Cornsilk + 'Brushes.Cornsilk' + + + + + + + Gainsboro - 'Brushes.Gainsboro(Generator)' + 'Brushes.Gainsboro' - - - - - @@ -1359,6 +1382,24 @@ + + + + + + + + + 'Font.Handler.get()' + 'Widget' + + + + + + + + @@ -1370,55 +1411,84 @@ - + + + + + + + 'FontFamily.Handler.get()' + 'Widget' + + + + + + + + + + + - + - 'FontFamily.Monospace' - 'FontFamily' + 'generator' + 'Fonts.Cached(FontFamily, float, FontStyle, FontDecoration, Generator)' - + - + - + - 'FontFamily.Sans' - 'FontFamily' + 'generator' + 'Fonts.Cached(string, float, FontStyle, FontDecoration, Generator)' - + - + - + - 'FontFamily.Serif' - 'FontFamily' + 'generator' + 'Fonts.Cursive(float, FontStyle, FontDecoration, Generator)' - + + + + + + + + + + + 'generator' + 'Fonts.Fantasy(float, FontStyle, FontDecoration, Generator)' + + + + - - - - @@ -1432,11 +1502,52 @@ + + + 'generator' + 'Fonts.Monospace(float, FontStyle, FontDecoration, Generator)' + + + + + + + - - - + + + + + 'generator' + 'Fonts.Sans(float, FontStyle, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'Fonts.Serif(float, FontStyle, FontDecoration, Generator)' + + + + + + + + + + + + @@ -1455,16 +1566,37 @@ + + + + + + + + + 'FontTypeface.Handler.get()' + 'Widget' + + + + + + + + - - - - 'Antialias' - AntiAlias - - - + + + + + DPI + 'Graphics.DPI' + Dpi + + + + @@ -1625,30 +1757,6 @@ - - - - - 'path' - 'Graphics.DrawPath(Color, GraphicsPath)' - 'GraphicsPath' - 'IGraphicsPath' - - - - - - - - - 'path' - 'Graphics.DrawPath(Pen, GraphicsPath)' - 'GraphicsPath' - 'IGraphicsPath' - - - - @@ -1729,30 +1837,6 @@ - - - - - 'path' - 'Graphics.FillPath(Brush, GraphicsPath)' - 'GraphicsPath' - 'IGraphicsPath' - - - - - - - - - 'path' - 'Graphics.FillPath(Color, GraphicsPath)' - 'GraphicsPath' - 'IGraphicsPath' - - - - @@ -1817,10 +1901,75 @@ + + + + + + + 'Graphics.Handler.get()' + 'Widget' + + + + + + + + + + + + + + + 'Graphics.IHandler.DrawLine(Pen, float, float, float, float)' + endx + 'endx' + + + + + 'Graphics.IHandler.DrawLine(Pen, float, float, float, float)' + endy + 'endy' + + + + + 'Graphics.IHandler.DrawLine(Pen, float, float, float, float)' + startx + 'startx' + + + + + 'Graphics.IHandler.DrawLine(Pen, float, float, float, float)' + starty + 'starty' + + + + + + + + + 'generator' + 'GraphicsPath.Create(Generator)' + + + + + + + + + @@ -1849,48 +1998,33 @@ - - - - - - - 'IBrush' - - - - - - - + - - - 'IGraphics.DrawLine(Pen, float, float, float, float)' - endx - 'endx' - - - - - 'IGraphics.DrawLine(Pen, float, float, float, float)' - endy - 'endy' - - - - - 'IGraphics.DrawLine(Pen, float, float, float, float)' - startx - 'startx' + + + 'generator' + 'GraphicsPath.GetRoundRect(RectangleF, float, Generator)' + + + + + - - - 'IGraphics.DrawLine(Pen, float, float, float, float)' - starty - 'starty' + + + + + + + 'generator' + 'GraphicsPath.GetRoundRect(RectangleF, float, float, float, float, Generator)' + + + + + @@ -1911,16 +2045,21 @@ - + - - - - - 'IIndexedBitmap.Palette' - - - + + + + + + + 'Image.Handler.get()' + 'Widget' + + + + + @@ -1928,7 +2067,7 @@ - + Png 'ImageFormat.Png' @@ -2013,89 +2152,104 @@ - + - + - - - 'IMatrixHandler.Create(float, float, float, float, float, float)' - xy - 'xy' - - - - - 'IMatrixHandler.Create(float, float, float, float, float, float)' - yx - 'yx' - - - - - 'IMatrixHandler.Create(float, float, float, float, float, float)' - yy - 'yy' + + + 'IndexedBitmap.Palette' - + - + - 'IndexedBitmap.Palette' + 'IndexedBitmap.IHandler.Palette' - + - + - - - 'IRegion.Set(Rectangle)' - Set + + + 'generator' + 'Matrix.Create(Generator)' + + + + + - - - - - + - + - 'Matrix.Create(float, float, float, float, float, float, Generator)' + 'Matrix.Create(float, float, float, float, float, float)' xy 'xy' - + - 'Matrix.Create(float, float, float, float, float, float, Generator)' + 'Matrix.Create(float, float, float, float, float, float)' yx 'yx' - + - 'Matrix.Create(float, float, float, float, float, float, Generator)' + 'Matrix.Create(float, float, float, float, float, float)' yy 'yy' + + + + + 'generator' + 'Matrix.Create(float, float, float, float, float, float, Generator)' + + + + + + + + + + + + + + 'generator' + 'Matrix.Create(float[], Generator)' + + + + + + + + + @@ -2116,14 +2270,43 @@ - + - + - - - Add - 'Padding.operator +(Padding, Padding)' + + + 'Matrix.IHandler.Create(float, float, float, float, float, float)' + xy + 'xy' + + + + + 'Matrix.IHandler.Create(float, float, float, float, float, float)' + yx + 'yx' + + + + + 'Matrix.IHandler.Create(float, float, float, float, float, float)' + yy + 'yy' + + + + + + + + + + + + + Add + 'Padding.operator +(Padding, Padding)' @@ -2226,33 +2409,38 @@ - + - - - Cornsilk - 'Pens.Cornsilk(Generator)' + + + 'generator' + 'Pens.Cached(Color, float, DashStyle, Generator)' - + - + + + + + Cornsilk + 'Pens.Cornsilk' + + + + + - + Gainsboro - 'Pens.Gainsboro(Generator)' + 'Pens.Gainsboro' - - - - - @@ -2378,6 +2566,36 @@ + + + + + Add + 'Point.operator +(Point, Point)' + + + + + + + + + Add + 'Point.operator +(Point, Size)' + + + + + + + + + Add + 'Point.operator +(Point, int)' + + + + @@ -2528,6 +2746,36 @@ + + + + + Add + 'PointF.operator +(PointF, PointF)' + + + + + + + + + Add + 'PointF.operator +(PointF, SizeF)' + + + + + + + + + Add + 'PointF.operator +(PointF, float)' + + + + @@ -3032,6 +3280,38 @@ + + + + + + + + + 'Region.Handler.get()' + 'Widget' + + + + + + + + + + + + + + + 'Region.IHandler.Set(Rectangle)' + Set + + + + + + @@ -3270,6 +3550,175 @@ + + + + + + + 'generator' + 'SystemFonts.Bold(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.Cached(SystemFont, float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.Default(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.Label(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.Menu(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.MenuBar(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.Message(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.Palette(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.StatusBar(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.TitleBar(float?, FontDecoration, Generator)' + + + + + + + + + + + + + + 'generator' + 'SystemFonts.ToolTip(float?, FontDecoration, Generator)' + + + + + + + + + + + @@ -3358,161 +3807,56 @@ - + - + - - - 'ActionCollection.RemoveHandler(string, EventHandler<EventArgs>)' - ID - 'actionID' - Id + + + 'Application' - - - - - + - - - 'ActionItemCollection.Add(string, bool, int)' - ID - 'actionID' - Id + + + 'init' + 'Application.Application(Application.InitHelper)' + + + + + - + - - - 'ActionItemCollection.Add(string, int)' - ID - 'actionID' - Id + + + 'Application.GetSystemCommands()' - - - - - SubMenu - 'ActionItemCollection.AddSubMenu(string, int)' - Submenu - - - - - 'ActionItemCollection.AddSubMenu(string, int)' - subMenu - 'subMenuText' - submenu - - - - - - - - - 'ActionItemCollection.GetSubmenu(string, int, bool, bool)' - subMenu - 'subMenuText' - submenu - - - - - - - - - 'ActionItemCollection' - 'ActionItemCollection.Merge(ActionItemCollection)' - - - - - - - - - - - SubMenu - 'ActionItemSubMenu' - Submenu - - - - - - - - - 'ActionItemSubMenu.ActionItemSubMenu(ActionCollection, string)' - subMenu - 'subMenuText' - submenu - - - - - - - - - 'ActionItemCollection' - 'ActionItemSubMenu.Actions' - - - - - - - - - ID - 'ActionItemSubMenu.ID' - Id - - - - - - - - - SubMenu - 'ActionItemSubMenu.SubMenuText' - Submenu - - - - - - - - - - - - - 'Application.Application(Generator)' - 'g' - - - - - + + + + + + + 'Application.Handler.get()' + 'Widget' + + + + + + + @@ -3524,143 +3868,54 @@ - + - - - - - 'BaseAction.Accelerators' - - - - - + - - - ID - 'BaseAction.ID' - Id + + + 'Application.IHandler.GetSystemCommands()' - - - - - + - + - 'Button.DefaultSize' - - - - - - - - - - - - - 'ButtonAction.GenerateMenuItem(Generator)' - 'ButtonAction.MenuConnector' - - - - - - - - - 'ButtonAction.GenerateToolBarItem(ActionItem, Generator, ToolBarTextAlign)' - 'ButtonAction.ToolBarConnector' - - - - - - - - - - - - - 'Cell.Cell(Generator, Type, bool)' - 'g' + 'url' + 'Application.IHandler.Open(string)' - - - - - - - 'CheckAction.GenerateMenuItem(Generator)' - 'CheckAction.MenuConnector' - - - - - - - - - 'CheckAction.GenerateToolBarItem(ActionItem, Generator, ToolBarTextAlign)' - 'CheckAction.ToolBarConnector' - - - - - + + + + + 'Application.InitHelper' + + + + + + + + - - - - - - - 'CheckActionExtensions.RemoveCheckHandler(this ActionCollection, string, EventHandler<EventArgs>)' - ID - 'actionID' - Id - - - - - + + + + + 'Cell.IHandler' + + + - - - - - 'CheckBox.CheckBox(Generator)' - 'g' - - - - - - - - - 'CheckBox.CheckBox(Generator, Type, bool)' - 'g' - - - - @@ -3673,93 +3928,82 @@ - - - - - - - 'CheckBoxCell.CheckBoxCell(Generator)' - 'g' - - - - - + + + + + 'CheckBoxCell.IHandler' + + + - + - - - - - 'CheckMenuItem.CheckMenuItem(Generator)' - 'g' - - - + + + + + + + 'Clipboard.Handler.get()' + 'Widget' + + + + + - - - - - + - - - 'CheckToolBarButton.CheckToolBarButton(Generator)' - 'g' + + + 'Clipboard.Types' - + - + - 'Clipboard.Types' + 'Clipboard.IHandler.Types' - + - - - - - 'ColorDialog.ColorDialog(Generator)' - 'g' - - - + + + + + + + 'ComboBoxCell.Handler.get()' + 'Widget' + + + + + - + - - - - - 'ComboBox.ComboBox(Generator)' - 'g' - - - - - + - - - 'ComboBox.ComboBox(Generator, Type, bool)' - 'g' + + + ID + 'Command.ID' + Id @@ -3768,58 +4012,76 @@ - - - - - 'CommonDialog.CommonDialog(Generator, Type, bool)' - 'g' - - - + + + + + + + 'CommonDialog.Handler.get()' + 'Widget' + + + + + - + - - - - - 'Container.Container(Generator, Type, bool)' - 'g' - - - + + + + + + + 'ContextMenu.Handler.get()' + 'Widget' + + + + + - + - + - - - 'ContextMenu.ContextMenu(Generator)' - 'g' + + + 'Control' - + - - - 'ContextMenu.ContextMenu(Generator, IEnumerable<IActionItem>)' - 'g' + + + 'Control.Bind(IndirectBinding, object, IndirectBinding, DualBindingMode, object, object)' + object + 'objectValue' - - - - + + + + + + + 'Control.Handler.get()' + 'Widget' + + + + + + @@ -3880,621 +4142,427 @@ - + - - - - - 'DateTimePicker.DefaultMode' - - - - - - - - - - - 'DateTimePickerMode' - - - - - - - - - - - 'Dialog.Dialog(Generator)' - 'g' - - - - - - - - - 'Dialog.Dialog(Generator, Type, bool)' - 'g' - - - - - - - - - - - - - 'DockContainer.DefaultPadding' - - - - - - - - - + - - - 'DrawableCell.DrawableCell(Generator)' - 'g' + + + PreLoad + 'Control.IHandler.OnPreLoad(EventArgs)' + Preload - - - - - + - + - XScale - 'DynamicItem.XScale' - Xscale + UnLoad + 'Control.IHandler.OnUnLoad(EventArgs)' + Unload - - - - - - - YScale - 'DynamicItem.YScale' - Yscale + + + Un + 'Control.IHandler.OnUnLoad(EventArgs)' + UN - + - - - - - 'DynamicTable' - 'ISupportInitialize.BeginInit()' - - - - - - - - - 'DynamicTable' - 'ISupportInitialize.EndInit()' - - - + + + + + + + 'Cursor.Handler.get()' + 'Widget' + + + + + - + - + - + - 'EnumComboBox<T>.SelectedValueBinding' - 'ObjectBinding<EnumComboBox<T>, T>' + 'generator' + 'Cursors.Cached(CursorType, Generator)' + + + + + - + - + - + - 'EnumRadioButtonList<T>.SelectedValueBinding' - 'ObjectBinding<EnumRadioButtonList<T>, T>' + 'DateTimePicker.DefaultMode' - - - - - - - 'FileDialog.FileDialog(Generator, Type, bool)' - 'g' - - - - - + + + + + 'DateTimePickerMode' + + + - - - - - - - 'Form.Form(Generator)' - 'g' - - - - - - - - - 'Form.Form(Generator, Type, bool)' - 'g' - - - - - + + + + + 'DialogDisplayMode' + 'DialogDisplayMode.Default' + + + + + 'DialogDisplayMode' + + + - - - - - - - 'ActionItemCollection' - 'GenerateActionArgs.GenerateActionArgs(ActionCollection, ActionItemCollection, ActionItemCollection)' - - - 'ActionItemCollection' - 'GenerateActionArgs.GenerateActionArgs(ActionCollection, ActionItemCollection, ActionItemCollection)' - - - - - - - - - 'GenerateActionArgs.GenerateActionArgs(Generator, Control)' - 'g' - - - - - - - - - 'ActionItemCollection' - 'GenerateActionArgs.Menu' - - - - - - - - - 'ActionItemCollection' - 'GenerateActionArgs.ToolBar' - - - - - + + + + + 'DrawableCell.IHandler' + + + - + - + - - - 'GridColumn.GridColumn(Generator)' - 'g' + + + ToXXX + FromXXX + 'DynamicItem.implicit operator DynamicItem(Control)' - + - - - 'GridColumn.GridColumn(Generator, Type, bool)' - 'g' + + + XScale + 'DynamicItem.XScale' + Xscale - - - - - + - - - 'GridItem.Values' + + + YScale + 'DynamicItem.YScale' + Yscale - + - + - - - 'GridView.GridView(Generator)' - 'g' + + + 'DynamicLayout.Rows' - + - + - - - 'GroupBox.GroupBox(Generator)' - 'g' + + + 'DynamicRow.Items' - - - - - + - - - 'url' - 'IApplication.Open(string)' + + + ToXXX + FromXXX + 'DynamicRow.implicit operator DynamicRow(Control)' - - - - - 'ICell' - - - - - - - - - 'ICheckBoxCell' - - - - - + - + - + - 'IClipboard.Types' + 'DynamicTable.Rows' - - - - - + - - - PreLoad - 'IControl.OnPreLoad(EventArgs)' - Preload + + + 'DynamicTable' + 'ISupportInitialize.BeginInit()' - + - - - UnLoad - 'IControl.OnUnLoad(EventArgs)' - Unload - - - - - Un - 'IControl.OnUnLoad(EventArgs)' - UN + + + 'DynamicTable' + 'ISupportInitialize.EndInit()' - - - - - 'IDataStore' - - - - - - - - - 'IDrawableCell' - - - - - + - + - + - 'IFileDialogFilter.Extensions' + 'EnumComboBox<T>.SelectedValueBinding' + 'ObjectBinding<EnumComboBox<T>, T>' - + - + - - - 'IGridView.ShowCellBorders' + + + 'EnumRadioButtonList<T>.SelectedValueBinding' + 'ObjectBinding<EnumRadioButtonList<T>, T>' - - - - - 'IImageTextCell' - - - - - - - - - 'IImageViewCell' - - - - - - - - - 'IListStore' - - - - - + - + - - - 'ImageMenuItem.ImageMenuItem(Generator)' - 'g' + + + 'Grid' - - - - - + - - - 'ImageTextCell.ImageTextCell(Generator)' - 'g' + + + 'initialize' + 'Grid.Grid(Generator, Grid.IHandler, bool)' + + + + + - - - - - + - - - 'ImageView.ImageView(Generator)' - 'g' + + + 'initialize' + 'Grid.Grid(Generator, Type, bool)' + + + + + - + - - - - - 'ImageViewCell.ImageViewCell(Generator)' - 'g' - - - + + + + + + + 'GridColumn.Handler.get()' + 'Widget' + + + + + - + - + - - - 'INumericUpDown.ReadOnly' - ReadOnly + + + 'GridItem.Values' - + - + - - - Filenames - 'IOpenFileDialog.Filenames' - FileNames + + + 'GridView' - + - - - Multi - 'IOpenFileDialog.MultiSelect' + + + 'GridView.Initialize()' + 'Widget' - + - + - - - 'IPasswordBox.ReadOnly' - ReadOnly + + + 'removedSelectedItems' + 'GridViewSelection.ResetSelection(SortedSet<int>, HashSet<object>, HashSet<object>)' + + + + + - - - - - SubMenu - 'ISubMenu' - Submenu - - - - - + - - - SubMenu - 'ISubMenuWidget' - Submenu + + + 'IDataStore' - + - + - - - 'ITextArea.ReadOnly' - ReadOnly + + + 'IFileDialogFilter.Extensions' - - - - - - - 'ITextBox.ReadOnly' - ReadOnly - - - - - + + + + + 'IListStore' + + + + + + + + + 'ImageTextCell.IHandler' + + + + + + + + + 'ImageViewCell.IHandler' + + + - + - + - 'ITextBoxCell' + 'ISubmenu' @@ -4526,324 +4594,349 @@ - - - - - - - 'IUITimer.Stop()' - Stop - - - - - - - - - - - - - 'IWebView.Stop()' - Stop - - - - - - - - - - - - - Maximizable - 'IWindow.Maximizable' - - - - - - - - - Minimizable - 'IWindow.Minimizable' - - - - - - - + - + - 'Key' + 'Keys' 0x80, 0x100, 0x200, 0x400, 0x800 - - - 'Key' - - - - - 'Semicolon' - SemiColon - - - + - 'Key.A' + 'Keys.A' + + + + + - + - 'Key.B' + 'Keys.B' + + + + + - + - 'Key.C' + 'Keys.C' + + + + + - + - 'Key.D' + 'Keys.D' + + + + + - + - 'Key.E' + 'Keys.E' + + + + + - + - 'Key.F' + 'Keys.F' + + + + + - + - 'Key.G' + 'Keys.G' + + + + + - + - 'Key.H' + 'Keys.H' + + + + + - + - 'Key.I' + 'Keys.I' + + + + + - + - 'Key.J' + 'Keys.J' + + + + + - + - 'Key.K' + 'Keys.K' + + + + + - + - 'Key.L' + 'Keys.L' + + + + + - + - 'Key.M' + 'Keys.M' + + + + + - + - 'Key.N' + 'Keys.N' + + + + + - + - 'Key.O' + 'Keys.O' + + + + + - + - 'Key.P' + 'Keys.P' + + + + + - + - 'Key.Q' + 'Keys.Q' + + + + + - + - 'Key.R' + 'Keys.R' + + + + + - + - 'Key.S' + 'Keys.S' + + + + + - + - 'Key.T' + 'Keys.T' + + + + + - + - 'Key.U' + 'Keys.U' + + + + + - + - 'Key.V' + 'Keys.V' + + + + + - - - 'Key.W' - - - - - - - - - 'Key.X' - - - - - - - + - 'Key.Y' + 'Keys.W' + + + + + - + - 'Key.Z' - - - - - - - - - - - - - 'Label.Label(Generator)' - 'g' + 'Keys.Z' + + + + + @@ -4858,79 +4951,23 @@ - - - - - - 'Layout.Layout(Generator, ILayout, bool)' - 'g' - - - - - - - - - 'Layout.Layout(Generator, Type, bool)' - 'g' - - - - - - - - - - - - - 'ListBox.ListBox(Generator)' - 'g' - - - - - - - - - - - - - 'ListControl.ListControl(Generator, Type, bool)' - 'g' - - - - - - + - - - 'Menu.Menu(Generator, Type, bool)' - 'g' + + + UnLoad + 'Menu.OnUnLoad(EventArgs)' + Unload - - - - - - - - - - - 'MenuActionItem.MenuActionItem(Generator, Type, bool)' - 'g' + + + Un + 'Menu.OnUnLoad(EventArgs)' + UN @@ -4939,37 +4976,54 @@ - - - - - 'MenuBar.MenuBar(Generator)' - 'g' - - - - - - - - - 'MenuBar.MenuBar(Generator, IEnumerable<IActionItem>)' - 'g' - - - + + + + + + + 'MenuBar.Handler.get()' + 'Widget' + + + + + - + + + + + + + 'MenuItem.Handler.get()' + 'Widget' + + + + + + + + + + + - - - 'MenuItem.MenuItem(Generator, Type, bool)' - 'g' + + + 'generator' + 'MessageBox.Show(Generator, Control, string, string, MessageBoxButtons, MessageBoxType, MessageBoxDefaultButton)' + + + + + @@ -4977,7 +5031,7 @@ - + 'MessageBoxButtons' @@ -5023,48 +5077,78 @@ - + - + + + + + 'Mouse.Buttons' + 'Mouse.GetButtons(Generator)' + + + + + + + + + + - + - 'Navigation.Navigation(Control, string)' - Navigation..ctor(Control, String) Navigation.Push(Control, String):Void + 'generator' + 'Mouse.GetButtons(Generator)' + + + + + - + - + - 'Navigation.Navigation(NavigationItem)' - Navigation..ctor(NavigationItem) Navigation.Push(INavigationItem):Void + 'generator' + 'Mouse.GetPosition(Generator)' + + + + + - + - - - 'Navigation.Navigation(Generator)' - 'g' + + + 'Mouse.Position' + 'Mouse.GetPosition(Generator)' + + + + + - + - + - - - 'NumericUpDown.NumericUpDown(Generator)' - 'g' + + + 'NumericUpDown.IHandler.ReadOnly' + ReadOnly @@ -5073,32 +5157,37 @@ - + - - - 'OpenFileDialog.OpenFileDialog(Generator)' - 'g' + + + Filenames + 'OpenFileDialog.Filenames' + FileNames - + - - - 'OpenFileDialog.OpenFileDialog(Generator, Type, bool)' - 'g' + + + Multi + 'OpenFileDialog.MultiSelect' + + + + - + Filenames - 'OpenFileDialog.Filenames' + 'OpenFileDialog.IHandler.Filenames' FileNames @@ -5106,52 +5195,37 @@ - + Multi - 'OpenFileDialog.MultiSelect' + 'OpenFileDialog.IHandler.MultiSelect' - - - - - 'PaintEventHandler' - - - - - - - - - - + - - - 'Panel.Panel(Generator)' - 'g' + + + 'Panel.DefaultPadding' - + - + - - - 'PasswordBox.PasswordBox(Generator)' - 'g' + + + 'PasswordBox.IHandler.ReadOnly' + ReadOnly @@ -5180,6 +5254,18 @@ + + + + + 'control' + 'PixelLayout.GetLocation(Control)' + 'Control' + 'Widget' + + + + @@ -5192,67 +5278,65 @@ - + - + - - - 'RadioAction.GenerateMenuItem(Generator)' - 'RadioAction.MenuConnector' + + + 'PrintDocument' - - - - - - - - - 'RadioButton.RadioButton(Generator, RadioButton)' - 'g' - - - + + + + + + + 'PrintDocument.Handler.get()' + 'Widget' + + + + + - + - - - - - 'RadioMenuItem.RadioMenuItem(Generator, RadioMenuItem)' - 'g' - - - + + + + + + + 'PrintSettings.Handler.get()' + 'Widget' + + + + + - + - - - - - 'SaveFileDialog.SaveFileDialog(Generator)' - 'g' - - - - - + - - - 'SaveFileDialog.SaveFileDialog(Generator, Type, bool)' - 'g' + + + 'initialize' + 'RadioButton.RadioButton(Generator, Type, RadioButton, bool)' + + + + + @@ -5271,6 +5355,20 @@ + + + + + + + 'Screen.Handler.get()' + 'Widget' + + + + + + @@ -5286,36 +5384,11 @@ - - - - - 'Scrollable.Scrollable(Generator)' - 'g' - - - - - - - - - + - - - 'SearchBox.SearchBox(Generator)' - 'g' - - - - - - - - - 'SearchBox.SearchBox(Generator, Type, bool)' - 'g' + + + 'Scrollable' @@ -5324,59 +5397,29 @@ - - - - - 'SelectFolderDialog.SelectFolderDialog(Generator)' - 'g' - - - - - - - - - 'SelectFolderDialog.SelectFolderDialog(Generator, Type, bool)' - 'g' - - - - - - - - - - - - - 'SeparatorMenuItem.SeparatorMenuItem(Generator)' - 'g' - - - + + + + + + + 'SelectFolderDialog.Handler.get()' + 'Widget' + + + + + - + - - - - - 'SeparatorToolBarItem.SeparatorToolBarItem(Generator)' - 'g' - - - - - + - 'SeparatorToolBarItem.Type' + 'SeparatorToolItem.Type' 'object.GetType()' @@ -5384,42 +5427,13 @@ - - - - - - - 'SingleValueCell.SingleValueCell(Generator, Type, bool)' - 'g' - - - - - - - - - - - 'Splitter.Splitter(Generator)' - 'g' - - - - - - - - - + - - - 'TabControl.TabControl(Generator)' - 'g' + + + 'Splitter' @@ -5504,6 +5518,42 @@ + + + + + 'control' + 'TableLayout.GetColumnScale(Control)' + 'Control' + 'Widget' + + + + + + + + + 'control' + 'TableLayout.GetLocation(Control)' + 'Control' + 'Widget' + + + + + + + + + 'control' + 'TableLayout.GetRowScale(Control)' + 'Control' + 'Widget' + + + + @@ -5529,165 +5579,223 @@ - - - - - + + + + + 'control' + 'TableLayout.SetColumnScale(Control, bool)' + 'Control' + 'Widget' + + + + + - - - 'TextArea.TextArea(Generator)' - 'g' + + + 'control' + 'TableLayout.SetRowScale(Control, bool)' + 'Control' + 'Widget' - + + + + + - + - 'TextArea.DefaultSize' + 'TableRow.Items' - + - + - - - 'TextBox.TextBox(Generator)' - 'g' + + + 'TextArea' - + - - - 'TextBox.TextBox(Generator, Type, bool)' - 'g' + + + 'TextArea.DefaultSize' - + - + - - - 'TextBoxCell.TextBoxCell(Generator)' - 'g' + + + 'TextArea.IHandler.ReadOnly' + ReadOnly - + - + - - - 'TextControl.TextControl(Generator, Type, bool)' - 'g' + + + 'TextBox.IHandler.ReadOnly' + ReadOnly - + - - - 'ThemedContainerHandler<T, W>' - 'W' - - - - - 'ThemedContainerHandler<T, W>' - 'W' + + + 'TextBoxCell.IHandler' - + - + - - - 'ToolBar.ToolBar(Generator)' - 'g' + + + 'TextControl' - + - - - Toolbar - 'ToolBar.ToolbarItemCollection' - ToolBar + + + 'ThemedContainerHandler<TControl, TWidget, TCallback>' - + + + + + - 'ToolBar.ToolbarItemCollection' + 'ThemedControlHandler<TControl, TWidget, TCallback>' - - - + - - - 'ToolBarActionItem.ToolBarActionItem(Generator, Type)' - 'g' + + + 'ThemedControlHandler<TControl, TWidget, TCallback>.MapPlatformCommand(string, Command)' + 'systemAction' + 'systemCommand' + 'Control.IHandler.MapPlatformCommand(string, Command)' + + + + + 'ThemedControlHandler<TControl, TWidget, TCallback>.MapPlatformCommand(string, Command)' + 'action' + 'command' + 'Control.IHandler.MapPlatformCommand(string, Command)' - + - + + + + + + + 'ToolBar.Handler.get()' + 'Widget' + + + + + + + - - - 'ToolBarButton.ToolBarButton(Generator)' - 'g' + + + UnLoad + 'ToolBar.OnUnLoad(EventArgs)' + Unload + + + + + Un + 'ToolBar.OnUnLoad(EventArgs)' + UN - + - + + + + + + + 'ToolItem.Handler.get()' + 'Widget' + + + + + + + - - - 'ToolBarItem.ToolBarItem(Generator, Type)' - 'g' + + + UnLoad + 'ToolItem.OnUnLoad(EventArgs)' + Unload + + + + + Un + 'ToolItem.OnUnLoad(EventArgs)' + UN @@ -5696,12 +5804,11 @@ - + - - - 'TreeGridView.TreeGridView(Generator)' - 'g' + + + 'TreeGridView' @@ -5710,12 +5817,11 @@ - + - - - 'TreeView.TreeView(Generator)' - 'g' + + + 'TreeView' @@ -5724,21 +5830,66 @@ - + - - - 'UITimer.UITimer(Generator, Type, bool)' - 'g' + + + 'UITimer.DefaultInterval' - + + + + + + + 'UITimer.Handler.get()' + 'Widget' + + + + + + + + + + + - + + + 'UITimer.IHandler.Stop()' + Stop + + + + + + + + + + + - 'UITimer.DefaultInterval' + 'WebView' + + + + + + + + + + + + + 'WebView.IHandler.Stop()' + Stop @@ -5749,7 +5900,7 @@ - + 'WebViewLoadingEventArgs.WebViewLoadingEventArgs(Uri, bool)' MainFrame @@ -5761,7 +5912,7 @@ - + MainFrame 'WebViewLoadingEventArgs.IsMainFrame' @@ -5787,6 +5938,15 @@ + + + + + 'Window' + + + + @@ -5809,127 +5969,69 @@ - - - - - - - - - 'EtoDirectoryInfo' - < - - - 'EtoDirectoryInfo' - > - - - + - - - - - 'EtoDirectoryInfo.AddVirtualDirectoryType<T>(string)' - 'T' - - - - - - - - - 'EtoDirectoryInfo.GetDirectories()' - - - - - - - - - 'EtoDirectoryInfo.GetPathDirectories()' - - - - - + - - - SubDirectory - 'EtoDirectoryInfo.GetSubDirectory(string)' - Subdirectory - - - - - 'EtoDirectoryInfo.GetSubDirectory(string)' - subDirectory - 'subDirectory' - subdirectory + + + Maximizable + 'Window.IHandler.Maximizable' - + - - - 'EtoDirectoryInfo.GetVirtualDirectories()' + + + Minimizable + 'Window.IHandler.Minimizable' - + + + + + - - - 'EtoFileInfo' - < - - - 'EtoFileInfo' - > + + + 'ThemedSpinnerDirection' - + - - - 'EtoFileInfo.ReadOnly' - ReadOnly + + + CounterClockwise + 'ThemedSpinnerDirection.CounterClockwise' + Counterclockwise - + + + + + - - - - - 'SystemIcons.SystemIcons(Generator)' - 'g' - - - - - + - 'SystemIcons.Handler.get()' + 'Thread.Handler.get()' 'Widget' @@ -5939,44 +6041,6 @@ - - - - - - - 'List<VirtualFileEntry>' - 'VirtualDirectoryInfo.Files' - - - - - 'VirtualDirectoryInfo.Files' - 'EtoDirectoryInfo.GetFiles()' - - - 'VirtualDirectoryInfo.Files' - 'EtoDirectoryInfo.GetFiles(IEnumerable<string>)' - - - - - - - - - - - - - 'VirtualDirectoryType.Type' - 'object.GetType()' - - - - - - @@ -5986,14 +6050,14 @@ - Now obsolete - Names of a color + Name of keys Obsoleted Obsoleted - Color name + obsolete Name of font - FontFamily is mutable - Name of color + obsolete generator parameter + same name as contained class, so we don't want this to conflict + This dummy class is used to call a correct constructor when initializing the generator for the first time. @@ -6003,12 +6067,21 @@ Define a custom attribute to replace {0}. + + Consider a design where {0} has no more than 2 type parameters. + Consider merging the types defined in '{0}' with another namespace. Consider a design that does not require that {0} be an out parameter. + + {0} appears to have no upstream public or protected callers. + + + {0} is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static methods, consider adding a private constructor to prevent the compiler from generating a default constructor. + Change {0} to be read-only by removing the property setter. @@ -6016,8 +6089,6 @@ In member {0}, the compound word '{1}' in parameter name {2} exists as a discrete term. If your usage is intended to be single word, case it as '{3}' or strip the first token entirely if it represents any sort of Hungarian notation. The discrete term '{0}' in member name {1} should be expressed as a compound word, '{2}'. The compound word '{0}' in member name {1} exists as a discrete term. If your usage is intended to be single word, case it as '{2}' or strip the first token entirely if it represents any sort of Hungarian notation. - The discrete term '{0}' in type name {1} should be expressed as a compound word, '{2}'. - The compound word '{0}' in type name {1} exists as a discrete term. If your usage is intended to be single word, case it as '{2}'. Consider changing the type of parameter {0} in {1} from {2} to its base type {3}. This method appears to only require base class members in its implementation. Suppress this violation if there is a compelling reason to require the more derived type in the method signature. @@ -6026,15 +6097,9 @@ Declare the first parameter of {0} as an object named 'sender'. Declare the second parameter of {0} as an EventArgs, or an instance of a type that extends EventArgs, named 'e'. - - {0} contains a call chain that results in a call to a virtual method defined by the class. Review the following call stack for unintended consequences: {1} - Modify {0} to catch a more specific exception than {1} or rethrow the exception. - - Remove the read-only designation from {0} or change the field to one that is an immutable reference type. If the reference type {1} is, in fact, immutable, exclude this message. - Remove {0} from {1} or make it an instance member. @@ -6044,9 +6109,6 @@ Change {0} in {1} to use Collection<T>, ReadOnlyCollection<T> or KeyedCollection<K,V> - - {0} creates a new instance of {1} which is never used. Pass the instance as an argument to another method, assign the instance to a variable, or remove the object creation if it is unnecessary. - {0} is marked with FlagsAttribute but a discrete member cannot be found for every settable bit that is used across the range of enum values. Remove FlagsAttribute from the type or define new members for the following (currently missing) values: {1} @@ -6057,7 +6119,8 @@ {0} creates an exception of type {1}, an exception type that should not be raised in a property. If this exception instance might be raised, use a different exception type, convert this property into a method, or change this property's logic so that it no longer raises an exception. - Remove all members that have the value zero from {0} except for one member that is named 'None'. + In enum {0}, change the name of {1} to 'None'. + Add a member to {0} that has a value of zero with a suggested name of 'None'. If enumeration name {0} is singular, change it to a plural form. @@ -6069,7 +6132,6 @@ Correct the casing of '{0}' in member name {1} by changing it to '{2}'. Correct the casing of '{0}' in member name {1} by changing it to '{2}'. '{2}' is an abbreviation and therefore is not subject to acronym casing guidelines. In member {0}, correct the casing of '{1}' in parameter name {2} by changing it to '{3}'. - In member {0}, correct the casing of '{1}' in parameter name {2} by changing it to '{3}'. '{3}' is an abbreviation and therefore is not subject to acronym casing guidelines. Correct the casing of '{0}' in type name {1} by changing it to '{2}'. @@ -6077,47 +6139,33 @@ Consider providing a more meaningful name than member name {0}. In method {0}, correct the spelling of '{1}' in parameter name {2} or remove it entirely if it represents any sort of Hungarian notation. In method {0}, consider providing a more meaningful name than parameter name {1}. - On method {0}, consider providing a more meaningful name than generic type parameter name {1}. - On type {0}, consider providing a more meaningful name than generic type parameter name {1}. - - - Change member names {0} and '{1}' so that they differ by more than case. - - - On method {0}, prefix generic type parameter name {1} with 'T'. - On type {0}, prefix generic type parameter name {1} with 'T'. + Rename {0} to end in '{1}'. In member {0}, consider replacing the data type identifier '{1}' in parameter name {2} with a more generic term, such as 'value'. - - Rename type name {0} so that it does not end in '{1}'. - Rename virtual/interface member {0} so that it no longer conflicts with the reserved language keyword '{1}'. Using a reserved keyword as the name of a virtual/interface member makes it harder for consumers in other languages to override/implement the member. In virtual/interface member {0}, rename parameter {1} so that it no longer conflicts with the reserved language keyword '{2}'. Using a reserved keyword as the name of a parameter on a virtual/interface member makes it harder for consumers in other languages to override/implement the member. + + Initialize all static fields in {0} when those fields are declared and remove the explicit static constructor. + Make {0} sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of {1} and is visible to derived classes. Add [Serializable] to {0} as this type implements ISerializable. - - The 'this' parameter (or 'Me' in Visual Basic) of {0} is never used. Mark the member as static (or Shared in Visual Basic) or use 'this'/'Me' in the method body or at least one property accessor, if appropriate. - Modify member {0} so that it no longer exposes the concrete type {1}. Use IXPathNavigable to represent XML data sources. Because it is a P/Invoke method, {0} should be defined in a class named NativeMethods, SafeNativeMethods, or UnsafeNativeMethods. - - Do not nest type {0}. Alternatively, change its accessibility so that it is not externally visible. - Consider making {0} non-public or a constant. @@ -6131,8 +6179,8 @@ Provide a method named '{0}' as a friendly alternate for operator {1}. Provide a method named '{0}' or '{1}' as an alternate for operator {2}. - - {0} should define operator '{1}' since it implements IComparable. + + In member {0}, change parameter name {1} to {2} in order to match the identifier as it has been declared in {3}. Change either member or parameter name {0} so that one differs from the other. @@ -6141,9 +6189,6 @@ {0} uses a multidimensional array of {1}. Replace it with a jagged array if possible. {0} is a multidimensional array. Replace it with a jagged array if possible. - - Because property {0} is write-only, either add a property getter with an accessibility that is greater than or equal to its setter or convert this property into a method. - Change {0} to return a collection or make it a method. @@ -6151,15 +6196,18 @@ The property name {0} is confusing given the existence of inherited method {1}. Rename or remove this property. The property name {0} is confusing given the existence of method {1}. Rename or remove one of these members. + + Parameter {0} of {1} is never used. Remove the parameter or use it in the method body. + + + Because the behavior of {0} could vary based on the current user's locale settings, replace this call in {1} with a call to {2}. If the result of {2} will be based on input from the user, specify {3} as the 'IFormatProvider' parameter. Otherwise, if the result will based on input stored and accessed by software, such as when it is loaded from disk or from a database, specify {4}. + The type name {0} conflicts in whole or in part with the namespace name '{1}' defined in the .NET Framework. Rename the type to eliminate the conflict. Change the type of parameter {0} of method {1} from string to System.Uri, or provide an overload of {1}, that allows {0} to be passed as a System.Uri object. - - Remove {0} and replace its usage with EventHandler<T> - Change {0} to a property if appropriate. diff --git a/Source/Eto.Gtk/Conversions.cs b/Source/Eto.Gtk/Conversions.cs new file mode 100644 index 0000000000..9771f7bf59 --- /dev/null +++ b/Source/Eto.Gtk/Conversions.cs @@ -0,0 +1,571 @@ +using System; +using Eto.Drawing; +using Eto.Forms; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp +{ + public static class Conversions + { + public static Gdk.Color ToGdk(this Color color) + { + return new Gdk.Color((byte)(color.R * byte.MaxValue), (byte)(color.G * byte.MaxValue), (byte)(color.B * byte.MaxValue)); + } + + public static Cairo.Color ToCairo(this Color color) + { + return new Cairo.Color((double)color.R, (double)color.G, (double)color.B, (double)color.A); + } + + #if GTK3 + public static Cairo.Color ToCairo(this Gdk.RGBA color) + { + return new Cairo.Color(color.Red, color.Green, color.Blue, color.Alpha); + } + + public static Gdk.RGBA ToRGBA(this Color color) + { + return new Gdk.RGBA { Red = color.R, Green = color.G, Blue = color.B, Alpha = color.A }; + } +#endif + + public static Color ToEto(this Cairo.Color color) + { + return new Color((float)color.R, (float)color.G, (float)color.B, (float)color.A); + } + + public static Cairo.Rectangle ToCairo(this Rectangle rectangle) + { + return new Cairo.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); + } + + public static Cairo.Rectangle ToCairo(this RectangleF rectangle) + { + return new Cairo.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); + } + + public static Rectangle ToEto(this Cairo.Rectangle rectangle) + { + return new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height); + } + + public static Cairo.Filter ToCairo(this ImageInterpolation value) + { + switch (value) + { + case ImageInterpolation.Default: + return Cairo.Filter.Bilinear; + case ImageInterpolation.None: + return Cairo.Filter.Nearest; + case ImageInterpolation.High: + return Cairo.Filter.Best; + case ImageInterpolation.Low: + return Cairo.Filter.Fast; + case ImageInterpolation.Medium: + return Cairo.Filter.Good; + default: + throw new NotSupportedException(); + } + } + + public static Gdk.InterpType ToGdk(this ImageInterpolation value) + { + + switch (value) + { + case ImageInterpolation.Default: + return Gdk.InterpType.Bilinear; + case ImageInterpolation.None: + return Gdk.InterpType.Nearest; + case ImageInterpolation.High: + return Gdk.InterpType.Hyper; + case ImageInterpolation.Low: + return Gdk.InterpType.Tiles; + case ImageInterpolation.Medium: + return Gdk.InterpType.Bilinear; + default: + throw new NotSupportedException(); + } + } + + public static Color ToEto(this Gdk.Color color) + { + return new Color((float)color.Red / ushort.MaxValue, (float)color.Green / ushort.MaxValue, (float)color.Blue / ushort.MaxValue); + } + + public static Gdk.Size ToGdk(this Size size) + { + return new Gdk.Size(size.Width, size.Height); + } + + public static Size ToEto(this Gdk.Size size) + { + return new Size(size.Width, size.Height); + } + + public static Size ToEto(this Gtk.Requisition req) + { + return new Size(req.Width, req.Height); + } + + public static Gdk.Point ToGdk(this Point point) + { + return new Gdk.Point(point.X, point.Y); + } + + public static Point ToEto(this Gdk.Point point) + { + return new Point(point.X, point.Y); + } + + public static Gdk.Rectangle ToGdk(this Rectangle rect) + { + return new Gdk.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); + } + + public static Rectangle ToEto(this Gdk.Rectangle rect) + { + return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height); + } + + public static DialogResult ToEto(this Gtk.ResponseType result) + { + switch (result) + { + case Gtk.ResponseType.None: + return DialogResult.None; + case Gtk.ResponseType.Reject: + return DialogResult.Abort; + case Gtk.ResponseType.Accept: + return DialogResult.Ignore; + case Gtk.ResponseType.Ok: + return DialogResult.Ok; + case Gtk.ResponseType.Cancel: + return DialogResult.Cancel; + case Gtk.ResponseType.Yes: + return DialogResult.Yes; + case Gtk.ResponseType.No: + return DialogResult.No; + default: + return DialogResult.None; + } + } + + public static string ToGdk(this ImageFormat format) + { + switch (format) + { + case ImageFormat.Jpeg: + return "jpeg"; + case ImageFormat.Bitmap: + return "bmp"; + case ImageFormat.Gif: + return "gif"; + case ImageFormat.Tiff: + return "tiff"; + case ImageFormat.Png: + return "png"; + default: + throw new Exception("Invalid format specified"); + } + } + + public static Gdk.CursorType ToGdk(this CursorType cursor) + { + switch (cursor) + { + case CursorType.Arrow: + return Gdk.CursorType.Arrow; + case CursorType.Crosshair: + return Gdk.CursorType.Crosshair; + case CursorType.Default: + return Gdk.CursorType.Arrow; + case CursorType.HorizontalSplit: + return Gdk.CursorType.SbHDoubleArrow; + case CursorType.VerticalSplit: + return Gdk.CursorType.SbVDoubleArrow; + case CursorType.IBeam: + return Gdk.CursorType.Xterm; + case CursorType.Move: + return Gdk.CursorType.Fleur; + case CursorType.Pointer: + return Gdk.CursorType.Hand2; + default: + throw new NotSupportedException(); + } + } + + public static Gtk.ButtonsType ToGtk(this MessageBoxButtons buttons) + { + switch (buttons) + { + default: + return Gtk.ButtonsType.Ok; + case MessageBoxButtons.OKCancel: + return Gtk.ButtonsType.OkCancel; + case MessageBoxButtons.YesNo: + return Gtk.ButtonsType.YesNo; + case MessageBoxButtons.YesNoCancel: + return Gtk.ButtonsType.YesNo; + } + } + + public static Gtk.ResponseType ToGtk(this MessageBoxDefaultButton button, MessageBoxButtons buttons) + { + switch (button) + { + case MessageBoxDefaultButton.OK: + if (buttons == MessageBoxButtons.YesNo || buttons == MessageBoxButtons.YesNoCancel) + return Gtk.ResponseType.Yes; + return Gtk.ResponseType.Ok; + case MessageBoxDefaultButton.No: + return Gtk.ResponseType.No; + case MessageBoxDefaultButton.Cancel: + return Gtk.ResponseType.Cancel; + case MessageBoxDefaultButton.Default: + switch (buttons) + { + case MessageBoxButtons.OK: + return Gtk.ResponseType.Ok; + case MessageBoxButtons.OKCancel: + case MessageBoxButtons.YesNoCancel: + return Gtk.ResponseType.Cancel; + case MessageBoxButtons.YesNo: + return Gtk.ResponseType.No; + default: + throw new NotSupportedException(); + } + default: + throw new NotSupportedException(); + } + } + + public static Gtk.MessageType ToGtk(this MessageBoxType type) + { + switch (type) + { + default: + return Gtk.MessageType.Info; + case MessageBoxType.Error: + return Gtk.MessageType.Error; + case MessageBoxType.Warning: + return Gtk.MessageType.Warning; + case MessageBoxType.Question: + return Gtk.MessageType.Question; + } + } + + public static Gtk.PageOrientation ToGtk(this PageOrientation value) + { + switch (value) + { + case PageOrientation.Landscape: + return Gtk.PageOrientation.Landscape; + case PageOrientation.Portrait: + return Gtk.PageOrientation.Portrait; + default: + throw new NotSupportedException(); + } + } + + public static PageOrientation ToEto(this Gtk.PageOrientation value) + { + switch (value) + { + case Gtk.PageOrientation.Landscape: + return PageOrientation.Landscape; + case Gtk.PageOrientation.Portrait: + return PageOrientation.Portrait; + default: + throw new NotSupportedException(); + } + } + + public static Gtk.PageRange ToGtkPageRange(this Range range) + { + return new Gtk.PageRange { Start = range.Start - 1, End = range.End - 1 }; + } + + public static Range ToEto(this Gtk.PageRange range) + { + return new Range(range.Start + 1, range.End); + } + + public static Gtk.PrintPages ToGtk(this PrintSelection value) + { + switch (value) + { + case PrintSelection.AllPages: + return Gtk.PrintPages.All; + case PrintSelection.SelectedPages: + return Gtk.PrintPages.Ranges; + default: + throw new NotSupportedException(); + } + } + + public static PrintSelection ToEto(this Gtk.PrintPages value) + { + switch (value) + { + case Gtk.PrintPages.All: + return PrintSelection.AllPages; + case Gtk.PrintPages.Ranges: + return PrintSelection.SelectedPages; + default: + throw new NotSupportedException(); + } + } + + public static float DegreesToRadians(float angle) + { + return (float)Math.PI * angle / 180.0f; + } + + public static void Apply(this Pen pen, GraphicsHandler graphics) + { + ((PenHandler)pen.Handler).Apply(pen, graphics); + } + + public static void Apply(this Brush brush, GraphicsHandler graphics) + { + ((BrushHandler)brush.Handler).Apply(brush.ControlObject, graphics); + } + + public static Cairo.LineJoin ToCairo(this PenLineJoin value) + { + switch (value) + { + case PenLineJoin.Miter: + return Cairo.LineJoin.Miter; + case PenLineJoin.Bevel: + return Cairo.LineJoin.Bevel; + case PenLineJoin.Round: + return Cairo.LineJoin.Round; + default: + throw new NotSupportedException(); + } + } + + public static PenLineJoin ToEto(this Cairo.LineJoin value) + { + switch (value) + { + case Cairo.LineJoin.Bevel: + return PenLineJoin.Bevel; + case Cairo.LineJoin.Miter: + return PenLineJoin.Miter; + case Cairo.LineJoin.Round: + return PenLineJoin.Round; + default: + throw new NotSupportedException(); + } + } + + public static Cairo.LineCap ToCairo(this PenLineCap value) + { + switch (value) + { + case PenLineCap.Butt: + return Cairo.LineCap.Butt; + case PenLineCap.Round: + return Cairo.LineCap.Round; + case PenLineCap.Square: + return Cairo.LineCap.Square; + default: + throw new NotSupportedException(); + } + } + + public static PenLineCap ToEto(this Cairo.LineCap value) + { + switch (value) + { + case Cairo.LineCap.Butt: + return PenLineCap.Butt; + case Cairo.LineCap.Round: + return PenLineCap.Round; + case Cairo.LineCap.Square: + return PenLineCap.Square; + default: + throw new NotSupportedException(); + } + } + + public static Cairo.PointD ToCairo(this PointF point) + { + return new Cairo.PointD(point.X, point.Y); + } + + public static PointF ToEto(this Cairo.PointD point) + { + return new PointF((float)point.X, (float)point.Y); + } + + public static GraphicsPathHandler ToHandler(this IGraphicsPath path) + { + return ((GraphicsPathHandler)path.ControlObject); + } + + public static void Apply(this IGraphicsPath path, Cairo.Context context) + { + ((GraphicsPathHandler)path.ControlObject).Apply(context); + } + + public static Cairo.Matrix ToCairo(this IMatrix matrix) + { + return (Cairo.Matrix)matrix.ControlObject; + } + + public static IMatrix ToEto(this Cairo.Matrix matrix) + { + return new MatrixHandler(matrix); + } + + public static Gdk.Pixbuf ToGdk(this Image image) + { + var handler = image.Handler as IGtkPixbuf; + return handler != null ? handler.Pixbuf : null; + } + + public static void SetCairoSurface(this Image image, Cairo.Context context, float x, float y) + { + Gdk.CairoHelper.SetSourcePixbuf(context, image.ToGdk(), x, y); + } + + public static GradientWrapMode ToEto(this Cairo.Extend extend) + { + switch (extend) + { + case Cairo.Extend.Reflect: + return GradientWrapMode.Reflect; + case Cairo.Extend.Repeat: + return GradientWrapMode.Repeat; + default: + throw new NotSupportedException(); + } + } + + public static Cairo.Extend ToCairo(this GradientWrapMode wrap) + { + switch (wrap) + { + case GradientWrapMode.Reflect: + return Cairo.Extend.Reflect; + case GradientWrapMode.Repeat: + return Cairo.Extend.Repeat; + default: + throw new NotSupportedException(); + } + } + + public static Gtk.Image ToGtk(this Image image, Gtk.IconSize? size = null) + { + if (image == null) + return null; + var handler = (IImageHandler)image.Handler; + var gtkimage = new Gtk.Image(); + handler.SetImage(gtkimage, size); + return gtkimage; + } + + public static void SetGtkImage(this Image image, Gtk.Image gtkimage, Gtk.IconSize? size = null) + { + if (image == null) + return; + var handler = (IImageHandler)image.Handler; + handler.SetImage(gtkimage, size); + } + + public static Cairo.FillRule ToCairo(this FillMode value) + { + switch (value) + { + case FillMode.Alternate: + return Cairo.FillRule.EvenOdd; + case FillMode.Winding: + return Cairo.FillRule.Winding; + default: + throw new NotSupportedException(); + } + } + + public static KeyEventArgs ToEto(this Gdk.EventKey args) + { + Keys key = args.Key.ToEto() | args.State.ToEtoKey(); + + if (key != Keys.None) + { + Keys modifiers = (key & Keys.ModifierMask); + if (args.KeyValue <= 128 && ((modifiers & ~Keys.Shift) == 0)) + return new KeyEventArgs(key, KeyEventType.KeyDown, (char)args.KeyValue); + return new KeyEventArgs(key, KeyEventType.KeyDown); + } + return args.KeyValue <= 128 ? new KeyEventArgs(key, KeyEventType.KeyDown, (char)args.KeyValue) : null; + } + + public static MouseButtons ToEtoMouseButtons(this Gdk.ModifierType modifiers) + { + MouseButtons buttons = MouseButtons.None; + if (modifiers.HasFlag(Gdk.ModifierType.Button1Mask)) + buttons |= MouseButtons.Primary; + if (modifiers.HasFlag(Gdk.ModifierType.Button2Mask)) + buttons |= MouseButtons.Middle; + if (modifiers.HasFlag(Gdk.ModifierType.Button3Mask)) + buttons |= MouseButtons.Alternate; + return buttons; + } + + public static MouseButtons ToEtoMouseButtons(this Gdk.EventButton ev) + { + switch (ev.Button) + { + case 1: + return MouseButtons.Primary; + case 2: + return MouseButtons.Middle; + case 3: + return MouseButtons.Alternate; + default: + return MouseButtons.None; + } + } + + public static DrawableCellStates ToEto(this Gtk.CellRendererState value) + { + if (value.HasFlag(Gtk.CellRendererState.Selected)) + return DrawableCellStates.Selected; + return DrawableCellStates.None; + } + + public static HorizontalAlign ToEto(this Gtk.Justification justification) + { + switch (justification) + { + case Gtk.Justification.Left: + return HorizontalAlign.Left; + case Gtk.Justification.Right: + return HorizontalAlign.Right; + case Gtk.Justification.Center: + return HorizontalAlign.Center; + default: + throw new NotSupportedException(); + } + } + + public static Gtk.Justification ToGtk(this HorizontalAlign align) + { + switch (align) + { + case HorizontalAlign.Left: + return Gtk.Justification.Left; + case HorizontalAlign.Center: + return Gtk.Justification.Center; + case HorizontalAlign.Right: + return Gtk.Justification.Right; + default: + throw new NotSupportedException(); + } + } + } +} diff --git a/Source/Eto.Platform.Gtk/CustomControls/AnalogClock.cs b/Source/Eto.Gtk/CustomControls/AnalogClock.cs similarity index 98% rename from Source/Eto.Platform.Gtk/CustomControls/AnalogClock.cs rename to Source/Eto.Gtk/CustomControls/AnalogClock.cs index 0a714c6c7f..ed3c580757 100644 --- a/Source/Eto.Platform.Gtk/CustomControls/AnalogClock.cs +++ b/Source/Eto.Gtk/CustomControls/AnalogClock.cs @@ -1,7 +1,7 @@ using System; using Gdk; -namespace Eto.Platform.GtkSharp.CustomControls +namespace Eto.GtkSharp.CustomControls { class AnalogClock : Gtk.DrawingArea { diff --git a/Source/Eto.Platform.Gtk/CustomControls/BaseComboBox.cs b/Source/Eto.Gtk/CustomControls/BaseComboBox.cs similarity index 96% rename from Source/Eto.Platform.Gtk/CustomControls/BaseComboBox.cs rename to Source/Eto.Gtk/CustomControls/BaseComboBox.cs index f6fcd8b415..56e18439ac 100644 --- a/Source/Eto.Platform.Gtk/CustomControls/BaseComboBox.cs +++ b/Source/Eto.Gtk/CustomControls/BaseComboBox.cs @@ -1,13 +1,12 @@ using System; using Gtk; -namespace Eto.Platform.GtkSharp.CustomControls +namespace Eto.GtkSharp.CustomControls { public class BaseComboBox : SizableBin { Entry entry; Button popupButton; - int vpadding; public BaseComboBox() { @@ -20,6 +19,9 @@ public BaseComboBox() #endif } #if GTK2 + int vpadding; + static readonly int DefaultEntryHeight = new ComboBoxEntry().SizeRequest().Height; + protected override void OnSizeRequested(ref Requisition requisition) { base.OnSizeRequested(ref requisition); @@ -127,8 +129,6 @@ Gtk.Widget CreatePopupButton() return popupButton; } - static readonly int DefaultEntryHeight = new Entry().SizeRequest().Height; - void Build() { var vbox = new VBox(); diff --git a/Source/Eto.Platform.Gtk/CustomControls/DateComboBox.cs b/Source/Eto.Gtk/CustomControls/DateComboBox.cs similarity index 98% rename from Source/Eto.Platform.Gtk/CustomControls/DateComboBox.cs rename to Source/Eto.Gtk/CustomControls/DateComboBox.cs index 59176345fa..7f377150fb 100644 --- a/Source/Eto.Platform.Gtk/CustomControls/DateComboBox.cs +++ b/Source/Eto.Gtk/CustomControls/DateComboBox.cs @@ -2,7 +2,7 @@ using Eto.Forms; using System.Globalization; -namespace Eto.Platform.GtkSharp.CustomControls +namespace Eto.GtkSharp.CustomControls { public class DateComboBox : BaseComboBox { diff --git a/Source/Eto.Platform.Gtk/CustomControls/DateComboBoxDialog.cs b/Source/Eto.Gtk/CustomControls/DateComboBoxDialog.cs similarity index 99% rename from Source/Eto.Platform.Gtk/CustomControls/DateComboBoxDialog.cs rename to Source/Eto.Gtk/CustomControls/DateComboBoxDialog.cs index 8b2e6fcfff..8422b6666f 100644 --- a/Source/Eto.Platform.Gtk/CustomControls/DateComboBoxDialog.cs +++ b/Source/Eto.Gtk/CustomControls/DateComboBoxDialog.cs @@ -1,7 +1,7 @@ using System; using Eto.Forms; -namespace Eto.Platform.GtkSharp.CustomControls +namespace Eto.GtkSharp.CustomControls { public class DateComboBoxDialog : Gtk.Window { diff --git a/Source/Eto.Platform.Gtk/CustomControls/SizableBin.cs b/Source/Eto.Gtk/CustomControls/SizableBin.cs similarity index 95% rename from Source/Eto.Platform.Gtk/CustomControls/SizableBin.cs rename to Source/Eto.Gtk/CustomControls/SizableBin.cs index 97662c59f8..58265a1460 100644 --- a/Source/Eto.Platform.Gtk/CustomControls/SizableBin.cs +++ b/Source/Eto.Gtk/CustomControls/SizableBin.cs @@ -1,7 +1,7 @@ using Gtk; using Gdk; -namespace Eto.Platform.GtkSharp.CustomControls +namespace Eto.GtkSharp.CustomControls { public class SizableBin : Bin { diff --git a/Source/Eto.Platform.Gtk/CustomControls/WindowExtensions.cs b/Source/Eto.Gtk/CustomControls/WindowExtensions.cs similarity index 94% rename from Source/Eto.Platform.Gtk/CustomControls/WindowExtensions.cs rename to Source/Eto.Gtk/CustomControls/WindowExtensions.cs index 60fa46a6ad..b729634305 100644 --- a/Source/Eto.Platform.Gtk/CustomControls/WindowExtensions.cs +++ b/Source/Eto.Gtk/CustomControls/WindowExtensions.cs @@ -1,5 +1,5 @@ -namespace Eto.Platform.GtkSharp.CustomControls +namespace Eto.GtkSharp.CustomControls { public static class WindowExtensions { diff --git a/Source/Eto.Gtk/Drawing/BitmapHandler.cs b/Source/Eto.Gtk/Drawing/BitmapHandler.cs new file mode 100644 index 0000000000..64cf8b49d4 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/BitmapHandler.cs @@ -0,0 +1,260 @@ +using System; +using System.IO; +using Eto.Drawing; +using System.Collections.Generic; + +namespace Eto.GtkSharp.Drawing +{ + /// + /// Bitmap data handler. + /// + /// (c) 2012-2013 by Curtis Wensley + /// See LICENSE for full terms + public class BitmapDataHandler : BitmapData + { + public BitmapDataHandler(Image image, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) + : base(image, data, scanWidth, bitsPerPixel, controlObject) + { + } + + public override int TranslateArgbToData(int argb) + { + return unchecked((int)(((uint)argb & 0xFF00FF00) | (((uint)argb & 0xFF) << 16) | (((uint)argb & 0xFF0000) >> 16))); + } + + public override int TranslateDataToArgb(int bitmapData) + { + return unchecked((int)(((uint)bitmapData & 0xFF00FF00) | (((uint)bitmapData & 0xFF) << 16) | (((uint)bitmapData & 0xFF0000) >> 16))); + } + } + + /// + /// Bitmap handler. + /// + /// (c) 2012-2013 by Curtis Wensley + /// See LICENSE for full terms + public class BitmapHandler : ImageHandler, Bitmap.IHandler, IGtkPixbuf + { + readonly Dictionary sizes = new Dictionary(); + + public bool Alpha { get; set; } + + public BitmapHandler() + { + } + + public BitmapHandler(Gdk.Pixbuf pixbuf) + { + this.Control = pixbuf; + } + + public void Create(string fileName) + { + Control = new Gdk.Pixbuf(fileName); + } + + public void Create(Stream stream) + { + Control = new Gdk.Pixbuf(stream); + } + + public void Create(int width, int height, PixelFormat pixelFormat) + { + switch (pixelFormat) + { + case PixelFormat.Format32bppRgba: + Control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, width, height); + Control.Fill(0); + Alpha = true; + break; + case PixelFormat.Format32bppRgb: + Control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, width, height); + Control.Fill(0x000000FF); + break; + case PixelFormat.Format24bppRgb: + Control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, width, height); + break; + /*case PixelFormat.Format16bppRgb555: + control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 5, width, height); + break;*/ + default: + throw new NotSupportedException(); + } + } + + public void Create(int width, int height, Graphics graphics) + { + Create(width, height, PixelFormat.Format32bppRgba); + } + + public void Create(Image image, int width, int height, ImageInterpolation interpolation) + { + var pixbuf = image.ToGdk(); + Control = pixbuf.ScaleSimple(width, height, interpolation.ToGdk()); + } + + public BitmapData Lock() + { + return new BitmapDataHandler(Widget, Control.Pixels, Control.Rowstride, Control.HasAlpha ? 32 : 24, null); + } + + public void Unlock(BitmapData bitmapData) + { + sizes.Clear(); + } + + public void Save(Stream stream, ImageFormat format) + { + string fileName = Guid.NewGuid().ToString(); + Control.Save(fileName, format.ToGdk()); + Stream fileStream = File.OpenRead(fileName); + var buffer = new byte[4096]; + + int size = fileStream.Read(buffer, 0, buffer.Length); + while (size > 0) + { + stream.Write(buffer, 0, size); + size = fileStream.Read(buffer, 0, buffer.Length); + } + fileStream.Close(); + File.Delete(fileName); + } + + public override Size Size + { + get { return new Size(Control.Width, Control.Height); } + } + + public override void SetImage(Gtk.Image imageView, Gtk.IconSize? iconSize) + { + if (iconSize != null) + imageView.SetFromIconSet(new Gtk.IconSet(Control), iconSize.Value); + else + imageView.Pixbuf = Control; + } + + public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) + { + var context = graphics.Control; + context.Save(); + destination.X += (float)graphics.InverseOffset; + destination.Y += (float)graphics.InverseOffset; + context.Rectangle(destination.ToCairo()); + double scalex = 1; + double scaley = 1; + if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f) + { + scalex = (double)destination.Width / (double)source.Width; + scaley = (double)destination.Height / (double)source.Height; + context.Scale(scalex, scaley); + } + Gdk.CairoHelper.SetSourcePixbuf(context, Control, (destination.Left / scalex) - source.Left, (destination.Top / scaley) - source.Top); + var pattern = (Cairo.SurfacePattern)context.Source; + pattern.Filter = graphics.ImageInterpolation.ToCairo(); + context.Fill(); + context.Restore(); + + if (EtoEnvironment.Platform.IsMac) + pattern.Dispose(); + + /* + Gdk.Pixbuf pb = Control; + + + if (source.Width != destination.Width || source.Height != destination.Height) { + Gdk.Pixbuf pbDest = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height); + double scalex = (double)(destination.Width) / (double)(source.Width); + double scaley = (double)(destination.Height) / (double)(source.Height); + pb.Scale (pbDest, 0, 0, destination.Width, destination.Height, -(source.X * scalex), -(source.Y * scaley), + scalex, scaley, Gdk.InterpType.Bilinear); + source.Location = new Point (0, 0); + pb = pbDest; + } + /* + * + pb.RenderToDrawable (graphics.Control, graphics.GC, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); + /* + * + Gdk.Pixmap pm, mask; + pb.RenderPixmapAndMask(out pm, out mask, 0); + graphics.Drawable.DrawDrawable(graphics.GC, pm, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height); + pm.Dispose(); + mask.Dispose(); + /* + * + graphics.Drawable.DrawPixbuf(null, pb, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); + /* + */ + /*if (pb != Control) + pb.Dispose ();*/ + } + + public Gdk.Pixbuf Pixbuf + { + get + { + return Control; + } + } + + public Gdk.Pixbuf GetPixbuf(Size maxSize, Gdk.InterpType interpolation = Gdk.InterpType.Bilinear) + { + Gdk.Pixbuf pixbuf = Control; + if (pixbuf.Width > maxSize.Width && pixbuf.Height > maxSize.Height) + { + if (!sizes.TryGetValue(maxSize, out pixbuf)) + { + pixbuf = Control.ScaleSimple(maxSize.Width, maxSize.Height, interpolation); + sizes[maxSize] = pixbuf; + } + } + + return pixbuf; + } + + public Bitmap Clone(Rectangle? rectangle = null) + { + if (rectangle == null) + return new Bitmap(new BitmapHandler(Control.Copy())); + else + { + var rect = rectangle.Value; + PixelFormat format; + if (Control.BitsPerSample == 24) + format = PixelFormat.Format24bppRgb; + else if (Control.HasAlpha) + format = PixelFormat.Format32bppRgba; + else + format = PixelFormat.Format32bppRgb; + var bmp = new Bitmap(rect.Width, rect.Height, format); + Control.CopyArea(rect.X, rect.Y, rect.Width, rect.Height, bmp.ToGdk(), 0, 0); + return bmp; + } + } + + public Color GetPixel(int x, int y) + { + using (var data = Lock()) + { + unsafe + { + var srcrow = (byte*)data.Data; + srcrow += y * data.ScanWidth; + srcrow += x * data.BytesPerPixel; + if (data.BytesPerPixel == 4) + { + return Color.FromArgb(data.TranslateDataToArgb(*(int*)srcrow)); + } + if (data.BytesPerPixel == 3) + { + var b = *(srcrow++); + var g = *(srcrow++); + var r = *(srcrow++); + return Color.FromArgb(r, g, b); + } + throw new NotSupportedException(); + } + } + } + } +} diff --git a/Source/Eto.Gtk/Drawing/BrushHandler.cs b/Source/Eto.Gtk/Drawing/BrushHandler.cs new file mode 100644 index 0000000000..18150fd9f3 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/BrushHandler.cs @@ -0,0 +1,15 @@ +using Eto.Drawing; + +namespace Eto.GtkSharp.Drawing +{ + /// + /// Handler for the + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public abstract class BrushHandler : Brush.IHandler + { + public abstract void Apply (object control, GraphicsHandler graphics); + } +} + diff --git a/Source/Eto.Gtk/Drawing/FontFamilyHandler.cs b/Source/Eto.Gtk/Drawing/FontFamilyHandler.cs new file mode 100644 index 0000000000..2192b829d9 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/FontFamilyHandler.cs @@ -0,0 +1,74 @@ +using System; +using Eto.Drawing; +using System.Collections.Generic; +using System.Linq; + +namespace Eto.GtkSharp.Drawing +{ + public class FontFamilyHandler : WidgetHandler, FontFamily.IHandler + { + public string Name { get; set; } + + public IEnumerable Typefaces + { + get { return Control.Faces.Select (r => new FontTypeface(Widget, new FontTypefaceHandler(r))); } + } + + public FontFamilyHandler () + { + } + + public FontFamilyHandler (Pango.FontFamily pangoFamily) + { + Control = pangoFamily; + Name = Control.Name; + } + + public void Create (string familyName) + { + Name = familyName; + switch (familyName.ToUpperInvariant()) { + case FontFamilies.MonospaceFamilyName: + Control = GetFontFamily("monospace", "FreeMono", "Courier"); + break; + case FontFamilies.SansFamilyName: + Control = GetFontFamily("sans", "FreeSans"); + break; + case FontFamilies.SerifFamilyName: + Control = GetFontFamily("serif", "FreeSerif"); + break; + case FontFamilies.CursiveFamilyName: + // from http://www.codestyle.org/css/font-family/sampler-Cursive.shtml#cursive-linux + Control = GetFontFamily("URW Chancery L", "Comic Sans MS", "Purisa", "Vemana2000", "Domestic Manners", "serif"); + break; + case FontFamilies.FantasyFamilyName: + // from http://www.codestyle.org/css/font-family/sampler-Fantasy.shtml#fantasy-linux + Control = GetFontFamily("Impact", "Penguin Attack", "Balker", "Marked Fool", "Junkyard", "Linux Biolinum", "serif"); + break; + default: + Control = GetFontFamily(familyName); + if (Control == null) + throw new ArgumentOutOfRangeException("familyName", familyName, "Font Family specified is not supported by this system"); + Name = Control.Name; + break; + } + } + + static Pango.FontFamily GetFontFamily(params string [] familyNames) + { + foreach (var familyName in familyNames) + { + var family = GetFontFamily (familyName); + if (family != null) + return family; + } + return null; + } + + public static Pango.FontFamily GetFontFamily(string familyName) + { + return FontsHandler.Context.Families.FirstOrDefault(r => string.Equals(r.Name, familyName, StringComparison.InvariantCultureIgnoreCase)); + } + } +} + diff --git a/Source/Eto.Gtk/Drawing/FontHandler.cs b/Source/Eto.Gtk/Drawing/FontHandler.cs new file mode 100644 index 0000000000..c4451176ee --- /dev/null +++ b/Source/Eto.Gtk/Drawing/FontHandler.cs @@ -0,0 +1,301 @@ +using System; +using Eto.Drawing; +using System.Linq; + +namespace Eto.GtkSharp.Drawing +{ + public static class FontHandlerExtensions + { + public static void Apply(this Font font, Gtk.TextTag tag) + { + if (tag != null) + { + if (font != null) + { + tag.Underline = font.FontDecoration.HasFlag(FontDecoration.Underline) ? Pango.Underline.Single : Pango.Underline.None; + tag.Strikethrough = font.FontDecoration.HasFlag(FontDecoration.Strikethrough); + } + else + { + tag.Underline = Pango.Underline.None; + tag.Strikethrough = false; + } + } + } + + public static void Apply(this Font font, Pango.Layout layout) + { + if (font != null) + { + var handler = (FontHandler)font.Handler; + layout.FontDescription = handler.Control; + layout.Attributes = handler.Attributes; + } + } + } + + public class FontHandler : WidgetHandler, Font.IHandler + { + FontFamily family; + FontTypeface typeface; + FontStyle? style; + Pango.AttrList attributes; + + public FontHandler() + { + } + + public FontHandler(Gtk.Widget widget) + : this (widget.Style.FontDescription) + { + } + + public FontHandler(Pango.FontDescription fontDescription) + { + Control = fontDescription; + } + + public FontHandler(string fontName) + { + Control = Pango.FontDescription.FromString(fontName); + } + + public void Create(SystemFont systemFont, float? size, FontDecoration decoration) + { + switch (systemFont) + { + case SystemFont.Default: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + case SystemFont.Bold: + Control = new Pango.FontDescription(); + Control.Merge(Gtk.Widget.DefaultStyle.FontDescription, true); + Control.Weight = Pango.Weight.Bold; + break; + case SystemFont.TitleBar: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + case SystemFont.ToolTip: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + case SystemFont.Label: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + case SystemFont.MenuBar: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + case SystemFont.Menu: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + case SystemFont.Message: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + case SystemFont.Palette: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + case SystemFont.StatusBar: + Control = Gtk.Widget.DefaultStyle.FontDescription; + break; + default: + throw new NotSupportedException(); + } + if (size != null) + { + var old = Control; + Control = new Pango.FontDescription(); + Control.Merge(old, true); + if (size != null) + Control.Size = (int)(size * Pango.Scale.PangoScale); + } + FontDecoration = decoration; + } + + public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) + { + this.family = family; + Control = new Pango.FontDescription(); + SetStyle(style); + Size = size; + FontDecoration = decoration; + + var familyHandler = (FontFamilyHandler)family.Handler; + Control.Family = familyHandler.Control.Name; + } + + public void Create(FontTypeface face, float size, FontDecoration decoration) + { + typeface = face; + Control = ((FontTypefaceHandler)face.Handler).Control.Describe(); + Size = size; + FontDecoration = decoration; + } + + void SetStyle(FontStyle style) + { + if ((style & FontStyle.Bold) != 0) + Control.Weight = Pango.Weight.Bold; + if ((style & FontStyle.Italic) != 0) + Control.Style = Pango.Style.Italic; + } + + public Pango.AttrList Attributes + { + get + { + if (attributes == null) + { + attributes = new Pango.AttrList(); + attributes.Insert(new Pango.AttrUnderline(FontDecoration.HasFlag(FontDecoration.Underline) ? Pango.Underline.Single : Pango.Underline.None)); + attributes.Insert(new Pango.AttrStrikethrough(FontDecoration.HasFlag(FontDecoration.Strikethrough))); + } + return attributes; + } + } + + public float Size + { + get { return (float)(Control.Size / Pango.Scale.PangoScale); } + private set { Control.Size = (int)(value * Pango.Scale.PangoScale); } + } + + public FontStyle FontStyle + { + get + { + if (style == null) + { + style = FontStyle.None; + if (Control.Weight == Pango.Weight.Bold) + style |= FontStyle.Bold; + if (Control.Style == Pango.Style.Italic) + style |= FontStyle.Italic; + } + return style.Value; + } + } + + public FontDecoration FontDecoration { get; private set; } + + public string FamilyName + { + get { return Control.Family; } + } + + public FontFamily Family + { + get + { + if (family == null) + { + family = new FontFamily(Control.Family); + } + return family; + } + } + + public FontTypeface Typeface + { + get + { + if (typeface == null) + { + typeface = Family.Typefaces.FirstOrDefault(r => r.FontStyle == FontStyle); + } + return typeface; + } + } + + Pango.FontMetrics metrics; + + public Pango.FontMetrics Metrics + { + get + { + if (metrics == null) + metrics = FontsHandler.Context.GetMetrics(Control, Pango.Language.Default); + return metrics; + } + } + + public float Ascent + { + get { return (float)Metrics.Ascent / (float)Pango.Scale.PangoScale; } + } + + public float Descent + { + get { return (float)Metrics.Descent / (float)Pango.Scale.PangoScale; } + } + + float? lineHeight; + + public float LineHeight + { + get + { + if (lineHeight == null) + { + using (var layout = new Pango.Layout(FontsHandler.Context)) + { + layout.FontDescription = Control; + layout.SetText("X"); + Pango.Rectangle ink, logical; + layout.GetExtents(out ink, out logical); + lineHeight = (float)logical.Height / (float)Pango.Scale.PangoScale; + } + } + return lineHeight ?? 0f; + } + } + + public float Baseline + { + get { return Ascent; } + } + + float? leading; + + public float Leading + { + get + { + if (leading == null) + { + using (var layout = new Pango.Layout(FontsHandler.Context)) + { + layout.FontDescription = Control; + layout.SetText("X"); + Pango.Rectangle ink, logical; + layout.GetExtents(out ink, out logical); + leading = (float)(ink.Y - logical.Y) / (float)Pango.Scale.PangoScale; + } + } + return leading ?? 0f; + } + } + + float? xheight; + + public float XHeight + { + get + { + if (xheight == null) + { + using (var layout = new Pango.Layout(FontsHandler.Context)) + { + layout.FontDescription = Control; + layout.SetText("x"); + layout.Spacing = 0; + layout.Alignment = Pango.Alignment.Left; + layout.Width = int.MaxValue; + Pango.Rectangle ink, logical; + layout.GetExtents(out ink, out logical); + xheight = (float)ink.Height / (float)Pango.Scale.PangoScale; + } + } + return xheight ?? 0f; + } + } + } +} diff --git a/Source/Eto.Gtk/Drawing/FontTypefaceHandler.cs b/Source/Eto.Gtk/Drawing/FontTypefaceHandler.cs new file mode 100644 index 0000000000..633afd8463 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/FontTypefaceHandler.cs @@ -0,0 +1,31 @@ +using Eto.Drawing; + +namespace Eto.GtkSharp.Drawing +{ + public class FontTypefaceHandler : WidgetHandler, FontTypeface.IHandler + { + public FontTypefaceHandler (Pango.FontFace pangoFace) + { + this.Control = pangoFace; + } + + public string Name + { + get { return Control.FaceName; } + } + + public FontStyle FontStyle + { + get { + var style = FontStyle.None; + var description = Control.Describe (); + if (description.Style.HasFlag (Pango.Style.Italic)) + style |= FontStyle.Italic; + if (description.Weight.HasFlag (Pango.Weight.Bold)) + style |= FontStyle.Bold; + return style; + } + } + } +} + diff --git a/Source/Eto.Gtk/Drawing/FontsHandler.cs b/Source/Eto.Gtk/Drawing/FontsHandler.cs new file mode 100644 index 0000000000..532821e3e6 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/FontsHandler.cs @@ -0,0 +1,42 @@ +using System; +using Eto.Drawing; +using System.Collections.Generic; +using System.Linq; + +namespace Eto.GtkSharp.Drawing +{ + public class FontsHandler : WidgetHandler, Fonts.IHandler + { + HashSet familyNames; + static Pango.Context context; + + public static Pango.Context Context + { + get + { + if (context == null) { + var window = new Gtk.Window (string.Empty); + context = window.PangoContext; + } + return context; + } + } + + public IEnumerable AvailableFontFamilies + { + get { return Context.Families.Select (r => new FontFamily (new FontFamilyHandler (r))); } + } + + public bool FontFamilyAvailable (string fontFamily) + { + if (familyNames == null) { + familyNames = new HashSet (StringComparer.InvariantCultureIgnoreCase); + foreach (var family in Context.Families) { + familyNames.Add (family.Name); + } + } + return familyNames.Contains (fontFamily); + } + } +} + diff --git a/Source/Eto.Gtk/Drawing/GraphicsHandler.cs b/Source/Eto.Gtk/Drawing/GraphicsHandler.cs new file mode 100644 index 0000000000..42236d145a --- /dev/null +++ b/Source/Eto.Gtk/Drawing/GraphicsHandler.cs @@ -0,0 +1,432 @@ +using System; +using Eto.Drawing; + +namespace Eto.GtkSharp.Drawing +{ + public class GraphicsHandler : WidgetHandler, Graphics.IHandler + { + Pango.Context pangoContext; + readonly Gtk.Widget widget; + Image image; + Cairo.ImageSurface surface; + double offset = 0.5; + double inverseoffset; + PixelOffsetMode pixelOffsetMode = PixelOffsetMode.None; + RectangleF? clipBounds; + IGraphicsPath clipPath; + bool disposeControl = true; + #if GTK2 + readonly Gdk.Drawable drawable; + + public GraphicsHandler(Gtk.Widget widget, Gdk.Drawable drawable, bool dispose = true) + { + this.widget = widget; + this.drawable = drawable; + this.Control = Gdk.CairoHelper.Create(drawable); + disposeControl = dispose; + } + #else + public GraphicsHandler (Gtk.Widget widget, Gdk.Window drawable) + { + this.widget = widget; + this.Control = Gdk.CairoHelper.Create (drawable); + } +#endif + public GraphicsHandler(Cairo.Context context, Pango.Context pangoContext, bool dispose = true) + { + this.Control = context; + this.pangoContext = pangoContext; + this.disposeControl = dispose; + } + + protected override bool DisposeControl { get { return disposeControl; } } + + public PixelOffsetMode PixelOffsetMode + { + get { return pixelOffsetMode; } + set + { + pixelOffsetMode = value; + offset = value == PixelOffsetMode.None ? 0.5 : 0; + inverseoffset = value == PixelOffsetMode.None ? 0 : 0.5; + } + } + + public float PointsPerPixel { get { return PangoContext != null ? 72f / (float)Pango.CairoHelper.ContextGetResolution(PangoContext) : 72f / 96f; } } + + public double Offset { get { return offset; } } + + public double InverseOffset { get { return inverseoffset; } } + + public GraphicsHandler() + { + } + + public bool IsRetained { get { return false; } } + + public bool AntiAlias + { + get { return Control.Antialias != Cairo.Antialias.None; } + set { Control.Antialias = value ? Cairo.Antialias.Default : Cairo.Antialias.None; } + } + + public ImageInterpolation ImageInterpolation + { + get; + set; + } + + public Pango.Context PangoContext + { + get + { + if (pangoContext == null && widget != null) + { + pangoContext = widget.PangoContext; + } + return pangoContext; + } + } + + public void CreateFromImage(Bitmap image) + { + this.image = image; + var handler = (BitmapHandler)image.Handler; + + var format = handler.Alpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24; + surface = new Cairo.ImageSurface(format, image.Size.Width, image.Size.Height); + Control = new Cairo.Context(surface); + Control.Save(); + Control.Rectangle(0, 0, image.Size.Width, image.Size.Height); + Gdk.CairoHelper.SetSourcePixbuf(Control, handler.Control, 0, 0); + Control.Operator = Cairo.Operator.Source; + Control.Fill(); + Control.Restore(); + } + + public void Flush() + { + if (image != null) + { + var handler = (BitmapHandler)image.Handler; + Gdk.Pixbuf pb = handler.GetPixbuf(Size.MaxValue); + if (pb != null) + { + + surface.Flush(); + var bd = handler.Lock(); + unsafe + { + var srcrow = (byte*)surface.DataPtr; + var destrow = (byte*)bd.Data; + for (int y = 0; y < image.Size.Height; y++) + { + var src = (int*)srcrow; + var dest = (int*)destrow; + for (int x = 0; x < image.Size.Width; x++) + { + *dest = bd.TranslateArgbToData(*src); + dest++; + src++; + } + destrow += bd.ScanWidth; + srcrow += surface.Stride; + } + } + handler.Unlock(bd); + } + } +#if GTK2 + if (Control != null) + { + // Analysis disable once RedundantCast - backward compatibility + ((IDisposable)Control).Dispose(); + if (surface != null) + { + Control = new Cairo.Context(surface); + } + else if (drawable != null) + { + Control = Gdk.CairoHelper.Create(drawable); + } + } +#endif + } + + public void DrawLine(Pen pen, float startx, float starty, float endx, float endy) + { + Control.MoveTo(startx + offset, starty + offset); + Control.LineTo(endx + offset, endy + offset); + pen.Apply(this); + } + + public void DrawRectangle(Pen pen, float x, float y, float width, float height) + { + Control.Rectangle(x + offset, y + offset, width, height); + pen.Apply(this); + } + + public void FillRectangle(Brush brush, float x, float y, float width, float height) + { + Control.Rectangle(x + inverseoffset, y + inverseoffset, width, height); + Control.Save(); + brush.Apply(this); + Control.Restore(); + } + + public void DrawEllipse(Pen pen, float x, float y, float width, float height) + { + Control.Save(); + Control.Translate(x + width / 2 + offset, y + height / 2 + offset); + double radius = Math.Max(width / 2.0, height / 2.0); + if (width > height) + Control.Scale(1.0, height / width); + else + Control.Scale(width / height, 1.0); + Control.Arc(0, 0, radius, 0, 2 * Math.PI); + Control.Restore(); + pen.Apply(this); + } + + public void FillEllipse(Brush brush, float x, float y, float width, float height) + { + Control.Save(); + Control.Translate(x + width / 2 + inverseoffset, y + height / 2 + inverseoffset); + double radius = Math.Max(width / 2.0, height / 2.0); + if (width > height) + Control.Scale(1.0, height / width); + else + Control.Scale(width / height, 1.0); + Control.Arc(0, 0, radius, 0, 2 * Math.PI); + Control.Restore(); + Control.Save(); + brush.Apply(this); + Control.Restore(); + } + + public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) + { + Control.Save(); + Control.Translate(x + width / 2 + offset, y + height / 2 + offset); + double radius = Math.Max(width / 2.0, height / 2.0); + if (width > height) + Control.Scale(1.0, height / width); + else + Control.Scale(width / height, 1.0); + if (sweepAngle < 0) + Control.ArcNegative(0, 0, radius, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle)); + else + Control.Arc(0, 0, radius, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle)); + Control.Restore(); + pen.Apply(this); + } + + public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) + { + Control.Save(); + Control.Translate(x + width / 2 + inverseoffset, y + height / 2 + inverseoffset); + double radius = Math.Max(width / 2.0, height / 2.0); + if (width > height) + Control.Scale(1.0, height / width); + else + Control.Scale(width / height, 1.0); + if (sweepAngle < 0) + Control.ArcNegative(0, 0, radius, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle)); + else + Control.Arc(0, 0, radius, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle)); + Control.LineTo(0, 0); + Control.Restore(); + Control.Save(); + brush.Apply(this); + Control.Restore(); + } + + public void FillPath(Brush brush, IGraphicsPath path) + { + Control.Save(); + Control.Translate(inverseoffset, inverseoffset); + path.Apply(Control); + Control.Restore(); + Control.Save(); + Control.FillRule = path.FillMode.ToCairo(); + brush.Apply(this); + Control.Restore(); + } + + public void DrawPath(Pen pen, IGraphicsPath path) + { + Control.Save(); + Control.Translate(offset, offset); + path.Apply(Control); + Control.Restore(); + pen.Apply(this); + } + + public void DrawImage(Image image, float x, float y) + { + ((IImageHandler)image.Handler).DrawImage(this, x, y); + } + + public void DrawImage(Image image, float x, float y, float width, float height) + { + ((IImageHandler)image.Handler).DrawImage(this, x, y, width, height); + } + + public void DrawImage(Image image, RectangleF source, RectangleF destination) + { + ((IImageHandler)image.Handler).DrawImage(this, source, destination); + } + + Pango.Layout CreateLayout() + { + return PangoContext != null ? new Pango.Layout(PangoContext) : Pango.CairoHelper.CreateLayout(Control); + } + + public void DrawText(Font font, SolidBrush brush, float x, float y, string text) + { + using (var layout = CreateLayout()) + { + font.Apply(layout); + layout.SetText(text); + Control.Save(); + Control.Color = brush.Color.ToCairo(); + Control.MoveTo(x, y); + Pango.CairoHelper.LayoutPath(Control, layout); + Control.Fill(); + Control.Restore(); + } + } + + public SizeF MeasureString(Font font, string text) + { + using (var layout = CreateLayout()) + { + font.Apply(layout); + layout.SetText(text); + int width, height; + layout.GetPixelSize(out width, out height); + return new SizeF(width, height); + } + } + + protected override void Dispose(bool disposing) + { + if (image != null) + { + Flush(); + image = null; + } + if (surface != null) + { + // Analysis disable once RedundantCast - backward compatibility + ((IDisposable)surface).Dispose(); + surface = null; + } + + base.Dispose(disposing); + } + + public void TranslateTransform(float offsetX, float offsetY) + { + Control.Translate(offsetX, offsetY); + } + + public void RotateTransform(float angle) + { + Control.Rotate(Conversions.DegreesToRadians(angle)); + } + + public void ScaleTransform(float scaleX, float scaleY) + { + Control.Scale(scaleX, scaleY); + } + + public void MultiplyTransform(IMatrix matrix) + { + Control.Transform(matrix.ToCairo()); + } + + public void SaveTransform() + { + ReverseClip(); + Control.Save(); + ApplyClip(); + } + + public void RestoreTransform() + { + Control.Restore(); + ApplyClip(); + } + + void ReverseClip() + { + if (clipBounds != null) + Control.ResetClip(); + } + + void ApplyClip() + { + if (clipPath != null) + { + clipPath.Apply(Control); + Control.Clip(); + } + else if (clipBounds != null) + { + Control.Rectangle(clipBounds.Value.ToCairo()); + Control.Clip(); + } + } + + public RectangleF ClipBounds + { + get + { + var bounds = clipBounds ?? (widget != null ? (RectangleF)widget.Allocation.ToEto() : RectangleF.Empty); + var matrix = Control.Matrix; + if (matrix.IsIdentity()) + return bounds; + var etoMatrix = matrix.ToEto(); + etoMatrix.Invert(); + return etoMatrix.TransformRectangle(bounds); + } + } + + public void SetClip(RectangleF rectangle) + { + ResetClip(); + clipBounds = rectangle; + ApplyClip(); + } + + public void SetClip(IGraphicsPath path) + { + ResetClip(); + clipPath = path; + clipBounds = path.Bounds; + ApplyClip(); + } + + public void ResetClip() + { + clipBounds = null; + Control.ResetClip(); + } + + public void Clear(SolidBrush brush) + { + Control.Save(); + Control.Operator = Cairo.Operator.Clear; + Control.Paint(); + Control.Restore(); + Control.Save(); + if (brush != null) + { + brush.Apply(this); + Control.Paint(); + } + Control.Restore(); + } + } +} diff --git a/Source/Eto.Gtk/Drawing/GraphicsPathHandler.cs b/Source/Eto.Gtk/Drawing/GraphicsPathHandler.cs new file mode 100644 index 0000000000..fb5c5d9028 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/GraphicsPathHandler.cs @@ -0,0 +1,364 @@ +using System; +using Eto.Drawing; +using System.Collections.Generic; +using System.Linq; + +namespace Eto.GtkSharp.Drawing +{ + /// + /// Handler for + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class GraphicsPathHandler : GraphicsPath.IHandler + { + IMatrix transform; + readonly List commands = new List (); + + bool firstFigureClosed; + bool isFirstFigure = true; + + public IEnumerable Points + { + get + { + foreach (var command in commands) { + if (command.Points == null) + continue; + foreach (var point in command.Points) { + if (transform != null) + yield return transform.TransformPoint (point); + else + yield return point; + } + } + } + } + + class CommandExecutor + { + public Cairo.Context Context { get; private set; } + + public bool First { get; private set; } + + public bool ForceConnect { get; set; } + + public CommandExecutor (Cairo.Context context) + { + this.Context = context; + this.First = true; + } + + public bool SetStart (float x, float y) + { + return SetStart (new PointF (x, y)); + } + + public void ResetStart () + { + First = true; + } + + public bool SetStart (PointF point) + { + First = false; + if (ForceConnect) { + ConnectTo (point); + return false; + } + return true; + } + + public void ConnectTo (float x, float y) + { + ConnectTo (new PointF(x, y)); + } + + public void ConnectTo (PointF point) + { + if (First) { + Context.MoveTo (point.X, point.Y); + First = false; + } else + Context.LineTo (point.X, point.Y); + ForceConnect = false; + } + + public void CloseFigure () + { + Context.ClosePath (); + First = true; + Context.NewSubPath (); + } + + } + + abstract class Command + { + public PointF[] Points { get; set; } + + public abstract void Apply (CommandExecutor exec); + } + + delegate void GraphicsPathCommandDelegate (CommandExecutor exec); + + class ActionCommand : Command + { + readonly GraphicsPathCommandDelegate apply; + + public ActionCommand (GraphicsPathCommandDelegate apply) + { + this.apply = apply; + } + + public override void Apply (CommandExecutor exec) + { + apply (exec); + } + } + + public void AddLines (IEnumerable points) + { + var pointArray = points.ToArray (); + Add (exec => { + for (int i=0; i { + if (exec.SetStart (x, y)) + exec.Context.MoveTo (x, y); + }, new PointF (x, y)); + } + + public void LineTo (float x, float y) + { + Add (exec => { + exec.SetStart (x, y); + exec.Context.LineTo (x, y); + }, new PointF (x, y)); + } + + public void AddLine (float startX, float startY, float endX, float endY) + { + Add (exec => { + exec.ConnectTo (startX, startY); + exec.Context.LineTo (endX, endY); + }, new PointF (startX, startY), new PointF (endX, endY)); + } + + void Add (GraphicsPathCommandDelegate apply, params PointF[] points) + { + commands.Add (new ActionCommand (apply) { Points = points }); + } + + public void Apply (Cairo.Context context) + { + var exec = new CommandExecutor (context); + Connect (exec); + } + + void Connect (CommandExecutor exec) + { + if (transform != null) { + exec.Context.Save (); + exec.Context.Transform (transform.ToCairo ()); + } + foreach (var command in commands) { + command.Apply (exec); + } + if (transform != null) { + exec.Context.Restore (); + } + } + + public void AddArc (float x, float y, float width, float height, float startAngle, float sweepAngle) + { + Add (exec => { + // degrees to radians conversion + double startRadians = startAngle * Math.PI / 180.0; + + // x and y radius + float dx = width / 2; + float dy = height / 2; + + // determine the start point + double xs = x + dx + (Math.Cos (startRadians) * dx); + double ys = y + dy + (Math.Sin (startRadians) * dy); + exec.SetStart ((float)xs, (float)ys); + + exec.Context.Save (); + exec.Context.Translate (x + width / 2, y + height / 2); + double radius = Math.Max (width / 2.0, height / 2.0); + if (width > height) + exec.Context.Scale (1.0, height / width); + else + exec.Context.Scale (width / height, 1.0); + + if (sweepAngle < 0) + exec.Context.ArcNegative (0, 0, radius, Conversions.DegreesToRadians (startAngle), Conversions.DegreesToRadians (startAngle + sweepAngle)); + else + exec.Context.Arc (0, 0, radius, Conversions.DegreesToRadians (startAngle), Conversions.DegreesToRadians (startAngle + sweepAngle)); + exec.Context.Restore (); + }, new PointF (x, y), new PointF (x + width, y + height)); + } + + public void AddBezier (PointF start, PointF control1, PointF control2, PointF end) + { + Add (exec => { + exec.ConnectTo (start); + exec.Context.CurveTo (control1.ToCairo (), control2.ToCairo (), end.ToCairo ()); + }, start, end); + } + + public void AddRectangle (float x, float y, float width, float height) + { + Add (exec => { + exec.Context.NewSubPath (); + exec.Context.Rectangle (x, y, width, height); + exec.ResetStart (); + }, new PointF (x, y), new PointF (x + width, y + height)); + isFirstFigure = false; + } + + public void AddPath (IGraphicsPath path, bool connect = false) + { + var handler = path.ToHandler (); + Add (exec => { + if (connect && !handler.firstFigureClosed) { + exec.ForceConnect = true; + handler.Connect (exec); + } else + handler.Apply (exec.Context); + }, handler.Points.ToArray ()); + } + + public void Transform (IMatrix matrix) + { + if (transform != null) + transform.Prepend (matrix); + else + transform = matrix; + } + + public void CloseFigure () + { + Add (exec => exec.CloseFigure()); + if (isFirstFigure) + firstFigureClosed = true; + } + + public void StartFigure () + { + Add (exec => { + exec.Context.NewSubPath (); + exec.ResetStart (); + }); + isFirstFigure = false; + } + + public void AddEllipse (float x, float y, float width, float height) + { + Add (exec => { + exec.Context.NewSubPath (); + exec.Context.Save (); + exec.Context.Translate (x + width / 2, y + height / 2); + double radius = Math.Max (width / 2.0, height / 2.0); + if (width > height) + exec.Context.Scale (1.0, height / width); + else + exec.Context.Scale (width / height, 1.0); + exec.Context.Arc (0, 0, radius, 0, 2 * Math.PI); + exec.Context.Restore (); + exec.ResetStart (); + }, new PointF (x, y), new PointF (x + width, y + height)); + isFirstFigure = false; + } + + public void AddCurve (IEnumerable points, float tension = 0.5f) + { + var pointArray = SplineHelper.SplineCurve (points, tension).ToArray (); + Add (exec => { + exec.SetStart (points.First ()); + SplineHelper.Draw(pointArray, exec.ConnectTo, (c1, c2, end) => exec.Context.CurveTo(c1.ToCairo(), c2.ToCairo(), end.ToCairo())); + }, pointArray); + } + + public void Dispose () + { + } + + public RectangleF Bounds + { + get { + bool first = true; + PointF minPoint = PointF.Empty; + PointF maxPoint = PointF.Empty; + foreach (var point in Points) { + if (first) { + minPoint = maxPoint = point; + first = false; + } else { + minPoint = PointF.Min (point, minPoint); + maxPoint = PointF.Max (point, maxPoint); + } + } + return new RectangleF (minPoint, maxPoint); + } + } + + public bool IsEmpty + { + get { return commands.Count == 0; } + } + + public PointF CurrentPoint + { + get { + // slow to get current point, but no other way? + using (var context = Playback ()) { + return context.CurrentPoint.ToEto (); + } + } + } + + Cairo.Context Playback () + { + using (var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 10, 10)) + { + var context = new Cairo.Context(surface); + Apply(context); + return context; + } + } + + public object ControlObject + { + get { return this; } + } + + public IGraphicsPath Clone() + { + var handler = new GraphicsPathHandler (); + handler.commands.AddRange(commands); + handler.transform = transform != null ? transform.Clone () : null; + handler.firstFigureClosed = firstFigureClosed; + handler.isFirstFigure = isFirstFigure; + return handler; + } + + public FillMode FillMode + { + get; set; + } + } +} + diff --git a/Source/Eto.Gtk/Drawing/IconHandler.cs b/Source/Eto.Gtk/Drawing/IconHandler.cs new file mode 100644 index 0000000000..b30b0e5cc8 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/IconHandler.cs @@ -0,0 +1,99 @@ +using System; +using System.IO; +using Eto.Drawing; +using System.Collections.Generic; + +namespace Eto.GtkSharp.Drawing +{ + public class IconHandler : ImageHandler, Icon.IHandler, IGtkPixbuf + { + readonly Dictionary sizes = new Dictionary(); + + public Gdk.Pixbuf Pixbuf { get; set; } + + #region IIcon Members + + public void Create(Stream stream) + { + Pixbuf = new Gdk.Pixbuf(stream); + Control = new Gtk.IconSet(Pixbuf); + } + + public void Create(string fileName) + { + Pixbuf = new Gdk.Pixbuf(fileName); + Control = new Gtk.IconSet(Pixbuf); + } + + #endregion + + public override Size Size + { + get + { + return new Size(Pixbuf.Width, Pixbuf.Height); + } + } + + public override void SetImage(Gtk.Image imageView, Gtk.IconSize? iconSize) + { + if (iconSize != null) + imageView.SetFromIconSet(Control, iconSize.Value); + else + imageView.Pixbuf = Pixbuf; + } + + public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) + { + var context = graphics.Control; + context.Save(); + destination.X += (float)graphics.InverseOffset; + destination.Y += (float)graphics.InverseOffset; + context.Rectangle(destination.ToCairo()); + double scalex = 1; + double scaley = 1; + if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f) + { + scalex = (double)destination.Width / (double)source.Width; + scaley = (double)destination.Height / (double)source.Height; + context.Scale(scalex, scaley); + } + Gdk.CairoHelper.SetSourcePixbuf(context, Pixbuf, (destination.Left / scalex) - source.Left, (destination.Top / scaley) - source.Top); + var pattern = (Cairo.SurfacePattern)context.Source; + pattern.Filter = graphics.ImageInterpolation.ToCairo(); + context.Fill(); + context.Restore(); + + if (EtoEnvironment.Platform.IsMac) + pattern.Dispose(); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (disposing) + { + if (Pixbuf != null) + { + Pixbuf.Dispose(); + Pixbuf = null; + } + } + } + + public Gdk.Pixbuf GetPixbuf(Size maxSize, Gdk.InterpType interpolation = Gdk.InterpType.Bilinear) + { + Gdk.Pixbuf pixbuf = Pixbuf; + if (pixbuf.Width > maxSize.Width && pixbuf.Height > maxSize.Height) + { + if (!sizes.TryGetValue(maxSize, out pixbuf)) + { + pixbuf = Pixbuf.ScaleSimple(maxSize.Width, maxSize.Height, interpolation); + sizes[maxSize] = pixbuf; + } + } + + return pixbuf; + } + } +} diff --git a/Source/Eto.Gtk/Drawing/ImageHandler.cs b/Source/Eto.Gtk/Drawing/ImageHandler.cs new file mode 100644 index 0000000000..6c53f29409 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/ImageHandler.cs @@ -0,0 +1,43 @@ +using Eto.Drawing; + +namespace Eto.GtkSharp.Drawing +{ + public interface IGtkPixbuf + { + Gdk.Pixbuf Pixbuf { get; } + + Gdk.Pixbuf GetPixbuf(Size maxSize, Gdk.InterpType interpolation = Gdk.InterpType.Bilinear); + } + + public interface IImageHandler + { + void DrawImage(GraphicsHandler graphics, float x, float y); + + void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height); + + void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination); + + void SetImage(Gtk.Image imageView, Gtk.IconSize? iconSize); + } + + public abstract class ImageHandler : WidgetHandler, Image.IHandler, IImageHandler + where TWidget: Image + { + + public abstract Size Size { get; } + + public abstract void SetImage(Gtk.Image imageView, Gtk.IconSize? iconSize); + + public virtual void DrawImage(GraphicsHandler graphics, float x, float y) + { + DrawImage(graphics, x, y, Size.Width, Size.Height); + } + + public virtual void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height) + { + DrawImage(graphics, new RectangleF(new Point(0, 0), Size), new RectangleF(x, y, width, height)); + } + + public abstract void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination); + } +} diff --git a/Source/Eto.Gtk/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Gtk/Drawing/IndexedBitmapHandler.cs new file mode 100644 index 0000000000..6c6d8ea9a6 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/IndexedBitmapHandler.cs @@ -0,0 +1,200 @@ + +#define GTK_2_6 +using System; +using System.Runtime.InteropServices; +using Eto.Drawing; +using System.Linq; + +namespace Eto.GtkSharp.Drawing +{ + public class IndexedBitmapDataHandler : BitmapData + { + public IndexedBitmapDataHandler (Image image, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) + : base(image, data, scanWidth, bitsPerPixel, controlObject) + { + } + + public override int TranslateArgbToData (int argb) + { + return argb; + } + + public override int TranslateDataToArgb (int bitmapData) + { + return bitmapData; + } + } + + public class IndexedBitmapHandler : ImageHandler, IndexedBitmap.IHandler + { + Size size; + int rowStride; + int bitsPerPixel; + uint[] colors; + + public int RowStride { + get { return rowStride; } + } + + public override Size Size { + get { return size; } + } + + public void Create (int width, int height, int bitsPerPixel) + { + this.bitsPerPixel = bitsPerPixel; + rowStride = width * bitsPerPixel / 8; + int colorCount = (int)Math.Pow (2, bitsPerPixel); + colors = new uint[colorCount]; + for (int i=0; i Color.FromArgb(unchecked((int)r))).ToList ()); + } + set { + if (value.Count != colors.Length) + throw new ArgumentException ("Input palette must have the same colors as the output"); + for (int i=0; i 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f) + { + scalex = (double)destination.Width / (double)source.Width; + scaley = (double)destination.Height / (double)source.Height; + context.Scale(scalex, scaley); + } + context.SetSourceSurface(surface, (int)destination.Left, (int)destination.Top); + context.Fill(); + context.Restore(); + } + + + /* + if (graphics == null || graphics.Control == null || graphics.GC == null) + throw new Exception("WHAA?"); + using (var drawable = new Gdk.Pixmap(graphics.Control, source.Right+1, source.Bottom+1)) + using (var gc = new Gdk.GC(drawable)) + { + if (drawable.Colormap == null) + drawable.Colormap = graphics.Control.Colormap; + drawable.DrawIndexedImage(gc, 0, 0, source.Right+1, source.Bottom+1, Gdk.RgbDither.None, Control, this.rowStride, GetPmap()); + if (source.Width != destination.Width || source.Height != destination.Height) + { + // scale da shit + Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, source.Width, source.Height); + pb.GetFromDrawable(drawable, drawable.Colormap, source.X, source.Y, 0, 0, source.Width, source.Height); + + Gdk.Pixbuf pbDest = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height); + pb.Scale(pbDest, 0, 0, destination.Width, destination.Height, 0, 0, (double)destination.Width / (double)source.Width, + (double)destination.Height / (double)source.Height, Gdk.InterpType.Bilinear); + pb.Dispose(); + + + graphics.Control.DrawPixbuf(graphics.GC, pbDest, 0, 0, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); + pbDest.Dispose(); + } + else + { + // no scaling necessary! + graphics.Control.DrawDrawable(graphics.GC, drawable, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height); + } + + }*/ + } + } +} diff --git a/Source/Eto.Gtk/Drawing/LinearGradientBrushHandler.cs b/Source/Eto.Gtk/Drawing/LinearGradientBrushHandler.cs new file mode 100644 index 0000000000..2f907e9397 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/LinearGradientBrushHandler.cs @@ -0,0 +1,79 @@ +using System; +using Eto.Drawing; +using System.Runtime.InteropServices; + +namespace Eto.GtkSharp.Drawing +{ + /// + /// Handler for + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class LinearGradientBrushHandler : BrushHandler, LinearGradientBrush.IHandler + { + [DllImport ("libcairo-2.dll", CallingConvention = CallingConvention.Cdecl)] + internal static extern Cairo.Extend cairo_pattern_get_extend (IntPtr pattern); + + [DllImport ("libcairo-2.dll", CallingConvention = CallingConvention.Cdecl)] + internal static extern void cairo_pattern_set_extend (IntPtr pattern, Cairo.Extend extend); + + class EtoGradient : Cairo.LinearGradient + { + public EtoGradient (double x0, double y0, double x1, double y1) + : base (x0, y0, x1, y1) + { + } + + public Cairo.Matrix Transform { get; set; } + } + + public object Create (Color startColor, Color endColor, PointF startPoint, PointF endPoint) + { + var gradient = new EtoGradient (startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); + cairo_pattern_set_extend (gradient.Pointer, Cairo.Extend.Repeat); + // not in windows?? gradient.Extend = Cairo.Extend.Repeat; + gradient.AddColorStop (0, startColor.ToCairo ()); + gradient.AddColorStop (1, endColor.ToCairo ()); + return gradient; + } + + public object Create (RectangleF rectangle, Color startColor, Color endColor, float angle) + { + throw new NotImplementedException (); + } + + public IMatrix GetTransform (LinearGradientBrush widget) + { + return ((EtoGradient)widget.ControlObject).Transform.ToEto (); + } + + public void SetTransform (LinearGradientBrush widget, IMatrix transform) + { + ((EtoGradient)widget.ControlObject).Transform = transform.ToCairo (); + } + + public GradientWrapMode GetGradientWrap (LinearGradientBrush widget) + { + var gradient = ((Cairo.LinearGradient)widget.ControlObject); + // return gradient.Extend.ToEto (); + return cairo_pattern_get_extend (gradient.Pointer).ToEto (); + } + + public void SetGradientWrap (LinearGradientBrush widget, GradientWrapMode gradientWrap) + { + var gradient = ((Cairo.LinearGradient)widget.ControlObject); + // gradient.Extend = gradientWrap.ToCairo (); + cairo_pattern_set_extend (gradient.Pointer, gradientWrap.ToCairo ()); + } + + public override void Apply (object control, GraphicsHandler graphics) + { + var gradient = ((EtoGradient)control); + if (!object.ReferenceEquals (gradient.Transform, null)) + graphics.Control.Transform (gradient.Transform); + graphics.Control.Pattern = gradient; + graphics.Control.Fill (); + } + } +} + diff --git a/Source/Eto.Gtk/Drawing/MatrixHandler.cs b/Source/Eto.Gtk/Drawing/MatrixHandler.cs new file mode 100644 index 0000000000..1b15e6a59e --- /dev/null +++ b/Source/Eto.Gtk/Drawing/MatrixHandler.cs @@ -0,0 +1,147 @@ +using System; +using Eto.Drawing; + +namespace Eto.GtkSharp.Drawing +{ + /// + /// Handler for + /// + /// (c) 2012-2013 by Curtis Wensley + /// See LICENSE for full terms + public class MatrixHandler : Matrix.IHandler + { + Cairo.Matrix control; + + public MatrixHandler () + { + } + + public MatrixHandler (Cairo.Matrix matrix) + { + this.control = matrix; + } + + public float[] Elements + { + get + { + return new float[] { + (float)control.Xx, + (float)control.Yx, + (float)control.Xy, + (float)control.Yy, + (float)control.X0, + (float)control.Y0 + }; + } + } + + public float Xx { get { return (float)control.Xx; } set { control.Xx = value; } } + + public float Xy { get { return (float)control.Xx; } set { control.Xx = value; } } + + public float Yx { get { return (float)control.Yx; } set { control.Yx = value; } } + + public float Yy { get { return (float)control.Yy; } set { control.Yy = value; } } + + public float X0 { get { return (float)control.X0; } set { control.X0 = value; } } + + public float Y0 { get { return (float)control.Y0; } set { control.Y0 = value; } } + + public void Create () + { + control = new Cairo.Matrix (); + } + + public void Create (float xx, float yx, float xy, float yy, float x0, float y0) + { + control = new Cairo.Matrix (xx, yx, xy, yy, x0, y0); + } + + public void Rotate (float angle) + { + control.Rotate (Conversions.DegreesToRadians (angle)); + } + + public void RotateAt (float angle, float centerX, float centerY) + { + angle = Conversions.DegreesToRadians (angle); + var sina = Math.Sin (angle); + var cosa = Math.Cos (angle); + var matrix = new Cairo.Matrix (cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa); + control = Cairo.Matrix.Multiply (matrix, control); + } + + public void Translate (float x, float y) + { + control.Translate (x, y); + } + + public void Scale (float scaleX, float scaleY) + { + control.Scale (scaleX, scaleY); + } + + public void ScaleAt (float scaleX, float scaleY, float centerX, float centerY) + { + var matrix = new Cairo.Matrix (scaleX, 0, 0, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); + control = Cairo.Matrix.Multiply (matrix, control); + } + + public void Skew (float skewX, float skewY) + { + var matrix = new Cairo.Matrix (1, Math.Tan (Conversions.DegreesToRadians (skewX)), Math.Tan (Conversions.DegreesToRadians (skewY)), 1, 0, 0); + control = Cairo.Matrix.Multiply (matrix, control); + } + + public void Append (IMatrix matrix) + { + var cairoMatrix = matrix.ControlObject as Cairo.Matrix; + control.Multiply (cairoMatrix); + } + + public void Prepend (IMatrix matrix) + { + var cairoMatrix = matrix.ControlObject as Cairo.Matrix; + control = Cairo.Matrix.Multiply (cairoMatrix, control); + } + + public PointF TransformPoint (Point point) + { + double x = point.X; + double y = point.Y; + control.TransformPoint (ref x, ref y); + return new PointF ((float)x, (float)y); + } + + public PointF TransformPoint (PointF point) + { + double x = point.X; + double y = point.Y; + control.TransformPoint (ref x, ref y); + return new PointF ((float)x, (float)y); + } + + public void Invert () + { + control.Invert (); + } + + public object ControlObject + { + get { return control; } + } + + public IMatrix Clone () + { + var matrix = new Cairo.Matrix(control.Xx, control.Yx, control.Xy, control.Yy, control.X0, control.Y0); + return new MatrixHandler (matrix); + } + + public void Dispose() + { + // do nothing + } + } +} + diff --git a/Source/Eto.Gtk/Drawing/PenHandler.cs b/Source/Eto.Gtk/Drawing/PenHandler.cs new file mode 100644 index 0000000000..1616449a50 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/PenHandler.cs @@ -0,0 +1,161 @@ +using System; +using Eto.Drawing; + +namespace Eto.GtkSharp.Drawing +{ + /// + /// Pen handler + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class PenHandler : Pen.IHandler + { + class PenObject + { + double[] cairodashes; + float thickness; + double cairooffset; + DashStyle dashStyle; + + public Cairo.Color Color { get; set; } + + public float Thickness + { + get { return thickness; } + set { + thickness = value; + SetDashStyle (); + } + } + + public Cairo.LineJoin LineJoin { get; set; } + + public Cairo.LineCap LineCap { get; set; } + + public float MiterLimit { get; set; } + + public DashStyle DashStyle + { + get { return dashStyle; } + set + { + dashStyle = value; + SetDashStyle (); + } + } + + void SetDashStyle () + { + if (dashStyle == null || dashStyle.IsSolid) + cairodashes = null; + else { + var dashes = DashStyle.Dashes; + cairooffset = DashStyle.Offset * Thickness; + + if (LineCap == Cairo.LineCap.Butt) { + cairodashes = Array.ConvertAll (dashes, x => (double)x * Thickness); + } + else { + if (Math.Abs(Thickness - 1) < 0.01f) + cairooffset += Thickness / 2; + cairodashes = new double[dashes.Length]; + for (int i = 0; i < cairodashes.Length; i++) { + var dash = dashes [i] * Thickness; + if ((i % 2) == 1) { + // gap must include square/round thickness + dash += Thickness; + } else { + // dash must exclude square/round thickness + dash -= Thickness; + } + cairodashes [i] = dash; + } + } + } + } + + public void Apply (GraphicsHandler graphics) + { + graphics.Control.Color = Color; + graphics.Control.LineWidth = Thickness; + graphics.Control.LineCap = LineCap; + graphics.Control.LineJoin = LineJoin; + if (cairodashes != null) + graphics.Control.SetDash (cairodashes, cairooffset); + graphics.Control.MiterLimit = MiterLimit; + graphics.Control.Stroke (); + } + } + + public object Create (Color color, float thickness) + { + return new PenObject { + Color = color.ToCairo (), + Thickness = thickness, + MiterLimit = 10f, + LineCap = PenLineCap.Square.ToCairo () + }; + } + + public Color GetColor (Pen widget) + { + return ((PenObject)widget.ControlObject).Color.ToEto (); + } + + public void SetColor (Pen widget, Color color) + { + ((PenObject)widget.ControlObject).Color = color.ToCairo (); + } + + public float GetThickness (Pen widget) + { + return ((PenObject)widget.ControlObject).Thickness; + } + + public void SetThickness (Pen widget, float thickness) + { + ((PenObject)widget.ControlObject).Thickness = thickness; + } + + public PenLineJoin GetLineJoin (Pen widget) + { + return ((PenObject)widget.ControlObject).LineJoin.ToEto (); + } + + public void SetLineJoin (Pen widget, PenLineJoin lineJoin) + { + ((PenObject)widget.ControlObject).LineJoin = lineJoin.ToCairo (); + } + + public PenLineCap GetLineCap (Pen widget) + { + return ((PenObject)widget.ControlObject).LineCap.ToEto (); + } + + public void SetLineCap (Pen widget, PenLineCap lineCap) + { + ((PenObject)widget.ControlObject).LineCap = lineCap.ToCairo (); + } + + public float GetMiterLimit (Pen widget) + { + return ((PenObject)widget.ControlObject).MiterLimit; + } + + public void SetMiterLimit (Pen widget, float miterLimit) + { + ((PenObject)widget.ControlObject).MiterLimit = miterLimit; + } + + public void SetDashStyle (Pen widget, DashStyle dashStyle) + { + ((PenObject)widget.ControlObject).DashStyle = dashStyle; + } + + public void Apply (Pen widget, GraphicsHandler graphics) + { + ((PenObject)widget.ControlObject).Apply (graphics); + } + } +} + diff --git a/Source/Eto.Gtk/Drawing/SolidBrushHandler.cs b/Source/Eto.Gtk/Drawing/SolidBrushHandler.cs new file mode 100644 index 0000000000..4499a4befe --- /dev/null +++ b/Source/Eto.Gtk/Drawing/SolidBrushHandler.cs @@ -0,0 +1,34 @@ +using Eto.Drawing; + +namespace Eto.GtkSharp.Drawing +{ + /// + /// Handler for the + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class SolidBrushHandler : BrushHandler, SolidBrush.IHandler + { + public override void Apply (object control, GraphicsHandler graphics) + { + graphics.Control.Color = (Cairo.Color)control; + graphics.Control.Fill (); + } + + public Color GetColor (SolidBrush widget) + { + return ((Cairo.Color)widget.ControlObject).ToEto (); + } + + public void SetColor (SolidBrush widget, Color color) + { + widget.ControlObject = color.ToCairo (); + } + + public object Create (Color color) + { + return color.ToCairo (); + } + } +} + diff --git a/Source/Eto.Gtk/Drawing/TextureBrushHandler.cs b/Source/Eto.Gtk/Drawing/TextureBrushHandler.cs new file mode 100644 index 0000000000..eef2ec0804 --- /dev/null +++ b/Source/Eto.Gtk/Drawing/TextureBrushHandler.cs @@ -0,0 +1,78 @@ +using Eto.Drawing; + +namespace Eto.GtkSharp.Drawing +{ + /// + /// Handler for the + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class TextureBrushHandler : BrushHandler, TextureBrush.IHandler + { + class TextureBrushObject + { + public Cairo.Matrix Transform { get; set; } + public Gdk.Pixbuf Pixbuf { get; set; } + public float Opacity { get; set; } + + public TextureBrushObject () + { + Opacity = 1.0f; + } + + public void Apply (GraphicsHandler graphics) + { + if (!object.ReferenceEquals (Transform, null)) + graphics.Control.Transform (Transform); + + Gdk.CairoHelper.SetSourcePixbuf (graphics.Control, Pixbuf, 0, 0); + var surfacePattern = graphics.Control.Source as Cairo.SurfacePattern; + if (surfacePattern != null) + surfacePattern.Extend = Cairo.Extend.Repeat; + if (Opacity < 1.0f) + { + graphics.Control.Clip(); + graphics.Control.PaintWithAlpha(Opacity); + } + else + graphics.Control.Fill(); + if (EtoEnvironment.Platform.IsMac && surfacePattern != null) + surfacePattern.Dispose(); + } + } + + public IMatrix GetTransform (TextureBrush widget) + { + return ((TextureBrushObject)widget.ControlObject).Transform.ToEto (); + } + + public void SetTransform (TextureBrush widget, IMatrix transform) + { + ((TextureBrushObject)widget.ControlObject).Transform = transform.ToCairo (); + } + + public object Create (Image image, float opacity) + { + return new TextureBrushObject { + Pixbuf = image.ToGdk (), + Opacity = opacity + }; + } + + public override void Apply (object control, GraphicsHandler graphics) + { + ((TextureBrushObject)control).Apply (graphics); + } + + public float GetOpacity (TextureBrush widget) + { + return ((TextureBrushObject)widget.ControlObject).Opacity; + } + + public void SetOpacity (TextureBrush widget, float opacity) + { + ((TextureBrushObject)widget.ControlObject).Opacity = opacity; + } + } +} + diff --git a/Source/Eto.Gtk/Eto.Gtk2 - Pcl.csproj b/Source/Eto.Gtk/Eto.Gtk2 - Pcl.csproj new file mode 100644 index 0000000000..dcaedb95d2 --- /dev/null +++ b/Source/Eto.Gtk/Eto.Gtk2 - Pcl.csproj @@ -0,0 +1,276 @@ + + + + + Debug + AnyCPU + {80915A80-CA54-11E3-9C1A-0800200C9A66} + Library + Eto.Gtk2 + v4.5 + Eto.Gtk2 + + + 512 + True + prompt + 4 + ..\..\.. + ..\..\Libraries + CAIRO;TRACE;GTK2 + + + True + + + ..\..\BuildOutput\Pcl\Debug\ + CAIRO;DEBUG;TRACE;GTK2 + false + full + 0618,0612 + + + ..\..\BuildOutput\Pcl\Release\ + true + pdbonly + 0618,0612 + + + + + System + + + + + ..\..\Libraries\webkit-sharp\webkit-sharp.dll + False + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + Code + + + Code + + + Code + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Drawing\SplineHelper.cs + + + + + + + Code + + + + + + Code + + + + Code + + + + + + + PlatformDetect.cs + + + + + + Code + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + \ No newline at end of file diff --git a/Source/Eto.Gtk/Eto.Gtk2.csproj b/Source/Eto.Gtk/Eto.Gtk2.csproj new file mode 100644 index 0000000000..b4cd73b32d --- /dev/null +++ b/Source/Eto.Gtk/Eto.Gtk2.csproj @@ -0,0 +1,267 @@ + + + + + Debug + AnyCPU + {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1} + Library + Eto.GtkSharp + Eto.Gtk2 + + + 512 + True + prompt + 4 + ..\..\.. + ..\..\Libraries + CAIRO;TRACE;GTK2 + + + True + + + ..\..\BuildOutput\Debug\ + CAIRO;DEBUG;TRACE;GTK2 + false + full + 0618,0612 + + + ..\..\BuildOutput\Release\ + true + pdbonly + 0618,0612 + + + + + System + + + + + ..\..\Libraries\webkit-sharp\webkit-sharp.dll + False + + + + + + + + + + {16289D2F-044C-49EF-83E9-9391AFF8FD2B} + Eto + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + Code + + + Code + + + + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + Code + + + Code + + + Code + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Drawing\SplineHelper.cs + + + + + + + Code + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Eto.Gtk/Eto.Gtk3 - Pcl.csproj b/Source/Eto.Gtk/Eto.Gtk3 - Pcl.csproj new file mode 100644 index 0000000000..068cc7114a --- /dev/null +++ b/Source/Eto.Gtk/Eto.Gtk3 - Pcl.csproj @@ -0,0 +1,287 @@ + + + + Local + {543B2F90-CA56-11E3-9C1A-0800200C9A66} + Debug + AnyCPU + + + JScript + Grid + IE50 + false + Library + + + Eto.Gtk3 + + + v4.5 + Eto.Gtk3 + + + ..\..\BuildOutput\Pcl\Release\ + CAIRO;TRACE;GTK3 + 285212672 + true + true + 4096 + true + true + pdbonly + 4 + true + 0618,0612 + + + true + ..\..\BuildOutput\Pcl\Debug\ + CAIRO;DEBUG;TRACE;GTK3 + 285212672 + true + 4096 + full + false + false + false + 4 + false + 0618,0612 + + + + + System + + + + ..\..\Libraries\GtkSharp3\atk-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\cairo-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\gdk-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\gio-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\glib-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\gtk-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\pango-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\webkit-sharp.dll + False + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Drawing\SplineHelper.cs + + + + + + + + + + + + + + + Code + + + + + + + PlatformDetect.cs + + + + + + + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + \ No newline at end of file diff --git a/Source/Eto.Gtk/Eto.Gtk3.csproj b/Source/Eto.Gtk/Eto.Gtk3.csproj new file mode 100644 index 0000000000..1564d78ddf --- /dev/null +++ b/Source/Eto.Gtk/Eto.Gtk3.csproj @@ -0,0 +1,278 @@ + + + + Local + {EECFE22F-A544-4498-AE2D-90C81BD2931A} + Debug + AnyCPU + + + Eto.Gtk3 + JScript + Grid + IE50 + false + Library + + + Eto.GtkSharp + + + + + ..\..\BuildOutput\Release\ + CAIRO;TRACE;GTK3 + 285212672 + true + true + 4096 + true + true + pdbonly + 4 + true + 0618,0612 + + + true + ..\..\BuildOutput\Debug\ + CAIRO;DEBUG;TRACE;GTK3 + 285212672 + true + 4096 + full + false + false + false + 4 + false + 0618,0612 + + + + + System + + + + ..\..\Libraries\GtkSharp3\atk-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\cairo-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\gdk-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\gio-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\glib-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\gtk-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\pango-sharp.dll + False + + + ..\..\Libraries\GtkSharp3\webkit-sharp.dll + False + + + + + {16289D2F-044C-49EF-83E9-9391AFF8FD2B} + Eto + + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Drawing\SplineHelper.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Eto.Gtk/EtoEnvironmentHandler.cs b/Source/Eto.Gtk/EtoEnvironmentHandler.cs new file mode 100644 index 0000000000..4e055c1970 --- /dev/null +++ b/Source/Eto.Gtk/EtoEnvironmentHandler.cs @@ -0,0 +1,33 @@ +using System; +using Eto; +using System.Reflection; +using System.IO; + +namespace Eto.GtkSharp +{ + public class EtoEnvironmentHandler : WidgetHandler, EtoEnvironment.IHandler + { + static Environment.SpecialFolder Convert (EtoSpecialFolder folder) + { + switch (folder) { + case EtoSpecialFolder.ApplicationSettings: + return Environment.SpecialFolder.ApplicationData; + case EtoSpecialFolder.Documents: + return Environment.SpecialFolder.MyDocuments; + default: + throw new NotSupportedException (); + } + } + + public string GetFolderPath (EtoSpecialFolder folder) + { + switch (folder) { + case EtoSpecialFolder.ApplicationResources: + return Path.GetDirectoryName (Assembly.GetEntryAssembly ().Location); + default: + return Environment.GetFolderPath (Convert (folder)); + } + } + } +} + diff --git a/Source/Eto.Platform.Gtk/EtoWebView.cs b/Source/Eto.Gtk/EtoWebView.cs similarity index 99% rename from Source/Eto.Platform.Gtk/EtoWebView.cs rename to Source/Eto.Gtk/EtoWebView.cs index b468035267..bed7b513a4 100644 --- a/Source/Eto.Platform.Gtk/EtoWebView.cs +++ b/Source/Eto.Gtk/EtoWebView.cs @@ -3,7 +3,7 @@ using GLib; using System.Runtime.InteropServices; -namespace Eto.Platform.GtkSharp +namespace Eto.GtkSharp { #if GTK2 public class NewWindowPolicyDecisionRequestedArgs : SignalArgs diff --git a/Source/Eto.Gtk/Forms/ApplicationHandler.cs b/Source/Eto.Gtk/Forms/ApplicationHandler.cs new file mode 100644 index 0000000000..3c95a69a7a --- /dev/null +++ b/Source/Eto.Gtk/Forms/ApplicationHandler.cs @@ -0,0 +1,192 @@ +using System; +using Eto.Forms; +using System.Diagnostics; +using System.Threading; +using System.ComponentModel; +using Eto.GtkSharp.Drawing; +using Eto.Drawing; +using System.Collections.Generic; +using Eto.GtkSharp.Forms; + +namespace Eto.GtkSharp.Forms +{ + public class ApplicationHandler : WidgetHandler, Application.IHandler + { + bool attached; + Gtk.StatusIcon statusIcon; + readonly List invokeResetEvents = new List(); + + protected override void Initialize() + { + base.Initialize(); + Helper.Init(); + + if (SynchronizationContext.Current == null) + SynchronizationContext.SetSynchronizationContext(new GtkSynchronizationContext()); + } + + public static int MainThreadID { get; set; } + + public void RunIteration() + { + Gtk.Application.RunIteration(); + } + + public void Restart() + { + Gtk.Application.Quit(); + + // TODO: restart! + } + + string badgeLabel; + + public string BadgeLabel + { + get { return badgeLabel; } + set + { + badgeLabel = value; + if (!string.IsNullOrEmpty(badgeLabel)) + { + if (statusIcon == null) + { + statusIcon = new Gtk.StatusIcon(); + statusIcon.Activate += delegate + { + var form = Application.Instance.MainForm; + if (form != null) + form.BringToFront(); + }; + } + var bmp = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, 32, 32); + using (var graphics = new Graphics(new Bitmap(new BitmapHandler(bmp)))) + { + graphics.Clear(); + DrawBadgeLabel(graphics, new Size(bmp.Width, bmp.Height), badgeLabel); + } + statusIcon.Pixbuf = bmp; + statusIcon.Visible = true; + } + else if (statusIcon != null) + statusIcon.Visible = false; + } + } + + protected virtual void DrawBadgeLabel(Graphics graphics, Size size, string badgeLabel) + { + var rect = new Rectangle(size); + rect.Inflate(-2, -2); + graphics.FillEllipse(Brushes.Red, rect); + graphics.DrawEllipse(new Pen(Colors.White, 2), rect); + var font = new Font(SystemFont.Bold, 10); + var labelSize = graphics.MeasureString(font, badgeLabel); + var labelPosition = ((PointF)(rect.Size - labelSize) / 2) + rect.Location; + graphics.DrawText(font, Colors.White, labelPosition, badgeLabel); + graphics.Flush(); + } + + public void Invoke(Action action) + { + if (Thread.CurrentThread.ManagedThreadId == ApplicationHandler.MainThreadID) + action(); + else + { + var resetEvent = new ManualResetEvent(false); + lock (invokeResetEvents) + invokeResetEvents.Add(resetEvent); + + Gtk.Application.Invoke(delegate + { + try + { + action(); + } + finally + { + resetEvent.Set(); + } + }); + resetEvent.WaitOne(); + lock (invokeResetEvents) + invokeResetEvents.Remove(resetEvent); + } + } + + public void AsyncInvoke(Action action) + { + Gtk.Application.Invoke(delegate + { + action(); + }); + } + + public void Attach(object context) + { + attached = true; + } + + public void OnMainFormChanged() + { + } + + public void Run() + { + //if (!Platform.IsWindows) Gdk.Threads.Init(); // do this in windows, and it stalls! ugh + MainThreadID = Thread.CurrentThread.ManagedThreadId; + + Callback.OnInitialized(Widget, EventArgs.Empty); + if (!attached) + { + Gtk.Application.Run(); + lock (invokeResetEvents) + { + // set all invokes so threads will continue when run loop exits + foreach (var reset in invokeResetEvents) + reset.Set(); + invokeResetEvents.Clear(); + } + + Gdk.Threads.Leave(); + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Application.TerminatingEvent: + // called automatically + break; + default: + base.AttachEvent(id); + break; + } + } + + public void Quit() + { + var args = new CancelEventArgs(); + var mainForm = Widget.MainForm != null ? Widget.MainForm.Handler as IGtkWindow : null; + if (mainForm != null) + args.Cancel = !mainForm.CloseWindow(ce => Callback.OnTerminating(Widget, ce)); + else + Callback.OnTerminating(Widget, args); + + if (!args.Cancel) + Gtk.Application.Quit(); + } + + public bool QuitIsSupported { get { return true; } } + + public void Open(string url) + { + var info = new ProcessStartInfo(url); + Process.Start(info); + } + + public Keys CommonModifier { get { return Keys.Control; } } + + public Keys AlternateModifier { get { return Keys.Alt; } } + } +} diff --git a/Source/Eto.Gtk/Forms/Cells/CellHandler.cs b/Source/Eto.Gtk/Forms/Cells/CellHandler.cs new file mode 100644 index 0000000000..d3e8be2143 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Cells/CellHandler.cs @@ -0,0 +1,188 @@ +using System; +using Eto.Forms; +using Eto.GtkSharp.Forms.Controls; +using System.Runtime.InteropServices; + +namespace Eto.GtkSharp.Forms.Cells +{ + public interface ICellDataSource + { + object GetItem(Gtk.TreePath path); + + void EndCellEditing(Gtk.TreePath path, int column); + + void BeginCellEditing(Gtk.TreePath path, int column); + + void SetColumnMap(int dataIndex, int column); + + int RowHeight { get; set; } + + void OnCellFormatting(GridCellFormatEventArgs args); + } + + public interface ICellHandler + { + void BindCell(ICellDataSource source, GridColumnHandler column, int columnIndex, ref int dataIndex); + + void SetEditable(Gtk.TreeViewColumn column, bool editable); + + GLib.Value GetValue(object dataItem, int column, int row); + + void HandleEvent(string eventHandler, bool defaultEvent = true); + + void AddCells(Gtk.TreeViewColumn column); + } + + static class GtkCell + { + [DllImport("gtksharpglue-2", CallingConvention = CallingConvention.Cdecl)] + internal static extern void gtksharp_cellrenderer_invoke_render(IntPtr gtype, IntPtr handle, IntPtr window, IntPtr widget, ref Gdk.Rectangle backgroundArea, ref Gdk.Rectangle cellArea, ref Gdk.Rectangle exposeArea, Gtk.CellRendererState flags); + } + + public abstract class SingleCellHandler : CellHandler + where TControl: Gtk.CellRenderer + where TWidget: Cell + { + public override void AddCells(Gtk.TreeViewColumn column) + { + column.PackStart(Control, true); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.CellEditingEvent: + Control.EditingStarted += Connector.HandleEditingStarted; + break; + default: + base.AttachEvent(id); + break; + } + } + + protected new SingleCellConnector Connector { get { return (SingleCellConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new SingleCellConnector(); + } + + protected class SingleCellConnector : WeakConnector + { + public new SingleCellHandler Handler { get { return (SingleCellHandler)base.Handler; } } + + public void HandleEditingStarted(object o, Gtk.EditingStartedArgs args) + { + Handler.Source.BeginCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); + } + } + } + + public abstract class CellHandler : WidgetHandler, Cell.IHandler, ICellHandler + where TWidget: Cell + where TControl: Gtk.CellRenderer + { + int? dataIndex; + int itemCol; + int rowCol; + + public GridColumnHandler Column { get; private set; } + + public int ColumnIndex { get; private set; } + + public ICellDataSource Source { get; private set; } + + public bool FormattingEnabled { get; private set; } + + public abstract void AddCells(Gtk.TreeViewColumn column); + + public void BindCell(ICellDataSource source, GridColumnHandler column, int columnIndex, ref int dataIndex) + { + Source = source; + Column = column; + ColumnIndex = columnIndex; + this.dataIndex = dataIndex; + BindCell(ref dataIndex); + BindBase(ref dataIndex); + } + + protected void ReBind() + { + if (dataIndex != null) + { + var dataIndexValue = dataIndex.Value; + BindCell(ref dataIndexValue); + BindBase(ref dataIndexValue); + } + } + + protected void BindBase(ref int dataIndex) + { + if (FormattingEnabled) + { + itemCol = SetColumnMap(dataIndex); + Column.Control.AddAttribute(Control, "item", dataIndex++); + rowCol = SetColumnMap(dataIndex); + Column.Control.AddAttribute(Control, "row", dataIndex++); + } + } + + public void Format(GridCellFormatEventArgs args) + { + Source.OnCellFormatting(args); + } + + protected abstract void BindCell(ref int dataIndex); + + protected int SetColumnMap(int dataIndex) + { + Source.SetColumnMap(dataIndex, ColumnIndex); + return dataIndex; + } + + public abstract void SetEditable(Gtk.TreeViewColumn column, bool editable); + + protected void SetValue(string path, object value) + { + SetValue(new Gtk.TreePath(path), value); + } + + protected void SetValue(Gtk.TreePath path, object value) + { + var item = Source.GetItem(path); + SetValue(item, value); + } + + public abstract void SetValue(object dataItem, object value); + + public GLib.Value GetValue(object dataItem, int dataColumn, int row) + { + if (FormattingEnabled) + { + if (dataColumn == itemCol) + return new GLib.Value(dataItem); + if (dataColumn == rowCol) + return new GLib.Value(row); + } + return GetValueInternal(dataItem, dataColumn, row); + } + + protected abstract GLib.Value GetValueInternal(object dataItem, int dataColumn, int row); + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.CellFormattingEvent: + FormattingEnabled = true; + ReBind(); + break; + default: + base.AttachEvent(id); + break; + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Cells/CheckBoxCellHandler.cs b/Source/Eto.Gtk/Forms/Cells/CheckBoxCellHandler.cs new file mode 100644 index 0000000000..b05ed020c9 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Cells/CheckBoxCellHandler.cs @@ -0,0 +1,128 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Cells +{ + public class CheckBoxCellHandler : SingleCellHandler, CheckBoxCell.IHandler + { + class Renderer : Gtk.CellRendererToggle + { + WeakReference handler; + public CheckBoxCellHandler Handler { get { return (CheckBoxCellHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [GLib.Property("item")] + public object Item { get; set; } + + [GLib.Property("row")] + public int Row { get; set; } + #if GTK2 + public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); + + // calling base crashes on windows + GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererToggle.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); + //base.Render (window, widget, background_area, cell_area, expose_area, flags); + } + #else + protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); + base.OnRender (cr, widget, background_area, cell_area, flags); + } +#endif + } + + public CheckBoxCellHandler() + { + Control = new Renderer { Handler = this }; + } + + protected override void Initialize() + { + base.Initialize(); + this.Control.Toggled += Connector.HandleToggled; + } + + protected new CheckBoxCellEventConnector Connector { get { return (CheckBoxCellEventConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new CheckBoxCellEventConnector(); + } + + protected class CheckBoxCellEventConnector : SingleCellConnector + { + public new CheckBoxCellHandler Handler { get { return (CheckBoxCellHandler)base.Handler; } } + + public void HandleToggled(object o, Gtk.ToggledArgs args) + { + Handler.SetValue(args.Path, !Handler.Control.Active); + } + + public void HandleEndCellEditing(object o, Gtk.ToggledArgs args) + { + Handler.Source.EndCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); + } + } + + protected override void BindCell(ref int dataIndex) + { + Column.Control.ClearAttributes(Control); + SetColumnMap(dataIndex); + Column.Control.AddAttribute(Control, "active", dataIndex++); + } + + public override void SetEditable(Gtk.TreeViewColumn column, bool editable) + { + Control.Activatable = editable; + } + + public override void SetValue(object dataItem, object value) + { + if (Widget.Binding != null) + { + Widget.Binding.SetValue(dataItem, value as bool?); + } + } + + protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) + { + if (Widget.Binding != null) + { + var ret = Widget.Binding.GetValue(dataItem); + if (ret != null) + return new GLib.Value(ret); + } + return new GLib.Value(false); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.CellEditedEvent: + Control.Toggled += Connector.HandleEndCellEditing; + break; + default: + base.AttachEvent(id); + break; + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Cells/ComboBoxCellHandler.cs b/Source/Eto.Gtk/Forms/Cells/ComboBoxCellHandler.cs new file mode 100644 index 0000000000..3da3c18682 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Cells/ComboBoxCellHandler.cs @@ -0,0 +1,180 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using System.Collections; + +namespace Eto.GtkSharp.Forms.Cells +{ + public class ComboBoxCellHandler : SingleCellHandler, ComboBoxCell.IHandler + { + CollectionHandler collection; + readonly Gtk.ListStore listStore; + + class Renderer : Gtk.CellRendererCombo + { + WeakReference handler; + public ComboBoxCellHandler Handler { get { return (ComboBoxCellHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [GLib.Property("item")] + public object Item { get; set; } + + [GLib.Property("row")] + public int Row { get; set; } + #if GTK2 + public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkTextCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); + // calling base crashes on windows + GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererCombo.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); + //base.Render (window, widget, background_area, cell_area, expose_area, flags); + } + #else + protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); + base.OnRender (cr, widget, background_area, cell_area, flags); + } +#endif + } + + public ComboBoxCellHandler() + { + listStore = new Gtk.ListStore(typeof(string), typeof(string)); + Control = new Renderer + { + Handler = this, + Model = listStore, + TextColumn = 0, + HasEntry = false + }; + } + + protected override void Initialize() + { + base.Initialize(); + this.Control.Edited += Connector.HandleEdited; + } + + protected new ComboBoxCellEventConnector Connector { get { return (ComboBoxCellEventConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ComboBoxCellEventConnector(); + } + + protected class ComboBoxCellEventConnector : SingleCellConnector + { + public new ComboBoxCellHandler Handler { get { return (ComboBoxCellHandler)base.Handler; } } + + public void HandleEdited(object o, Gtk.EditedArgs args) + { + Handler.SetValue(args.Path, args.NewText); + } + + public void HandleEndEditing(object o, Gtk.EditedArgs args) + { + Handler.Source.EndCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); + } + } + + protected override void BindCell(ref int dataIndex) + { + Column.Control.ClearAttributes(Control); + SetColumnMap(dataIndex); + Column.Control.AddAttribute(Control, "text", dataIndex++); + } + + public override void SetEditable(Gtk.TreeViewColumn column, bool editable) + { + Control.Editable = editable; + } + + public override void SetValue(object dataItem, object value) + { + if (Widget.Binding != null) + { + Widget.Binding.SetValue(dataItem, value); + } + } + + protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) + { + + if (Widget.Binding != null) + { + var ret = Widget.Binding.GetValue(dataItem); + if (ret != null) + return new GLib.Value(ret); + } + + return new GLib.Value((string)null); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.CellEditedEvent: + Control.Edited += Connector.HandleEndEditing; + break; + default: + base.AttachEvent(id); + break; + } + } + + public class CollectionHandler : EnumerableChangedHandler + { + public ComboBoxCellHandler Handler { get; set; } + + public override void AddItem(object item) + { + Handler.listStore.AppendValues(Handler.Widget.ComboTextBinding.GetValue(item), Handler.Widget.ComboKeyBinding.GetValue(item)); + } + + public override void InsertItem(int index, object item) + { + Handler.listStore.InsertWithValues(index, Handler.Widget.ComboTextBinding.GetValue(item), Handler.Widget.ComboKeyBinding.GetValue(item)); + } + + public override void RemoveItem(int index) + { + Gtk.TreeIter iter; + if (Handler.listStore.IterNthChild(out iter, index)) + Handler.listStore.Remove(ref iter); + } + + public override void RemoveAllItems() + { + Handler.listStore.Clear(); + } + } + + public IEnumerable DataStore + { + get { return collection != null ? collection.Collection : null; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler{ Handler = this }; + collection.Register(value); + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Cells/DrawableCellHandler.cs b/Source/Eto.Gtk/Forms/Cells/DrawableCellHandler.cs new file mode 100644 index 0000000000..a376757ccc --- /dev/null +++ b/Source/Eto.Gtk/Forms/Cells/DrawableCellHandler.cs @@ -0,0 +1,101 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Cells +{ + public class DrawableCellHandler : SingleCellHandler, DrawableCell.IHandler + { + class Renderer : Gtk.CellRenderer + { + WeakReference handler; + + public DrawableCellHandler Handler { get { return (DrawableCellHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [GLib.Property("item")] + public object Item { get; set; } + + [GLib.Property("row")] + public int Row { get; set; } + + #if GTK2 + public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); + + using (var graphics = new Graphics(new GraphicsHandler(widget, window))) + { + var args = new DrawableCellPaintEventArgs(graphics, cell_area.ToEto(), flags.ToEto(), Item); + Handler.Callback.OnPaint(Handler.Widget, args); + } + } + #else + protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); + using (var graphics = new Graphics(new GraphicsHandler(cr, null, false))) + { + var args = new DrawableCellPaintEventArgs(graphics, cell_area.ToEto(), flags.ToEto(), Item); + Handler.Callback.OnPaint(Handler.Widget, args); + } + } + #endif + } + + + public DrawableCellHandler() + { + Control = new Renderer { Handler = this }; + } + + protected override void BindCell(ref int dataIndex) + { + Column.Control.ClearAttributes(Control); + SetColumnMap(dataIndex); + Column.Control.AddAttribute(Control, "item", dataIndex++); + } + + public override void SetEditable(Gtk.TreeViewColumn column, bool editable) + { + } + + public override void SetValue(object dataItem, object value) + { + // can't set + } + + protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) + { + return new GLib.Value(dataItem); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.CellEditedEvent: + // no editing here + break; + default: + base.AttachEvent(id); + break; + } + } + } +} + diff --git a/Source/Eto.Platform.Gtk/Forms/Cells/GridCellFormattingEventArgs.cs b/Source/Eto.Gtk/Forms/Cells/GridCellFormattingEventArgs.cs similarity index 87% rename from Source/Eto.Platform.Gtk/Forms/Cells/GridCellFormattingEventArgs.cs rename to Source/Eto.Gtk/Forms/Cells/GridCellFormattingEventArgs.cs index 166173269d..556a4f3b5a 100644 --- a/Source/Eto.Platform.Gtk/Forms/Cells/GridCellFormattingEventArgs.cs +++ b/Source/Eto.Gtk/Forms/Cells/GridCellFormattingEventArgs.cs @@ -1,8 +1,8 @@ using Eto.Forms; using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; +using Eto.GtkSharp.Drawing; -namespace Eto.Platform.GtkSharp.Forms.Cells +namespace Eto.GtkSharp.Forms.Cells { public class GtkGridCellFormatEventArgs : GridCellFormatEventArgs where T: Gtk.CellRenderer @@ -48,7 +48,7 @@ public override Color ForegroundColor { public override Font Font { get { - return font ?? (font = new Font (Column.Generator, new FontHandler (Renderer.FontDesc))); + return font ?? (font = new Font(new FontHandler(Renderer.FontDesc))); } set { font = value; diff --git a/Source/Eto.Gtk/Forms/Cells/ImageTextCellHandler.cs b/Source/Eto.Gtk/Forms/Cells/ImageTextCellHandler.cs new file mode 100644 index 0000000000..65125f4991 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Cells/ImageTextCellHandler.cs @@ -0,0 +1,186 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Cells +{ + public class ImageTextCellHandler : CellHandler, ImageTextCell.IHandler + { + readonly Gtk.CellRendererPixbuf imageCell; + int imageDataIndex; + int textDataIndex; + + class Renderer : Gtk.CellRendererText + { + WeakReference handler; + public ImageTextCellHandler Handler { get { return (ImageTextCellHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [GLib.Property("item")] + public object Item { get; set; } + + [GLib.Property("row")] + public int Row { get; set; } + #if GTK2 + public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkTextCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); + + // calling base crashes on windows /w gtk 2.12.9 + GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererText.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); + //base.Render (window, widget, background_area, cell_area, expose_area, flags); + } + #else + protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); + base.OnRender (cr, widget, background_area, cell_area, flags); + } +#endif + } + + class ImageRenderer : Gtk.CellRendererPixbuf + { + public ImageTextCellHandler Handler { get; set; } + + [GLib.Property("item")] + public object Item { get; set; } + + [GLib.Property("row")] + public int Row { get; set; } + #if GTK2 + protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); + + // calling base crashes on windows /w gtk 2.12.9 + GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererPixbuf.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); + //base.Render (window, widget, background_area, cell_area, expose_area, flags); + } + #else + protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); + base.OnRender (cr, widget, background_area, cell_area, flags); + } +#endif + } + + public ImageTextCellHandler() + { + imageCell = new ImageRenderer { Handler = this }; + Control = new Renderer { Handler = this }; + } + + protected override void Initialize() + { + base.Initialize(); + this.Control.Edited += Connector.HandleEdited; + } + + protected new ImageTextCellEventConnector Connector { get { return (ImageTextCellEventConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ImageTextCellEventConnector(); + } + + protected class ImageTextCellEventConnector : WeakConnector + { + public new ImageTextCellHandler Handler { get { return (ImageTextCellHandler)base.Handler; } } + + public void HandleEdited(object o, Gtk.EditedArgs args) + { + Handler.SetValue(args.Path, args.NewText); + } + + public void HandleEndCellEditing(object o, Gtk.EditedArgs args) + { + Handler.Source.EndCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); + } + } + + public override void AddCells(Gtk.TreeViewColumn column) + { + column.PackStart(imageCell, false); + column.PackStart(Control, true); + } + + protected override void BindCell(ref int dataIndex) + { + Column.Control.ClearAttributes(Control); + imageDataIndex = SetColumnMap(dataIndex); + Column.Control.AddAttribute(imageCell, "pixbuf", dataIndex++); + textDataIndex = SetColumnMap(dataIndex); + Column.Control.AddAttribute(Control, "text", dataIndex++); + BindBase(ref dataIndex); + } + + public override void SetEditable(Gtk.TreeViewColumn column, bool editable) + { + Control.Editable = editable; + } + + public override void SetValue(object dataItem, object value) + { + if (Widget.TextBinding != null) + { + Widget.TextBinding.SetValue(dataItem, Convert.ToString(value)); + } + } + + protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) + { + if (dataColumn == imageDataIndex) + { + if (Widget.ImageBinding != null) + { + var ret = Widget.ImageBinding.GetValue(dataItem); + var image = ret as Image; + if (image != null) + return new GLib.Value(((IGtkPixbuf)image.Handler).GetPixbuf(new Size(16, 16), ImageInterpolation.ToGdk())); + } + return new GLib.Value((Gdk.Pixbuf)null); + } + if (dataColumn == textDataIndex) + { + var ret = Widget.TextBinding.GetValue(dataItem); + if (ret != null) + return new GLib.Value(Convert.ToString(ret)); + } + return new GLib.Value((string)null); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.CellEditedEvent: + Control.Edited += Connector.HandleEndCellEditing; + break; + default: + base.AttachEvent(id); + break; + } + } + + public ImageInterpolation ImageInterpolation { get; set; } + } +} + diff --git a/Source/Eto.Gtk/Forms/Cells/ImageViewCellHandler.cs b/Source/Eto.Gtk/Forms/Cells/ImageViewCellHandler.cs new file mode 100644 index 0000000000..ba5c981aa5 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Cells/ImageViewCellHandler.cs @@ -0,0 +1,101 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Cells +{ + public class ImageViewCellHandler : SingleCellHandler, ImageViewCell.IHandler + { + class Renderer : Gtk.CellRendererPixbuf + { + WeakReference handler; + public ImageViewCellHandler Handler { get { return (ImageViewCellHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [GLib.Property("item")] + public object Item { get; set; } + + [GLib.Property("row")] + public int Row { get; set; } + +#if GTK2 + public override void GetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void Render (Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); + + // calling base crashes on windows + GtkCell.gtksharp_cellrenderer_invoke_render (Gtk.CellRendererPixbuf.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); + //base.Render (window, widget, background_area, cell_area, expose_area, flags); + } +#else + protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); + base.OnRender (cr, widget, background_area, cell_area, flags); + } +#endif + } + + + public ImageViewCellHandler () + { + Control = new Renderer { Handler = this }; + } + + protected override void BindCell (ref int dataIndex) + { + Column.Control.ClearAttributes (Control); + SetColumnMap (dataIndex); + Column.Control.AddAttribute (Control, "pixbuf", dataIndex++); + } + + public override void SetEditable (Gtk.TreeViewColumn column, bool editable) + { + } + + public override void SetValue (object dataItem, object value) + { + // can't set + } + + protected override GLib.Value GetValueInternal (object dataItem, int dataColumn, int row) + { + if (Widget.Binding != null) { + var ret = Widget.Binding.GetValue (dataItem); + var image = ret as Image; + if (image != null) + return new GLib.Value(((IGtkPixbuf)image.Handler).GetPixbuf (new Size (16, 16), ImageInterpolation.ToGdk())); + } + return new GLib.Value((Gdk.Pixbuf)null); + } + + public override void AttachEvent (string id) + { + switch (id) { + case Grid.CellEditedEvent: + // no editing here + break; + default: + base.AttachEvent (id); + break; + } + } + + public ImageInterpolation ImageInterpolation { get; set; } + } +} + diff --git a/Source/Eto.Gtk/Forms/Cells/TextBoxCellHandler.cs b/Source/Eto.Gtk/Forms/Cells/TextBoxCellHandler.cs new file mode 100644 index 0000000000..837ba4c5e4 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Cells/TextBoxCellHandler.cs @@ -0,0 +1,128 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Cells +{ + public class TextBoxCellHandler : SingleCellHandler, TextBoxCell.IHandler + { + class Renderer : Gtk.CellRendererText + { + WeakReference handler; + public TextBoxCellHandler Handler { get { return (TextBoxCellHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [GLib.Property("item")] + public object Item { get; set; } + + [GLib.Property("row")] + public int Row { get; set; } + #if GTK2 + public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkTextCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); + + // calling base crashes on windows + GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererText.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); + //base.Render (window, widget, background_area, cell_area, expose_area, flags); + } + #else + protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) + { + base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); + height = Math.Max(height, Handler.Source.RowHeight); + } + + protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) + { + if (Handler.FormattingEnabled) + Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); + base.OnRender (cr, widget, background_area, cell_area, flags); + } +#endif + } + + public TextBoxCellHandler() + { + Control = new Renderer { Handler = this }; + } + + protected override void Initialize() + { + base.Initialize(); + this.Control.Edited += Connector.HandleEdited; + } + + protected new TextBoxCellEventConnector Connector { get { return (TextBoxCellEventConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new TextBoxCellEventConnector(); + } + + protected class TextBoxCellEventConnector : SingleCellConnector + { + public new TextBoxCellHandler Handler { get { return (TextBoxCellHandler)base.Handler; } } + + public void HandleEdited(object o, Gtk.EditedArgs args) + { + Handler.SetValue(args.Path, args.NewText); + } + + public void HandleEndEditing(object o, Gtk.EditedArgs args) + { + Handler.Source.EndCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); + } + } + + protected override void BindCell(ref int dataIndex) + { + Column.Control.ClearAttributes(Control); + SetColumnMap(dataIndex); + Column.Control.AddAttribute(Control, "text", dataIndex++); + } + + public override void SetEditable(Gtk.TreeViewColumn column, bool editable) + { + Control.Editable = editable; + } + + public override void SetValue(object dataItem, object value) + { + if (Widget.Binding != null) + { + Widget.Binding.SetValue(dataItem, Convert.ToString(value)); + } + } + + protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) + { + if (Widget.Binding != null) + { + var ret = Widget.Binding.GetValue(dataItem); + if (ret != null) + return new GLib.Value(Convert.ToString(ret)); + } + return new GLib.Value((string)null); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.CellEditedEvent: + Control.Edited += Connector.HandleEndEditing; + break; + default: + base.AttachEvent(id); + break; + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/ClipboardHandler.cs b/Source/Eto.Gtk/Forms/ClipboardHandler.cs new file mode 100644 index 0000000000..36337b1932 --- /dev/null +++ b/Source/Eto.Gtk/Forms/ClipboardHandler.cs @@ -0,0 +1,182 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using System.Linq; +using Eto.GtkSharp.Drawing; +using System.Collections.Generic; + +namespace Eto.GtkSharp.Forms +{ + public class ClipboardHandler : WidgetHandler, Clipboard.IHandler + { + delegate void GetClipboardData(ClipboardData data,Gtk.SelectionData selection); + + class ClipboardData + { + public Gtk.TargetEntry Target { get; set; } + + public object Data { get; set; } + + public GetClipboardData GetClipboardData { get; set; } + + public void GetData(Gtk.SelectionData selectionData) + { + if (GetClipboardData != null) + GetClipboardData(this, selectionData); + } + } + + readonly List clipboard = new List(); + + public ClipboardHandler() + { + Control = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false)); + } + + void Update() + { + var targets = clipboard.Select(r => r.Target); + Control.SetWithData(targets.ToArray(), (clip, selectionData, info) => + { + if (info < clipboard.Count) + { + var clipdata = clipboard[(int)info]; + clipdata.GetData(selectionData); + } + }, clip => + { + + }); + } + + void AddEntry(string type, object data, GetClipboardData getData) + { + clipboard.Add(new ClipboardData + { + Target = new Gtk.TargetEntry(type, 0, (uint)clipboard.Count), + Data = data, + GetClipboardData = getData + }); + Update(); + } + + Gtk.SelectionData GetSelectionData(string type) + { + var target = Gdk.Atom.Intern(type, false); + if (Control.WaitIsTargetAvailable(target)) + { + var data = Control.WaitForContents(target); + if (data != null) + return data; + } + return null; + } + + #region IClipboard implementation + + public void SetString(string value, string type) + { + AddEntry(type, value, delegate(ClipboardData data, Gtk.SelectionData selection) + { + selection.Text = data.Data as string; + }); + } + + public string Html + { + set + { + AddEntry("text/html", value, delegate(ClipboardData data, Gtk.SelectionData selection) + { + selection.Text = data.Data as string; + }); + } + get + { + var selection = GetSelectionData("text/html"); + return selection != null ? selection.Text : null; + } + } + + public string Text + { + set + { + AddEntry("UTF8_STRING", value, delegate(ClipboardData data, Gtk.SelectionData selection) + { + selection.Text = data.Data as string; + }); + } + get { return Control.WaitForText(); } + + } + + public Image Image + { + set + { + var pixbuf = value.ControlObject as Gdk.Pixbuf; + /* TODO: AddEntry(type, value, delegate(ClipboardData data, Gtk.SelectionData selection) { + selection = value; + });*/ + if (pixbuf != null) + Control.Image = pixbuf; + else + throw new NotSupportedException(); + } + get + { + var image = Control.WaitForImage(); + if (image != null) + { + var handler = new BitmapHandler(image); + return new Bitmap(handler); + } + return null; + } + } + + public void SetData(byte[] value, string type) + { + AddEntry(type, value, delegate(ClipboardData data, Gtk.SelectionData selection) + { + selection.Set(Gdk.Atom.Intern(type, false), 0, value); + }); + } + + public string GetString(string type) + { + var selection = GetSelectionData(type); + return selection != null ? selection.Text : null; + } + + public byte[] GetData(string type) + { + var selection = GetSelectionData(type); + return selection != null && selection.Length > 0 ? selection.Data : null; + } + + public void Clear() + { + Control.Clear(); + clipboard.Clear(); + } + + public string[] Types + { + get + { + //return Control.Data.Keys.OfType ().ToArray (); + return null; + } + } + + #endregion + + #region IWidget implementation + + #endregion + + } +} + diff --git a/Source/Eto.Gtk/Forms/ColorDialogHandler.cs b/Source/Eto.Gtk/Forms/ColorDialogHandler.cs new file mode 100644 index 0000000000..16005dcf92 --- /dev/null +++ b/Source/Eto.Gtk/Forms/ColorDialogHandler.cs @@ -0,0 +1,38 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms +{ + public class ColorDialogHandler : WidgetHandler, ColorDialog.IHandler + { + public ColorDialogHandler () + { + Control = new Gtk.ColorSelectionDialog(string.Empty); + + } + + public Eto.Drawing.Color Color { + get { return Control.ColorSelection.CurrentColor.ToEto (); } + set { Control.ColorSelection.CurrentColor = value.ToGdk (); } + } + + public DialogResult ShowDialog (Window parent) + { + if (parent != null) + { + Control.TransientFor = ((Gtk.Window)parent.ControlObject); + Control.Modal = true; + } + + Control.ShowAll (); + var response = (Gtk.ResponseType)Control.Run (); + Control.Hide (); + + if (response == Gtk.ResponseType.Ok) { + Callback.OnColorChanged(Widget, EventArgs.Empty); + } + return response.ToEto (); + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/ButtonHandler.cs b/Source/Eto.Gtk/Forms/Controls/ButtonHandler.cs new file mode 100644 index 0000000000..fb3753d911 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/ButtonHandler.cs @@ -0,0 +1,174 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + /// + /// Button handler. + /// + /// (c) 2012-2013 by Curtis Wensley + /// See LICENSE for full terms + public class ButtonHandler : GtkControl, Button.IHandler + { + Image image; + readonly Gtk.AccelLabel label; + readonly Gtk.Image gtkimage; + readonly Gtk.Table table; + ButtonImagePosition imagePosition; + + public static int MinimumWidth = 80; + + protected override Gtk.Widget FontControl + { + get { return label; } + } + + public ButtonHandler() + { + Control = new Gtk.Button(); + // need separate widgets as the theme can (and usually) disables images on buttons + // gtk3 can override the theme per button, but gtk2 cannot + table = new Gtk.Table(3, 3, false); + table.ColumnSpacing = 0; + table.RowSpacing = 0; + label = new Gtk.AccelLabel(string.Empty); + label.NoShowAll = true; + table.Attach(label, 1, 2, 1, 2, Gtk.AttachOptions.Expand, Gtk.AttachOptions.Expand, 0, 0); + gtkimage = new Gtk.Image(); + gtkimage.NoShowAll = true; + SetImagePosition(false); + Control.Add(table); + } + + protected override void Initialize() + { + base.Initialize(); + Control.Clicked += Connector.HandleClicked; + Control.SizeAllocated += Connector.HandleButtonSizeAllocated; + } + + protected new ButtonConnector Connector { get { return (ButtonConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ButtonConnector(); + } + + protected class ButtonConnector : GtkControlConnector + { + public new ButtonHandler Handler { get { return (ButtonHandler)base.Handler; } } + + public void HandleClicked(object sender, EventArgs e) + { + Handler.Callback.OnClick(Handler.Widget, EventArgs.Empty); + } + + public void HandleButtonSizeAllocated(object o, Gtk.SizeAllocatedArgs args) + { + var handler = Handler; + if (handler != null) + { + var c = (Gtk.Button)o; + var size = args.Allocation; + if (size.Width > 1 || size.Height > 1) + { + size.Width = Math.Max(size.Width, MinimumWidth); + if (args.Allocation != size) + c.SetSizeRequest(size.Width, size.Height); + } + } + } + } + + public override string Text + { + get { return MnuemonicToString(label.Text); } + set + { + label.TextWithMnemonic = StringToMnuemonic(value); + SetImagePosition(); + } + } + + public Image Image + { + get { return image; } + set + { + image = value; + image.SetGtkImage(gtkimage); + if (value == null) + gtkimage.Hide(); + else + gtkimage.Show(); + } + } + + void SetImagePosition(bool removeImage = true) + { + uint left, top; + bool shouldHideLabel = false; + + switch (ImagePosition) + { + case ButtonImagePosition.Above: + left = 1; + top = 0; + shouldHideLabel = true; + break; + case ButtonImagePosition.Below: + left = 1; + top = 2; + shouldHideLabel = true; + break; + case ButtonImagePosition.Left: + left = 0; + top = 1; + break; + case ButtonImagePosition.Right: + left = 2; + top = 1; + break; + case ButtonImagePosition.Overlay: + left = 1; + top = 1; + break; + default: + throw new NotSupportedException(); + } + shouldHideLabel &= string.IsNullOrEmpty(label.Text); + if (shouldHideLabel) + label.Hide(); + else + label.Show(); + + var right = left + 1; + var bottom = top + 1; + var options = shouldHideLabel ? Gtk.AttachOptions.Expand : Gtk.AttachOptions.Shrink; + if (removeImage) + table.Remove(gtkimage); + table.Attach(gtkimage, left, right, top, bottom, options, options, 0, 0); + + } + + public ButtonImagePosition ImagePosition + { + get { return imagePosition; } + set + { + if (imagePosition != value) + { + imagePosition = value; + SetImagePosition(); + } + } + } + + public Color TextColor + { + get { return label.Style.Foreground(Gtk.StateType.Normal).ToEto(); } + set { label.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/CalendarHandler.cs b/Source/Eto.Gtk/Forms/Controls/CalendarHandler.cs new file mode 100644 index 0000000000..533cd2efc9 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/CalendarHandler.cs @@ -0,0 +1,242 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class CalendarHandler : GtkControl, Calendar.IHandler + { + Gtk.EventBox align; + CalendarMode mode; + Gtk.Calendar endCalendar; + Gtk.Box box; + DateTime minDate = DateTime.MinValue; + DateTime maxDate = DateTime.MaxValue; + int suppressRangeChanged; + + public override Gtk.Widget ContainerControl + { + get { return align; } + } + + public CalendarHandler() + { + Control = new Gtk.Calendar { Date = DateTime.Today }; + Control.DaySelected += HandleDaySelected; + + align = new Gtk.EventBox(); + align.Child = Control; + } + + void SetContent() + { + if (mode == CalendarMode.Single) + { + if (box != null) + box.Remove(Control); + align.Remove(box); + align.Child = Control; + } + else + { + align.Remove(Control); + suppressRangeChanged++; + if (endCalendar == null) + { + endCalendar = new Gtk.Calendar(); + endCalendar.Show(); + if (Control.Day == 0) + endCalendar.Day = 0; + else + endCalendar.Date = Control.Date; + endCalendar.DaySelected += HandleEndDaySelected; + } + if (Control.Day == 0) + endCalendar.Day = 0; + suppressRangeChanged--; + + if (box == null) + box = new Gtk.HBox(); + else + box.Remove(endCalendar); + box.PackStart(Control, true, true, 0); + box.PackStart(endCalendar, true, true, 0); + box.Show(); + align.Child = box; + } + } + + void HandleEndDaySelected(object sender, EventArgs e) + { + var date = endCalendar.Date; + if (endCalendar.Day != 0) + { + if (date < MinDate) + { + endCalendar.Date = MinDate; + return; + } + if (date > MaxDate) + { + endCalendar.Date = MaxDate; + return; + } + } + if (date < Control.Date || (Control.Day == 0 && endCalendar.Day != 0)) + { + Control.Date = date; + return; + } + + if (suppressRangeChanged == 0) + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + + void HandleDaySelected(object sender, EventArgs e) + { + var date = Control.Date; + if (Control.Day != 0) + { + if (date < MinDate) + { + Control.Date = MinDate; + return; + } + if (date > MaxDate) + { + Control.Date = MaxDate; + return; + } + } + + Callback.OnSelectedDateChanged(Widget, EventArgs.Empty); + if (endCalendar != null && (date > endCalendar.Date || endCalendar.Day == 0)) + { + if (Control.Day == 0) + endCalendar.Day = 0; + else + endCalendar.Date = date; + return; + } + if (suppressRangeChanged == 0) + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Calendar.SelectedDateChangedEvent: + break; + case Calendar.SelectedRangeChangedEvent: + break; + default: + base.AttachEvent(id); + break; + } + } + + public DateTime MinDate + { + get { return minDate; } + set + { + if (minDate != value) + { + minDate = value; + var range = SelectedRange; + var start = range.Start; + var end = range.End; + if (start < minDate) + start = minDate; + if (end < minDate) + end = minDate; + + SelectedRange = new Range(start, end); + } + } + } + + public DateTime MaxDate + { + get { return maxDate; } + set + { + if (maxDate != value) + { + maxDate = value; + var range = SelectedRange; + var start = range.Start; + var end = range.End; + if (start > maxDate) + start = maxDate; + if (end > maxDate) + end = maxDate; + + SelectedRange = new Range(start, end); + } + } + } + + public Range SelectedRange + { + get + { + if (mode == CalendarMode.Range && endCalendar != null) + { + return new Range(Control.Date, endCalendar.Date); + } + return new Range(Control.Date, Control.Date); + } + set + { + if (value != SelectedRange) + { + if (mode == CalendarMode.Range) + { + suppressRangeChanged++; + if (value.Start != Control.Date) + Control.Date = value.Start; + endCalendar.Date = value.End; + suppressRangeChanged--; + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + else + { + Control.Date = value.Start; + } + } + } + } + + public DateTime SelectedDate + { + get { return Control.Date; } + set + { + if (value != SelectedDate) + { + Control.Date = value; + if (endCalendar != null) + endCalendar.Date = value; + } + } + } + + public CalendarMode Mode + { + get { return mode; } + set + { + if (mode != value) + { + var range = SelectedRange; + mode = value; + SetContent(); + if (range != SelectedRange) + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/CheckBoxHandler.cs b/Source/Eto.Gtk/Forms/Controls/CheckBoxHandler.cs new file mode 100644 index 0000000000..be4fd1d263 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/CheckBoxHandler.cs @@ -0,0 +1,122 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class CheckBoxHandler : GtkControl, CheckBox.IHandler + { + Font font; + readonly Gtk.EventBox box; + + public override Gtk.Widget ContainerControl + { + get { return box; } + } + + public CheckBoxHandler() + { + Control = new Gtk.CheckButton(); + box = new Gtk.EventBox { Child = Control }; + } + + protected override void Initialize() + { + base.Initialize(); + Control.Toggled += Connector.HandleToggled; + } + + protected new CheckBoxConnector Connector { get { return (CheckBoxConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new CheckBoxConnector(); + } + + protected class CheckBoxConnector : GtkControlConnector + { + bool toggling; + public new CheckBoxHandler Handler { get { return (CheckBoxHandler)base.Handler; } } + + public void HandleToggled(object sender, EventArgs e) + { + var h = Handler; + var c = h.Control; + if (toggling) + return; + + toggling = true; + if (h.ThreeState) + { + if (!c.Inconsistent && c.Active) + c.Inconsistent = true; + else if (c.Inconsistent) + { + c.Inconsistent = false; + c.Active = true; + } + } + h.Callback.OnCheckedChanged(h.Widget, EventArgs.Empty); + toggling = false; + + } + } + + public override string Text + { + get { return MnuemonicToString(Control.Label); } + set { Control.Label = StringToMnuemonic(value); } + } + + public override Font Font + { + get + { + if (font == null) + font = new Font(new FontHandler(Control.Child)); + return font; + } + set + { + font = value; + if (font != null) + Control.Child.ModifyFont(((FontHandler)font.Handler).Control); + else + Control.Child.ModifyFont(null); + } + } + + public bool? Checked + { + get { return Control.Inconsistent ? null : (bool?)Control.Active; } + set + { + if (value == null) + Control.Inconsistent = true; + else + { + Control.Inconsistent = false; + Control.Active = value.Value; + } + } + } + + public bool ThreeState + { + get; + set; + } + + public Color TextColor + { + get { return Control.Child.Style.Foreground(Gtk.StateType.Normal).ToEto(); } + set + { + Control.Child.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); + Control.Child.ModifyFg(Gtk.StateType.Active, value.ToGdk()); + Control.Child.ModifyFg(Gtk.StateType.Prelight, value.ToGdk()); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/ColorPickerHandler.cs b/Source/Eto.Gtk/Forms/Controls/ColorPickerHandler.cs new file mode 100644 index 0000000000..e351c1a1ac --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/ColorPickerHandler.cs @@ -0,0 +1,50 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class ColorPickerHandler : GtkControl, ColorPicker.IHandler + { + public ColorPickerHandler() + { + Control = new Gtk.ColorButton(); + } + + protected new ColorPickerConnector Connector { get { return (ColorPickerConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ColorPickerConnector(); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case ColorPicker.ColorChangedEvent: + Control.ColorSet += Connector.HandleSelectedColorChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + protected class ColorPickerConnector : GtkControlConnector + { + new ColorPickerHandler Handler { get { return (ColorPickerHandler)base.Handler; } } + + public void HandleSelectedColorChanged(object sender, EventArgs e) + { + Handler.Callback.OnColorChanged(Handler.Widget, EventArgs.Empty); + } + } + + public Eto.Drawing.Color Color + { + get { return Control.Color.ToEto(); } + set { Control.Color = value.ToGdk(); } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/ComboBoxHandler.cs b/Source/Eto.Gtk/Forms/Controls/ComboBoxHandler.cs new file mode 100644 index 0000000000..b31f0af708 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/ComboBoxHandler.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Eto.Drawing; +using Eto.Forms; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class ComboBoxHandler : DropDownHandler, ComboBox.IHandler + { + Gtk.Entry entry; + Gtk.EntryCompletion completion; + + protected override void Create() + { + listStore = new Gtk.ListStore(typeof(string)); +#if GTK2 + Control = new Gtk.ComboBoxEntry(listStore, 0); +#else + Control = Gtk.ComboBox.NewWithModelAndEntry(listStore); + Control.EntryTextColumn = 0; +#endif + text = Control.Cells[0] as Gtk.CellRendererText; + Control.SetAttributes(text, "text", 0); + entry = (Gtk.Entry)Control.Child; + entry.IsEditable = true; + Control.Changed += Connector.HandleChanged; + } + + protected new ComboBoxConnector Connector { get { return (ComboBoxConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ComboBoxConnector(); + } + + protected class ComboBoxConnector : DropDownConnector + { + public new ComboBoxHandler Handler { get { return (ComboBoxHandler)base.Handler; } } + + public void HandleTextChanged(object sender, EventArgs e) + { + Handler.Callback.OnTextChanged(Handler.Widget, EventArgs.Empty); + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case ComboBox.TextChangedEvent: + entry.Changed += Connector.HandleTextChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + public override Font Font + { + get + { + return font ?? (font = new Font(new FontHandler(text.FontDesc))); + } + set + { + font = value; + if (font != null) + { + var newfont = ((FontHandler)font.Handler).Control; + entry.ModifyFont(newfont); + text.FontDesc = newfont; + } + } + } + + public override string Text + { + get { return entry.Text; } + set { entry.Text = value ?? string.Empty; } + } + + public bool ReadOnly + { + get { return !entry.IsEditable; } + set { entry.IsEditable = !value; } + } + + public override int SelectedIndex + { + get + { + return base.SelectedIndex; + } + set + { + base.SelectedIndex = value; + if (value == -1) + { + Text = null; + } + } + } + + public bool AutoComplete + { + get { return completion != null; } + set + { + if (AutoComplete != value) + { + if (value) + { + completion = new Gtk.EntryCompletion(); + completion.Model = listStore; + completion.MinimumKeyLength = 1; + completion.TextColumn = 0; + entry.Completion = completion; + } + else + { + completion = null; + entry.Completion = null; + } + } + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Gtk/Forms/Controls/DateTimePickerHandler.cs b/Source/Eto.Gtk/Forms/Controls/DateTimePickerHandler.cs new file mode 100644 index 0000000000..1499caff86 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/DateTimePickerHandler.cs @@ -0,0 +1,93 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class DateTimePickerHandler : GtkControl, DateTimePicker.IHandler + { + public DateTimePickerHandler() + { + Control = new CustomControls.DateComboBox(); + this.Mode = DateTimePicker.DefaultMode; + } + + protected override void Initialize() + { + base.Initialize(); + Control.DateChanged += Connector.HandleDateChanged; + } + + protected new DateTimePickerConnector Connector { get { return (DateTimePickerConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new DateTimePickerConnector(); + } + + protected class DateTimePickerConnector : GtkControlConnector + { + public new DateTimePickerHandler Handler { get { return (DateTimePickerHandler)base.Handler; } } + + public void HandleDateChanged(object sender, EventArgs e) + { + Handler.Callback.OnValueChanged(Handler.Widget, EventArgs.Empty); + } + } + + protected override void GrabFocus() + { + Control.Entry.GrabFocus(); + } + + protected override Gtk.Widget FontControl + { + get { return Control.Entry; } + } + + public DateTime? Value + { + get { return Control.SelectedDate; } + set { Control.SelectedDate = value; } + } + + public DateTime MinDate + { + get { return Control.MinDate; } + set { Control.MinDate = value; } + } + + public DateTime MaxDate + { + get { return Control.MaxDate; } + set { Control.MaxDate = value; } + } + + public DateTimePickerMode Mode + { + get { return Control.Mode; } + set { Control.Mode = value; } + } + + public Color TextColor + { + get { return Control.Entry.Style.Text(Gtk.StateType.Normal).ToEto(); } + set + { + Control.NormalColor = value.ToGdk(); + Control.Entry.ModifyText(Gtk.StateType.Normal, value.ToGdk()); + } + } + + public override Color BackgroundColor + { + get { return Control.Entry.Style.Base(Gtk.StateType.Normal).ToEto(); } + set + { + Control.Entry.ModifyBase(Gtk.StateType.Normal, value.ToGdk()); + Control.QueueDraw(); + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/DrawableHandler.cs b/Source/Eto.Gtk/Forms/Controls/DrawableHandler.cs new file mode 100644 index 0000000000..f24f04a65b --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/DrawableHandler.cs @@ -0,0 +1,109 @@ +using Eto.Drawing; +using Eto.Forms; +using Eto.GtkSharp.Drawing; +using System; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class DrawableHandler : GtkPanel, Drawable.IHandler + { + Gtk.VBox content; + + public bool SupportsCreateGraphics { get { return true; } } + + public void Create() + { + Control = new Gtk.EventBox(); + Control.Events |= Gdk.EventMask.ExposureMask; + //Control.ModifyBg(Gtk.StateType.Normal, new Gdk.Color(0, 0, 0)); + //Control.DoubleBuffered = false; + Control.CanFocus = false; + Control.CanDefault = true; + Control.Events |= Gdk.EventMask.ButtonPressMask; + + content = new Gtk.VBox(); + + Control.Add(content); + } + + protected override void Initialize() + { + base.Initialize(); +#if GTK2 + Control.ExposeEvent += Connector.HandleExpose; +#else + Control.Drawn += Connector.HandleDrawn; +#endif + Control.ButtonPressEvent += Connector.HandleDrawableButtonPressEvent; + } + + public void Create(bool largeCanvas) + { + Create(); + } + + public bool CanFocus + { + get { return Control.CanFocus; } + set { Control.CanFocus = value; } + } + + protected new DrawableConnector Connector { get { return (DrawableConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new DrawableConnector(); + } + + protected class DrawableConnector : GtkPanelEventConnector + { + public new DrawableHandler Handler { get { return (DrawableHandler)base.Handler; } } + + public void HandleDrawableButtonPressEvent(object o, Gtk.ButtonPressEventArgs args) + { + if (Handler.CanFocus) + Handler.Control.GrabFocus(); + } + +#if GTK2 + public void HandleExpose(object o, Gtk.ExposeEventArgs args) + { + var h = Handler; + Gdk.EventExpose ev = args.Event; + using (var graphics = new Graphics(new GraphicsHandler(h.Control, ev.Window))) + { + Rectangle rect = ev.Region.Clipbox.ToEto(); + h.Callback.OnPaint(h.Widget, new PaintEventArgs(graphics, rect)); + } + } +#else + public void HandleDrawn(object o, Gtk.DrawnArgs args) + { + var h = Handler; + using (var graphics = new Graphics(new GraphicsHandler(args.Cr, h.Control.CreatePangoContext(), false))) + { + h.Callback.OnPaint(h.Widget, new PaintEventArgs (graphics, new Rectangle(h.Size))); + } + } +#endif + } + + public void Update(Rectangle rect) + { + using (var graphics = new Graphics(new GraphicsHandler(Control, Control.GdkWindow))) + { + Callback.OnPaint(Widget, new PaintEventArgs(graphics, rect)); + } + } + + public Graphics CreateGraphics() + { + return new Graphics(new GraphicsHandler(Control, Control.GdkWindow)); + } + + protected override void SetContainerContent(Gtk.Widget content) + { + this.content.Add(content); + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/DropDownHandler.cs b/Source/Eto.Gtk/Forms/Controls/DropDownHandler.cs new file mode 100644 index 0000000000..dbdf79ea0a --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/DropDownHandler.cs @@ -0,0 +1,159 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; +using System.Collections; +using System.Collections.Generic; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class DropDownHandler : DropDownHandler + { + protected override void Create() + { + listStore = new Gtk.ListStore(typeof(string)); + Control = new Gtk.ComboBox(listStore); + text = new Gtk.CellRendererText(); + Control.PackStart(text, false); + Control.SetAttributes(text, "text", 0); + Control.Changed += Connector.HandleChanged; + } + } + + public abstract class DropDownHandler : GtkControl, DropDown.IHandler + where TControl: Gtk.ComboBox + where TWidget: DropDown + where TCallback: DropDown.ICallback + { + protected Font font; + CollectionHandler collection; + protected Gtk.ListStore listStore; + protected Gtk.CellRendererText text; + + protected override void Initialize() + { + Create(); + base.Initialize(); + } + + protected abstract void Create(); + + protected new DropDownConnector Connector { get { return (DropDownConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new DropDownConnector(); + } + + protected class DropDownConnector : GtkControlConnector + { + int? lastIndex; + public new DropDownHandler Handler { get { return (DropDownHandler)base.Handler; } } + + public void HandleChanged(object sender, EventArgs e) + { + var newIndex = Handler.SelectedIndex; + if (newIndex != lastIndex) + { + Handler.Callback.OnSelectedIndexChanged(Handler.Widget, EventArgs.Empty); + lastIndex = newIndex; + } + } + } + + public virtual int SelectedIndex + { + get { return Control.Active; } + set { Control.Active = value; } + } + + public override Font Font + { + get + { + return font ?? (font = new Font(new FontHandler(text.FontDesc))); + } + set + { + font = value; + if (font != null) + { + text.FontDesc = ((FontHandler)font.Handler).Control; + } + } + } + + public class CollectionHandler : EnumerableChangedHandler + { + public DropDownHandler Handler { get; set; } + + public override void AddItem(object item) + { + var binding = Handler.Widget.TextBinding; + Handler.listStore.AppendValues(binding.GetValue(item)); + Handler.Control.QueueResize(); + } + + public override void InsertItem(int index, object item) + { + var binding = Handler.Widget.TextBinding; + Handler.listStore.InsertWithValues(index, binding.GetValue(item)); + Handler.Control.QueueResize(); + } + + public override void RemoveItem(int index) + { + Gtk.TreeIter iter; + if (Handler.listStore.IterNthChild(out iter, index)) + Handler.listStore.Remove(ref iter); + Handler.Control.QueueResize(); + } + + public override void RemoveAllItems() + { + Handler.listStore.Clear(); + Handler.Control.QueueResize(); + } + } + + public IEnumerable DataStore + { + get { return collection != null ? collection.Collection : null; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler { Handler = this }; + collection.Register(value); + } + } + + public Color TextColor + { + get { return text.ForegroundGdk.ToEto(); } + set + { + text.ForegroundGdk = value.ToGdk(); + if (Widget.Loaded) + Control.QueueDraw(); + } + } + + public override Color BackgroundColor + { + get { return Control.Child.Style.Base(Gtk.StateType.Normal).ToEto(); } + set + { + Control.Child.ModifyBg(Gtk.StateType.Normal, value.ToGdk()); + Control.Child.ModifyBase(Gtk.StateType.Normal, value.ToGdk()); + Control.Child.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); + Control.ModifyBg(Gtk.StateType.Normal, value.ToGdk()); + Control.ModifyBase(Gtk.StateType.Normal, value.ToGdk()); + Control.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); + if (Widget.Loaded) + Control.QueueDraw(); + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/GridColumnHandler.cs b/Source/Eto.Gtk/Forms/Controls/GridColumnHandler.cs new file mode 100644 index 0000000000..4b8579cd52 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/GridColumnHandler.cs @@ -0,0 +1,173 @@ +using Eto.Forms; +using Eto.GtkSharp.Forms.Cells; +using System; + +namespace Eto.GtkSharp.Forms.Controls +{ + public interface IGridHandler + { + bool IsEventHandled(string handler); + + void ColumnClicked(GridColumnHandler column); + } + + public interface IGridColumnHandler + { + GLib.Value GetValue(object dataItem, int dataColumn, int row); + + void BindCell(IGridHandler grid, ICellDataSource source, int columnIndex, ref int dataIndex); + + void SetupEvents(); + } + + public class GridColumnHandler : WidgetHandler, GridColumn.IHandler, IGridColumnHandler + { + Cell dataCell; + bool autoSize; + bool editable; + bool cellsAdded; + IGridHandler grid; + + public GridColumnHandler() + { + Control = new Gtk.TreeViewColumn(); + AutoSize = true; + Resizable = true; + DataCell = new TextBoxCell(); + } + + public string HeaderText + { + get { return Control.Title; } + set { Control.Title = value; } + } + + public bool Resizable + { + get { return Control.Resizable; } + set { Control.Resizable = value; } + } + + public bool Sortable + { + get { return Control.Clickable; } + set { Control.Clickable = value; } + } + + public bool AutoSize + { + get + { + return autoSize; + } + set + { + autoSize = value; + Control.Sizing = value ? Gtk.TreeViewColumnSizing.GrowOnly : Gtk.TreeViewColumnSizing.Fixed; + } + } + + void SetCellAttributes() + { + if (dataCell != null) + { + ((ICellHandler)dataCell.Handler).SetEditable(Control, editable); + SetupEvents(); + } + } + + public bool Editable + { + get + { + return editable; + } + set + { + editable = value; + SetCellAttributes(); + } + } + + public int Width + { + get { return Control.Width; } + set { Control.FixedWidth = value; } + } + + public Cell DataCell + { + get + { + return dataCell; + } + set + { + dataCell = value; + } + } + + public bool Visible + { + get { return Control.Visible; } + set { Control.Visible = value; } + } + + public void BindCell(IGridHandler grid, ICellDataSource source, int columnIndex, ref int dataIndex) + { + this.grid = grid; + if (dataCell != null) + { + var cellhandler = (ICellHandler)dataCell.Handler; + if (!cellsAdded) + { + cellhandler.AddCells(Control); + cellsAdded = true; + } + SetCellAttributes(); + cellhandler.BindCell(source, this, columnIndex, ref dataIndex); + } + } + + public void SetupEvents() + { + if (grid == null) + return; + if (grid.IsEventHandled(Grid.CellEditingEvent)) + HandleEvent(Grid.CellEditingEvent); + if (grid.IsEventHandled(Grid.CellEditedEvent)) + HandleEvent(Grid.CellEditedEvent); + if (grid.IsEventHandled(Grid.ColumnHeaderClickEvent)) + HandleEvent(Grid.ColumnHeaderClickEvent); + if (grid.IsEventHandled(Grid.CellFormattingEvent)) + HandleEvent(Grid.CellFormattingEvent); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.ColumnHeaderClickEvent: + var handler = new WeakReference(this); + Control.Clicked += (sender, e) => + { + var h = ((GridColumnHandler)handler.Target); + if (h != null && h.grid != null) + h.grid.ColumnClicked(h); + }; + break; + default: + ((ICellHandler)dataCell.Handler).HandleEvent(id); + break; + } + } + + public GLib.Value GetValue(object dataItem, int dataColumn, int row) + { + if (dataCell != null) + return ((ICellHandler)dataCell.Handler).GetValue(dataItem, dataColumn, row); + return new GLib.Value((string)null); + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/GridHandler.cs b/Source/Eto.Gtk/Forms/Controls/GridHandler.cs new file mode 100644 index 0000000000..cf71f1aa61 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/GridHandler.cs @@ -0,0 +1,330 @@ +using System; +using Eto.Forms; +using System.Linq; +using System.Collections.Generic; +using Eto.GtkSharp.Forms.Cells; +using Eto.GtkSharp.Forms.Menu; + +namespace Eto.GtkSharp.Forms.Controls +{ + public abstract class GridHandler : GtkControl, Grid.IHandler, ICellDataSource, IGridHandler + where TWidget : Grid + where TCallback: Grid.ICallback + { + ColumnCollection columns; + ContextMenu contextMenu; + readonly Dictionary columnMap = new Dictionary(); + + protected bool SkipSelectedChange { get; set; } + + protected Gtk.TreeView Tree { get; private set; } + + protected Dictionary ColumnMap { get { return columnMap; } } + + protected GridHandler() + { + Control = new Gtk.ScrolledWindow + { + ShadowType = Gtk.ShadowType.In + }; + } + + protected abstract ITreeModelImplementor CreateModelImplementor(); + + protected void UpdateModel() + { + SkipSelectedChange = true; + var selected = SelectedRows; + Tree.Model = new Gtk.TreeModelAdapter(CreateModelImplementor()); + SetSelectedRows(selected); + SkipSelectedChange = false; + } + + protected override void Initialize() + { + base.Initialize(); + Tree = new Gtk.TreeView(); + UpdateModel(); + Tree.HeadersVisible = true; + + Control.Add(Tree); + + Tree.Events |= Gdk.EventMask.ButtonPressMask; + Tree.ButtonPressEvent += Connector.HandleTreeButtonPressEvent; + + columns = new ColumnCollection { Handler = this }; + columns.Register(Widget.Columns); + } + + protected new GridConnector Connector { get { return (GridConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new GridConnector(); + } + + protected class GridConnector : GtkControlConnector + { + public new GridHandler Handler { get { return (GridHandler)base.Handler; } } + + [GLib.ConnectBefore] + public void HandleTreeButtonPressEvent(object o, Gtk.ButtonPressEventArgs args) + { + var handler = Handler; + if (handler.contextMenu != null && args.Event.Button == 3 && args.Event.Type == Gdk.EventType.ButtonPress) + { + var menu = ((ContextMenuHandler)handler.contextMenu.Handler).Control; + menu.Popup(); + menu.ShowAll(); + } + } + + int[] selectedRows; + + static bool ArraysEqual(T[] a1, T[] a2) + { + if (ReferenceEquals(a1, a2)) + return true; + + if (a1 == null || a2 == null) + return false; + + if (a1.Length != a2.Length) + return false; + + EqualityComparer comparer = EqualityComparer.Default; + for (int i = 0; i < a1.Length; i++) + { + if (!comparer.Equals(a1[i], a2[i])) return false; + } + return true; + } + + public void HandleGridSelectionChanged(object sender, EventArgs e) + { + if (!Handler.SkipSelectedChange) + { + var selected = Handler.SelectedRows.ToArray(); + if (!ArraysEqual(selectedRows, selected)) + { + Handler.Callback.OnSelectionChanged(Handler.Widget, EventArgs.Empty); + selectedRows = selected; + } + } + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.ColumnHeaderClickEvent: + case Grid.CellEditingEvent: + case Grid.CellEditedEvent: + case Grid.CellFormattingEvent: + SetupColumnEvents(); + break; + case Grid.SelectionChangedEvent: + Tree.Selection.Changed += Connector.HandleGridSelectionChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + Tree.AppendColumn(new Gtk.TreeViewColumn()); + UpdateColumns(); + } + + void SetupColumnEvents() + { + if (!Widget.Loaded) + return; + foreach (var col in Widget.Columns.Select(r => r.Handler).OfType()) + { + col.SetupEvents(); + } + } + + protected virtual void UpdateColumns() + { + if (!Widget.Loaded) + return; + columnMap.Clear(); + int columnIndex = 0; + int dataIndex = 0; + foreach (var col in Widget.Columns.Select(r => r.Handler).OfType()) + { + col.BindCell(this, this, columnIndex++, ref dataIndex); + col.SetupEvents(); + } + } + + class ColumnCollection : EnumerableChangedHandler + { + public GridHandler Handler { get; set; } + + public override void AddItem(GridColumn item) + { + var colhandler = (GridColumnHandler)item.Handler; + Handler.Tree.AppendColumn(colhandler.Control); + Handler.UpdateColumns(); + } + + public override void InsertItem(int index, GridColumn item) + { + var colhandler = (GridColumnHandler)item.Handler; + if (Handler.Tree.Columns.Length > 0) + Handler.Tree.InsertColumn(colhandler.Control, index); + else + Handler.Tree.AppendColumn(colhandler.Control); + Handler.UpdateColumns(); + } + + public override void RemoveItem(int index) + { + var colhandler = (GridColumnHandler)Handler.Widget.Columns[index].Handler; + Handler.Tree.RemoveColumn(colhandler.Control); + Handler.UpdateColumns(); + } + + public override void RemoveAllItems() + { + foreach (var col in Handler.Tree.Columns) + { + Handler.Tree.RemoveColumn(col); + } + Handler.UpdateColumns(); + } + + } + + public bool ShowHeader + { + get { return Tree.HeadersVisible; } + set { Tree.HeadersVisible = value; } + } + + public bool AllowColumnReordering + { + get { return Tree.Reorderable; } + set { Tree.Reorderable = value; } + } + + public int NumberOfColumns + { + get + { + return Widget.Columns.Count; + } + } + + public abstract object GetItem(Gtk.TreePath path); + + public abstract Gtk.TreeIter GetIterAtRow(int row); + public abstract Gtk.TreePath GetPathAtRow(int row); + + public void SetColumnMap(int dataIndex, int column) + { + columnMap[dataIndex] = column; + } + + public ContextMenu ContextMenu + { + get { return contextMenu; } + set { contextMenu = value; } + } + + public void EndCellEditing(Gtk.TreePath path, int column) + { + var row = path.Indices.Length > 0 ? path.Indices[0] : -1; + var item = GetItem(path); + Callback.OnCellEdited(Widget, new GridViewCellEventArgs(Widget.Columns[column], row, column, item)); + } + + public void BeginCellEditing(Gtk.TreePath path, int column) + { + var row = path.Indices.Length > 0 ? path.Indices[0] : -1; + var item = GetItem(path); + Callback.OnCellEditing(Widget, new GridViewCellEventArgs(Widget.Columns[column], row, column, item)); + } + + public void ColumnClicked(GridColumnHandler column) + { + Callback.OnColumnHeaderClick(Widget, new GridColumnEventArgs(column.Widget)); + } + + public bool AllowMultipleSelection + { + get { return Tree.Selection.Mode == Gtk.SelectionMode.Multiple; } + set { Tree.Selection.Mode = value ? Gtk.SelectionMode.Multiple : Gtk.SelectionMode.Browse; } + } + + public virtual IEnumerable SelectedRows + { + get + { + return Tree.Selection.GetSelectedRows().Select(r => r.Indices[0]); + } + set + { + SkipSelectedChange = true; + SetSelectedRows(value); + SkipSelectedChange = false; + Callback.OnSelectionChanged(Widget, EventArgs.Empty); + } + } + + protected abstract void SetSelectedRows(IEnumerable value); + + public int RowHeight + { + get; + set; + } + + public void SelectAll() + { + Tree.Selection.SelectAll(); + } + + public void SelectRow(int row) + { + Tree.Selection.SelectIter(GetIterAtRow(row)); + } + + public void UnselectRow(int row) + { + Tree.Selection.UnselectIter(GetIterAtRow(row)); + } + + public void UnselectAll() + { + Tree.Selection.UnselectAll(); + } + + public void BeginEdit(int row, int column) + { + var nameColumn = Tree.Columns[column]; + #if GTK2 + var cellRenderer = nameColumn.CellRenderers[0]; + #else + var cellRenderer = nameColumn.Cells[0]; + #endif + var path = Tree.Model.GetPath(GetIterAtRow(row)); + Tree.Model.IterNChildren(); + Tree.SetCursorOnCell(path, nameColumn, cellRenderer, true); + } + + public void OnCellFormatting(GridCellFormatEventArgs args) + { + Callback.OnCellFormatting(Widget, args); + } + + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/GridViewHandler.cs b/Source/Eto.Gtk/Forms/Controls/GridViewHandler.cs new file mode 100644 index 0000000000..441728b32c --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/GridViewHandler.cs @@ -0,0 +1,208 @@ +using Eto.Forms; +using System.Collections.Generic; +using Eto.GtkSharp.Forms.Cells; +using System.Collections; +using System.Linq; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class GridViewHandler : GridHandler, GridView.IHandler, ICellDataSource, IGtkEnumerableModelHandler + { + GtkEnumerableModel model; + CollectionHandler collection; + bool showCellBorders; + + protected override ITreeModelImplementor CreateModelImplementor() + { + model = new GtkEnumerableModel { Handler = this, Count = collection != null ? collection.Count : 0 }; + return model; + } + + public class CollectionHandler : EnumerableChangedHandler + { + public GridViewHandler Handler { get; set; } + + public override void AddRange(IEnumerable items) + { + Handler.UpdateModel(); + } + + public override void AddItem(object item) + { + var count = Count; + var iter = Handler.model.GetIterAtRow(count); + var path = Handler.model.GetPathAtRow(count); + Handler.model.Count++; + Handler.Tree.Model.EmitRowInserted(path, iter); + } + + public override void InsertItem(int index, object item) + { + var iter = Handler.model.GetIterAtRow(index); + var path = Handler.model.GetPathAtRow(index); + Handler.model.Count++; + Handler.Tree.Model.EmitRowInserted(path, iter); + } + + public override void RemoveItem(int index) + { + var path = Handler.model.GetPathAtRow(index); + Handler.model.Count--; + Handler.Tree.Model.EmitRowDeleted(path); + } + + public override void RemoveAllItems() + { + Handler.UpdateModel(); + } + } + + public IEnumerable DataStore + { + get { return collection != null ? collection.Collection : null; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler { Handler = this }; + collection.Register(value); + } + } + + public bool ShowCellBorders + { + get { return showCellBorders; } + set + { + if (showCellBorders != value) + { + showCellBorders = value; + SetBorders(); + } + } + } + + protected override void UpdateColumns() + { + base.UpdateColumns(); + SetBorders(); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case GridView.CellDoubleClickEvent: + Tree.RowActivated += (sender, e) => + { + var rowIndex = e.Path.Indices.Length > 0 ? e.Path.Indices[0] : -1; + var columnIndex = GetColumnOfItem(e.Column); + var item = GetItem(e.Path); + var column = columnIndex == -1 ? null : Widget.Columns[columnIndex]; + Callback.OnCellDoubleClick(Widget, new GridViewCellEventArgs(column, rowIndex, columnIndex, item)); + }; + break; + default: + base.AttachEvent(id); + break; + } + } + + void SetBorders() + { + int spacing = showCellBorders ? 10 : 0; + foreach (var column in Tree.Columns) + { + column.Spacing = spacing; + } + } + + public IEnumerable SelectedItems + { + get + { + if (collection != null) + { + foreach (var row in SelectedRows) + yield return collection.ElementAt(row); + } + } + } + + public override Gtk.TreeIter GetIterAtRow(int row) + { + return model.GetIterAtRow(row); + } + + public override Gtk.TreePath GetPathAtRow(int row) + { + return model.GetPathAtRow(row); + } + + protected override void SetSelectedRows(IEnumerable value) + { + Tree.Selection.UnselectAll(); + if (value != null && collection != null) + { + int start = -1; + int end = -1; + var count = collection.Count; + + foreach (var row in value.Where(r => r < count).OrderBy(r => r)) + { + if (start == -1) + start = end = row; + else if (row == end + 1) + end = row; + else + { + if (start == end) + Tree.Selection.SelectIter(GetIterAtRow(start)); + else + Tree.Selection.SelectRange(GetPathAtRow(start), GetPathAtRow(end)); + start = end = -1; + } + } + if (start != -1) + { + if (start == end) + Tree.Selection.SelectIter(GetIterAtRow(start)); + else + Tree.Selection.SelectRange(GetPathAtRow(start), GetPathAtRow(end)); + } + } + } + + public override object GetItem(Gtk.TreePath path) + { + return model.GetItemAtPath(path); + } + + public GLib.Value GetColumnValue(object item, int dataColumn, int row) + { + int column; + if (ColumnMap.TryGetValue(dataColumn, out column)) + { + var colHandler = (IGridColumnHandler)Widget.Columns[column].Handler; + return colHandler.GetValue(item, dataColumn, row); + } + return new GLib.Value((string)null); + } + + public int GetRowOfItem(object item) + { + return collection != null ? collection.IndexOf(item) : -1; + } + + public int GetColumnOfItem(Gtk.TreeViewColumn item) + { + return Widget.Columns.Select(r => r.Handler as GridColumnHandler).Select(r => r.Control).ToList().IndexOf(item); + } + + public EnumerableChangedHandler Collection + { + get { return collection; } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/GroupBoxHandler.cs b/Source/Eto.Gtk/Forms/Controls/GroupBoxHandler.cs new file mode 100644 index 0000000000..9fa3725a49 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/GroupBoxHandler.cs @@ -0,0 +1,61 @@ +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class GroupBoxHandler : GtkPanel, GroupBox.IHandler + { + public GroupBoxHandler () + { + Control = new Gtk.Frame (); + } + + protected override Gtk.Widget FontControl + { + get { return Control.LabelWidget; } + } + + public override string Text { + get { return Control.Label; } + set { Control.Label = value; } + } + + public override Size ClientSize { + get { + if (Control.Visible && Control.Child != null) + return Control.Child.Allocation.Size.ToEto (); + else { + var label = Control.LabelWidget; + var size = Size; + size.Height -= label.Allocation.Height + 10; + size.Width -= 10; + return size; + } + } + set { + var label = Control.LabelWidget; + var size = value; + size.Height += label.Allocation.Height + 10; + size.Width += 10; + Size = size; + } + } + + protected override void SetContainerContent(Gtk.Widget content) + { + Control.Add(content); + + /*if (clientSize != null) { + var label = Control.LabelWidget; + Control.SetSizeRequest(clientSize.Value.Width + 10, clientSize.Value.Height + label.Allocation.Height + 10); + clientSize = null; + }*/ + } + + public Color TextColor + { + get { return Control.LabelWidget.Style.Foreground(Gtk.StateType.Normal).ToEto(); } + set { Control.LabelWidget.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/GtkEnumerableModel.cs b/Source/Eto.Gtk/Forms/Controls/GtkEnumerableModel.cs new file mode 100644 index 0000000000..4847dbfe5b --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/GtkEnumerableModel.cs @@ -0,0 +1,195 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using System.Linq; + +namespace Eto.GtkSharp.Forms.Controls +{ + public interface IGtkEnumerableModelHandler + where TItem: class + { + EnumerableChangedHandler Collection { get; } + + int NumberOfColumns { get; } + + GLib.Value GetColumnValue (TItem item, int column, int row); + + int GetRowOfItem (TItem item); + } + + public class GtkEnumerableModel : GLib.Object, ITreeModelImplementor + where TItem: class + { + WeakReference weakHandler; + public IGtkEnumerableModelHandler Handler { get { return (IGtkEnumerableModelHandler)weakHandler.Target; } set { weakHandler = new WeakReference(value); } } + + public int Count { get; set; } + + public Gtk.TreeIter GetIterAtRow (int row) + { + return new Gtk.TreeIter { UserData = (IntPtr)(row+1) }; + } + + public Gtk.TreePath GetPathAtRow (int row) + { + var path = new Gtk.TreePath (); + path.AppendIndex (row); + return path; + } + + public TItem GetItemAtPath (Gtk.TreePath path) + { + var row = GetRow (path); + return row >= 0 ? Handler.Collection.ElementAt(row) : default(TItem); + } + + public TItem GetItemAtPath (string path) + { + return GetItemAtPath (new Gtk.TreePath (path)); + } + + public TItem GetItemAtIter (Gtk.TreeIter iter) + { + var node = NodeFromIter (iter); + return node >= 0 ? Handler.Collection.ElementAt(node) : default(TItem); + } + + int GetRow (Gtk.TreePath path) + { + var handler = Handler; + if (handler != null && path.Indices.Length > 0 && Count > 0) + return path.Indices[0]; + return -1; + } + + public Gtk.TreeModelFlags Flags { + get { return Gtk.TreeModelFlags.ListOnly; } + } + + public int NColumns { + get { return Handler.NumberOfColumns; } + } + + public GLib.GType GetColumnType (int col) + { + GLib.GType result = GLib.GType.String; + return result; + } + + public int NodeFromIter (Gtk.TreeIter iter) + { + return ((int)iter.UserData) - 1; + } + + public bool GetIter (out Gtk.TreeIter iter, Gtk.TreePath path) + { + if (path == null) + throw new ArgumentNullException ("path"); + + + var row = GetRow (path); + if (row >= 0) { + iter = new Gtk.TreeIter { UserData = (IntPtr)(row + 1) }; + return true; + } + iter = Gtk.TreeIter.Zero; + return false; + } + + public Gtk.TreePath GetPath (Gtk.TreeIter iter) + { + var node = NodeFromIter (iter); + + var path = new Gtk.TreePath (); + path.AppendIndex (node); + return path; + } + + public void GetValue (Gtk.TreeIter iter, int col, ref GLib.Value val) + { + var row = ((int)iter.UserData) - 1; + if (row >= 0) { + var item = Handler.Collection.ElementAt(row); + val = Handler.GetColumnValue (item, col, row); + } else + val = Handler.GetColumnValue (null, col, row); + + } + + public bool IterNext (ref Gtk.TreeIter iter) + { + var row = ((int)iter.UserData) - 1; + if (row >= 0 && Handler.Collection != null && row < Count - 1) + { + iter = new Gtk.TreeIter { UserData = (IntPtr)(row + 2) }; + return true; + } + iter = Gtk.TreeIter.Zero; + return false; + } + + public bool IterPrevious (ref Gtk.TreeIter iter) + { + var row = (int)iter.UserData - 1; + if (row > 0) { + iter = new Gtk.TreeIter { UserData = (IntPtr)(row) }; + return true; + } + iter = Gtk.TreeIter.Zero; + return false; + } + + public bool IterChildren (out Gtk.TreeIter child, Gtk.TreeIter parent) + { + if (parent.UserData == IntPtr.Zero && Count > 0) + { + child = new Gtk.TreeIter { UserData = (IntPtr)1 }; + return true; + } + child = Gtk.TreeIter.Zero; + return false; + } + + public bool IterHasChild (Gtk.TreeIter iter) + { + return false; + } + + public int IterNChildren (Gtk.TreeIter iter) + { + var handler = Handler; + if (iter.UserData == IntPtr.Zero && handler.Collection != null) + return handler.Collection.Count; + return 0; + } + + public bool IterNthChild (out Gtk.TreeIter child, Gtk.TreeIter parent, int n) + { + var handler = Handler; + if (parent.UserData == IntPtr.Zero && handler != null && handler.Collection != null) + { + if (n < handler.Collection.Count) + { + child = new Gtk.TreeIter { UserData = (IntPtr)(n+1) }; + return true; + } + } + child = Gtk.TreeIter.Zero; + return false; + } + + public bool IterParent (out Gtk.TreeIter parent, Gtk.TreeIter child) + { + parent = Gtk.TreeIter.Zero; + return false; + } + + public void RefNode (Gtk.TreeIter iter) + { + } + + public void UnrefNode (Gtk.TreeIter iter) + { + } + } +} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/GtkListModel.cs b/Source/Eto.Gtk/Forms/Controls/GtkListModel.cs similarity index 99% rename from Source/Eto.Platform.Gtk/Forms/Controls/GtkListModel.cs rename to Source/Eto.Gtk/Forms/Controls/GtkListModel.cs index 81a2d5feda..440106d8be 100644 --- a/Source/Eto.Platform.Gtk/Forms/Controls/GtkListModel.cs +++ b/Source/Eto.Gtk/Forms/Controls/GtkListModel.cs @@ -1,7 +1,7 @@ using System; using Eto.Forms; -namespace Eto.Platform.GtkSharp +namespace Eto.GtkSharp.Forms.Controls { public interface IGtkListModelHandler where TStore: IDataStore diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/GtkTreeModel.cs b/Source/Eto.Gtk/Forms/Controls/GtkTreeModel.cs similarity index 99% rename from Source/Eto.Platform.Gtk/Forms/Controls/GtkTreeModel.cs rename to Source/Eto.Gtk/Forms/Controls/GtkTreeModel.cs index 53949f1205..5ed9e72f39 100644 --- a/Source/Eto.Platform.Gtk/Forms/Controls/GtkTreeModel.cs +++ b/Source/Eto.Gtk/Forms/Controls/GtkTreeModel.cs @@ -4,7 +4,7 @@ using Eto.Forms; using System.Runtime.InteropServices; -namespace Eto.Platform.GtkSharp +namespace Eto.GtkSharp.Forms.Controls { public class GtkTreeModel : GLib.Object, ITreeModelImplementor where TStore: class, IDataStore diff --git a/Source/Eto.Gtk/Forms/Controls/ImageViewHandler.cs b/Source/Eto.Gtk/Forms/Controls/ImageViewHandler.cs new file mode 100644 index 0000000000..5dc9083ccc --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/ImageViewHandler.cs @@ -0,0 +1,100 @@ +using System; +using Eto.Forms; +using Eto.GtkSharp.Drawing; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class ImageViewHandler : GtkControl, ImageView.IHandler + { + Image image; + bool widthSet; + bool heightSet; + + public ImageViewHandler() + { + Control = new Gtk.DrawingArea + { + CanFocus = false, + CanDefault = true + }; + Control.Events |= Gdk.EventMask.ExposureMask; + } + + protected override void Initialize() + { + base.Initialize(); +#if GTK2 + Control.ExposeEvent += Connector.HandleExpose; +#else + Control.Drawn += Connector.HandleDrawn; +#endif + } + + protected new ImageViewConnector Connector { get { return (ImageViewConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ImageViewConnector(); + } + + protected class ImageViewConnector : GtkControlConnector + { + public new ImageViewHandler Handler { get { return (ImageViewHandler)base.Handler; } } + +#if GTK2 + public void HandleExpose(object o, Gtk.ExposeEventArgs args) + { + Gdk.EventExpose ev = args.Event; + var h = Handler; + var handler = new GraphicsHandler(h.Control, ev.Window); +#else + public void HandleDrawn(object o, Gtk.DrawnArgs args) + { + var h = Handler; + var handler = new GraphicsHandler(args.Cr, h.Control.CreatePangoContext(), false); +#endif + using (var graphics = new Graphics(handler)) + { + + var widgetSize = new Size(h.Control.Allocation.Width, h.Control.Allocation.Height); + var imageSize = (SizeF)h.image.Size; + var scaleWidth = widgetSize.Width / imageSize.Width; + var scaleHeight = widgetSize.Height / imageSize.Height; + imageSize *= Math.Min(scaleWidth, scaleHeight); + var location = new PointF((widgetSize.Width - imageSize.Width) / 2, (widgetSize.Height - imageSize.Height) / 2); + + var destRect = new Rectangle(Point.Round(location), Size.Truncate(imageSize)); + graphics.DrawImage(h.image, destRect); + } + } + } + + public override Size Size + { + get { return base.Size; } + set + { + base.Size = value; + widthSet = value.Width >= 0; + heightSet = value.Height >= 0; + } + } + + public Image Image + { + get { return image; } + set + { + image = value; + if (image != null && !widthSet || !heightSet) + { + Control.SetSizeRequest(widthSet ? Size.Width : image.Size.Width, heightSet ? Size.Height : image.Size.Height); + } + if (Control.Visible) + Control.QueueDraw(); + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/LabelHandler.cs b/Source/Eto.Gtk/Forms/Controls/LabelHandler.cs new file mode 100644 index 0000000000..6b4462b601 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/LabelHandler.cs @@ -0,0 +1,209 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class LabelHandler : GtkControl, Label.IHandler + { + readonly Gtk.EventBox eventBox; + HorizontalAlign horizontalAlign = HorizontalAlign.Left; + VerticalAlign verticalAlign = VerticalAlign.Top; + + public override Gtk.Widget ContainerControl + { + get { return eventBox; } + } + + public override Gtk.Widget EventControl + { + get { return eventBox; } + } + + public class EtoLabel : Gtk.Label + { + int wrapWidth; + +#if GTK2 + protected override void OnSizeRequested(ref Gtk.Requisition requisition) + { + //base.OnSizeRequested (ref requisition); + int width, height; + Layout.GetPixelSize(out width, out height); + requisition.Width = width; + requisition.Height = height; + } +#else + protected override void OnGetPreferredWidth (out int minimum_width, out int natural_width) + { + base.OnGetPreferredWidth (out minimum_width, out natural_width); + //minimum_width = natural_width; // = 500; //this.Layout.Width; + } + + protected override void OnAdjustSizeRequest (Gtk.Orientation orientation, out int minimum_size, out int natural_size) + { + base.OnAdjustSizeRequest (orientation, out minimum_size, out natural_size); + if (orientation == Gtk.Orientation.Horizontal) + minimum_size = natural_size; + } + +#endif + + protected override void OnSizeAllocated(Gdk.Rectangle allocation) + { + base.OnSizeAllocated(allocation); + SetWrapWidth(allocation.Width); + } + + void SetWrapWidth(int width) + { + if (width == 0) + return; + Layout.Width = (int)(width * Pango.Scale.PangoScale); + if (wrapWidth != width) + { + wrapWidth = width; + QueueResize(); + } + } + } + + public LabelHandler() + { + eventBox = new Gtk.EventBox(); + //eventBox.VisibleWindow = false; + Control = new EtoLabel + { + SingleLineMode = false, + LineWrap = true, + LineWrapMode = Pango.WrapMode.Word + }; + Control.SetAlignment(0, 0); + eventBox.Child = Control; + } + + public WrapMode Wrap + { + get + { + if (!Control.LineWrap) + return WrapMode.None; + if (Control.LineWrapMode == Pango.WrapMode.Word) + return WrapMode.Word; + return WrapMode.Character; + } + set + { + switch (value) + { + case WrapMode.None: + Control.Wrap = false; + Control.LineWrap = false; + Control.SingleLineMode = true; + break; + case WrapMode.Word: + Control.Wrap = true; + Control.LineWrapMode = Pango.WrapMode.Word; + Control.LineWrap = true; + Control.SingleLineMode = false; + break; + case WrapMode.Character: + Control.Wrap = true; + Control.LineWrapMode = Pango.WrapMode.Char; + Control.LineWrap = true; + Control.SingleLineMode = false; + break; + default: + throw new NotSupportedException(); + } + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + break; + default: + base.AttachEvent(id); + break; + } + } + + public virtual Color TextColor + { + get { return Control.Style.Foreground(Gtk.StateType.Normal).ToEto(); } + set { Control.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); } + } + + public override string Text + { + get { return MnuemonicToString(Control.Text); } + set { Control.TextWithMnemonic = StringToMnuemonic(value); } + } + + public HorizontalAlign HorizontalAlign + { + get { return horizontalAlign; } + set + { + horizontalAlign = value; + SetAlignment(); + } + } + + void SetAlignment() + { + float xalignment; + float yalignment; + switch (horizontalAlign) + { + default: + xalignment = 0F; + break; + case HorizontalAlign.Center: + xalignment = 0.5F; + break; + case HorizontalAlign.Right: + xalignment = 1F; + break; + } + switch (verticalAlign) + { + case VerticalAlign.Middle: + yalignment = 0.5F; + break; + default: + yalignment = 0F; + break; + case VerticalAlign.Bottom: + yalignment = 1F; + break; + } + Control.SetAlignment(xalignment, yalignment); + Control.Justify = horizontalAlign.ToGtk(); + } + + public VerticalAlign VerticalAlign + { + get { return verticalAlign; } + set + { + verticalAlign = value; + SetAlignment(); + } + } + + public override Font Font + { + get { return base.Font; } + set + { + base.Font = value; + Control.Attributes = value != null ? ((FontHandler)value.Handler).Attributes : null; + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/LinkButtonHandler.cs b/Source/Eto.Gtk/Forms/Controls/LinkButtonHandler.cs new file mode 100644 index 0000000000..6a3280854e --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/LinkButtonHandler.cs @@ -0,0 +1,86 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using System.Linq; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class LinkButtonHandler : GtkControl, LinkButton.IHandler + { + + Gtk.EventBox box; + + public override Gtk.Widget ContainerControl + { + get { return box; } + } + + public LinkButtonHandler() + { + Control = new Gtk.LinkButton(string.Empty); + Control.SetAlignment(0f, .5f); + Control.TooltipText = null; + box = new Gtk.EventBox(); + box.Child = Control; + } + + public Color TextColor + { + get { return Control.Style.Foreground(Gtk.StateType.Normal).ToEto(); } + set + { + Control.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); + Control.ModifyText(Gtk.StateType.Normal, value.ToGdk()); + Control.Child.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); + Control.Child.ModifyText(Gtk.StateType.Normal, value.ToGdk()); + } + } + + public Color DisabledTextColor + { + get { return Control.Style.Foreground(Gtk.StateType.Insensitive).ToEto(); } + set + { + Control.ModifyFg(Gtk.StateType.Insensitive, value.ToGdk()); + Control.Child.ModifyFg(Gtk.StateType.Insensitive, value.ToGdk()); + } + } + + public override string Text + { + get { return Control.Label; } + set { Control.Label = value; } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case LinkButton.ClickEvent: + Control.Clicked += Connector.HandleClicked; + break; + default: + base.AttachEvent(id); + break; + } + } + + protected new LinkButtonConnector Connector { get { return (LinkButtonConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new LinkButtonConnector(); + } + + protected class LinkButtonConnector : GtkControlConnector + { + public new LinkButtonHandler Handler { get { return (LinkButtonHandler)base.Handler; } } + + public void HandleClicked(object sender, EventArgs e) + { + Handler.Callback.OnClick(Handler.Widget, EventArgs.Empty); + } + } + + } +} \ No newline at end of file diff --git a/Source/Eto.Gtk/Forms/Controls/ListBoxHandler.cs b/Source/Eto.Gtk/Forms/Controls/ListBoxHandler.cs new file mode 100644 index 0000000000..f88023fbc6 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/ListBoxHandler.cs @@ -0,0 +1,238 @@ +using System; +using Eto.Forms; +using Eto.GtkSharp.Drawing; +using Eto.Drawing; +using System.Linq; +using System.Collections.Generic; +using System.Collections; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class ListBoxHandler : GtkControl, ListBox.IHandler, IGtkEnumerableModelHandler + { + readonly Gtk.ScrolledWindow scroll; + GtkEnumerableModel model; + ContextMenu contextMenu; + CollectionHandler collection; + public static Size MaxImageSize = new Size(16, 16); + + public override Gtk.Widget ContainerControl + { + get { return scroll; } + } + + public ListBoxHandler() + { + model = new GtkEnumerableModel{ Handler = this }; + + scroll = new Gtk.ScrolledWindow(); + scroll.ShadowType = Gtk.ShadowType.In; + Control = new Gtk.TreeView(new Gtk.TreeModelAdapter(model)); + Size = new Size(80, 80); + //tree.FixedHeightMode = true; + Control.ShowExpanders = false; + scroll.Add(Control); + + Control.Events |= Gdk.EventMask.ButtonPressMask; + + Control.AppendColumn("Img", new Gtk.CellRendererPixbuf(), "pixbuf", 1); + Control.AppendColumn("Data", new Gtk.CellRendererText(), "text", 0); + Control.HeadersVisible = false; + } + + protected override void Initialize() + { + base.Initialize(); + Control.ButtonPressEvent += Connector.HandleTreeButtonPressEvent; + Control.Selection.Changed += Connector.HandleSelectionChanged; + Control.RowActivated += Connector.HandleTreeRowActivated; + } + + protected new ListBoxEventConnector Connector { get { return (ListBoxEventConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ListBoxEventConnector(); + } + + protected class ListBoxEventConnector : GtkControlConnector + { + public new ListBoxHandler Handler { get { return (ListBoxHandler)base.Handler; } } + + [GLib.ConnectBefore] + public void HandleTreeButtonPressEvent(object o, Gtk.ButtonPressEventArgs args) + { + if (Handler.contextMenu != null && args.Event.Button == 3 && args.Event.Type == Gdk.EventType.ButtonPress) + { + var menu = (Gtk.Menu)Handler.contextMenu.ControlObject; + menu.Popup(); + menu.ShowAll(); + } + } + + public void HandleSelectionChanged(object sender, EventArgs e) + { + Handler.Callback.OnSelectedIndexChanged(Handler.Widget, EventArgs.Empty); + } + + public void HandleTreeRowActivated(object o, Gtk.RowActivatedArgs args) + { + Handler.Callback.OnActivated(Handler.Widget, EventArgs.Empty); + } + } + + public int SelectedIndex + { + get + { + Gtk.TreeIter iter; + + if (Control.Selection != null && Control.Selection.GetSelected(out iter)) + { + var val = model.NodeFromIter(iter); + if (val >= 0) + return val; + } + + return -1; + } + set + { + if (value == -1) + { + if (Control.Selection != null) + Control.Selection.UnselectAll(); + return; + } + var path = new Gtk.TreePath(); + path.AppendIndex(value); + Gtk.TreeViewColumn focus_column = Control.Columns[0]; + + Control.SetCursor(path, focus_column, false); + } + } + + public ContextMenu ContextMenu + { + get { return contextMenu; } + set { contextMenu = value; } + } + + public GLib.Value GetColumnValue(object item, int column, int row) + { + switch (column) + { + case 0: + return new GLib.Value(Widget.TextBinding.GetValue(item)); + case 1: + if (Widget.ImageBinding != null) + { + var img = Widget.ImageBinding.GetValue(item); + if (img != null) + { + var imgHandler = img.Handler as IGtkPixbuf; + if (imgHandler != null) + return new GLib.Value(imgHandler.GetPixbuf(MaxImageSize)); + } + } + return new GLib.Value((Gdk.Pixbuf)null); + default: + throw new InvalidOperationException(); + } + } + + public class CollectionHandler : EnumerableChangedHandler + { + public ListBoxHandler Handler { get; set; } + + protected override void OnRegisterCollection(EventArgs e) + { + Handler.model = new GtkEnumerableModel{ Handler = Handler, Count = Count }; + Handler.Control.Model = new Gtk.TreeModelAdapter(Handler.model); + } + + protected override void OnUnregisterCollection(EventArgs e) + { + Handler.Control.Model = null; + } + + public override void AddItem(object item) + { + var count = Count; + var iter = Handler.model.GetIterAtRow(count); + var path = Handler.model.GetPathAtRow(count); + Handler.model.Count++; + Handler.Control.Model.EmitRowInserted(path, iter); + } + + public override void InsertItem(int index, object item) + { + var iter = Handler.model.GetIterAtRow(index); + var path = Handler.model.GetPathAtRow(index); + Handler.model.Count++; + Handler.Control.Model.EmitRowInserted(path, iter); + } + + public override void RemoveItem(int index) + { + var path = Handler.model.GetPathAtRow(index); + Handler.model.Count--; + Handler.Control.Model.EmitRowDeleted(path); + } + + public override void RemoveAllItems() + { + Handler.model = new GtkEnumerableModel{ Handler = Handler }; + Handler.Control.Model = new Gtk.TreeModelAdapter(Handler.model); + } + } + + public IEnumerable DataStore + { + get { return collection != null ? collection.Collection : null; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler{ Handler = this }; + collection.Register(value); + } + } + + public int NumberOfColumns + { + get { return 2; } + } + + public int GetRowOfItem(object item) + { + return collection == null ? -1 : collection.IndexOf(item); + } + + EnumerableChangedHandler IGtkEnumerableModelHandler.Collection + { + get { return collection; } + } + + public Gtk.CellRendererText TextCell + { + get { return ((Gtk.CellRendererText)Control.Columns[1].Cells[0]); } + } + + public Color TextColor + { + get { return TextCell.ForegroundGdk.ToEto(); } + set + { + TextCell.ForegroundGdk = value.ToGdk(); + Control.QueueDraw(); + } + } + + public override Color BackgroundColor + { + get { return Control.Style.Base(Gtk.StateType.Normal).ToEto(); } + set { Control.ModifyBase(Gtk.StateType.Normal, value.ToGdk()); } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/NativeControlHandler.cs b/Source/Eto.Gtk/Forms/Controls/NativeControlHandler.cs new file mode 100644 index 0000000000..3303f322fb --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/NativeControlHandler.cs @@ -0,0 +1,14 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class NativeControlHandler : GtkControl + { + public NativeControlHandler(Gtk.Widget nativeControl) + { + Control = nativeControl; + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/NumericUpDownHandler.cs b/Source/Eto.Gtk/Forms/Controls/NumericUpDownHandler.cs new file mode 100644 index 0000000000..44416de1da --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/NumericUpDownHandler.cs @@ -0,0 +1,100 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class NumericUpDownHandler : GtkControl, NumericUpDown.IHandler + { + public NumericUpDownHandler() + { + Control = new Gtk.SpinButton(double.MinValue, double.MaxValue, 1); + Control.WidthRequest = 80; + Control.Wrap = true; + Value = 0; + } + + protected override void Initialize() + { + base.Initialize(); + Control.ValueChanged += Connector.HandleValueChanged; + } + + protected new NumericUpDownConnector Connector { get { return (NumericUpDownConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new NumericUpDownConnector(); + } + + protected class NumericUpDownConnector : GtkControlConnector + { + public new NumericUpDownHandler Handler { get { return (NumericUpDownHandler)base.Handler; } } + + public void HandleValueChanged(object sender, EventArgs e) + { + Handler.Callback.OnValueChanged(Handler.Widget, EventArgs.Empty); + } + } + public override string Text + { + get { return Control.Text; } + set { Control.Text = value; } + } + + public bool ReadOnly + { + get { return !Control.IsEditable; } + set { Control.IsEditable = !value; } + } + + public double Value + { + get { return Control.Value; } + set { Control.Value = value; } + } + + public double MaxValue + { + get { return Control.Adjustment.Upper; } + set { Control.Adjustment.Upper = value; } + } + + public double MinValue + { + get { return Control.Adjustment.Lower; } + set { Control.Adjustment.Lower = value; } + } + + public double Increment + { + get { + double step, page; + Control.GetIncrements(out step, out page); + return step; + } + set + { + Control.SetIncrements(value, value * 2); + } + } + + public int DecimalPlaces + { + get { return (int)Control.Digits; } + set { Control.Digits = (uint)value; } + } + + public Color TextColor + { + get { return Control.Style.Text(Gtk.StateType.Normal).ToEto(); } + set { Control.ModifyText(Gtk.StateType.Normal, value.ToGdk()); } + } + + public override Color BackgroundColor + { + get { return Control.Style.Base(Gtk.StateType.Normal).ToEto(); } + set { Control.ModifyBase(Gtk.StateType.Normal, value.ToGdk()); } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/PanelHandler.cs b/Source/Eto.Gtk/Forms/Controls/PanelHandler.cs new file mode 100644 index 0000000000..17e938d4f0 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/PanelHandler.cs @@ -0,0 +1,22 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class PanelHandler : GtkPanel, Panel.IHandler + { + readonly Gtk.VBox box; + + public PanelHandler() + { + Control = new Gtk.EventBox(); + //Control.VisibleWindow = false; // can't use this as it causes overlapping widgets + box = new Gtk.VBox(); + Control.Add(box); + } + + protected override void SetContainerContent(Gtk.Widget content) + { + box.Add(content); + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/PasswordBoxHandler.cs b/Source/Eto.Gtk/Forms/Controls/PasswordBoxHandler.cs new file mode 100644 index 0000000000..d7f8e24b9f --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/PasswordBoxHandler.cs @@ -0,0 +1,83 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class PasswordBoxHandler : GtkControl, PasswordBox.IHandler + { + public PasswordBoxHandler() + { + Control = new Gtk.Entry(); + Control.Visibility = false; + Control.SetSizeRequest(20, -1); + Control.ActivatesDefault = true; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + Control.Changed += Connector.HandleTextChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + protected new PasswordBoxConnector Connector { get { return (PasswordBoxConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new PasswordBoxConnector(); + } + + protected class PasswordBoxConnector : GtkControlConnector + { + public new PasswordBoxHandler Handler { get { return (PasswordBoxHandler)base.Handler; } } + + public void HandleTextChanged(object sender, EventArgs e) + { + Handler.Callback.OnTextChanged(Handler.Widget, EventArgs.Empty); + } + } + + public char PasswordChar + { + get { return Control.InvisibleChar; } + set { Control.InvisibleChar = value; } + } + + public override string Text + { + get { return Control.Text; } + set { Control.Text = value ?? string.Empty; } + } + + public Color TextColor + { + get { return Control.Style.Text(Gtk.StateType.Normal).ToEto(); } + set { Control.ModifyText(Gtk.StateType.Normal, value.ToGdk()); } + } + + public bool ReadOnly + { + get { return !Control.IsEditable; } + set { Control.IsEditable = !value; } + } + + public int MaxLength + { + get { return Control.MaxLength; } + set { Control.MaxLength = value; } + } + + public override Color BackgroundColor + { + get { return Control.Style.Base(Gtk.StateType.Normal).ToEto(); } + set { Control.ModifyBase(Gtk.StateType.Normal, value.ToGdk()); } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/ProgressBarHandler.cs b/Source/Eto.Gtk/Forms/Controls/ProgressBarHandler.cs new file mode 100644 index 0000000000..9ca8764c69 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/ProgressBarHandler.cs @@ -0,0 +1,106 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class ProgressBarHandler : GtkControl, ProgressBar.IHandler + { + int minValue; + int maxValue = 100; + bool indeterminate; + UITimer timer; + public static double UpdateInterval = 0.2; + public static double PulseStep = 0.1; + + public ProgressBarHandler() + { + this.Control = new Gtk.ProgressBar + { + Fraction = 0 + }; + } + + protected new ProgressBarConnector Connector { get { return (ProgressBarConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ProgressBarConnector(); + } + + protected class ProgressBarConnector : GtkControlConnector + { + public new ProgressBarHandler Handler { get { return (ProgressBarHandler)base.Handler; } } + + public void TimerElapsed(object sender, EventArgs e) + { + var timer = (UITimer)sender; + var handler = Handler; + if (handler != null) + handler.Control.Pulse(); + else + timer.Stop(); + } + } + + public bool Indeterminate + { + get { return indeterminate; } + set + { + indeterminate = value; + if (indeterminate) + { + if (timer == null) + { + timer = new UITimer(); + timer.Elapsed += Connector.TimerElapsed; + } + timer.Interval = UpdateInterval; + Control.PulseStep = PulseStep; + timer.Start(); + } + else if (timer != null) + timer.Stop(); + } + } + + public int MaxValue + { + get { return maxValue; } + set + { + var val = Value; + maxValue = value; + Value = val; + } + } + + public int MinValue + { + get { return minValue; } + set + { + var val = Value; + minValue = value; + Value = val; + } + } + + public int Value + { + get { return (int)((Control.Fraction * MaxValue) + MinValue); } + set + { + Control.Fraction = Math.Max(0, Math.Min(1, ((double)value - MinValue) / (double)MaxValue)); + } + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (timer != null) + timer.Stop(); + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/RadioButtonHandler.cs b/Source/Eto.Gtk/Forms/Controls/RadioButtonHandler.cs new file mode 100644 index 0000000000..a0105b0bc7 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/RadioButtonHandler.cs @@ -0,0 +1,80 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class RadioButtonHandler : GtkControl, RadioButton.IHandler + { + Gtk.EventBox box; + Gtk.AccelLabel label; + + protected override Gtk.Widget FontControl + { + get { return label; } + } + + public override Gtk.Widget ContainerControl + { + get { return box; } + } + + public void Create(RadioButton controller) + { + if (controller != null) + Control = new Gtk.RadioButton(RadioButtonHandler.GetControl(controller)); + else + { + Control = new Gtk.RadioButton((Gtk.RadioButton)null); + // make gtk work like others in that no radio button is initially selected + var inactive = new Gtk.RadioButton(Control); + inactive.Active = true; + } + label = new Gtk.AccelLabel(""); + Control.Add(label); //control.AddMnemonicLabel(label); + Control.Toggled += Connector.HandleCheckedChanged; + box = new Gtk.EventBox(); + box.Child = Control; + } + + protected new RadioButtonConnector Connector { get { return (RadioButtonConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new RadioButtonConnector(); + } + + protected class RadioButtonConnector : GtkControlConnector + { + public new RadioButtonHandler Handler { get { return (RadioButtonHandler)base.Handler; } } + + public void HandleCheckedChanged(object sender, EventArgs e) + { + Handler.Callback.OnCheckedChanged(Handler.Widget, EventArgs.Empty); + } + } + + public override string Text + { + get { return MnuemonicToString(label.Text); } + set { label.TextWithMnemonic = StringToMnuemonic(value); } + } + + public bool Checked + { + get { return Control.Active; } + set { Control.Active = value; } + } + + public Color TextColor + { + get { return label.Style.Foreground(Gtk.StateType.Normal).ToEto(); } + set + { + label.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); + label.ModifyFg(Gtk.StateType.Active, value.ToGdk()); + label.ModifyFg(Gtk.StateType.Prelight, value.ToGdk()); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/ScrollableHandler.cs b/Source/Eto.Gtk/Forms/Controls/ScrollableHandler.cs new file mode 100644 index 0000000000..7525b36049 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/ScrollableHandler.cs @@ -0,0 +1,251 @@ +using System; +using Eto.Drawing; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class ScrollableHandler : GtkPanel, Scrollable.IHandler + { + readonly Gtk.Viewport vp; + readonly Gtk.HBox hbox; + readonly Gtk.VBox vbox; + BorderType border; + bool expandWidth = true; + bool expandHeight = true; + Gtk.Widget layoutWidget; + #if GTK2 + bool autoSize = true; + #endif + + public BorderType Border + { + get + { + return border; + } + set + { + border = value; + switch (border) + { + case BorderType.Bezel: + Control.ShadowType = Gtk.ShadowType.In; + break; + case BorderType.Line: + Control.ShadowType = Gtk.ShadowType.In; + break; + case BorderType.None: + Control.ShadowType = Gtk.ShadowType.None; + break; + default: + throw new NotSupportedException(); + } + } + } + + public ScrollableHandler() + { + Control = new Gtk.ScrolledWindow(); + vp = new Gtk.Viewport(); + hbox = new Gtk.HBox(); + vbox = new Gtk.VBox(); + vbox.PackStart(hbox, true, true, 0); + vp.Add(vbox); + + // autosize the scrolled window to the size of the content + Control.Add(vp); + vp.ShadowType = Gtk.ShadowType.None; + this.Border = BorderType.Bezel; + } + + protected override void Initialize() + { + base.Initialize(); +#if GTK2 + Control.SizeRequested += Connector.HandleControlSizeRequested; + vp.SizeRequested += Connector.HandleViewportSizeRequested; +#endif + Control.VScrollbar.VisibilityNotifyEvent += Connector.HandleScrollbarVisibilityChanged; + Control.HScrollbar.VisibilityNotifyEvent += Connector.HandleScrollbarVisibilityChanged; + } + + protected new ScrollableConnector Connector { get { return (ScrollableConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ScrollableConnector(); + } + + protected class ScrollableConnector : GtkPanelEventConnector + { + public new ScrollableHandler Handler { get { return (ScrollableHandler)base.Handler; } } +#if GTK2 + public void HandleControlSizeRequested(object o, Gtk.SizeRequestedArgs args) + { + if (Handler.autoSize) + { + args.Requisition = Handler.vp.SizeRequest(); + } + } + + public void HandleViewportSizeRequested(object o, Gtk.SizeRequestedArgs args) + { + var handler = Handler; + if (handler != null) + { + var viewport = (Gtk.Viewport)o; + if (handler.autoSize) + { + var size = viewport.SizeRequest(); + //Console.WriteLine ("Autosizing to {0}x{1}", size.Width, size.Height); + args.Requisition = size; + } + } + } +#endif + public void HandleScrollbarVisibilityChanged(object sender, EventArgs e) + { + Handler.Callback.OnSizeChanged(Handler.Widget, EventArgs.Empty); + } + + public void HandleScrollableScrollEvent(object o, Gtk.ScrollEventArgs args) + { + var pos = new Point((int)args.Event.X, (int)args.Event.Y); + Handler.Callback.OnScroll(Handler.Widget, new ScrollEventArgs(pos)); + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Scrollable.ScrollEvent: + Control.Events |= Gdk.EventMask.ScrollMask; + Control.ScrollEvent += Connector.HandleScrollableScrollEvent; + break; + default: + base.AttachEvent(id); + break; + } + } + + #if GTK2 + public override Size Size + { + get { return base.Size; } + set + { + base.Size = value; + autoSize = false; + } + } + #endif + + protected override void SetContainerContent(Gtk.Widget content) + { + layoutWidget = content; + hbox.PackStart(content, false, true, 0); + SetPacking(); + } + + void SetPacking() + { + if (layoutWidget != null) + hbox.SetChildPacking(layoutWidget, expandWidth, expandWidth, 0, Gtk.PackType.Start); + vbox.SetChildPacking(hbox, expandHeight, expandHeight, 0, Gtk.PackType.Start); + } + + protected override void SetBackgroundColor(Color? color) + { + if (color != null) + vp.ModifyBg(Gtk.StateType.Normal, color.Value.ToGdk()); + else + vp.ModifyBg(Gtk.StateType.Normal); + } + + public override Size ClientSize + { + get + { + Gdk.Rectangle rect = vp.Allocation; + int spacing = Convert.ToInt32(Control.StyleGetProperty("scrollbar-spacing")) + 1; + return new Size(rect.Width - spacing, rect.Height - spacing); + } + set + { + int spacing = Convert.ToInt32(Control.StyleGetProperty("scrollbar-spacing")) + 1; + vp.SetSizeRequest(value.Width + spacing, value.Height + spacing); + } + } + + public void UpdateScrollSizes() + { + Control.CheckResize(); + vp.CheckResize(); + } + + public Point ScrollPosition + { + get { return new Point((int)vp.Hadjustment.Value, (int)vp.Vadjustment.Value); } + set + { + Size clientSize = ClientSize; + Size scrollSize = ScrollSize; + vp.Hadjustment.Value = Math.Min(value.X, scrollSize.Width - clientSize.Width); + vp.Vadjustment.Value = Math.Min(value.Y, scrollSize.Height - clientSize.Height); + } + } + + public Size ScrollSize + { + get + { + //return scrollSize; + return new Size((int)(vp.Hadjustment.Upper), (int)(vp.Vadjustment.Upper)); + } + set + { + //scrollSize = value; + vp.Hadjustment.Upper = value.Width; + vp.Vadjustment.Upper = value.Height; + } + } + + public Rectangle VisibleRect + { + get { return new Rectangle(ScrollPosition, Size.Min(ScrollSize, ClientSize)); } + } + + public bool ExpandContentWidth + { + get { return expandWidth; } + set + { + if (expandWidth != value) + { + expandWidth = value; + SetPacking(); + } + } + } + + public bool ExpandContentHeight + { + get { return expandHeight; } + set + { + if (expandHeight != value) + { + expandHeight = value; + SetPacking(); + } + } + } + + public float MinimumZoom { get { return 1f; } set { } } + + public float MaximumZoom { get { return 1f; } set { } } + + public float Zoom { get { return 1f; } set { } } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/SearchBoxHandler.cs b/Source/Eto.Gtk/Forms/Controls/SearchBoxHandler.cs new file mode 100644 index 0000000000..c21d952dd0 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/SearchBoxHandler.cs @@ -0,0 +1,9 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class SearchBoxHandler : TextBoxHandler, SearchBox.IHandler + { + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/SliderHandler.cs b/Source/Eto.Gtk/Forms/Controls/SliderHandler.cs new file mode 100644 index 0000000000..f67afa9e6b --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/SliderHandler.cs @@ -0,0 +1,128 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class SliderHandler : GtkControl, Slider.IHandler + { + int min; + int max = 100; + int tick = 1; + Gtk.Scale scale; + + public SliderHandler() + { + this.Control = new Gtk.EventBox(); + //Control.VisibleWindow = false; + scale = new Gtk.HScale(min, max, 1); + this.Control.Child = scale; + } + + protected override void Initialize() + { + base.Initialize(); + scale.ValueChanged += Connector.HandleScaleValueChanged; + } + + protected new SliderConnector Connector { get { return (SliderConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new SliderConnector(); + } + + protected class SliderConnector : GtkControlConnector + { + int? lastValue; + + public new SliderHandler Handler { get { return (SliderHandler)base.Handler; } } + + public void HandleScaleValueChanged(object sender, EventArgs e) + { + var scale = Handler.scale; + var tick = Handler.tick; + var value = (int)scale.Value; + var offset = value % tick; + if (Handler.SnapToTick && offset != 0) + { + if (offset > tick / 2) + scale.Value = value - offset + tick; + else + scale.Value -= offset; + } + else if (lastValue == null || lastValue.Value != value) + { + Handler.Callback.OnValueChanged(Handler.Widget, EventArgs.Empty); + lastValue = value; + } + } + } + + public int MaxValue + { + get { return max; } + set + { + max = value; + scale.SetRange(min, max); + } + } + + public int MinValue + { + get { return min; } + set + { + min = value; + scale.SetRange(min, max); + } + } + + public int Value + { + get { return (int)scale.Value; } + set { scale.Value = value; } + } + + public bool SnapToTick { get; set; } + + public int TickFrequency + { + get + { + return tick; + } + set + { + tick = value; + // TODO: Only supported from GTK 2.16 + } + } + + public SliderOrientation Orientation + { + get + { + return (scale is Gtk.HScale) ? SliderOrientation.Horizontal : SliderOrientation.Vertical; + } + set + { + if (Orientation != value) + { + scale.ValueChanged -= Connector.HandleScaleValueChanged; + Control.Remove(scale); + scale.Destroy(); + scale.Dispose(); + if (value == SliderOrientation.Horizontal) + scale = new Gtk.HScale(min, max, 1); + else + scale = new Gtk.VScale(min, max, 1); + scale.ValueChanged += Connector.HandleScaleValueChanged; + Control.Child = scale; + scale.ShowAll(); + } + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/SpinnerHandler.cs b/Source/Eto.Gtk/Forms/Controls/SpinnerHandler.cs new file mode 100644 index 0000000000..b0c89f6954 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/SpinnerHandler.cs @@ -0,0 +1,48 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class SpinnerHandler : GtkControl, Spinner.IHandler + { + bool enabled; + public SpinnerHandler() + { + Control = new Gtk.Spinner(); + } + + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + if (enabled) + Control.Start(); + } + + public override void OnUnLoad(EventArgs e) + { + base.OnUnLoad(e); + if (enabled) + Control.Stop(); + } + + public override bool Enabled + { + get { return enabled; } + set + { + if (enabled != value) + { + enabled = value; + if (Widget.Loaded) + { + if (enabled) + Control.Start(); + else + Control.Stop(); + } + } + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/SplitterHandler.cs b/Source/Eto.Gtk/Forms/Controls/SplitterHandler.cs new file mode 100644 index 0000000000..c2a9880af4 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/SplitterHandler.cs @@ -0,0 +1,159 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class SplitterHandler : GtkContainer, Splitter.IHandler + { + readonly Gtk.EventBox container; + Control panel1; + Control panel2; + SplitterOrientation orientation; + SplitterFixedPanel fixedPanel; + int? position; + + class EtoHPaned : Gtk.HPaned + { + #if GTK2 + protected override void OnSizeRequested(ref Gtk.Requisition requisition) + { + base.OnSizeRequested(ref requisition); + if (PositionSet && Child1 != null) + { + var childreq = Child1.Requisition; + if (childreq.Width > 0) + requisition.Width += Position - childreq.Width; + } + } + #endif + } + + class EtoVPaned : Gtk.VPaned + { + #if GTK2 + protected override void OnSizeRequested(ref Gtk.Requisition requisition) + { + base.OnSizeRequested(ref requisition); + if (PositionSet && Child1 != null) + { + var childreq = Child1.Requisition; + if (childreq.Height > 0) + requisition.Height += Position - childreq.Height; + } + } + #endif + } + + public override Gtk.Widget ContainerControl + { + get { return container; } + } + + public SplitterHandler() + { + container = new Gtk.EventBox(); + Create(); + } + + public int Position + { + get { return Control.Position; } + set { position = Control.Position = value; } + } + + public SplitterFixedPanel FixedPanel + { + get { return fixedPanel; } + set + { + if (fixedPanel != value) + { + fixedPanel = value; + Create(); + } + } + } + + public SplitterOrientation Orientation + { + get { return (Control is Gtk.HPaned) ? SplitterOrientation.Horizontal : SplitterOrientation.Vertical; } + set + { + if (orientation != value) + { + orientation = value; + Create(); + } + } + } + + void Create() + { + Gtk.Paned old = Control; + if (orientation == SplitterOrientation.Horizontal) + Control = new EtoHPaned(); + else + Control = new EtoVPaned(); + if (container.Child != null) + container.Remove(container.Child); + container.Child = Control; + if (old != null) + { + var child1 = old.Child1; + var child2 = old.Child2; + old.Remove(child2); + old.Remove(child1); + Control.Pack1(child1 ?? EmptyContainer(), fixedPanel != SplitterFixedPanel.Panel1, true); + Control.Pack2(child2 ?? EmptyContainer(), fixedPanel != SplitterFixedPanel.Panel2, true); + old.Destroy(); + } + else + { + Control.Pack1(EmptyContainer(), fixedPanel != SplitterFixedPanel.Panel1, true); + Control.Pack2(EmptyContainer(), fixedPanel != SplitterFixedPanel.Panel2, true); + } + if (position != null) + Control.Position = position.Value; + } + + static Gtk.Widget EmptyContainer() + { + var bin = new Gtk.VBox(); + return bin; + } + + public Control Panel1 + { + get { return panel1; } + set + { + panel1 = value; + var setposition = position != null && (Control.Child1 == null || Control.Child2 == null); + if (Control.Child1 != null) + Control.Remove(Control.Child1); + var widget = panel1 != null ? panel1.GetContainerWidget() : EmptyContainer(); + Control.Pack1(widget, fixedPanel != SplitterFixedPanel.Panel1, true); + if (setposition) + Control.Position = position.Value; + widget.ShowAll(); + } + } + + public Control Panel2 + { + get { return panel2; } + set + { + panel2 = value; + var setposition = position != null && (Control.Child1 == null || Control.Child2 == null); + if (Control.Child2 != null) + Control.Remove(Control.Child2); + var widget = panel2 != null ? panel2.GetContainerWidget() : EmptyContainer(); + Control.Pack2(widget, fixedPanel != SplitterFixedPanel.Panel2, true); + if (setposition) + Control.Position = position.Value; + widget.ShowAll(); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/TabControlHandler.cs b/Source/Eto.Gtk/Forms/Controls/TabControlHandler.cs new file mode 100644 index 0000000000..7b93b1e1c7 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/TabControlHandler.cs @@ -0,0 +1,84 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class TabControlHandler : GtkContainer, TabControl.IHandler + { + public TabControlHandler() + { + Control = new Gtk.Notebook(); + } + + protected override void Initialize() + { + base.Initialize(); + Control.SwitchPage += Connector.HandleSwitchPage; + } + + protected override bool IsTransparentControl + { + get { return false; } + } + + protected override Color DefaultBackgroundColor + { + get { return ContainerContentControl.Style.Base(Gtk.StateType.Normal).ToEto(); } + } + + protected new TabControlConnector Connector { get { return (TabControlConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new TabControlConnector(); + } + + protected class TabControlConnector : GtkControlConnector + { + public new TabControlHandler Handler { get { return (TabControlHandler)base.Handler; } } + + public void HandleSwitchPage(object o, Gtk.SwitchPageArgs args) + { + var handler = Handler; + if (handler != null && handler.Widget.Loaded) + handler.Callback.OnSelectedIndexChanged(handler.Widget, EventArgs.Empty); + } + } + + public int SelectedIndex + { + get { return Control.CurrentPage; } + set { Control.CurrentPage = value; } + } + + public void InsertTab(int index, TabPage page) + { + var pageHandler = (TabPageHandler)page.Handler; + + if (Widget.Loaded) + { + pageHandler.ContainerControl.ShowAll(); + pageHandler.LabelControl.ShowAll(); + } + + if (index == -1) + Control.AppendPage(pageHandler.ContainerControl, pageHandler.LabelControl); + else + Control.InsertPage(pageHandler.ContainerControl, pageHandler.LabelControl, index); + } + + public void ClearTabs() + { + while (Control.NPages > 0) + Control.RemovePage(0); + } + + public void RemoveTab(int index, TabPage page) + { + Control.RemovePage(index); + if (Widget.Loaded && Control.NPages == 0) + Callback.OnSelectedIndexChanged(Widget, EventArgs.Empty); + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/TabPageHandler.cs b/Source/Eto.Gtk/Forms/Controls/TabPageHandler.cs new file mode 100644 index 0000000000..9d104b74eb --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/TabPageHandler.cs @@ -0,0 +1,79 @@ +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class TabPageHandler : GtkPanel, TabPage.IHandler + { + Gtk.Label label; + readonly Gtk.HBox tab; + Gtk.Image gtkimage; + Image image; + public static Size MaxImageSize = new Size(16, 16); + + public TabPageHandler() + { + Control = new Gtk.VBox(); + tab = new Gtk.HBox(); + label = new Gtk.Label(); + tab.PackEnd(label, true, true, 0); + tab.ShowAll(); + } + + public Gtk.Widget LabelControl + { + get { return tab; } + } + + protected override void SetContainerContent(Gtk.Widget content) + { + Control.PackStart(content, true, true, 0); + } + + public Image Image + { + get { return image; } + set + { + if (gtkimage == null) + { + gtkimage = new Gtk.Image(); + tab.PackStart(gtkimage, true, true, 0); + } + image = value; + if (image != null) + { + var imagehandler = (IGtkPixbuf)image.Handler; + gtkimage.Pixbuf = imagehandler.GetPixbuf(MaxImageSize); + gtkimage.ShowAll(); + } + else + { + gtkimage.Visible = false; + gtkimage.Pixbuf = null; + } + + } + } + + public override string Text + { + get { return MnuemonicToString(label.Text); } + set { label.TextWithMnemonic = StringToMnuemonic(value); } + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (disposing) + { + if (label != null) + { + label.Dispose(); + label = null; + } + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/TextAreaHandler.cs b/Source/Eto.Gtk/Forms/Controls/TextAreaHandler.cs new file mode 100644 index 0000000000..3a69fb7b3b --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/TextAreaHandler.cs @@ -0,0 +1,308 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class TextAreaHandler : GtkControl, TextArea.IHandler + { + bool sendSelectionChanged = true; + readonly Gtk.ScrolledWindow scroll; + Gtk.TextTag tag; + + public override Gtk.Widget ContainerControl + { + get { return scroll; } + } + + public override Size DefaultSize { get { return TextArea.DefaultSize; } } + + public TextAreaHandler() + { + scroll = new Gtk.ScrolledWindow(); + scroll.ShadowType = Gtk.ShadowType.In; + Control = new Gtk.TextView(); + Size = TextArea.DefaultSize; + scroll.Add(Control); + Wrap = true; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + Control.Buffer.Changed += Connector.HandleBufferChanged; + break; + case TextArea.SelectionChangedEvent: + Control.Buffer.MarkSet += Connector.HandleSelectionChanged; + break; + case TextArea.CaretIndexChangedEvent: + Control.Buffer.MarkSet += Connector.HandleCaretIndexChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + protected new TextAreaConnector Connector { get { return (TextAreaConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new TextAreaConnector(); + } + + protected class TextAreaConnector : GtkControlConnector + { + Range lastSelection; + int? lastCaretIndex; + + public new TextAreaHandler Handler { get { return (TextAreaHandler)base.Handler; } } + + public void HandleBufferChanged(object sender, EventArgs e) + { + Handler.Callback.OnTextChanged(Handler.Widget, EventArgs.Empty); + } + + public void HandleSelectionChanged(object o, Gtk.MarkSetArgs args) + { + var handler = Handler; + var selection = handler.Selection; + if (handler.sendSelectionChanged && selection != lastSelection) + { + handler.Callback.OnSelectionChanged(handler.Widget, EventArgs.Empty); + lastSelection = selection; + } + } + + public void HandleCaretIndexChanged(object o, Gtk.MarkSetArgs args) + { + var handler = Handler; + var caretIndex = handler.CaretIndex; + if (handler.sendSelectionChanged && caretIndex != lastCaretIndex) + { + handler.Callback.OnCaretIndexChanged(handler.Widget, EventArgs.Empty); + lastCaretIndex = caretIndex; + } + } + + public void HandleApplyTag(object sender, EventArgs e) + { + var buffer = Handler.Control.Buffer; + var tag = Handler.tag; + buffer.ApplyTag(tag, buffer.StartIter, buffer.EndIter); + } + } + + public override string Text + { + get { return Control.Buffer.Text; } + set + { + Control.Buffer.Text = value; + if (tag != null) + Control.Buffer.ApplyTag(tag, Control.Buffer.StartIter, Control.Buffer.EndIter); + } + } + + public virtual Color TextColor + { + get { return Control.Style.Foreground(Gtk.StateType.Normal).ToEto(); } + set + { + #if GTK2 + Control.ModifyText(Gtk.StateType.Normal, value.ToGdk()); + #else + Control.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); + #endif + } + } + + Color? backgroundColor; + + public override Color BackgroundColor + { + get + { + return backgroundColor ?? Colors.White; + } + set + { + backgroundColor = value; + if (backgroundColor != null) + { + #if GTK2 + Control.ModifyBase(Gtk.StateType.Normal, backgroundColor.Value.ToGdk()); + #else + Control.ModifyBg(Gtk.StateType.Normal, backgroundColor.Value.ToGdk()); + #endif + } + } + } + + public bool ReadOnly + { + get { return !Control.Editable; } + set { Control.Editable = !value; } + } + + public bool Wrap + { + get { return Control.WrapMode != Gtk.WrapMode.None; } + set { Control.WrapMode = value ? Gtk.WrapMode.WordChar : Gtk.WrapMode.None; } + } + + public void Append(string text, bool scrollToCursor) + { + var end = Control.Buffer.EndIter; + Control.Buffer.Insert(ref end, text); + if (scrollToCursor) + { + var mark = Control.Buffer.CreateMark(null, end, false); + Control.ScrollToMark(mark, 0, false, 0, 0); + } + } + + public string SelectedText + { + get + { + Gtk.TextIter start, end; + if (Control.Buffer.GetSelectionBounds(out start, out end)) + { + return Control.Buffer.GetText(start, end, false); + } + return null; + } + set + { + sendSelectionChanged = false; + Gtk.TextIter start, end; + if (Control.Buffer.GetSelectionBounds(out start, out end)) + { + var startOffset = start.Offset; + Control.Buffer.Delete(ref start, ref end); + if (value != null) + { + Control.Buffer.Insert(ref start, value); + start = Control.Buffer.GetIterAtOffset(startOffset); + end = Control.Buffer.GetIterAtOffset(startOffset + value.Length); + Control.Buffer.SelectRange(start, end); + } + } + else if (value != null) + Control.Buffer.InsertAtCursor(value); + if (tag != null) + Control.Buffer.ApplyTag(tag, Control.Buffer.StartIter, Control.Buffer.EndIter); + Callback.OnSelectionChanged(Widget, EventArgs.Empty); + sendSelectionChanged = true; + } + } + + public Range Selection + { + get + { + Gtk.TextIter start, end; + if (Control.Buffer.GetSelectionBounds(out start, out end)) + return new Range(start.Offset, end.Offset); + return new Range(Control.Buffer.CursorPosition, 0); + } + set + { + sendSelectionChanged = false; + var start = Control.Buffer.GetIterAtOffset(value.Start); + var end = Control.Buffer.GetIterAtOffset(value.End); + Control.Buffer.SelectRange(start, end); + Callback.OnSelectionChanged(Widget, EventArgs.Empty); + sendSelectionChanged = true; + } + } + + public void SelectAll() + { + Control.Buffer.SelectRange(Control.Buffer.StartIter, Control.Buffer.EndIter); + } + + public int CaretIndex + { + get { return Control.Buffer.GetIterAtMark(Control.Buffer.InsertMark).Offset; } + set + { + var ins = Control.Buffer.GetIterAtOffset(value); + Control.Buffer.SelectRange(ins, ins); + } + } + + public bool AcceptsTab + { + get { return Control.AcceptsTab; } + set { Control.AcceptsTab = value; } + } + + bool acceptsReturn = true; + + public bool AcceptsReturn + { + get { return acceptsReturn; } + set + { + if (value != acceptsReturn) + { + if (!acceptsReturn) + Widget.KeyDown -= HandleKeyDown; + //Control.KeyPressEvent -= PreventEnterKey; + acceptsReturn = value; + if (!acceptsReturn) + Widget.KeyDown += HandleKeyDown; + //Control.KeyPressEvent += PreventEnterKey; + } + } + } + + void HandleKeyDown (object sender, KeyEventArgs e) + { + if (e.KeyData == Keys.Enter) + e.Handled = true; + } + + static void PreventEnterKey(object o, Gtk.KeyPressEventArgs args) + { + if (args.Event.Key == Gdk.Key.Return) + args.RetVal = false; + } + + public override Font Font + { + get { return base.Font; } + set + { + base.Font = value; + if (value != null) + { + if (tag == null) + { + tag = new Gtk.TextTag("font"); + Control.Buffer.TagTable.Add(tag); + Control.Buffer.Changed += Connector.HandleApplyTag; + Control.Buffer.ApplyTag(tag, Control.Buffer.StartIter, Control.Buffer.EndIter); + } + value.Apply(tag); + } + else + { + Control.Buffer.RemoveAllTags(Control.Buffer.StartIter, Control.Buffer.EndIter); + } + } + } + + public HorizontalAlign HorizontalAlign + { + get { return Control.Justification.ToEto(); } + set { Control.Justification = value.ToGtk(); } + } + + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/TextBoxHandler.cs b/Source/Eto.Gtk/Forms/Controls/TextBoxHandler.cs new file mode 100644 index 0000000000..2278597c02 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/TextBoxHandler.cs @@ -0,0 +1,154 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class TextBoxHandler : GtkControl, TextBox.IHandler + { + string placeholderText; + + public TextBoxHandler() + { + Control = new Gtk.Entry(); + Control.SetSizeRequest(100, -1); + Control.ActivatesDefault = true; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + Control.Changed += Connector.HandleTextChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + protected new TextBoxConnector Connector { get { return (TextBoxConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new TextBoxConnector(); + } + + protected class TextBoxConnector : GtkControlConnector + { + public new TextBoxHandler Handler { get { return (TextBoxHandler)base.Handler; } } + + public void HandleTextChanged(object sender, EventArgs e) + { + Handler.Callback.OnTextChanged(Handler.Widget, EventArgs.Empty); + } + + #if GTK2 + + public void HandleExposeEvent(object o, Gtk.ExposeEventArgs args) + { + var control = Handler.Control; + if (!string.IsNullOrEmpty(control.Text) || args.Event.Window == control.GdkWindow) + return; + + if (Handler.placeholderLayout == null) + { + Handler.placeholderLayout = new Pango.Layout(control.PangoContext); + Handler.placeholderLayout.FontDescription = control.PangoContext.FontDescription.Copy(); + } + Handler.placeholderLayout.SetText(Handler.placeholderText); + + int currentHeight, currentWidth; + args.Event.Window.GetSize(out currentWidth, out currentHeight); + + int width, height; + Handler.placeholderLayout.GetPixelSize(out width, out height); + + var style = control.Style; + var bc = style.Base(Gtk.StateType.Normal); + var tc = style.Text(Gtk.StateType.Normal); + + using (var gc = new Gdk.GC(args.Event.Window)) + { + gc.Copy(style.TextGC(Gtk.StateType.Normal)); + + gc.RgbFgColor = new Gdk.Color((byte)(((int)bc.Red + tc.Red) / 2 / 256), (byte)(((int)bc.Green + (int)tc.Green) / 2 / 256), (byte)((bc.Blue + tc.Blue) / 2 / 256)); + + args.Event.Window.DrawLayout(gc, 2, (currentHeight - height) / 2 + 1, Handler.placeholderLayout); + } + } + #endif + } + #if GTK2 + Pango.Layout placeholderLayout; + public override Eto.Drawing.Font Font + { + get { return base.Font; } + set + { + base.Font = value; + placeholderLayout = null; + } + } + #else + protected override void SetBackgroundColor(Eto.Drawing.Color? color) + { + } + #endif + + public override string Text + { + get { return Control.Text; } + set { Control.Text = value ?? string.Empty; } + } + + public bool ReadOnly + { + get { return !Control.IsEditable; } + set { Control.IsEditable = !value; } + } + + public int MaxLength + { + get { return Control.MaxLength; } + set { Control.MaxLength = value; } + } + + public string PlaceholderText + { + get { return placeholderText; } + set + { +#if GTK2 + if (!string.IsNullOrEmpty(placeholderText)) + Control.ExposeEvent -= Connector.HandleExposeEvent; + placeholderText = value; + if (!string.IsNullOrEmpty(placeholderText)) + Control.ExposeEvent += Connector.HandleExposeEvent; +#else + placeholderText = value; +#endif + } + } + + public void SelectAll() + { + Control.GrabFocus(); + if (!string.IsNullOrEmpty(Control.Text)) + Control.SelectRegion(0, Control.Text.Length); + } + + public Color TextColor + { + get { return Control.Style.Text(Gtk.StateType.Normal).ToEto(); } + set { Control.ModifyText(Gtk.StateType.Normal, value.ToGdk()); } + } + + public override Color BackgroundColor + { + get { return Control.Style.Base(Gtk.StateType.Normal).ToEto(); } + set { Control.ModifyBase(Gtk.StateType.Normal, value.ToGdk()); } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Controls/TreeGridViewHandler.cs b/Source/Eto.Gtk/Forms/Controls/TreeGridViewHandler.cs new file mode 100644 index 0000000000..c7c58212ff --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/TreeGridViewHandler.cs @@ -0,0 +1,320 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using Eto.GtkSharp.Forms.Cells; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class TreeGridViewHandler : GridHandler, TreeGridView.IHandler, ICellDataSource, IGtkListModelHandler> + { + protected new TreeGridView.ICallback Callback { get { return (TreeGridView.ICallback)base.Callback; } } + + GtkTreeModel> model; + CollectionHandler collection; + bool? selectCollapsingItem; + ITreeGridItem lastSelected; + + protected override void Initialize() + { + base.Initialize(); + + // these are always handled to set the expanded property + HandleEvent(TreeGridView.ExpandedEvent); + HandleEvent(TreeGridView.CollapsedEvent); + HandleEvent(TreeGridView.CollapsingEvent); + } + + protected override ITreeModelImplementor CreateModelImplementor() + { + model = new GtkTreeModel> { Handler = this }; + return model; + } + + public class CollectionHandler : DataStoreChangedHandler> + { + WeakReference handler; + public TreeGridViewHandler Handler { get { return (TreeGridViewHandler)handler.Target; } set { handler = new WeakReference(value); } } + + void ExpandItems(ITreeGridStore store, Gtk.TreePath path) + { + for (int i = 0; i < store.Count; i++) + { + var item = store[i]; + if (item.Expandable && item.Expanded) + { + var newpath = path.Copy(); + newpath.AppendIndex(i); + Handler.Tree.ExpandToPath(newpath); + ExpandItems((ITreeGridStore)item, newpath); + } + } + } + + void ExpandItems() + { + var store = Handler.collection.Collection; + var path = new Gtk.TreePath(); + ExpandItems(store, path); + } + + public override void AddRange(IEnumerable items) + { + Handler.UpdateModel(); + ExpandItems(); + } + + public override void AddItem(ITreeGridItem item) + { + var path = new Gtk.TreePath(); + path.AppendIndex(Collection.Count); + var iter = Handler.model.GetIterFromItem(item, path); + Handler.Tree.Model.EmitRowInserted(path, iter); + } + + public override void InsertItem(int index, ITreeGridItem item) + { + var path = new Gtk.TreePath(); + path.AppendIndex(index); + var iter = Handler.model.GetIterFromItem(item, path); + Handler.Tree.Model.EmitRowInserted(path, iter); + } + + public override void RemoveItem(int index) + { + var path = new Gtk.TreePath(); + path.AppendIndex(index); + Handler.Tree.Model.EmitRowDeleted(path); + } + + public override void RemoveAllItems() + { + Handler.UpdateModel(); + } + } + + public ITreeGridStore DataStore + { + get { return collection != null ? collection.Collection : null; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler { Handler = this }; + collection.Register(value); + } + } + + public ITreeGridItem SelectedItem + { + get + { + Gtk.TreeIter iter; + return Tree.Selection.GetSelected(out iter) ? model.GetItemAtIter(iter) : null; + } + set + { + if (value != null) + { + var path = model.GetPathFromItem(value); + if (path != null) + { + Tree.ExpandToPath(path); + Tree.Selection.SelectPath(path); + Tree.ScrollToCell(path, null, false, 0, 0); + } + } + else + Tree.Selection.UnselectAll(); + } + } + + bool ChildIsSelected(ITreeGridItem item) + { + var node = SelectedItem; + + while (node != null) + { + if (node == item) + return true; + node = node.Parent; + } + return false; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TreeGridView.ExpandingEvent: + Tree.TestExpandRow += Connector.HandleTestExpandRow; + break; + case TreeGridView.ExpandedEvent: + Tree.RowExpanded += Connector.HandleRowExpanded; + break; + case TreeGridView.CollapsingEvent: + Tree.TestCollapseRow += Connector.HandleTestCollapseRow; + break; + case TreeGridView.CollapsedEvent: + Tree.RowCollapsed += Connector.HandleRowCollapsed; + break; + case TreeGridView.SelectedItemChangedEvent: + Tree.Selection.Changed += Connector.HandleSelectionChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + protected new TreeGridViewConnector Connector { get { return (TreeGridViewConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new TreeGridViewConnector(); + } + + protected class TreeGridViewConnector : GridConnector + { + public new TreeGridViewHandler Handler { get { return (TreeGridViewHandler)base.Handler; } } + + public void HandleTestExpandRow(object o, Gtk.TestExpandRowArgs args) + { + var h = Handler; + var e = new TreeGridViewItemCancelEventArgs(h.GetItem(args.Path) as ITreeGridItem); + h.Callback.OnExpanding(h.Widget, e); + args.RetVal = e.Cancel; + } + + public void HandleRowExpanded(object o, Gtk.RowExpandedArgs args) + { + var h = Handler; + var e = new TreeGridViewItemEventArgs(h.GetItem(args.Path) as ITreeGridItem); + e.Item.Expanded = true; + h.Callback.OnExpanded(h.Widget, e); + } + + public void HandleTestCollapseRow(object o, Gtk.TestCollapseRowArgs args) + { + var h = Handler; + var e = new TreeGridViewItemCancelEventArgs(h.GetItem(args.Path) as ITreeGridItem); + h.Callback.OnCollapsing(h.Widget, e); + args.RetVal = e.Cancel; + if (!e.Cancel) + { + h.selectCollapsingItem = !h.AllowMultipleSelection && h.ChildIsSelected(e.Item); + h.SkipSelectedChange = true; + } + } + + public void HandleRowCollapsed(object o, Gtk.RowCollapsedArgs args) + { + var h = Handler; + var e = new TreeGridViewItemEventArgs(h.GetItem(args.Path) as ITreeGridItem); + e.Item.Expanded = false; + h.Callback.OnCollapsed(h.Widget, e); + h.SkipSelectedChange = false; + if (h.selectCollapsingItem == true) + { + h.Tree.Selection.UnselectAll(); + h.Tree.Selection.SelectPath(args.Path); + h.selectCollapsingItem = null; + } + } + + public void HandleSelectionChanged(object sender, EventArgs e) + { + var h = Handler; + var item = h.SelectedItem; + if (!h.SkipSelectedChange && !object.ReferenceEquals(item, h.lastSelected)) + { + h.Callback.OnSelectedItemChanged(h.Widget, EventArgs.Empty); + h.lastSelected = item; + } + } + } + + public override object GetItem(Gtk.TreePath path) + { + return model.GetItemAtPath(path); + } + + public override Gtk.TreeIter GetIterAtRow(int row) + { + throw new NotImplementedException(); + } + + public override Gtk.TreePath GetPathAtRow(int row) + { + throw new NotImplementedException(); + } + + protected override void SetSelectedRows(IEnumerable value) + { + } + + public GLib.Value GetColumnValue(ITreeGridItem item, int dataColumn, int row) + { + int column; + if (ColumnMap.TryGetValue(dataColumn, out column)) + { + var colHandler = (IGridColumnHandler)Widget.Columns[column].Handler; + return colHandler.GetValue(item, dataColumn, row); + } + return new GLib.Value((string)null); + } + + public int GetRowOfItem(ITreeGridItem item) + { + return collection == null ? -1 : collection.IndexOf(item); + } + + int GetCount(Gtk.TreeIter parent, int upToIndex) + { + int rows = upToIndex == -1 ? model.IterNChildren(parent) : upToIndex; + int count = 0; + for (int i = 0; i < rows; i++) + { + Gtk.TreeIter iter; + if (model.IterNthChild(out iter, parent, i)) + { + var childPath = model.GetPath(iter); + + if (Tree.GetRowExpanded(childPath)) + { + count += GetCount(iter, -1); + } + } + count++; + } + return count; + } + + public override IEnumerable SelectedRows + { + get + { + var rows = Tree.Selection.GetSelectedRows(); + foreach (var row in rows) + { + int count = 0; + var path = new Gtk.TreePath(); + count += GetCount(Gtk.TreeIter.Zero, row.Indices[0]); + // slow but works for now + for (int i = 0; i < row.Indices.Length - 1; i++) + { + path.AppendIndex(row.Indices[i]); + Gtk.TreeIter iter; + if (model.GetIter(out iter, path)) + count += GetCount(iter, row.Indices[i + 1]); + } + count += row.Indices.Length - 1; + //count += row.Indices[row.Indices.Length - 1]; + + yield return count; + } + + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/TreeViewHandler.cs b/Source/Eto.Gtk/Forms/Controls/TreeViewHandler.cs new file mode 100644 index 0000000000..c126dc3be9 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/TreeViewHandler.cs @@ -0,0 +1,407 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; +using System.Collections.Generic; +using Eto.GtkSharp.Forms.Menu; + +namespace Eto.GtkSharp.Forms.Controls +{ + public class TreeViewHandler : GtkControl, TreeView.IHandler, IGtkListModelHandler + { + GtkTreeModel model; + CollectionHandler collection; + readonly Gtk.TreeView tree; + ContextMenu contextMenu; + bool cancelExpandCollapseEvents; + readonly Gtk.CellRendererText textCell; + public static Size MaxImageSize = new Size(16, 16); + + public override Gtk.Widget EventControl + { + get { return tree; } + } + + public class CollectionHandler : DataStoreChangedHandler + { + WeakReference handler; + public TreeViewHandler Handler { get { return (TreeViewHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public void ExpandItems(ITreeStore store, Gtk.TreePath path) + { + Handler.cancelExpandCollapseEvents = true; + PerformExpandItems(store, path); + Handler.cancelExpandCollapseEvents = false; + } + + void PerformExpandItems(ITreeStore store, Gtk.TreePath path) + { + var newpath = path.Copy(); + newpath.AppendIndex(0); + for (int i = 0; i < store.Count; i++) + { + var item = store[i]; + if (item.Expandable) + { + if (item.Expanded) + { + Handler.tree.ExpandToPath(newpath); + PerformExpandItems(item, newpath); + } + else + { + Handler.tree.CollapseRow(newpath); + } + } + newpath.Next(); + } + } + + public void ExpandItems() + { + var store = Handler.collection.Collection; + ExpandItems(store, new Gtk.TreePath()); + } + + public override void AddRange(IEnumerable items) + { + Handler.UpdateModel(); + ExpandItems(); + } + + public override void AddItem(ITreeItem item) + { + var path = new Gtk.TreePath(); + path.AppendIndex(Collection.Count); + var iter = Handler.model.GetIterFromItem(item, path); + Handler.tree.Model.EmitRowInserted(path, iter); + } + + public override void InsertItem(int index, ITreeItem item) + { + var path = new Gtk.TreePath(); + path.AppendIndex(index); + var iter = Handler.model.GetIterFromItem(item, path); + Handler.tree.Model.EmitRowInserted(path, iter); + } + + public override void RemoveItem(int index) + { + var path = new Gtk.TreePath(); + path.AppendIndex(index); + Handler.tree.Model.EmitRowDeleted(path); + } + + public override void RemoveAllItems() + { + Handler.UpdateModel(); + } + } + + void UpdateModel() + { + model = new GtkTreeModel { Handler = this }; + tree.Model = new Gtk.TreeModelAdapter(model); + } + + public TreeViewHandler() + { + tree = new Gtk.TreeView(); + UpdateModel(); + tree.HeadersVisible = false; + + var col = new Gtk.TreeViewColumn(); + var pbcell = new Gtk.CellRendererPixbuf(); + col.PackStart(pbcell, false); + col.SetAttributes(pbcell, "pixbuf", 1); + textCell = new Gtk.CellRendererText(); + col.PackStart(textCell, true); + col.SetAttributes(textCell, "text", 0); + tree.AppendColumn(col); + + tree.ShowExpanders = true; + + Control = new Gtk.ScrolledWindow(); + Control.ShadowType = Gtk.ShadowType.In; + Control.Add(tree); + + tree.Events |= Gdk.EventMask.ButtonPressMask; + } + + protected override void Initialize() + { + base.Initialize(); + tree.ButtonPressEvent += Connector.HandleTreeButtonPressEvent; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TreeView.ExpandingEvent: + tree.TestExpandRow += Connector.HandleTestExpandRow; + break; + case TreeView.ExpandedEvent: + tree.RowExpanded += Connector.HandleRowExpanded; + break; + case TreeView.CollapsingEvent: + tree.TestCollapseRow += Connector.HandleTestCollapseRow; + break; + case TreeView.CollapsedEvent: + tree.RowCollapsed += Connector.HandleRowCollapsed; + break; + case TreeView.ActivatedEvent: + tree.RowActivated += Connector.HandleRowActivated; + break; + case TreeView.SelectionChangedEvent: + tree.Selection.Changed += Connector.HandleSelectionChanged; + break; + case TreeView.LabelEditingEvent: + textCell.EditingStarted += Connector.HandleEditingStarted; + break; + case TreeView.LabelEditedEvent: + textCell.Edited += Connector.HandleEdited; + break; + default: + base.AttachEvent(id); + break; + } + } + + public object GetItem(Gtk.TreePath path) + { + return model.GetItemAtPath(path); + } + + protected new TreeViewConnector Connector { get { return (TreeViewConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new TreeViewConnector(); + } + + protected class TreeViewConnector : GtkControlConnector + { + public new TreeViewHandler Handler { get { return (TreeViewHandler)base.Handler; } } + + public void HandleTestExpandRow(object o, Gtk.TestExpandRowArgs args) + { + var handler = Handler; + if (handler.cancelExpandCollapseEvents) + return; + var e = new TreeViewItemCancelEventArgs(handler.GetItem(args.Path) as ITreeItem); + handler.Callback.OnExpanding(handler.Widget, e); + args.RetVal = e.Cancel; + } + + public void HandleTestCollapseRow(object o, Gtk.TestCollapseRowArgs args) + { + var handler = Handler; + if (handler.cancelExpandCollapseEvents) + return; + var e = new TreeViewItemCancelEventArgs(handler.GetItem(args.Path) as ITreeItem); + handler.Callback.OnCollapsing(handler.Widget, e); + args.RetVal = e.Cancel; + } + + public void HandleRowExpanded(object o, Gtk.RowExpandedArgs args) + { + var handler = Handler; + if (handler.cancelExpandCollapseEvents) + return; + var item = handler.GetItem(args.Path) as ITreeItem; + if (item != null && !item.Expanded) + { + item.Expanded = true; + handler.collection.ExpandItems(item, args.Path); + handler.Callback.OnExpanded(handler.Widget, new TreeViewItemEventArgs(item)); + } + } + + public void HandleRowCollapsed(object o, Gtk.RowCollapsedArgs args) + { + var handler = Handler; + if (handler.cancelExpandCollapseEvents) + return; + var item = handler.GetItem(args.Path) as ITreeItem; + if (item != null && item.Expanded) + { + item.Expanded = false; + handler.Callback.OnCollapsed(handler.Widget, new TreeViewItemEventArgs(item)); + } + } + + public void HandleRowActivated(object o, Gtk.RowActivatedArgs args) + { + Handler.Callback.OnActivated(Handler.Widget, new TreeViewItemEventArgs(Handler.model.GetItemAtPath(args.Path))); + } + + public void HandleSelectionChanged(object sender, EventArgs e) + { + Handler.Callback.OnSelectionChanged(Handler.Widget, EventArgs.Empty); + } + + public void HandleEditingStarted(object o, Gtk.EditingStartedArgs args) + { + var handler = Handler; + var item = handler.model.GetItemAtPath(args.Path); + if (item != null) + { + var itemArgs = new TreeViewItemCancelEventArgs(item); + handler.Callback.OnLabelEditing(handler.Widget, itemArgs); + args.RetVal = itemArgs.Cancel; + } + } + + public void HandleEdited(object o, Gtk.EditedArgs args) + { + var handler = Handler; + var item = handler.model.GetItemAtPath(args.Path); + if (item != null) + { + handler.Callback.OnLabelEdited(handler.Widget, new TreeViewItemEditEventArgs(item, args.NewText)); + item.Text = args.NewText; + } + } + + [GLib.ConnectBefore] + public void HandleTreeButtonPressEvent(object o, Gtk.ButtonPressEventArgs args) + { + var handler = Handler; + if (handler.contextMenu != null && args.Event.Button == 3 && args.Event.Type == Gdk.EventType.ButtonPress) + { + var menu = ((ContextMenuHandler)handler.contextMenu.Handler).Control; + menu.Popup(); + menu.ShowAll(); + } + } + } + + public ITreeStore DataStore + { + get { return collection != null ? collection.Collection : null; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler { Handler = this }; + collection.Register(value); + } + } + + public ContextMenu ContextMenu + { + get { return contextMenu; } + set { contextMenu = value; } + } + + public ITreeItem SelectedItem + { + get + { + Gtk.TreeIter iter; + if (tree.Selection.GetSelected(out iter)) + { + return model.GetItemAtIter(iter); + } + return null; + } + set + { + if (value != null) + { + var path = model.GetPathFromItem(value); + if (path != null) + { + tree.ExpandToPath(path); + tree.Selection.SelectPath(path); + tree.ScrollToCell(path, null, false, 0, 0); + } + } + else + tree.Selection.UnselectAll(); + } + } + + public GLib.Value GetColumnValue(ITreeItem item, int column, int row) + { + switch (column) + { + case 0: + return new GLib.Value(item.Text); + case 1: + if (item.Image != null) + { + var image = item.Image.Handler as IGtkPixbuf; + if (image != null) + return new GLib.Value(image.GetPixbuf(MaxImageSize)); + } + return new GLib.Value((Gdk.Pixbuf)null); + } + throw new InvalidOperationException(); + } + + public int NumberOfColumns + { + get { return 2; } + } + + public int GetRowOfItem(ITreeItem item) + { + return collection != null ? collection.IndexOf(item) : -1; + } + + public void RefreshData() + { + UpdateModel(); + collection.ExpandItems(); + } + + public void RefreshItem(ITreeItem item) + { + var path = model.GetPathFromItem(item); + if (path != null && path.Depth > 0 && !object.ReferenceEquals(item, collection.Collection)) + { + Gtk.TreeIter iter; + tree.Model.GetIter(out iter, path); + tree.Model.EmitRowChanged(path, iter); + tree.Model.EmitRowHasChildToggled(path, iter); + cancelExpandCollapseEvents = true; + if (item.Expanded) + { + tree.CollapseRow(path); + tree.ExpandRow(path, false); + collection.ExpandItems(item, path); + } + else + tree.CollapseRow(path); + cancelExpandCollapseEvents = false; + } + else + RefreshData(); + } + + public ITreeItem GetNodeAt(PointF point) + { + Gtk.TreePath path; + if (tree.GetPathAtPos((int)point.X, (int)point.Y, out path)) + { + return model.GetItemAtPath(path); + } + return null; + } + + public bool LabelEdit + { + get { return textCell.Editable; } + set { textCell.Editable = value; } + } + + public Color TextColor + { + get { return textCell.ForegroundGdk.ToEto(); } + set { textCell.ForegroundGdk = value.ToGdk(); } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Controls/WebViewHandler.cs b/Source/Eto.Gtk/Forms/Controls/WebViewHandler.cs new file mode 100644 index 0000000000..7169376269 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Controls/WebViewHandler.cs @@ -0,0 +1,259 @@ +using System; +using Eto.Forms; +using System.Threading; +#if GTK3 +using NewWindowPolicyDecisionRequestedArgs = WebKit.NewWindowPolicyDecisionRequestedArgs; +#endif + +namespace Eto.GtkSharp.Forms.Controls +{ + public class WebViewHandler : GtkControl, WebView.IHandler + { + readonly Gtk.ScrolledWindow scroll; + readonly ManualResetEventSlim returnResetEvent = new ManualResetEventSlim(); + string scriptReturnValue; + const string EtoReturnPrefix = "etoscriptreturn://"; + + public Gtk.ScrolledWindow Scroll + { + get { return scroll; } + } + + public override Gtk.Widget ContainerControl + { + get { return scroll; } + } + + public WebViewHandler() + { + scroll = new Gtk.ScrolledWindow(); + + try + { + Control = new EtoWebView(); + } + catch (Exception ex) + { + throw new EtoException("GTK WebView is only supported on Linux, and requires webkit-sharp", ex); + } + scroll.Add(Control); + } + + protected override void Initialize() + { + base.Initialize(); + Control.PopulatePopup += Connector.HandlePopulatePopup; + HandleEvent(WebView.DocumentLoadingEvent); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case WebView.NavigatedEvent: + HandleEvent(WebView.DocumentLoadedEvent); + break; + case WebView.DocumentLoadedEvent: + Control.LoadFinished += Connector.HandleLoadFinished; + break; + case WebView.DocumentLoadingEvent: +#if GTK2 + Control.NavigationRequested += Connector.HandleNavigationRequested; +#else + Control.NavigationPolicyDecisionRequested += Connector.HandleNavigationPolicyDecisitionRequested; +#endif + break; + case WebView.OpenNewWindowEvent: + // note: requires libwebkitgtk 1.1.4+ + Control.NewWindowPolicyDecisionRequested += Connector.HandleNewWindowPolicyDecisionRequested; + break; + case WebView.DocumentTitleChangedEvent: + Control.TitleChanged += Connector.HandleTitleChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + protected new WebViewConnector Connector { get { return (WebViewConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new WebViewConnector(); + } + + protected class WebViewConnector : GtkControlConnector + { + public new WebViewHandler Handler { get { return (WebViewHandler)base.Handler; } } + + public void HandlePopulatePopup(object o, WebKit.PopulatePopupArgs args) + { + var handler = Handler; + if (handler.BrowserContextMenuEnabled) + return; + // don't allow context menu by default + foreach (var child in args.Menu.Children) + { + args.Menu.Remove(child); + } + } + + public void HandleLoadFinished(object o, WebKit.LoadFinishedArgs args) + { + var handler = Handler; + var uri = args.Frame.Uri != null ? new Uri(args.Frame.Uri) : null; + var e = new WebViewLoadedEventArgs(uri); + if (args.Frame == handler.Control.MainFrame) + handler.Callback.OnNavigated(handler.Widget, e); + handler.Callback.OnDocumentLoaded(handler.Widget, e); + } +#if GTK2 + public void HandleNavigationRequested(object o, WebKit.NavigationRequestedArgs args) + { + var handler = Handler; + if (args.Request.Uri.StartsWith(EtoReturnPrefix, StringComparison.Ordinal)) + { + // pass back the response to ExecuteScript() + handler.scriptReturnValue = Uri.UnescapeDataString(args.Request.Uri.Substring(EtoReturnPrefix.Length).Replace('+', ' ')); + handler.returnResetEvent.Set(); + args.RetVal = WebKit.NavigationResponse.Ignore; + } + else + { + var e = new WebViewLoadingEventArgs(new Uri(args.Request.Uri), false); + handler.Callback.OnDocumentLoading(handler.Widget, e); + args.RetVal = e.Cancel ? WebKit.NavigationResponse.Ignore : WebKit.NavigationResponse.Accept; + } + } + +#else + public void HandleNavigationPolicyDecisitionRequested(object o, WebKit.NavigationPolicyDecisionRequestedArgs args) + { + var handler = Handler; + if (args.Request.Uri.StartsWith(EtoReturnPrefix, StringComparison.Ordinal)) + { + // pass back the response to ExecuteScript() + handler.scriptReturnValue = Uri.UnescapeDataString(args.Request.Uri.Substring(EtoReturnPrefix.Length).Replace('+', ' ')); + handler.returnResetEvent.Set(); + args.PolicyDecision.Ignore(); + } + else + { + var e = new WebViewLoadingEventArgs(new Uri(args.Request.Uri), false); + handler.Callback.OnDocumentLoading(handler.Widget, e); + if (e.Cancel) + args.PolicyDecision.Ignore(); + else + args.PolicyDecision.Use(); + } + } +#endif + + public void HandleNewWindowPolicyDecisionRequested(object sender, NewWindowPolicyDecisionRequestedArgs args) + { + var handler = Handler; + var e = new WebViewNewWindowEventArgs(new Uri(args.Request.Uri), args.Frame.Name); + handler.Callback.OnOpenNewWindow(handler.Widget, e); + #if GTK2 + if (e.Cancel) + args.Decision.Ignore(); + else + args.Decision.Use(); + #else + if (e.Cancel) + args.PolicyDecision.Ignore(); + else + args.PolicyDecision.Use(); + #endif + args.RetVal = true; + } + + public void HandleTitleChanged(object o, WebKit.TitleChangedArgs args) + { + Handler.Callback.OnDocumentTitleChanged(Handler.Widget, new WebViewTitleEventArgs(args.Title)); + } + } + + public Uri Url + { + get { return new Uri(Control.Uri); } + set + { + if (value != null) + { + Control.LoadUri(value.AbsoluteUri); + } + else + Control.LoadHtmlString(string.Empty, string.Empty); + } + } + + public string DocumentTitle + { + get + { + return Control.MainFrame.Title; + } + } + + public string ExecuteScript(string script) + { + // no access to DOM or return value, so get return value via URL (limited length, but better than nothing) + var getResultScript = @"try {{ var fn = function () {{ {0} }}; window.location.href = '" + EtoReturnPrefix + @"' + encodeURIComponent(fn()); }} catch (e) {{ window.location.href = '" + EtoReturnPrefix + @"'; }}"; + returnResetEvent.Reset(); + Control.ExecuteScript(string.Format(getResultScript, script)); + while (!returnResetEvent.Wait(0)) + { + Gtk.Application.RunIteration(); + } + return scriptReturnValue; + } + + public void LoadHtml(string html, Uri baseUri) + { + Control.LoadHtmlString(html, baseUri != null ? baseUri.AbsoluteUri : null); + } + + public void Stop() + { + Control.StopLoading(); + } + + public void Reload() + { + Control.Reload(); + } + + public void GoBack() + { + Control.GoBack(); + } + + public void GoForward() + { + Control.GoForward(); + } + + public bool CanGoBack + { + get { return Control.CanGoBack(); } + } + + public bool CanGoForward + { + get { return Control.CanGoForward(); } + } + + public void ShowPrintDialog() + { + Control.ExecuteScript("print();"); + } + + public bool BrowserContextMenuEnabled + { + get; + set; + } + } +} diff --git a/Source/Eto.Gtk/Forms/CursorHandler.cs b/Source/Eto.Gtk/Forms/CursorHandler.cs new file mode 100644 index 0000000000..c8e5cb07ef --- /dev/null +++ b/Source/Eto.Gtk/Forms/CursorHandler.cs @@ -0,0 +1,14 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms +{ + public class CursorHandler : WidgetHandler, Cursor.IHandler + { + + public void Create (CursorType cursor) + { + Control = new Gdk.Cursor(cursor.ToGdk ()); + } + } +} + diff --git a/Source/Eto.Gtk/Forms/DialogHandler.cs b/Source/Eto.Gtk/Forms/DialogHandler.cs new file mode 100644 index 0000000000..b998faf7e8 --- /dev/null +++ b/Source/Eto.Gtk/Forms/DialogHandler.cs @@ -0,0 +1,93 @@ +using System; +using Eto.Forms; +using System.Threading.Tasks; +using Eto.GtkSharp.Forms.Controls; + +namespace Eto.GtkSharp.Forms +{ + public class DialogHandler : GtkWindow, Dialog.IHandler + { + public class MyDialog : Gtk.Dialog + { + #if GTK3 + protected override void OnAdjustSizeAllocation(Gtk.Orientation orientation, out int minimum_size, out int natural_size, out int allocated_pos, out int allocated_size) + { + base.OnAdjustSizeAllocation(orientation, out minimum_size, out natural_size, out allocated_pos, out allocated_size); + if (orientation == Gtk.Orientation.Horizontal) + allocated_size = natural_size; + } + #endif + } + + public DialogHandler() + { + Control = new MyDialog(); +#if GTK2 + Control.AllowShrink = false; + Control.AllowGrow = false; + Control.HasSeparator = false; +#else + Control.Resizable = false; + Control.HasResizeGrip = false; +#endif + } + + protected override void Initialize() + { + base.Initialize(); +#if GTK2 + Control.VBox.PackStart(WindowActionControl, false, true, 0); + Control.VBox.PackStart(WindowContentControl, true, true, 0); +#else + Control.ActionArea.Add(WindowActionControl); + Control.ContentArea.Add(WindowContentControl); +#endif + } + + public Button AbortButton { get; set; } + + public Button DefaultButton { get; set; } + + public DialogDisplayMode DisplayMode { get; set; } + + public void ShowModal(Control parent) + { + if (parent != null) + { + Control.TransientFor = ((Gtk.Window)(parent.ParentWindow).ControlObject); + Control.Modal = true; + } + Control.ShowAll(); + + if (DefaultButton != null) + { + var widget = DefaultButton.GetContainerWidget(); + if (widget != null) + { +#if GTK2 + widget.SetFlag(Gtk.WidgetFlags.CanDefault); +#else + widget.CanDefault = true; +#endif + Control.Default = widget; + } + } + // TODO: implement cancel button somehow? + + Control.Run(); + Control.Hide(); + } + + public Task ShowModalAsync(Control parent) + { + var tcs = new TaskCompletionSource(); + Application.Instance.AsyncInvoke(() => + { + ShowModal(parent); + tcs.SetResult(true); + }); + + return tcs.Task; + } + } +} diff --git a/Source/Eto.Gtk/Forms/FontDialogHandler.cs b/Source/Eto.Gtk/Forms/FontDialogHandler.cs new file mode 100644 index 0000000000..4e7b976664 --- /dev/null +++ b/Source/Eto.Gtk/Forms/FontDialogHandler.cs @@ -0,0 +1,62 @@ +using Eto.Drawing; +using Eto.Forms; +using System; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms +{ + public class FontDialogHandler : WidgetHandler, FontDialog.IHandler + { + public FontDialogHandler() + { + Control = new Gtk.FontSelectionDialog(null); + } + + public Font Font + { + get; + set; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case FontDialog.FontChangedEvent: + // handled in ShowDialog + break; + default: + base.AttachEvent(id); + break; + } + } + + public DialogResult ShowDialog(Window parent) + { + if (parent != null) + { + Control.TransientFor = ((Gtk.Window)parent.ControlObject); + Control.Modal = true; + } + if (Font != null) + { + var fontHandler = Font.Handler as FontHandler; + Control.SetFontName(fontHandler.Control.ToString()); + } + else + Control.SetFontName(string.Empty); + + Control.ShowAll(); + var response = (Gtk.ResponseType)Control.Run(); + Control.Hide(); + + if (response == Gtk.ResponseType.Apply || response == Gtk.ResponseType.Ok) + { + Font = new Font(new FontHandler(Control.FontName)); + Callback.OnFontChanged(Widget, EventArgs.Empty); + return DialogResult.Ok; + } + return DialogResult.Cancel; + } + } +} diff --git a/Source/Eto.Gtk/Forms/FormHandler.cs b/Source/Eto.Gtk/Forms/FormHandler.cs new file mode 100644 index 0000000000..a2f1bf8f7a --- /dev/null +++ b/Source/Eto.Gtk/Forms/FormHandler.cs @@ -0,0 +1,34 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms +{ + public class FormHandler : GtkWindow, Form.IHandler + { + public FormHandler(Gtk.Window window) + { + Control = window; + } + + public FormHandler() + { + Control = new Gtk.Window(Gtk.WindowType.Toplevel); +#if GTK2 + Control.AllowShrink = true; + Control.AllowGrow = true; +#else + Control.Resizable = true; +#endif + Control.SetPosition(Gtk.WindowPosition.Center); + + var vbox = new Gtk.VBox(); + vbox.PackStart(WindowActionControl, false, true, 0); + vbox.PackStart(WindowContentControl, true, true, 0); + Control.Add(vbox); + } + + public void Show() + { + Control.ShowAll(); + } + } +} diff --git a/Source/Eto.Gtk/Forms/GtkContainer.cs b/Source/Eto.Gtk/Forms/GtkContainer.cs new file mode 100644 index 0000000000..d58fd10391 --- /dev/null +++ b/Source/Eto.Gtk/Forms/GtkContainer.cs @@ -0,0 +1,30 @@ +using System.Linq; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Forms.Controls; + +namespace Eto.GtkSharp.Forms +{ + public abstract class GtkContainer : GtkControl, Container.IHandler + where TControl: Gtk.Widget + where TWidget: Container + where TCallback: Container.ICallback + { + public bool RecurseToChildren { get { return true; } } + + public virtual Size ClientSize + { + get { return Size; } + set { Size = value; } + } + + public override void SetBackgroundColor() + { + base.SetBackgroundColor(); + foreach (var child in Widget.Controls.Select(r => r.GetGtkControlHandler()).Where(r => r != null)) + { + child.SetBackgroundColor(); + } + } + } +} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/GtkControl.cs b/Source/Eto.Gtk/Forms/GtkControl.cs similarity index 85% rename from Source/Eto.Platform.Gtk/Forms/Controls/GtkControl.cs rename to Source/Eto.Gtk/Forms/GtkControl.cs index 74201ac3c1..9d633c151b 100644 --- a/Source/Eto.Platform.Gtk/Forms/Controls/GtkControl.cs +++ b/Source/Eto.Gtk/Forms/GtkControl.cs @@ -2,13 +2,13 @@ using System.Text.RegularExpressions; using Eto.Forms; using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; +using Eto.GtkSharp.Drawing; using GLib; using System.Text; using System.Linq; using System.Collections.Generic; -namespace Eto.Platform.GtkSharp +namespace Eto.GtkSharp.Forms { public interface IGtkControl { @@ -48,9 +48,10 @@ public static IGtkControl GetGtkControlHandler(this Control control) } } - public abstract class GtkControl : WidgetHandler, IControl, IGtkControl + public abstract class GtkControl : WidgetHandler, Control.IHandler, IGtkControl where TControl: Gtk.Widget where TWidget: Control + where TCallback: Control.ICallback { Font font; Size size; @@ -63,7 +64,7 @@ public abstract class GtkControl : WidgetHandler protected class GtkControlConnector : WeakConnector { - public new GtkControl Handler { get { return (GtkControl)base.Handler; } } + new GtkControl Handler { get { return (GtkControl)base.Handler; } } public void HandleScrollEvent(object o, Gtk.ScrollEventArgs args) { var p = new PointF((float)args.Event.X, (float)args.Event.Y); - Key modifiers = args.Event.State.ToEtoKey(); + Keys modifiers = args.Event.State.ToEtoKey(); MouseButtons buttons = args.Event.State.ToEtoMouseButtons(); SizeF delta; @@ -402,59 +421,62 @@ public void HandleScrollEvent(object o, Gtk.ScrollEventArgs args) throw new NotSupportedException(); } - Handler.Widget.OnMouseWheel(new MouseEventArgs(buttons, modifiers, p, delta)); + Handler.Callback.OnMouseWheel(Handler.Widget, new MouseEventArgs(buttons, modifiers, p, delta)); } + [GLib.ConnectBefore] public void HandleControlLeaveNotifyEvent(object o, Gtk.LeaveNotifyEventArgs args) { var p = new PointF((float)args.Event.X, (float)args.Event.Y); - Key modifiers = args.Event.State.ToEtoKey(); + Keys modifiers = args.Event.State.ToEtoKey(); MouseButtons buttons = MouseButtons.None; - Handler.Widget.OnMouseLeave(new MouseEventArgs(buttons, modifiers, p)); + Handler.Callback.OnMouseLeave(Handler.Widget, new MouseEventArgs(buttons, modifiers, p)); } + [GLib.ConnectBefore] public void HandleControlEnterNotifyEvent(object o, Gtk.EnterNotifyEventArgs args) { var p = new PointF((float)args.Event.X, (float)args.Event.Y); - Key modifiers = args.Event.State.ToEtoKey(); + Keys modifiers = args.Event.State.ToEtoKey(); MouseButtons buttons = MouseButtons.None; - Handler.Widget.OnMouseEnter(new MouseEventArgs(buttons, modifiers, p)); + Handler.Callback.OnMouseEnter(Handler.Widget, new MouseEventArgs(buttons, modifiers, p)); } + [GLib.ConnectBefore] public void HandleMotionNotifyEvent(System.Object o, Gtk.MotionNotifyEventArgs args) { var p = new PointF((float)args.Event.X, (float)args.Event.Y); - Key modifiers = args.Event.State.ToEtoKey(); + Keys modifiers = args.Event.State.ToEtoKey(); MouseButtons buttons = args.Event.State.ToEtoMouseButtons(); - Handler.Widget.OnMouseMove(new MouseEventArgs(buttons, modifiers, p)); + Handler.Callback.OnMouseMove(Handler.Widget, new MouseEventArgs(buttons, modifiers, p)); } public void HandleButtonReleaseEvent(object o, Gtk.ButtonReleaseEventArgs args) { var p = new PointF((float)args.Event.X, (float)args.Event.Y); - Key modifiers = args.Event.State.ToEtoKey(); + Keys modifiers = args.Event.State.ToEtoKey(); MouseButtons buttons = args.Event.ToEtoMouseButtons(); - Handler.Widget.OnMouseUp(new MouseEventArgs(buttons, modifiers, p)); + Handler.Callback.OnMouseUp(Handler.Widget, new MouseEventArgs(buttons, modifiers, p)); } public void HandleButtonPressEvent(object sender, Gtk.ButtonPressEventArgs args) { var p = new PointF((float)args.Event.X, (float)args.Event.Y); - Key modifiers = args.Event.State.ToEtoKey(); + Keys modifiers = args.Event.State.ToEtoKey(); MouseButtons buttons = args.Event.ToEtoMouseButtons(); if (Handler.Control.CanFocus && !Handler.Control.HasFocus) Handler.Control.GrabFocus(); if (args.Event.Type == Gdk.EventType.ButtonPress) { - Handler.Widget.OnMouseDown(new MouseEventArgs(buttons, modifiers, p)); + Handler.Callback.OnMouseDown(Handler.Widget, new MouseEventArgs(buttons, modifiers, p)); } else if (args.Event.Type == Gdk.EventType.TwoButtonPress) { - Handler.Widget.OnMouseDoubleClick(new MouseEventArgs(buttons, modifiers, p)); + Handler.Callback.OnMouseDoubleClick(Handler.Widget, new MouseEventArgs(buttons, modifiers, p)); } } @@ -464,7 +486,7 @@ public void HandleSizeAllocated(object o, Gtk.SizeAllocatedArgs args) { // only call when the size has actually changed, gtk likes to call anyway!! grr. Handler.asize = args.Allocation.Size.ToEto(); - Handler.Widget.OnSizeChanged(EventArgs.Empty); + Handler.Callback.OnSizeChanged(Handler.Widget, EventArgs.Empty); } } @@ -474,7 +496,7 @@ public void HandleKeyPressEvent(object o, Gtk.KeyPressEventArgs args) var e = args.Event.ToEto(); if (e != null) { - Handler.Widget.OnKeyDown(e); + Handler.Callback.OnKeyDown(Handler.Widget, e); args.RetVal = e.Handled; } } @@ -484,25 +506,28 @@ public void HandleKeyReleaseEvent(object o, Gtk.KeyReleaseEventArgs args) var e = args.Event.ToEto(); if (e != null) { - Handler.Widget.OnKeyUp(e); + Handler.Callback.OnKeyUp(Handler.Widget, e); args.RetVal = e.Handled; } } public void FocusInEvent(object o, Gtk.FocusInEventArgs args) { - Handler.Widget.OnGotFocus(EventArgs.Empty); + Handler.Callback.OnGotFocus(Handler.Widget, EventArgs.Empty); } public void FocusOutEvent(object o, Gtk.FocusOutEventArgs args) { - Handler.Widget.OnLostFocus(EventArgs.Empty); + // Handler can be null here after window is closed + var handler = Handler; + if (handler != null) + handler.Callback.OnLostFocus(Handler.Widget, EventArgs.Empty); } public void VisibilityNotifyEvent(object o, Gtk.VisibilityNotifyEventArgs args) { if (args.Event.State == Gdk.VisibilityState.FullyObscured) - Handler.Widget.OnShown(EventArgs.Empty); + Handler.Callback.OnShown(Handler.Widget, EventArgs.Empty); } public void HandleControlRealized(object sender, EventArgs e) @@ -522,7 +547,7 @@ public virtual Font Font get { if (font == null) - font = new Font(Widget.Generator, new FontHandler(FontControl)); + font = new Font(new FontHandler(FontControl)); return font; } set diff --git a/Source/Eto.Platform.Gtk/Forms/GtkFileDialog.cs b/Source/Eto.Gtk/Forms/GtkFileDialog.cs similarity index 90% rename from Source/Eto.Platform.Gtk/Forms/GtkFileDialog.cs rename to Source/Eto.Gtk/Forms/GtkFileDialog.cs index a2b1d1173c..5b3bab7b63 100644 --- a/Source/Eto.Platform.Gtk/Forms/GtkFileDialog.cs +++ b/Source/Eto.Gtk/Forms/GtkFileDialog.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; using System.Linq; -namespace Eto.Platform.GtkSharp +namespace Eto.GtkSharp.Forms { - public abstract class GtkFileDialog : WidgetHandler, IFileDialog + public abstract class GtkFileDialog : WidgetHandler, FileDialog.IHandler where TControl: Gtk.FileChooserDialog where TWidget: FileDialog { @@ -109,7 +109,8 @@ public DialogResult ShowDialog(Window parent) Control.Hide (); DialogResult response = ((Gtk.ResponseType)result).ToEto (); - if (response == DialogResult.Ok) System.IO.Directory.SetCurrentDirectory(Control.CurrentFolder); + if (response == DialogResult.Ok && !string.IsNullOrEmpty(Control.CurrentFolder)) + System.IO.Directory.SetCurrentDirectory(Control.CurrentFolder); return response; } diff --git a/Source/Eto.Platform.Gtk/Forms/GtkPanel.cs b/Source/Eto.Gtk/Forms/GtkPanel.cs similarity index 87% rename from Source/Eto.Platform.Gtk/Forms/GtkPanel.cs rename to Source/Eto.Gtk/Forms/GtkPanel.cs index c5724425f8..4a1f8bd463 100644 --- a/Source/Eto.Platform.Gtk/Forms/GtkPanel.cs +++ b/Source/Eto.Gtk/Forms/GtkPanel.cs @@ -2,11 +2,12 @@ using Eto.Forms; using Eto.Drawing; -namespace Eto.Platform.GtkSharp +namespace Eto.GtkSharp.Forms { - public abstract class GtkPanel : GtkContainer + public abstract class GtkPanel : GtkContainer where TControl: Gtk.Widget where TWidget: Panel + where TCallback: Panel.ICallback { readonly Gtk.Alignment alignment; Control content; @@ -19,7 +20,7 @@ public override Gtk.Widget ContainerContentControl protected GtkPanel() { alignment = new Gtk.Alignment(0, 0, 1, 1); - Padding = DockContainer.DefaultPadding; + Padding = Panel.DefaultPadding; } protected override void Initialize() @@ -43,7 +44,7 @@ protected override WeakConnector CreateConnector() protected class GtkPanelEventConnector : GtkControlConnector { - public new GtkPanel Handler { get { return (GtkPanel)base.Handler; } } + public new GtkPanel Handler { get { return (GtkPanel)base.Handler; } } #if GTK2 public void HandleContentSizeRequested(object o, Gtk.SizeRequestedArgs args) { diff --git a/Source/Eto.Gtk/Forms/GtkSynchronizationContext.cs b/Source/Eto.Gtk/Forms/GtkSynchronizationContext.cs new file mode 100644 index 0000000000..180a30b17d --- /dev/null +++ b/Source/Eto.Gtk/Forms/GtkSynchronizationContext.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading; +using GLib; + +namespace Eto.GtkSharp.Forms +{ + public class GtkSynchronizationContext : SynchronizationContext + { + public override void Post(SendOrPostCallback d, object state) + { + Idle.Add(() => + { + d(state); + return false; + }); + } + + public override void Send(SendOrPostCallback d, object state) + { + var evt = new ManualResetEvent(false); + Exception exception = null; + + Idle.Add(() => + { + try + { + d(state); + } + catch (Exception ex) + { + exception = ex; + } + finally + { + evt.Set(); + } + return false; + }); + + evt.WaitOne(); + + if (exception != null) + throw exception; + } + } +} \ No newline at end of file diff --git a/Source/Eto.Platform.Gtk/Forms/GtkWindow.cs b/Source/Eto.Gtk/Forms/GtkWindow.cs similarity index 79% rename from Source/Eto.Platform.Gtk/Forms/GtkWindow.cs rename to Source/Eto.Gtk/Forms/GtkWindow.cs index dc1e6eddd4..1d767c0d96 100644 --- a/Source/Eto.Platform.Gtk/Forms/GtkWindow.cs +++ b/Source/Eto.Gtk/Forms/GtkWindow.cs @@ -3,10 +3,11 @@ using System.Linq; using Eto.Drawing; using Eto.Forms; -using Eto.Platform.GtkSharp.Drawing; -using Eto.Platform.GtkSharp.Forms; +using Eto.GtkSharp.Drawing; +using Eto.GtkSharp.Forms; +using Eto.GtkSharp.Forms.Menu; -namespace Eto.Platform.GtkSharp +namespace Eto.GtkSharp.Forms { public interface IGtkWindow { @@ -15,9 +16,10 @@ public interface IGtkWindow Gtk.Window Control { get; } } - public abstract class GtkWindow : GtkPanel, IWindow, IGtkWindow + public abstract class GtkWindow : GtkPanel, Window.IHandler, IGtkWindow where TControl: Gtk.Window where TWidget: Window + where TCallback: Window.ICallback { Gtk.VBox vbox; readonly Gtk.VBox actionvbox; @@ -27,10 +29,11 @@ public abstract class GtkWindow : GtkPanel readonly Gtk.Box bottomToolbarBox; MenuBar menuBar; Icon icon; - ToolBar toolBar; + Eto.Forms.ToolBar toolBar; Gtk.AccelGroup accelGroup; Rectangle? restoreBounds; Point? currentLocation; + Size? initialSize; WindowState state; WindowStyle style; bool topmost; @@ -47,6 +50,11 @@ protected GtkWindow() containerBox.Visible = true; bottomToolbarBox = new Gtk.VBox(); + + actionvbox.PackStart(menuBox, false, false, 0); + actionvbox.PackStart(topToolbarBox, false, false, 0); + vbox.PackStart(containerBox, true, true, 0); + vbox.PackStart(bottomToolbarBox, false, false, 0); } protected override Color DefaultBackgroundColor @@ -132,53 +140,68 @@ public override Size Size { get { - return (Control.Visible ? Control.Allocation.Size : Control.DefaultSize).ToEto(); + return Control.GdkWindow != null ? Control.GdkWindow.FrameExtents.Size.ToEto() : initialSize ?? Control.DefaultSize.ToEto(); } set { - if (Control.Visible) - Control.SizeAllocate(new Gdk.Rectangle(Control.Allocation.Location, value.ToGdk())); + if (Control.GdkWindow != null) + { + var diff = Control.GdkWindow.FrameExtents.Size.ToEto() - Control.Allocation.Size.ToEto(); + Control.Resize(value.Width - diff.Width, value.Height - diff.Height); + } else - Control.SetDefaultSize(value.Width, value.Height); + { + Control.Resize(value.Width, value.Height); + if (initialSize == null) + Control.Shown += HandleControlShown; + initialSize = value; + } } } + void HandleControlShown(object sender, EventArgs e) + { + Control.Shown -= HandleControlShown; + var frameExtents = Control.GdkWindow.FrameExtents.Size.ToEto(); + // HACK: get twice to get 'real' size? Ubuntu 14.04 returns inflated size the first call. + frameExtents = Control.GdkWindow.FrameExtents.Size.ToEto(); + + var diff = frameExtents - Control.Allocation.Size.ToEto(); + Control.Resize(initialSize.Value.Width - diff.Width, initialSize.Value.Height - diff.Height); + initialSize = null; + } + public override Size ClientSize { get { - int width, height; - containerBox.GetSizeRequest(out width, out height); - return new Size(width, height); + return containerBox.IsRealized ? containerBox.Allocation.Size.ToEto() : containerBox.SizeRequest().ToEto(); } set { if (Control.IsRealized) { - int width, height; - Control.GetSize(out width, out height); - - var size = new Size(width, height); - containerBox.GetSizeRequest(out width, out height); - size -= new Size(width, height); - size += value; - Control.Resize(size.Width, size.Height); + var diff = vbox.Allocation.Size.ToEto() - containerBox.Allocation.Size.ToEto(); + Control.Resize(value.Width + diff.Width, value.Height + diff.Height); } else { Control.SetSizeRequest(-1, -1); containerBox.SetSizeRequest(value.Width, value.Height); + containerBox.Realized += HandleContainerRealized; } } } + void HandleContainerRealized(object sender, EventArgs e) + { + containerBox.SetSizeRequest(-1, -1); + containerBox.Realized -= HandleContainerRealized; + } + protected override void Initialize() { base.Initialize(); - actionvbox.PackStart(menuBox, false, false, 0); - actionvbox.PackStart(topToolbarBox, false, false, 0); - vbox.PackStart(containerBox, true, true, 0); - vbox.PackStart(bottomToolbarBox, false, false, 0); HandleEvent(Window.WindowStateChangedEvent); // to set restore bounds properly HandleEvent(Window.ClosingEvent); // to chain application termination events @@ -227,9 +250,10 @@ protected override WeakConnector CreateConnector() protected class GtkWindowConnector : GtkPanelEventConnector { Size? oldSize; + public WindowState OldState { get; set; } - public new GtkWindow Handler { get { return (GtkWindow)base.Handler; } } + public new GtkWindow Handler { get { return (GtkWindow)base.Handler; } } public void HandleDeleteEvent(object o, Gtk.DeleteEventArgs args) { @@ -238,12 +262,14 @@ public void HandleDeleteEvent(object o, Gtk.DeleteEventArgs args) public void HandleShown(object sender, EventArgs e) { - Handler.Widget.OnShown(EventArgs.Empty); + Handler.Callback.OnShown(Handler.Widget, EventArgs.Empty); } public void HandleWindowStateEvent(object o, Gtk.WindowStateEventArgs args) { var handler = Handler; + if (handler == null) + return; var windowState = handler.WindowState; if (windowState == WindowState.Normal) { @@ -264,7 +290,7 @@ public void HandleWindowStateEvent(object o, Gtk.WindowStateEventArgs args) if (windowState != OldState) { OldState = windowState; - Handler.Widget.OnWindowStateChanged(EventArgs.Empty); + Handler.Callback.OnWindowStateChanged(Handler.Widget, EventArgs.Empty); } } @@ -274,7 +300,7 @@ public void HandleWindowKeyPressEvent(object o, Gtk.KeyPressEventArgs args) var e = args.Event.ToEto(); if (e != null) { - Handler.Widget.OnKeyDown(e); + Handler.Callback.OnKeyDown(Handler.Widget, e); args.RetVal = e.Handled; } } @@ -285,7 +311,7 @@ public void HandleWindowSizeAllocated(object o, Gtk.SizeAllocatedArgs args) var newSize = handler.Size; if (handler.Control.IsRealized && oldSize != newSize) { - handler.Widget.OnSizeChanged(EventArgs.Empty); + Handler.Callback.OnSizeChanged(Handler.Widget, EventArgs.Empty); oldSize = newSize; } } @@ -299,7 +325,7 @@ public void HandleConfigureEvent(object o, Gtk.ConfigureEventArgs args) handler.currentLocation = new Point(args.Event.X, args.Event.Y); if (handler.Control.IsRealized && handler.Widget.Loaded && oldLocation != handler.currentLocation) { - handler.Widget.OnLocationChanged(EventArgs.Empty); + handler.Callback.OnLocationChanged(handler.Widget, EventArgs.Empty); oldLocation = handler.currentLocation; } handler.currentLocation = null; @@ -319,29 +345,15 @@ public MenuBar Menu Control.AddAccelGroup(accelGroup); // set accelerators menuBar = value; - SetAccelerators(menuBar); + var handler = menuBar != null ? menuBar.Handler as IMenuHandler : null; + if (handler != null) + handler.SetAccelGroup(accelGroup); + menuBox.PackStart((Gtk.Widget)value.ControlObject, true, true, 0); ((Gtk.Widget)value.ControlObject).ShowAll(); } } - void SetAccelerators(ISubMenuWidget item) - { - if (item != null && item.Items != null) - foreach (var child in item.Items) - { - var actionItem = child; - if (actionItem != null && actionItem.Shortcut != Key.None) - { - var widget = (Gtk.Widget)actionItem.ControlObject; - var key = new Gtk.AccelKey(actionItem.Shortcut.ToGdkKey(), actionItem.Shortcut.ToGdkModifier(), Gtk.AccelFlags.Visible | Gtk.AccelFlags.Locked); - widget.AddAccelerator("activate", accelGroup, key); - } - SetAccelerators(child as ISubMenuWidget); - } - - } - protected override void SetContainerContent(Gtk.Widget content) { containerBox.PackStart(content, true, true, 0); @@ -356,7 +368,7 @@ public string Title public bool CloseWindow(Action closing = null) { var args = new CancelEventArgs(); - Widget.OnClosing(args); + Callback.OnClosing(Widget, args); var shouldQuit = false; if (!args.Cancel) { @@ -367,14 +379,15 @@ public bool CloseWindow(Action closing = null) var windows = Gdk.Screen.Default.ToplevelWindows; if (windows.Count(r => r.IsViewable) == 1 && ReferenceEquals(windows.First(r => r.IsViewable), Control.GdkWindow)) { - Application.Instance.OnTerminating(args); + var app = ((ApplicationHandler)Application.Instance.Handler); + app.Callback.OnTerminating(app.Widget, args); shouldQuit = !args.Cancel; } } } if (!args.Cancel) { - Widget.OnClosed(EventArgs.Empty); + Callback.OnClosed(Widget, EventArgs.Empty); if (shouldQuit) Gtk.Application.Quit(); @@ -414,7 +427,7 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } - public ToolBar ToolBar + public Eto.Forms.ToolBar ToolBar { get { @@ -534,7 +547,7 @@ public Screen Screen if (screen != null && gdkWindow != null) { var monitor = screen.GetMonitorAtWindow(gdkWindow); - return new Screen(Generator, new ScreenHandler(screen, monitor)); + return new Screen(new ScreenHandler(screen, monitor)); } return null; } diff --git a/Source/Eto.Gtk/Forms/Menu/ButtonMenuItemHandler.cs b/Source/Eto.Gtk/Forms/Menu/ButtonMenuItemHandler.cs new file mode 100644 index 0000000000..def32e4f7d --- /dev/null +++ b/Source/Eto.Gtk/Forms/Menu/ButtonMenuItemHandler.cs @@ -0,0 +1,134 @@ +using System; +using Eto.Drawing; +using Eto.Forms; +using Eto.GtkSharp.Forms.Controls; + +namespace Eto.GtkSharp.Forms.Menu +{ + public class ButtonMenuItemHandler : MenuActionItemHandler, ButtonMenuItem.IHandler + { + string tooltip; + string text; + Keys shortcut; + Image image; + readonly Gtk.AccelLabel label; + + public ButtonMenuItemHandler() + { + Control = new Gtk.ImageMenuItem(); + label = new Gtk.AccelLabel(string.Empty); + label.Xalign = 0; + label.UseUnderline = true; + label.AccelWidget = Control; + Control.Add(label); + Control.ShowAll(); + } + + protected override void Initialize() + { + base.Initialize(); + Control.Activated += Connector.HandleActivated; + } + + protected new ButtonMenuItemConnector Connector { get { return (ButtonMenuItemConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ButtonMenuItemConnector(); + } + + protected class ButtonMenuItemConnector : WeakConnector + { + public new ButtonMenuItemHandler Handler { get { return (ButtonMenuItemHandler)base.Handler; } } + + public void HandleActivated(object sender, EventArgs e) + { + var handler = Handler; + if (handler.Control.Submenu != null) + handler.ValidateItems (); + handler.Callback.OnClick(handler.Widget, e); + } + } + + public bool Enabled + { + get { return Control.Sensitive; } + set { Control.Sensitive = value; } + } + + + public string Text + { + get { return text; } + set + { + text = value; + //string val = (shortcutText.Length > 0) ? text+"\t"+shortcutText : text; + label.Text = GtkControl.StringToMnuemonic(text); + label.UseUnderline = true; + } + } + + public string ToolTip + { + get { return tooltip; } + set + { + tooltip = value; + //label.TooltipText = value; + } + } + + + public Keys Shortcut + { + get { return shortcut; } + set + { + shortcut = value; + SetAccelerator(); + } + } + + protected override Keys GetShortcut() + { + return Shortcut; + } + + public Image Image + { + get { return image; } + set + { + image = value; + Control.Image = image.ToGtk (Gtk.IconSize.Menu); + } + } + + public void AddMenu(int index, MenuItem item) + { + if (Control.Submenu == null) Control.Submenu = new Gtk.Menu(); + ((Gtk.Menu)Control.Submenu).Insert((Gtk.Widget)item.ControlObject, index); + SetChildAccelGroup(item); + } + + public void RemoveMenu(MenuItem item) + { + if (Control.Submenu == null) return; + var menu = (Gtk.Menu)Control.Submenu; + menu.Remove((Gtk.Widget)item.ControlObject); + if (menu.Children.Length == 0) + { + Control.Submenu = null; + } + } + + public void Clear() + { + foreach (Gtk.Widget w in Control.Children) + { + Control.Remove(w); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Menu/CheckMenuItemHandler.cs b/Source/Eto.Gtk/Forms/Menu/CheckMenuItemHandler.cs new file mode 100644 index 0000000000..4488f53665 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Menu/CheckMenuItemHandler.cs @@ -0,0 +1,111 @@ +using System; +using Eto.Forms; +using Eto.GtkSharp.Forms.Controls; + +namespace Eto.GtkSharp.Forms.Menu +{ + public class CheckMenuItemHandler : MenuActionItemHandler, CheckMenuItem.IHandler + { + string text; + string tooltip; + Keys shortcut; + readonly Gtk.AccelLabel label; + + public CheckMenuItemHandler() + { + Control = new Gtk.CheckMenuItem(); + label = new Gtk.AccelLabel(string.Empty); + label.Xalign = 0; + label.UseUnderline = true; + label.AccelWidget = Control; + Control.Add(label); + Control.ShowAll(); + } + + protected override void Initialize() + { + base.Initialize(); + Control.Toggled += Connector.HandleToggled; + } + + protected new CheckMenuItemConnector Connector { get { return (CheckMenuItemConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new CheckMenuItemConnector(); + } + + protected class CheckMenuItemConnector : WeakConnector + { + public new CheckMenuItemHandler Handler { get { return (CheckMenuItemHandler)base.Handler; } } + + public void HandleToggled(object sender, EventArgs e) + { + var handler = Handler; + if (!handler.isBeingChecked) + { + handler.isBeingChecked = true; + handler.Control.Active = !handler.Control.Active; // don't let Gtk turn it on/off + handler.isBeingChecked = false; + handler.Callback.OnClick(handler.Widget, e); + } + } + } + + public string Text + { + get { return text; } + set + { + text = value; + string val = text; + label.Text = GtkControl.StringToMnuemonic(val); + label.UseUnderline = true; + } + } + + public string ToolTip + { + get { return tooltip; } + set + { + tooltip = value; + //label.TooltipText = value; + } + } + + public Keys Shortcut + { + get { return shortcut; } + set + { + shortcut = value; + SetAccelerator(); + } + } + + protected override Keys GetShortcut() + { + return Shortcut; + } + + bool isBeingChecked; + + public bool Checked + { + get { return Control.Active; } + set + { + isBeingChecked = true; + Control.Active = value; + isBeingChecked = false; + } + } + + public bool Enabled + { + get { return Control.Sensitive; } + set { Control.Sensitive = value; } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Menu/ContextMenuHandler.cs b/Source/Eto.Gtk/Forms/Menu/ContextMenuHandler.cs new file mode 100644 index 0000000000..601ec35612 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Menu/ContextMenuHandler.cs @@ -0,0 +1,44 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Menu +{ + public class ContextMenuHandler : MenuHandler, ContextMenu.IHandler + { + public ContextMenuHandler() + { + Control = new Gtk.Menu(); + Control.ShowAll(); + } + + public void AddMenu(int index, MenuItem item) + { + Control.Insert((Gtk.Widget)item.ControlObject, index); + SetChildAccelGroup(item); + } + + public void RemoveMenu(MenuItem item) + { + Control.Remove((Gtk.Widget)item.ControlObject); + } + + public void Clear() + { + foreach (Gtk.Widget w in Control.Children) + { + Control.Remove(w); + } + } + + protected override Keys GetShortcut() + { + return Keys.None; + } + + public void Show(Control relativeTo) + { + ValidateItems(); + Control.ShowAll(); + Control.Popup(); + } + } +} diff --git a/Source/Eto.Gtk/Forms/Menu/MenuBarHandler.cs b/Source/Eto.Gtk/Forms/Menu/MenuBarHandler.cs new file mode 100644 index 0000000000..9f2b82be60 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Menu/MenuBarHandler.cs @@ -0,0 +1,93 @@ +using Eto.Forms; +using System.Collections.Generic; + +namespace Eto.GtkSharp.Forms.Menu +{ + /// + /// Summary description for MenuBarHandler. + /// + public class MenuBarHandler : MenuHandler, MenuBar.IHandler + { + + public MenuBarHandler() + { + Control = new Gtk.MenuBar(); + Control.ShowAll(); + } + + protected override Keys GetShortcut() + { + return Keys.None; + } + + public void AddMenu(int index, MenuItem item) + { + Control.Insert((Gtk.Widget)item.ControlObject, index); + SetChildAccelGroup(item); + } + + public void RemoveMenu(MenuItem item) + { + Control.Remove((Gtk.Widget)item.ControlObject); + var handler = item.Handler as IMenuHandler; + if (handler != null) + handler.SetAccelGroup(null); + } + + public void Clear() + { + foreach (Gtk.Widget w in Control.Children) + { + Control.Remove(w); + } + } + + MenuItem quitItem; + public void SetQuitItem(MenuItem item) + { + item.Order = 1000; + if (quitItem != null) + ApplicationMenu.Items.Remove(quitItem); + else + ApplicationMenu.Items.AddSeparator(999); + ApplicationMenu.Items.Add(item); + quitItem = item; + } + + MenuItem aboutItem; + public void SetAboutItem(MenuItem item) + { + item.Order = 1000; + if (aboutItem != null) + HelpMenu.Items.Remove(aboutItem); + else + HelpMenu.Items.AddSeparator(999); + HelpMenu.Items.Add(item); + aboutItem = item; + } + + public void CreateSystemMenu() + { + // no system menu items + } + + public void CreateLegacySystemMenu() + { + + } + public IEnumerable GetSystemCommands() + { + yield break; + } + + public ButtonMenuItem ApplicationMenu + { + get { return Widget.Items.GetSubmenu("&File", -100); } + } + + public ButtonMenuItem HelpMenu + { + get { return Widget.Items.GetSubmenu("&Help", 1000); } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Menu/MenuHandler.cs b/Source/Eto.Gtk/Forms/Menu/MenuHandler.cs new file mode 100644 index 0000000000..0eae46dc39 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Menu/MenuHandler.cs @@ -0,0 +1,68 @@ +using System; +using Eto.Forms; +using System.Linq; + +namespace Eto.GtkSharp.Forms.Menu +{ + public interface IMenuHandler + { + void SetAccelGroup(Gtk.AccelGroup accel); + } + + public abstract class MenuHandler : WidgetHandler, Eto.Forms.Menu.IHandler, IMenuHandler + where TWidget: Eto.Forms.Menu + where TCallback : Eto.Forms.Menu.ICallback + { + protected void ValidateItems() + { + var subMenu = Widget as ISubmenu; + if (subMenu != null) + { + foreach (var item in subMenu.Items) + { + var handler = item.Handler as IMenuActionItemHandler; + if (handler != null) + handler.TriggerValidate(); + } + } + } + + public virtual void SetAccelGroup(Gtk.AccelGroup accel) + { + AccelGroup = accel; + SetAccelerator(); + var subMenu = Widget as ISubmenu; + if (subMenu != null) + { + foreach (var item in subMenu.Items.Select(r => r.Handler).OfType()) + { + item.SetAccelGroup(accel); + } + } + } + + protected virtual void SetChildAccelGroup(MenuItem item) + { + if (item == null) + return; + var handler = item.Handler as IMenuHandler; + if (handler != null) + handler.SetAccelGroup(AccelGroup); + } + + protected abstract Keys GetShortcut(); + + protected void SetAccelerator() + { + var shortcut = GetShortcut(); + if (AccelGroup != null && shortcut != Keys.None) + { + var widget = (Gtk.Widget)Widget.ControlObject; + var key = new Gtk.AccelKey(shortcut.ToGdkKey(), shortcut.ToGdkModifier(), Gtk.AccelFlags.Visible | Gtk.AccelFlags.Locked); + widget.AddAccelerator("activate", AccelGroup, key); + } + } + + protected Gtk.AccelGroup AccelGroup { get; private set; } + } +} diff --git a/Source/Eto.Gtk/Forms/Menu/RadioMenuItemHandler.cs b/Source/Eto.Gtk/Forms/Menu/RadioMenuItemHandler.cs new file mode 100644 index 0000000000..8c3d67ab6f --- /dev/null +++ b/Source/Eto.Gtk/Forms/Menu/RadioMenuItemHandler.cs @@ -0,0 +1,164 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Menu +{ + /// + /// Summary description for MenuBarHandler. + /// + public class RadioMenuItemHandler : MenuActionItemHandler, RadioMenuItem.IHandler + { + string text; + Keys shortcut; + Gtk.AccelLabel label; + Gtk.Label accelLabel; + bool isActivating; + bool enabled = true; + bool isChecked; + RadioMenuItemHandler controller; + + public RadioMenuItemHandler() + { + label = new Gtk.AccelLabel(string.Empty); + label.Xalign = 0; + label.UseUnderline = true; + label.AccelWidget = Control; + accelLabel = new Gtk.Label(); + accelLabel.Xalign = 1; + accelLabel.Visible = false; + } + + public void Create(RadioMenuItem controller) + { + if (controller != null) + { + Control = new Gtk.RadioMenuItem((Gtk.RadioMenuItem)controller.ControlObject); + this.controller = (RadioMenuItemHandler)controller.Handler; + } + else + { + this.controller = this; + Control = new Gtk.RadioMenuItem(string.Empty); + foreach (Gtk.Widget w in Control.Children) + { + Control.Remove(w); + } + } + + Control.Sensitive = enabled; + var hbox = new Gtk.HBox(false, 4); + hbox.Add(label); + hbox.Add(accelLabel); + Control.Add(hbox); + Control.Toggled += Connector.HandleToggled; + Control.ShowAll(); + } + + protected new RadioMenuItemConnector Connector { get { return (RadioMenuItemConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new RadioMenuItemConnector(); + } + + protected class RadioMenuItemConnector : WeakConnector + { + public new RadioMenuItemHandler Handler { get { return (RadioMenuItemHandler)base.Handler; } } + + public void HandleToggled(object sender, EventArgs e) + { + var handler = Handler; + if (!handler.controller.isActivating) + { + handler.Callback.OnClick(handler.Widget, e); + } + } + } + + public string Text + { + get { return text; } + set + { + text = value; + label.TextWithMnemonic = value; + } + } + + public string ToolTip + { + get { return label.TooltipText; } + set { label.TooltipText = value; } + } + + public Keys Shortcut + { + get { return shortcut; } + set + { + shortcut = value; + accelLabel.Text = value.ToShortcutString(); + accelLabel.Visible = accelLabel.Text.Length > 0; + SetAccelerator(); + } + } + + protected override Keys GetShortcut() + { + return Shortcut; + } + + public bool Checked + { + get { return Control != null ? Control.Active : isChecked; } + set + { + isChecked = value; + if (Control != null) + { + controller.isActivating = true; + Control.Active = value; + controller.isActivating = false; + } + } + } + + public bool Enabled + { + get { return Control != null ? enabled : Control.Sensitive; } + set { + if (Control != null) + Control.Sensitive = value; + else + enabled = value; + } + } + + public void AddMenu(int index, MenuItem item) + { + if (Control.Submenu == null) + Control.Submenu = new Gtk.Menu(); + ((Gtk.Menu)Control.Submenu).Insert((Gtk.Widget)item.ControlObject, index); + } + + public void RemoveMenu(MenuItem item) + { + if (Control.Submenu == null) + return; + var menu = (Gtk.Menu)Control.Submenu; + menu.Remove((Gtk.Widget)item.ControlObject); + if (menu.Children.Length == 0) + { + Control.Submenu = null; + } + } + + public void Clear() + { + foreach (Gtk.Widget w in Control.Children) + { + Control.Remove(w); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/Menu/SeparatorMenuItemHandler.cs b/Source/Eto.Gtk/Forms/Menu/SeparatorMenuItemHandler.cs new file mode 100644 index 0000000000..dfcbd6094f --- /dev/null +++ b/Source/Eto.Gtk/Forms/Menu/SeparatorMenuItemHandler.cs @@ -0,0 +1,47 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Menu +{ + public class SeparatorMenuItemHandler : MenuHandler, SeparatorMenuItem.IHandler + { + public SeparatorMenuItemHandler() + { + Control = new Gtk.SeparatorMenuItem(); + Control.ShowAll(); + } + + public void CreateFromCommand(Command command) + { + } + + protected override Keys GetShortcut() + { + return Keys.None; + } + + public string Text + { + get { return null; } + set { throw new NotSupportedException(); } + } + + public string ToolTip + { + get { return null; } + set { throw new NotSupportedException(); } + } + + public Keys Shortcut + { + get { return Keys.None; } + set { throw new NotSupportedException(); } + } + + public bool Enabled + { + get { return false; } + set { } + } + } +} diff --git a/Source/Eto.Gtk/Forms/MessageBoxHandler.cs b/Source/Eto.Gtk/Forms/MessageBoxHandler.cs new file mode 100644 index 0000000000..4e5ef93396 --- /dev/null +++ b/Source/Eto.Gtk/Forms/MessageBoxHandler.cs @@ -0,0 +1,61 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms +{ + public class MessageBoxHandler : WidgetHandler, MessageBox.IHandler + { + Gtk.MessageDialog control; + + public string Text { get; set; } + + public string Caption { get; set; } + + public MessageBoxType Type { get; set; } + + public MessageBoxButtons Buttons { get; set; } + + public MessageBoxDefaultButton DefaultButton { get; set; } + + public DialogResult ShowDialog(Control parent) + { + Gtk.Window parentWindow = null; + if (parent != null && parent.ParentWindow != null) + parentWindow = parent.ParentWindow.ControlObject as Gtk.Window; + + control = new Gtk.MessageDialog(parentWindow, Gtk.DialogFlags.Modal, Type.ToGtk(), Buttons.ToGtk(), false, Text); + control.TypeHint = Gdk.WindowTypeHint.Dialog; + var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null); + if (!string.IsNullOrEmpty(caption)) + control.Title = caption; + if (Buttons == MessageBoxButtons.YesNoCancel) + { + // must add cancel manually + var b = (Gtk.Button)control.AddButton(Gtk.Stock.Cancel, (int)Gtk.ResponseType.Cancel); + b.UseStock = true; + } + control.DefaultResponse = DefaultButton.ToGtk(Buttons); + int ret = control.Run(); + control.Destroy(); + var result = ((Gtk.ResponseType)ret).ToEto(); + if (result == DialogResult.None) + { + switch (Buttons) + { + case MessageBoxButtons.OK: + result = DialogResult.Ok; + break; + case MessageBoxButtons.YesNo: + result = DialogResult.No; + break; + case MessageBoxButtons.OKCancel: + case MessageBoxButtons.YesNoCancel: + result = DialogResult.Cancel; + break; + } + } + return result; + } + } + +} diff --git a/Source/Eto.Gtk/Forms/MouseHandler.cs b/Source/Eto.Gtk/Forms/MouseHandler.cs new file mode 100644 index 0000000000..dce8910a9b --- /dev/null +++ b/Source/Eto.Gtk/Forms/MouseHandler.cs @@ -0,0 +1,30 @@ +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms +{ + public class MouseHandler : Mouse.IHandler + { + public PointF Position + { + get + { + int x, y; + Gdk.Display.Default.GetPointer (out x, out y); + return new PointF (x, y); + } + } + + public MouseButtons Buttons + { + get + { + int x, y; + Gdk.ModifierType modifier; + Gdk.Display.Default.GetPointer (out x, out y, out modifier); + return modifier.ToEtoMouseButtons (); + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/OpenFileDialog.cs b/Source/Eto.Gtk/Forms/OpenFileDialog.cs new file mode 100644 index 0000000000..c1a6a0e1ee --- /dev/null +++ b/Source/Eto.Gtk/Forms/OpenFileDialog.cs @@ -0,0 +1,29 @@ +using Eto.Forms; +using System.Collections.Generic; + +namespace Eto.GtkSharp.Forms +{ + public class OpenFileDialogHandler : GtkFileDialog, OpenFileDialog.IHandler + { + public OpenFileDialogHandler() + { + Control = new Gtk.FileChooserDialog(string.Empty, null, Gtk.FileChooserAction.Open); + Control.SetCurrentFolder(System.IO.Directory.GetCurrentDirectory()); + + Control.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); + Control.AddButton(Gtk.Stock.Open, Gtk.ResponseType.Ok); + } + + public bool MultiSelect + { + get { return Control.SelectMultiple; } + set { Control.SelectMultiple = value; } + } + + public IEnumerable Filenames + { + get { return Control.Filenames; } + } + + } +} diff --git a/Source/Eto.Gtk/Forms/PixelLayoutHandler.cs b/Source/Eto.Gtk/Forms/PixelLayoutHandler.cs new file mode 100644 index 0000000000..8406b6c837 --- /dev/null +++ b/Source/Eto.Gtk/Forms/PixelLayoutHandler.cs @@ -0,0 +1,47 @@ +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Forms.Controls; + +namespace Eto.GtkSharp.Forms +{ + public class PixelLayoutHandler : GtkContainer, PixelLayout.IHandler + { + public PixelLayoutHandler() + { + Control = new Gtk.Fixed(); + } + + public void Add(Control child, int x, int y) + { + var ctl = child.GetGtkControlHandler(); + + var widget = ctl.ContainerControl; + if (widget.Parent != null) + ((Gtk.Container)widget.Parent).Remove(widget); + Control.Put(widget, x, y); + ctl.CurrentLocation = new Point(x, y); + widget.ShowAll(); + } + + public void Move(Control child, int x, int y) + { + var ctl = child.GetGtkControlHandler(); + if (ctl.CurrentLocation.X != x || ctl.CurrentLocation.Y != y) + { + Control.Move(ctl.ContainerControl, x, y); + + ctl.CurrentLocation = new Point(x, y); + } + } + + public void Remove(Control child) + { + Control.Remove(child.GetContainerWidget()); + } + + public void Update() + { + Control.ResizeChildren(); + } + } +} diff --git a/Source/Eto.Gtk/Forms/Printing/PrintDialogHandler.cs b/Source/Eto.Gtk/Forms/Printing/PrintDialogHandler.cs new file mode 100644 index 0000000000..368aa4e637 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Printing/PrintDialogHandler.cs @@ -0,0 +1,90 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Printing +{ + public class PrintDialogHandler : WidgetHandler, PrintDialog.IHandler + { + PrintSettings settings; + + public PrintDialogHandler () + { + AllowPageRange =true; + } + + public PrintDocument Document { get; set; } + + public class CustomOptions : Gtk.VBox { + public Gtk.CheckButton SelectionOnly { get; private set; } + + public CustomOptions () + { + this.Spacing = 10; + SelectionOnly = new Gtk.CheckButton { Label = "Selection Only" }; + this.PackStart (SelectionOnly, false, false, 10); + } + } + + public DialogResult ShowDialog (Window parent) + { + var parentWindow = parent != null ? (Gtk.Window)parent.ControlObject : null; + Control = new Gtk.PrintUnixDialog(string.Empty, parentWindow); + + if (parent != null) + { + Control.TransientFor = ((Gtk.Window)parent.ControlObject); + Control.Modal = true; + } + + const Gtk.PrintCapabilities caps = Gtk.PrintCapabilities.Preview + | Gtk.PrintCapabilities.Collate + | Gtk.PrintCapabilities.GeneratePdf + | Gtk.PrintCapabilities.Copies + | Gtk.PrintCapabilities.PageSet + | Gtk.PrintCapabilities.GeneratePs + | Gtk.PrintCapabilities.Scale + | Gtk.PrintCapabilities.NumberUp + | Gtk.PrintCapabilities.Reverse; + var printSettingsHandler = (PrintSettingsHandler)PrintSettings.Handler; + + Control.PageSetup = PrintSettings.ToGtkPageSetup (); + Control.PrintSettings = PrintSettings.ToGtkPrintSettings (); + var customOptions = new CustomOptions(); + customOptions.SelectionOnly.Active = printSettingsHandler.SelectionOnly; + + if (AllowSelection) + Control.AddCustomTab (customOptions, new Gtk.Label { Text = "Other Options" }); + + Control.ManualCapabilities = caps; + Control.ShowAll (); + var response = (Gtk.ResponseType)Control.Run (); + Control.Hide (); + + printSettingsHandler.Set(Control.PrintSettings, Control.PageSetup, customOptions.SelectionOnly.Active); + if (response == Gtk.ResponseType.Apply) { + printSettingsHandler.ShowPreview = true; + return DialogResult.Ok; + } + + return response.ToEto (); + } + public PrintSettings PrintSettings { + get { + if (settings == null) settings = new PrintSettings(); + return settings; + } + set { + settings = value; + } + } + + // not supported in gtk + public bool AllowPageRange { + get; set; + } + + public bool AllowSelection { + get; set; + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Printing/PrintDocumentHandler.cs b/Source/Eto.Gtk/Forms/Printing/PrintDocumentHandler.cs new file mode 100644 index 0000000000..6a0e3e999f --- /dev/null +++ b/Source/Eto.Gtk/Forms/Printing/PrintDocumentHandler.cs @@ -0,0 +1,85 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.GtkSharp.Drawing; + +namespace Eto.GtkSharp.Forms.Printing +{ + public class PrintDocumentHandler : WidgetHandler, PrintDocument.IHandler + { + PrintSettings settings; + + public PrintDocumentHandler() + { + Control = new Gtk.PrintOperation(); + } + + public void Print() + { + var settingsHandler = (PrintSettingsHandler)PrintSettings.Handler; + Control.PrintSettings = settingsHandler.Control; + if (settingsHandler.ShowPreview) + Control.Run(Gtk.PrintOperationAction.Preview, null); + else + Control.Run(Gtk.PrintOperationAction.Print, null); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case PrintDocument.PrintingEvent: + Control.BeginPrint += (o, args) => Callback.OnPrinting(Widget, EventArgs.Empty); + break; + case PrintDocument.PrintedEvent: + Control.EndPrint += (o, args) => Callback.OnPrinted(Widget, EventArgs.Empty); + break; + + case PrintDocument.PrintPageEvent: + Control.DrawPage += (o, args) => + { + using (var graphics = new Graphics(new GraphicsHandler(args.Context.CairoContext, args.Context.CreatePangoContext()))) + { + var width = args.Context.Width; //.PageSetup.GetPageWidth(Gtk.Unit.Points); + var height = args.Context.Height; //.PageSetup.GetPageHeight(Gtk.Unit.Points); + var e = new PrintPageEventArgs(graphics, new SizeF((float)width, (float)height), args.PageNr); + Callback.OnPrintPage(Widget, e); + } + }; + break; + default: + base.AttachEvent(id); + break; + } + } + + public string Name + { + get { return Control.JobName; } + set { Control.JobName = value; } + } + + public PrintSettings PrintSettings + { + get + { + if (settings == null) + settings = Control.PrintSettings.ToEto(Control.DefaultPageSetup, false); + return settings; + } + set + { + settings = value; + Control.DefaultPageSetup = settings.ToGtkPageSetup(); + Control.PrintSettings = settings.ToGtkPrintSettings(); + } + } + + public int PageCount + { + get { return Control.NPages; } + set { Control.NPages = value; } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/Printing/PrintSettingsHandler.cs b/Source/Eto.Gtk/Forms/Printing/PrintSettingsHandler.cs new file mode 100644 index 0000000000..6336849d02 --- /dev/null +++ b/Source/Eto.Gtk/Forms/Printing/PrintSettingsHandler.cs @@ -0,0 +1,105 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.Printing +{ + public static class PrintSettingsExtensions + { + public static PrintSettings ToEto (this Gtk.PrintSettings settings, Gtk.PageSetup setup, bool selectionOnly) + { + return settings == null ? null : new PrintSettings(new PrintSettingsHandler(settings, setup, selectionOnly)); + } + + public static Gtk.PrintSettings ToGtkPrintSettings (this PrintSettings settings) + { + return settings == null ? null : ((PrintSettingsHandler)settings.Handler).Control; + } + + public static Gtk.PageSetup ToGtkPageSetup (this PrintSettings settings) + { + return settings == null ? null : ((PrintSettingsHandler)settings.Handler).PageSetup; + } + } + + public class PrintSettingsHandler : WidgetHandler, PrintSettings.IHandler + { + public bool SelectionOnly { get; set; } + + public Gtk.PageSetup PageSetup { get; set; } + + public bool ShowPreview { get; set; } + + public PrintSettingsHandler () + { + Control = new Gtk.PrintSettings(); + PageSetup = new Gtk.PageSetup(); + MaximumPageRange = new Range(1, 1); + Collate = true; + } + + public PrintSettingsHandler (Gtk.PrintSettings settings, Gtk.PageSetup setup, bool selectionOnly) + { + MaximumPageRange = new Range(1, 1); + Set (settings, setup, selectionOnly); + } + + public void Set (Gtk.PrintSettings settings, Gtk.PageSetup setup, bool selectionOnly) + { + Control = settings; + PageSetup = setup; + SelectionOnly = selectionOnly; + } + + public int Copies { + get { return Control.NCopies; } + set { Control.NCopies = value; } + } + + public Range MaximumPageRange + { + get; set; + } + + public Range SelectedPageRange + { + get { + int num_ranges; + return Control.GetPageRanges (out num_ranges).ToEto (); + } + set { + Control.SetPageRanges(value.ToGtkPageRange (), 1); + } + } + + public PrintSelection PrintSelection { + get { + if (SelectionOnly) + return PrintSelection.Selection; + return Control.PrintPages.ToEto (); + } + set { + if (value == Eto.Forms.PrintSelection.Selection) + SelectionOnly = true; + else { + Control.PrintPages = value.ToGtk (); + SelectionOnly = false; + } + } + } + + public PageOrientation Orientation { + get { return PageSetup.Orientation.ToEto (); } + set { PageSetup.Orientation = value.ToGtk (); } + } + + public bool Collate { + get { return Control.Collate; } + set { Control.Collate = value; } + } + + public bool Reverse { + get { return Control.Reverse; } + set { Control.Reverse = value; } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/SaveFileDialog.cs b/Source/Eto.Gtk/Forms/SaveFileDialog.cs new file mode 100644 index 0000000000..af93d92c02 --- /dev/null +++ b/Source/Eto.Gtk/Forms/SaveFileDialog.cs @@ -0,0 +1,17 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms +{ + public class SaveFileDialogHandler : GtkFileDialog, SaveFileDialog.IHandler + { + public SaveFileDialogHandler() + { + Control = new Gtk.FileChooserDialog(string.Empty, null, Gtk.FileChooserAction.Save); + Control.DoOverwriteConfirmation = true; + Control.SetCurrentFolder(System.IO.Directory.GetCurrentDirectory()); + + Control.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); + Control.AddButton(Gtk.Stock.Save, Gtk.ResponseType.Ok); + } + } +} diff --git a/Source/Eto.Gtk/Forms/ScreenHandler.cs b/Source/Eto.Gtk/Forms/ScreenHandler.cs new file mode 100644 index 0000000000..31fae30754 --- /dev/null +++ b/Source/Eto.Gtk/Forms/ScreenHandler.cs @@ -0,0 +1,53 @@ +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms +{ + public class ScreenHandler : WidgetHandler, Screen.IHandler + { + readonly int monitor; + + public ScreenHandler (Gdk.Screen screen, int monitor) + { + this.Control = screen; + this.monitor = monitor; + } + + public float RealScale + { + get { return (float)Control.Resolution / 72f; } + } + + public float Scale + { + get { return (float)Control.Resolution / 72f; } + } + + public RectangleF Bounds + { + get { + return Control.GetMonitorGeometry (monitor).ToEto (); + } + } + + public RectangleF WorkingArea + { + get + { + // todo: available with GTK 3.4 + return Control.GetMonitorGeometry (monitor).ToEto (); + } + } + + public int BitsPerPixel + { + get { return 24; } + } + + public bool IsPrimary + { + get { return monitor == 0; } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/ScreensHandler.cs b/Source/Eto.Gtk/Forms/ScreensHandler.cs new file mode 100644 index 0000000000..82bd1b6e15 --- /dev/null +++ b/Source/Eto.Gtk/Forms/ScreensHandler.cs @@ -0,0 +1,39 @@ +using Eto.Forms; +using System.Collections.Generic; + +namespace Eto.GtkSharp.Forms +{ + public class ScreensHandler : Screen.IScreensHandler + { + public void Initialize () + { + } + + public Widget Widget { get; set; } + + public Eto.Platform Platform { get; set; } + + public IEnumerable Screens + { + get + { + var display = Gdk.Display.Default; + for (int i = 0; i < display.NScreens; i++) { + var screen = display.GetScreen (i); + for (int monitor = 0; monitor < screen.NMonitors; monitor++) { + yield return new Screen (Platform, new ScreenHandler (screen, monitor)); + } + } + } + } + + public Screen PrimaryScreen + { + get + { + return new Screen(Platform, new ScreenHandler(Gdk.Display.Default.DefaultScreen, 0)); + } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/SelectFolderDialogHandler.cs b/Source/Eto.Gtk/Forms/SelectFolderDialogHandler.cs new file mode 100644 index 0000000000..65af9d20d3 --- /dev/null +++ b/Source/Eto.Gtk/Forms/SelectFolderDialogHandler.cs @@ -0,0 +1,44 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms +{ + public class SelectFolderDialogHandler : WidgetHandler, SelectFolderDialog.IHandler + { + public SelectFolderDialogHandler () + { + Control = new Gtk.FileChooserDialog(string.Empty, null, Gtk.FileChooserAction.SelectFolder); + Control.SetCurrentFolder(System.IO.Directory.GetCurrentDirectory()); + + Control.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); + Control.AddButton(Gtk.Stock.Save, Gtk.ResponseType.Ok); + } + + + public DialogResult ShowDialog (Window parent) + { + if (parent != null) Control.TransientFor = (Gtk.Window)parent.ControlObject; + + int result = Control.Run(); + + Control.Hide (); + + DialogResult response = ((Gtk.ResponseType)result).ToEto (); + if (response == DialogResult.Ok) System.IO.Directory.SetCurrentDirectory(Control.CurrentFolder); + + return response; + } + + public string Title + { + get { return Control.Title; } + set { Control.Title = value; } + } + + public string Directory + { + get { return Control.CurrentFolder; } + set { Control.SetCurrentFolder(value); } + } + } +} + diff --git a/Source/Eto.Gtk/Forms/TableLayoutHandler.cs b/Source/Eto.Gtk/Forms/TableLayoutHandler.cs new file mode 100644 index 0000000000..f1ba256d1a --- /dev/null +++ b/Source/Eto.Gtk/Forms/TableLayoutHandler.cs @@ -0,0 +1,224 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using System.Linq; + +namespace Eto.GtkSharp.Forms +{ + public class TableLayoutHandler : GtkContainer, TableLayout.IHandler + { + const Gtk.AttachOptions SCALED_OPTIONS = Gtk.AttachOptions.Expand | Gtk.AttachOptions.Shrink | Gtk.AttachOptions.Fill; + Gtk.Alignment align; + Gtk.EventBox box; + bool[] columnScale; + int lastColumnScale; + bool[] rowScale; + int lastRowScale; + Control[,] controls; + Gtk.Widget[,] blank; + Size? spacing; + + public override Gtk.Widget ContainerControl + { + get { return box; } + } + + public Size Spacing + { + get { return Control != null ? new Size((int)Control.ColumnSpacing, (int)Control.RowSpacing) : spacing ?? Size.Empty; } + set + { + if (Control == null) + spacing = value; + else + { + Control.ColumnSpacing = (uint)value.Width; + Control.RowSpacing = (uint)value.Height; + } + } + } + + public Padding Padding + { + get + { + uint top, bottom, left, right; + align.GetPadding(out top, out bottom, out left, out right); + return new Padding((int)left, (int)top, (int)right, (int)bottom); + } + set + { + align.SetPadding((uint)value.Top, (uint)value.Bottom, (uint)value.Left, (uint)value.Right); + } + } + + public void Add(Control child, int x, int y) + { + Attach(child, x, y); + if (child != null) + { + var widget = child.GetContainerWidget(); + widget.ShowAll(); + } + } + + public void Move(Control child, int x, int y) + { + Attach(child, x, y); + } + + Gtk.AttachOptions GetColumnOptions(int column) + { + var scale = columnScale[column] || column == lastColumnScale; + return scale ? SCALED_OPTIONS : Gtk.AttachOptions.Fill; + } + + Gtk.AttachOptions GetRowOptions(int row) + { + var scale = rowScale[row] || row == lastRowScale; + return scale ? SCALED_OPTIONS : Gtk.AttachOptions.Fill; + } + + public TableLayoutHandler() + { + align = new Gtk.Alignment(0, 0, 1.0F, 1.0F); + box = new Gtk.EventBox { Child = align }; + Spacing = TableLayout.DefaultSpacing; + Padding = TableLayout.DefaultPadding; + } + + public void CreateControl(int cols, int rows) + { + columnScale = new bool[cols]; + lastColumnScale = cols - 1; + rowScale = new bool[rows]; + lastRowScale = rows - 1; + Control = new Gtk.Table((uint)rows, (uint)cols, false); + controls = new Control[rows, cols]; + blank = new Gtk.Widget[rows, cols]; + align.Add(Control); + if (spacing != null) + { + Control.ColumnSpacing = (uint)spacing.Value.Width; + Control.RowSpacing = (uint)spacing.Value.Height; + spacing = null; + } + } + + public void SetColumnScale(int column, bool scale) + { + columnScale[column] = scale; + var lastScale = lastColumnScale; + lastColumnScale = columnScale.Any(r => r) ? -1 : columnScale.Length - 1; + AttachColumn(column); + if (lastScale != lastColumnScale && column != columnScale.Length - 1) + { + AttachColumn(columnScale.Length - 1); + } + } + + public bool GetColumnScale(int column) + { + return columnScale[column]; + } + + void AttachColumn(int column) + { + for (int y = 0; y < controls.GetLength (0); y++) + { + Attach(controls[y, column], column, y); + } + } + + void AttachRow(int row) + { + for (int x = 0; x < controls.GetLength (1); x++) + { + Attach(controls[row, x], x, row); + } + } + + bool Attach(Control child, int x, int y) + { + var old = controls[y, x]; + if (old != null && !object.ReferenceEquals(old, child)) + { + var widget = old.GetContainerWidget(); + if (widget.Parent != null) + Control.Remove(widget); + } + + if (child != null) + { + var blankWidget = blank[y, x]; + if (blankWidget != null) + { + if (blankWidget.Parent != null) + Control.Remove(blankWidget); + blank[y, x] = null; + } + + controls[y, x] = child; + var widget = child.GetContainerWidget(); + if (widget.Parent != null) + ((Gtk.Container)widget.Parent).Remove(widget); + Control.Attach(widget, (uint)x, (uint)x + 1, (uint)y, (uint)y + 1, GetColumnOptions(x), GetRowOptions(y), 0, 0); + widget.ShowAll(); + return true; + } + else + { + controls[y, x] = null; + var blankWidget = blank[y, x]; + if (blankWidget == null) + blankWidget = blank[y, x] = new Gtk.VBox(); + else if (blankWidget.Parent != null) + Control.Remove(blankWidget); + Control.Attach(blankWidget, (uint)x, (uint)x + 1, (uint)y, (uint)y + 1, GetColumnOptions(x), GetRowOptions(y), 0, 0); + } + return false; + } + + public void Remove(Control child) + { + for (int y = 0; y r) ? -1 : rowScale.Length - 1; + AttachRow(row); + if (lastScale != lastRowScale && row != rowScale.Length - 1) + { + AttachRow(rowScale.Length - 1); + } + } + + public bool GetRowScale(int row) + { + return rowScale[row]; + } + + public void Update() + { + Control.ResizeChildren(); + } + } +} diff --git a/Source/Eto.Gtk/Forms/ToolBar/ButtonToolItemHandler.cs b/Source/Eto.Gtk/Forms/ToolBar/ButtonToolItemHandler.cs new file mode 100644 index 0000000000..04272b3f9b --- /dev/null +++ b/Source/Eto.Gtk/Forms/ToolBar/ButtonToolItemHandler.cs @@ -0,0 +1,46 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.ToolBar +{ + + public class ButtonToolItemHandler : ToolItemHandler, ButtonToolItem.IHandler + { + + #region IToolBarButton Members + + + #endregion + + public override void CreateControl(ToolBarHandler handler, int index) + { + Gtk.Toolbar tb = handler.Control; + + Control = new Gtk.ToolButton(GtkImage, Text); + Control.IsImportant = true; + Control.Sensitive = Enabled; + //Control.TooltipText = this.ToolTip; + //control.CanFocus = false; + tb.Insert(Control, index); + if (tb.Visible) Control.ShowAll(); + Control.Clicked += Connector.HandleClicked; + } + + protected new ButtonToolItemConnector Connector { get { return (ButtonToolItemConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new ButtonToolItemConnector(); + } + + protected class ButtonToolItemConnector : WeakConnector + { + public new ButtonToolItemHandler Handler { get { return (ButtonToolItemHandler)base.Handler; } } + + public void HandleClicked(object sender, EventArgs e) + { + Handler.Widget.OnClick(e); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/ToolBar/CheckToolItemHandler.cs b/Source/Eto.Gtk/Forms/ToolBar/CheckToolItemHandler.cs new file mode 100644 index 0000000000..aa1af5591e --- /dev/null +++ b/Source/Eto.Gtk/Forms/ToolBar/CheckToolItemHandler.cs @@ -0,0 +1,59 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.ToolBar +{ + public class CheckToolItemHandler : ToolItemHandler, CheckToolItem.IHandler + { + bool ischecked; + + public bool Checked + { + get { return (Control != null) ? Control.Active : ischecked; } + set + { + if (value != ischecked) + { + if (Control != null) + Control.Active = value; + ischecked = value; + } + } + } + + public override void CreateControl(ToolBarHandler handler, int index) + { + Gtk.Toolbar tb = handler.Control; + + Control = new Gtk.ToggleToolButton(); + Control.Active = ischecked; + Control.Label = Text; + //Control.TooltipText = this.ToolTip; + Control.IconWidget = GtkImage; + Control.Sensitive = Enabled; + Control.CanFocus = false; + Control.IsImportant = true; + tb.Insert(Control, index); + if (tb.Visible) + Control.ShowAll(); + Control.Toggled += Connector.HandleToggled; + } + + protected new CheckToolItemConnector Connector { get { return (CheckToolItemConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new CheckToolItemConnector(); + } + + protected class CheckToolItemConnector : WeakConnector + { + public new CheckToolItemHandler Handler { get { return (CheckToolItemHandler)base.Handler; } } + + public void HandleToggled(object sender, EventArgs e) + { + Handler.Widget.OnClick(EventArgs.Empty); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/ToolBar/RadioToolItemHandler.cs b/Source/Eto.Gtk/Forms/ToolBar/RadioToolItemHandler.cs new file mode 100644 index 0000000000..da6ef613a3 --- /dev/null +++ b/Source/Eto.Gtk/Forms/ToolBar/RadioToolItemHandler.cs @@ -0,0 +1,60 @@ +using System; +using Eto.Forms; +using System.Linq; + +namespace Eto.GtkSharp.Forms.ToolBar +{ + public class RadioToolItemHandler : ToolItemHandler, RadioToolItem.IHandler + { + bool ischecked; + + public bool Checked + { + get { return (Control != null) ? Control.Active : ischecked; } + set + { + if (value != ischecked) + { + if (Control != null) + Control.Active = value; + ischecked = value; + } + } + } + + public override void CreateControl(ToolBarHandler handler, int index) + { + Gtk.Toolbar tb = handler.Control; + + Control = new Gtk.RadioToolButton(handler.RadioGroup); + Control.Active = ischecked; + Control.Label = Text; + //Control.TooltipText = this.ToolTip; + Control.IconWidget = GtkImage; + Control.Sensitive = Enabled; + Control.CanFocus = false; + Control.IsImportant = true; + tb.Insert(Control, index); + if (tb.Visible) + Control.ShowAll(); + Control.Toggled += Connector.HandleToggled; + } + + protected new RadioToolItemConnector Connector { get { return (RadioToolItemConnector)base.Connector; } } + + protected override WeakConnector CreateConnector() + { + return new RadioToolItemConnector(); + } + + protected class RadioToolItemConnector : WeakConnector + { + public new RadioToolItemHandler Handler { get { return (RadioToolItemHandler)base.Handler; } } + + public void HandleToggled(object sender, EventArgs e) + { + Handler.Widget.OnClick(EventArgs.Empty); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/ToolBar/SeparatorToolItemHandler.cs b/Source/Eto.Gtk/Forms/ToolBar/SeparatorToolItemHandler.cs new file mode 100644 index 0000000000..63e616193b --- /dev/null +++ b/Source/Eto.Gtk/Forms/ToolBar/SeparatorToolItemHandler.cs @@ -0,0 +1,38 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.ToolBar +{ + public class SeparatorToolItemHandler : ToolItemHandler, SeparatorToolItem.IHandler + { + SeparatorToolItemType type; + + public override void CreateControl(ToolBarHandler handler, int index) + { + Gtk.Toolbar tb = handler.Control; + Control = new Gtk.SeparatorToolItem(); + SetType(); + tb.Insert(Control, index); + if (tb.Visible) + Control.ShowAll(); + } + + void SetType() + { + if (Control != null) + { + Control.Expand = type == SeparatorToolItemType.FlexibleSpace; + Control.Draw = type == SeparatorToolItemType.Divider; + } + } + + public SeparatorToolItemType Type + { + get { return type; } + set + { + type = value; + SetType(); + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/ToolBar/ToolBarHandler.cs b/Source/Eto.Gtk/Forms/ToolBar/ToolBarHandler.cs new file mode 100644 index 0000000000..c67fba0d87 --- /dev/null +++ b/Source/Eto.Gtk/Forms/ToolBar/ToolBarHandler.cs @@ -0,0 +1,79 @@ +using Eto.Forms; + +namespace Eto.GtkSharp.Forms.ToolBar +{ + public class ToolBarHandler : WidgetHandler, Eto.Forms.ToolBar.IHandler + { + ToolBarDock dock = ToolBarDock.Top; + + #if GTK2 + Gtk.RadioButton radioGroup; + public GLib.SList RadioGroup + { + get { return (radioGroup ?? (radioGroup = new Gtk.RadioButton("g"))).Group; } + } + #elif GTK3 + Gtk.RadioToolButton radioGroup; + public Gtk.RadioToolButton RadioGroup + { + get { return (radioGroup ?? (radioGroup = new Gtk.RadioToolButton(new Gtk.RadioToolButton[0]))); } + } + #endif + + public ToolBarHandler() + { + Control = new Gtk.Toolbar(); + //control.ToolbarStyle = Gtk.ToolbarStyle.Both; + } + + public ToolBarDock Dock + { + get { return dock; } + set { dock = value; } + } + + public void AddButton(ToolItem item, int index) + { + ((IToolBarItemHandler)item.Handler).CreateControl(this, index); + } + + public void RemoveButton(ToolItem item) + { + if (item.ControlObject != null) Control.Remove((Gtk.Widget)item.ControlObject); + } + + public void Clear() + { + foreach (Gtk.Widget w in Control.Children) + { + Control.Remove(w); + } + } + + public ToolBarTextAlign TextAlign + { + get + { + switch (Control.ToolbarStyle) + { + case Gtk.ToolbarStyle.BothHoriz: + return ToolBarTextAlign.Right; + default: + return ToolBarTextAlign.Underneath; + } + } + set + { + switch (value) + { + case ToolBarTextAlign.Right: + Control.ToolbarStyle = Gtk.ToolbarStyle.BothHoriz; + break; + default: + Control.ToolbarStyle = Gtk.ToolbarStyle.Both; + break; + } + } + } + } +} diff --git a/Source/Eto.Gtk/Forms/ToolBar/ToolItemHandler.cs b/Source/Eto.Gtk/Forms/ToolBar/ToolItemHandler.cs new file mode 100644 index 0000000000..839597fe1b --- /dev/null +++ b/Source/Eto.Gtk/Forms/ToolBar/ToolItemHandler.cs @@ -0,0 +1,51 @@ +using Eto.Forms; +using Eto.Drawing; + +namespace Eto.GtkSharp.Forms.ToolBar +{ + public interface IToolBarItemHandler + { + void CreateControl(ToolBarHandler handler, int index); + + } + + public abstract class ToolItemHandler : WidgetHandler, ToolItem.IHandler, IToolBarItemHandler + where TControl: Gtk.Widget + where TWidget: ToolItem + { + bool enabled = true; + Image image; + + protected Gtk.Image GtkImage { get; set; } + + public abstract void CreateControl(ToolBarHandler handler, int index); + + public string Text { get; set; } + + public string ToolTip { get; set; } + + public Image Image + { + get { return image; } + set + { + image = value; + GtkImage = image.ToGtk (Gtk.IconSize.Button); + } + } + + public bool Enabled + { + get { return enabled; } + set { + enabled = value; + if (Control != null) + Control.Sensitive = value; + } + } + + public void CreateFromCommand(Command command) + { + } + } +} diff --git a/Source/Eto.Gtk/Forms/UITimerHandler.cs b/Source/Eto.Gtk/Forms/UITimerHandler.cs new file mode 100644 index 0000000000..d2654caba9 --- /dev/null +++ b/Source/Eto.Gtk/Forms/UITimerHandler.cs @@ -0,0 +1,40 @@ +using System; +using Eto.Forms; + +namespace Eto.GtkSharp.Forms +{ + public class UITimerHandler : WidgetHandler, UITimer.IHandler + { + bool enabled; + bool stopped = true; + + public void Start () + { + if (enabled) return; + enabled = true; + if (!stopped) return; + stopped = false; + GLib.Timeout.Add((uint)(Interval * 1000), delegate { + if (!enabled) { + stopped = true; return false; + } + Callback.OnElapsed(Widget, EventArgs.Empty); + return true; + }); + } + + public void Stop () + { + enabled = false; + } + + public double Interval { get; set; } + + protected override void Dispose(bool disposing) + { + base.Dispose (disposing); + enabled = false; + } + } +} + diff --git a/Source/Eto.Platform.Gtk/Gtk3Compatibility.cs b/Source/Eto.Gtk/Gtk3Compatibility.cs similarity index 91% rename from Source/Eto.Platform.Gtk/Gtk3Compatibility.cs rename to Source/Eto.Gtk/Gtk3Compatibility.cs index 89d6564454..4b579c8ae7 100644 --- a/Source/Eto.Platform.Gtk/Gtk3Compatibility.cs +++ b/Source/Eto.Gtk/Gtk3Compatibility.cs @@ -1,5 +1,5 @@ -namespace Eto.Platform.GtkSharp +namespace Eto.GtkSharp { #if GTK2 diff --git a/Source/Eto.Gtk/GtkHelpers.cs b/Source/Eto.Gtk/GtkHelpers.cs new file mode 100644 index 0000000000..6290052e14 --- /dev/null +++ b/Source/Eto.Gtk/GtkHelpers.cs @@ -0,0 +1,62 @@ +using System; +using Eto.Forms; +using Eto.GtkSharp; +using Eto.GtkSharp.Forms.Controls; +using Eto.GtkSharp.Forms; + +namespace Eto.Forms +{ + public static class + #if GTK2 + Gtk2Helpers + #elif GTK3 + Gtk3Helpers + #endif + { + /// + /// Gets the native Gtk widget that contains the Eto.Forms control. + /// + /// + /// Note for some controls, this will not be the 'main' native control. + /// For example, a GridView on OS X will return a NSScrollView instead of a NSTableView, since the table view + /// itself does not scroll. + /// + /// When you intend on using the control inside an existing native application, set to + /// true so that it can prepare for attaching to the native application by sending OnPreLoad/Load/LoadComplete events. + /// + /// The native control that can be used to add this control to an existing application. + /// Control to get the native control for. + /// If set to true the control is to be attached to an existing application, or false to get the native control directly. + public static Gtk.Widget ToNative(this Control control, bool attach = false) + { + if (attach && !control.Loaded) + { + control.AttachNative(); + control.GetContainerWidget().ShowAll(); + } + return control.GetContainerWidget(); + } + + /// + /// Wraps the specified to an Eto control that can be used directly in Eto.Forms code. + /// + /// The eto control wrapper around the native control. + /// Native control to wrap. + public static Control ToEto(this Gtk.Widget nativeWidget) + { + return new Control(new NativeControlHandler(nativeWidget)); + } + + /// + /// Wraps the specified Gtk in an Eto control so it can be used as a parent when showing dialogs, etc. + /// + /// The eto window wrapper around the native Gtk window. + /// Gtk Window to wrap. + public static Window ToEtoWindow(this Gtk.Window window) + { + return new Form(new FormHandler(window)); + } + + } +} + diff --git a/Source/Eto.Gtk/IO/SystemIcons.cs b/Source/Eto.Gtk/IO/SystemIcons.cs new file mode 100644 index 0000000000..a355c28c83 --- /dev/null +++ b/Source/Eto.Gtk/IO/SystemIcons.cs @@ -0,0 +1,23 @@ +using Eto.Drawing; +using Eto.IO; + +namespace Eto.GtkSharp.IO +{ + public class SystemIconsHandler : SystemIcons.IHandler + { + #region ISystemIcons Members + + public Icon GetFileIcon(string fileName, IconSize size) + { + return null; + } + + public Icon GetStaticIcon(StaticIconType type, IconSize size) + { + return null; + } + + #endregion + + } +} diff --git a/Source/Eto.Gtk/KeyMap.cs b/Source/Eto.Gtk/KeyMap.cs new file mode 100644 index 0000000000..5687f7ae46 --- /dev/null +++ b/Source/Eto.Gtk/KeyMap.cs @@ -0,0 +1,157 @@ +using Eto.Forms; +using System.Collections.Generic; + +namespace Eto.GtkSharp +{ + public static class KeyMap + { + static readonly Dictionary keymap = new Dictionary(); + static readonly Dictionary inversekeymap = new Dictionary(); + + public static Keys ToEto (this Gdk.Key gkey) + { + Keys key; + return keymap.TryGetValue(gkey, out key) ? key : Keys.None; + } + + public static Keys ToEtoKey (this Gdk.ModifierType modifier) + { + Keys result = Keys.None; + if ((modifier & Gdk.ModifierType.Mod1Mask) > 0) result |= Keys.Alt; + if ((modifier & Gdk.ModifierType.ControlMask) > 0) result |= Keys.Control; + if ((modifier & Gdk.ModifierType.SuperMask) > 0) result |= Keys.Application; + if ((modifier & Gdk.ModifierType.ShiftMask) > 0) result |= Keys.Shift; + return result; + } + + public static Gdk.Key ToGdkKey (this Keys key) + { + Gdk.Key result; + if (inversekeymap.TryGetValue(key & Keys.KeyMask, out result)) return result; + return (Gdk.Key)0; + } + + public static Gdk.ModifierType ToGdkModifier (this Keys key) + { + Gdk.ModifierType result = Gdk.ModifierType.None; + if (key.HasFlag(Keys.Alt)) result |= Gdk.ModifierType.Mod1Mask; + if (key.HasFlag(Keys.Control)) result |= Gdk.ModifierType.ControlMask; + if (key.HasFlag(Keys.Application)) result |= Gdk.ModifierType.SuperMask; + if (key.HasFlag(Keys.Shift)) result |= Gdk.ModifierType.ShiftMask; + return result; + } + + static KeyMap() + { + keymap.Add(Gdk.Key.A, Keys.A); + keymap.Add(Gdk.Key.B, Keys.B); + keymap.Add(Gdk.Key.C, Keys.C); + keymap.Add(Gdk.Key.D, Keys.D); + keymap.Add(Gdk.Key.E, Keys.E); + keymap.Add(Gdk.Key.F, Keys.F); + keymap.Add(Gdk.Key.G, Keys.G); + keymap.Add(Gdk.Key.H, Keys.H); + keymap.Add(Gdk.Key.I, Keys.I); + keymap.Add(Gdk.Key.J, Keys.J); + keymap.Add(Gdk.Key.K, Keys.K); + keymap.Add(Gdk.Key.L, Keys.L); + keymap.Add(Gdk.Key.M, Keys.M); + keymap.Add(Gdk.Key.N, Keys.N); + keymap.Add(Gdk.Key.O, Keys.O); + keymap.Add(Gdk.Key.P, Keys.P); + keymap.Add(Gdk.Key.Q, Keys.Q); + keymap.Add(Gdk.Key.R, Keys.R); + keymap.Add(Gdk.Key.S, Keys.S); + keymap.Add(Gdk.Key.T, Keys.T); + keymap.Add(Gdk.Key.U, Keys.U); + keymap.Add(Gdk.Key.V, Keys.V); + keymap.Add(Gdk.Key.W, Keys.W); + keymap.Add(Gdk.Key.X, Keys.X); + keymap.Add(Gdk.Key.Y, Keys.Y); + keymap.Add(Gdk.Key.Z, Keys.Z); + keymap.Add(Gdk.Key.F1, Keys.F1); + keymap.Add(Gdk.Key.F2, Keys.F2); + keymap.Add(Gdk.Key.F3, Keys.F3); + keymap.Add(Gdk.Key.F4, Keys.F4); + keymap.Add(Gdk.Key.F5, Keys.F5); + keymap.Add(Gdk.Key.F6, Keys.F6); + keymap.Add(Gdk.Key.F7, Keys.F7); + keymap.Add(Gdk.Key.F8, Keys.F8); + keymap.Add(Gdk.Key.F9, Keys.F9); + keymap.Add(Gdk.Key.F10, Keys.F10); + keymap.Add(Gdk.Key.F11, Keys.F11); + keymap.Add(Gdk.Key.F12, Keys.F12); + keymap.Add(Gdk.Key.Key_0, Keys.D0); + keymap.Add(Gdk.Key.Key_1, Keys.D1); + keymap.Add(Gdk.Key.Key_2, Keys.D2); + keymap.Add(Gdk.Key.Key_3, Keys.D3); + keymap.Add(Gdk.Key.Key_4, Keys.D4); + keymap.Add(Gdk.Key.Key_5, Keys.D5); + keymap.Add(Gdk.Key.Key_6, Keys.D6); + keymap.Add(Gdk.Key.Key_7, Keys.D7); + keymap.Add(Gdk.Key.Key_8, Keys.D8); + keymap.Add(Gdk.Key.Key_9, Keys.D9); + keymap.Add(Gdk.Key.Up, Keys.Up); + keymap.Add(Gdk.Key.Down, Keys.Down); + keymap.Add(Gdk.Key.Left, Keys.Left); + keymap.Add(Gdk.Key.Right, Keys.Right); + keymap.Add(Gdk.Key.Page_Down, Keys.PageDown); + keymap.Add(Gdk.Key.Page_Up, Keys.PageUp); + keymap.Add(Gdk.Key.Home, Keys.Home); + keymap.Add(Gdk.Key.End, Keys.End); + keymap.Add(Gdk.Key.space, Keys.Space); + keymap.Add(Gdk.Key.Delete, Keys.Delete); + keymap.Add(Gdk.Key.BackSpace, Keys.Backspace); + keymap.Add(Gdk.Key.Insert, Keys.Insert); + keymap.Add(Gdk.Key.Tab, Keys.Tab); + keymap.Add(Gdk.Key.Escape, Keys.Escape); + keymap.Add(Gdk.Key.Return, Keys.Enter); + + keymap.Add(Gdk.Key.period, Keys.Decimal); + keymap.Add(Gdk.Key.comma, Keys.Comma); + keymap.Add(Gdk.Key.equal, Keys.Equal); + keymap.Add(Gdk.Key.minus, Keys.Minus); + keymap.Add(Gdk.Key.backslash, Keys.Backslash); + keymap.Add(Gdk.Key.slash, Keys.ForwardSlash); + keymap.Add(Gdk.Key.division, Keys.Divide); + //keymap.Add(Gdk.Key.dollar, Keys.Dollar); + keymap.Add(Gdk.Key.Menu, Keys.ContextMenu); + + foreach (var val in keymap) + { + inversekeymap.Add(val.Value, val.Key); + } + + keymap.Add((Gdk.Key)0x1000010, Keys.ContextMenu); // os x + keymap.Add(Gdk.Key.a, Keys.A); + keymap.Add(Gdk.Key.b, Keys.B); + keymap.Add(Gdk.Key.c, Keys.C); + keymap.Add(Gdk.Key.d, Keys.D); + keymap.Add(Gdk.Key.e, Keys.E); + keymap.Add(Gdk.Key.f, Keys.F); + keymap.Add(Gdk.Key.g, Keys.G); + keymap.Add(Gdk.Key.h, Keys.H); + keymap.Add(Gdk.Key.i, Keys.I); + keymap.Add(Gdk.Key.j, Keys.J); + keymap.Add(Gdk.Key.k, Keys.K); + keymap.Add(Gdk.Key.l, Keys.L); + keymap.Add(Gdk.Key.m, Keys.M); + keymap.Add(Gdk.Key.n, Keys.N); + keymap.Add(Gdk.Key.o, Keys.O); + keymap.Add(Gdk.Key.p, Keys.P); + keymap.Add(Gdk.Key.q, Keys.Q); + keymap.Add(Gdk.Key.r, Keys.R); + keymap.Add(Gdk.Key.s, Keys.S); + keymap.Add(Gdk.Key.t, Keys.T); + keymap.Add(Gdk.Key.u, Keys.U); + keymap.Add(Gdk.Key.v, Keys.V); + keymap.Add(Gdk.Key.w, Keys.W); + keymap.Add(Gdk.Key.x, Keys.X); + keymap.Add(Gdk.Key.y, Keys.Y); + keymap.Add(Gdk.Key.z, Keys.Z); + + } + + } +} + diff --git a/Source/Eto.Gtk/MenuActionItemHandler.cs b/Source/Eto.Gtk/MenuActionItemHandler.cs new file mode 100644 index 0000000000..944ec3df36 --- /dev/null +++ b/Source/Eto.Gtk/MenuActionItemHandler.cs @@ -0,0 +1,40 @@ +using System; +using Eto.Forms; +using Eto.GtkSharp.Forms.Menu; + +namespace Eto.GtkSharp +{ + public interface IMenuActionItemHandler + { + void TriggerValidate(); + } + + public abstract class MenuActionItemHandler : MenuHandler, IMenuActionItemHandler + where TControl: Gtk.MenuItem + where TWidget: MenuItem + where TCallback: MenuItem.ICallback + { + public override void AttachEvent(string id) + { + switch (id) + { + case MenuItem.ValidateEvent: + // handled by the contextmenu/menubar + break; + default: + base.AttachEvent(id); + break; + } + } + + public void TriggerValidate() + { + Callback.OnValidate(Widget, EventArgs.Empty); + } + + public void CreateFromCommand(Command command) + { + } + } +} + diff --git a/Source/Eto.Gtk/Platform.cs b/Source/Eto.Gtk/Platform.cs new file mode 100644 index 0000000000..24a7dda6c8 --- /dev/null +++ b/Source/Eto.Gtk/Platform.cs @@ -0,0 +1,171 @@ +using System; +using Eto.Drawing; +using Eto.Forms; +using Eto.IO; +using Eto.GtkSharp.Drawing; +using Eto.GtkSharp.Forms.Cells; +using Eto.GtkSharp.Forms.Controls; +using Eto.GtkSharp.Forms.Printing; +using Eto.GtkSharp.Forms; +using Eto.GtkSharp.IO; +using Eto.Forms.ThemedControls; +using Eto.GtkSharp.Forms.Menu; +using Eto.GtkSharp.Forms.ToolBar; + +namespace Eto.GtkSharp +{ + static class Helper + { + public static void Init() + { + var args = new string[0]; + if (Gtk.Application.InitCheck(string.Empty, ref args)) + { + Gdk.Threads.Enter(); + } + } + } + + public class Platform : Eto.Platform + { + public override bool IsDesktop { get { return true; } } + + public override bool IsGtk { get { return true; } } + + public override bool IsValid + { + get + { + try + { + return typeof(Gtk.Application) != null; + } + catch + { + return false; + } + } + } + + #if GTK2 + public override string ID { get { return "gtk2"; } } + #else + public override string ID { get { return "gtk3"; } } + #endif + public Platform() + { + if (EtoEnvironment.Platform.IsWindows && Environment.Is64BitProcess) + throw new NotSupportedException("Please compile/run GTK in x86 mode (32-bit) on windows"); + + AddTo(this); + } + + public static void AddTo(Eto.Platform p) + { + // Drawing + p.Add(() => new BitmapHandler()); + p.Add(() => new FontFamilyHandler()); + p.Add(() => new FontHandler()); + p.Add(() => new FontsHandler()); + p.Add(() => new GraphicsHandler()); + p.Add(() => new GraphicsPathHandler()); + p.Add(() => new IconHandler()); + p.Add(() => new IndexedBitmapHandler()); + p.Add(() => new MatrixHandler()); + p.Add(() => new PenHandler()); + p.Add(() => new SolidBrushHandler()); + p.Add(() => new TextureBrushHandler()); + p.Add(() => new LinearGradientBrushHandler()); + + // Forms.Cells + p.Add(() => new CheckBoxCellHandler()); + p.Add(() => new ComboBoxCellHandler()); + p.Add(() => new ImageTextCellHandler()); + p.Add(() => new ImageViewCellHandler()); + p.Add(() => new TextBoxCellHandler()); + p.Add(() => new DrawableCellHandler()); + + // Forms.Controls + p.Add(() => new ButtonHandler()); + p.Add(() => new CalendarHandler()); + p.Add(() => new CheckBoxHandler()); + p.Add(() => new DropDownHandler()); + p.Add(() => new ComboBoxHandler()); + p.Add(() => new ColorPickerHandler()); + p.Add(() => new DateTimePickerHandler()); + p.Add(() => new DrawableHandler()); + p.Add(() => new GridColumnHandler()); + p.Add(() => new GridViewHandler()); + p.Add(() => new GroupBoxHandler()); + p.Add(() => new ImageViewHandler()); + p.Add(() => new LabelHandler()); + p.Add(() => new LinkButtonHandler()); + p.Add(() => new ListBoxHandler()); + p.Add(() => new NumericUpDownHandler()); + p.Add(() => new PanelHandler()); + p.Add(() => new PasswordBoxHandler()); + p.Add(() => new ProgressBarHandler()); + p.Add(() => new RadioButtonHandler()); + p.Add(() => new ScrollableHandler()); + p.Add(() => new SearchBoxHandler()); + p.Add(() => new SliderHandler()); + #if GTK3 + p.Add(() => new SpinnerHandler()); + #else + p.Add(() => new ThemedSpinnerHandler()); + #endif + p.Add(() => new SplitterHandler()); + p.Add(() => new TabControlHandler()); + p.Add(() => new TabPageHandler()); + p.Add(() => new TextAreaHandler()); + p.Add(() => new TextBoxHandler()); + p.Add(() => new TreeGridViewHandler()); + p.Add(() => new TreeViewHandler()); + p.Add(() => new WebViewHandler()); + p.Add(() => new ScreensHandler()); + + // Forms.Menu + p.Add(() => new CheckMenuItemHandler()); + p.Add(() => new ContextMenuHandler()); + p.Add(() => new ButtonMenuItemHandler()); + p.Add(() => new MenuBarHandler()); + p.Add(() => new RadioMenuItemHandler()); + p.Add(() => new SeparatorMenuItemHandler()); + + // Forms.Printing + p.Add(() => new PrintDialogHandler()); + p.Add(() => new PrintDocumentHandler()); + p.Add(() => new PrintSettingsHandler()); + + // Forms.ToolBar + p.Add(() => new CheckToolItemHandler()); + p.Add(() => new RadioToolItemHandler()); + p.Add(() => new SeparatorToolItemHandler()); + p.Add(() => new ButtonToolItemHandler()); + p.Add(() => new ToolBarHandler()); + + // Forms + p.Add(() => new ApplicationHandler()); + p.Add(() => new ClipboardHandler()); + p.Add(() => new ColorDialogHandler()); + p.Add(() => new CursorHandler()); + p.Add(() => new DialogHandler()); + p.Add(() => new FontDialogHandler()); + p.Add(() => new FormHandler()); + p.Add(() => new MessageBoxHandler()); + p.Add(() => new OpenFileDialogHandler()); + p.Add(() => new PixelLayoutHandler()); + p.Add(() => new SaveFileDialogHandler()); + p.Add(() => new SelectFolderDialogHandler()); + p.Add(() => new TableLayoutHandler()); + p.Add(() => new UITimerHandler()); + p.Add(() => new MouseHandler()); + + // IO + p.Add(() => new SystemIconsHandler()); + + // General + p.Add(() => new EtoEnvironmentHandler()); + } + } +} diff --git a/Source/Eto.Gtk/Properties/AssemblyInfo.cs b/Source/Eto.Gtk/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..2991b49bd7 --- /dev/null +++ b/Source/Eto.Gtk/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +using System.Reflection; + +#if GTK2 +[assembly: AssemblyTitle("Eto.Forms - GTK2 Platform")] +[assembly: AssemblyDescription("GTK2 Platform for the Eto.Forms UI Framework")] +#else +[assembly: AssemblyTitle("Eto.Forms - GTK3 Platform")] +[assembly: AssemblyDescription("GTK3 Platform for the Eto.Forms UI Framework")] +#endif \ No newline at end of file diff --git a/Source/Eto.Json/DefaultNamespaceManager.cs b/Source/Eto.Json/DefaultNamespaceManager.cs deleted file mode 100644 index 83d236306e..0000000000 --- a/Source/Eto.Json/DefaultNamespaceManager.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; - -namespace Eto.Json -{ - public class DefaultNamespaceManager : NamespaceManager - { - public DefaultNamespaceManager () - { - var asm = typeof(Eto.Forms.Application).Assembly; - DefaultNamespace = new NamespaceInfo("Eto.Forms", asm); - Namespaces.Add ("drawing", new NamespaceInfo("Eto.Drawing", asm)); - } - } - -} diff --git a/Source/Eto.Json/DelegateConverter.cs b/Source/Eto.Json/DelegateConverter.cs deleted file mode 100644 index 477055e72f..0000000000 --- a/Source/Eto.Json/DelegateConverter.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System.Reflection; - -namespace Eto.Json -{ - public class DelegateConverter : JsonConverter - { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var instance = serializer.Context.Context; - if (instance != null) - { - var obj = JToken.ReadFrom(reader) as JValue; - if (obj != null) - { - var methodName = Convert.ToString(obj.Value); - var instanceType = instance.GetType(); - var method = instanceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); - if (method == null) - throw new JsonSerializationException(string.Format("Could not find method {0} of type {1}", methodName, instanceType)); - return Delegate.CreateDelegate(objectType, instance, method); - } - } - return null; - } - - public override bool CanConvert(Type objectType) - { - return typeof(Delegate).IsAssignableFrom(objectType); - } - } -} - diff --git a/Source/Eto.Json/DynamicLayoutConverter.cs b/Source/Eto.Json/DynamicLayoutConverter.cs deleted file mode 100644 index 489986e416..0000000000 --- a/Source/Eto.Json/DynamicLayoutConverter.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using Eto.Forms; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json; - -namespace Eto.Json -{ - public class DynamicLayoutConverter : JsonConverter - { - public override bool CanWrite - { - get { return false; } - } - - public override bool CanConvert(Type objectType) - { - return typeof(DynamicItem).IsAssignableFrom(objectType) || typeof(DynamicRow).IsAssignableFrom (objectType); - } - - public override object ReadJson (Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - object instance; - JContainer container; - if (reader.TokenType == JsonToken.Null) { - return null; - } - if (reader.TokenType == JsonToken.StartArray) { - container = JArray.Load (reader); - if (objectType == typeof(DynamicRow)) { - var dynamicRow = new DynamicRow (); - instance = dynamicRow; - serializer.Populate (container.CreateReader (), dynamicRow.Items); - } - else if (objectType == typeof(DynamicItem)) { - var dynamicTable = new DynamicTable (); - instance = dynamicTable; - serializer.Populate (container.CreateReader (), dynamicTable.Rows); - } - else throw new EtoException("Invalid object graph"); - } else { - container = JObject.Load (reader); - if (container["$type"] == null) { - if (container["Rows"] != null) - instance = new DynamicTable (); - else if (container["Control"] != null) - instance = new DynamicControl (); - else - throw new EtoException("Could not infer the type of object to create"); - - serializer.Populate(container.CreateReader(), instance); - } - else { - var type = Type.GetType ((string)container ["$type"]); - if (!typeof(DynamicItem).IsAssignableFrom (type)) { - var dynamicControl = new DynamicControl (); - dynamicControl.Control = serializer.Deserialize (container.CreateReader ()) as Control; - instance = dynamicControl; - } else { - instance = serializer.Deserialize (container.CreateReader ()); - } - } - } - if (objectType == typeof(DynamicRow) && instance.GetType () != typeof(DynamicRow)) { - var row = new DynamicRow(); - row.Items.Add (instance as DynamicItem); - return row; - } - - return instance; - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - } -} - diff --git a/Source/Eto.Json/Eto.Json - Android.csproj b/Source/Eto.Json/Eto.Json - Android.csproj deleted file mode 100644 index fc11b033a5..0000000000 --- a/Source/Eto.Json/Eto.Json - Android.csproj +++ /dev/null @@ -1,77 +0,0 @@ - - - - Debug - AnyCPU - {757FCF9A-E2D0-4031-9A11-82A2A49FA892} - {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Eto.Json - Resources\Resource.designer.cs - Resource - Resources - Assets - True - Eto.Json - v4.3 - ..\..\..\ - true - - - true - full - false - ..\..\BuildOutput\Android\Debug - DEBUG; - prompt - 4 - None - false - - - full - true - ..\..\BuildOutput\Android\Release - prompt - 4 - false - false - - - - ..\packages\Newtonsoft.Json.6.0.2\lib\portable-net40+sl5+wp80+win8+monotouch+monoandroid\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - - - - {73A5AD74-68BC-448C-A38C-CFBAF014A311} - Eto - Android - - - - - 4.5.11 - False - - - - \ No newline at end of file diff --git a/Source/Eto.Json/Eto.Json - iOS.csproj b/Source/Eto.Json/Eto.Json - iOS.csproj deleted file mode 100644 index 9926ac9c9f..0000000000 --- a/Source/Eto.Json/Eto.Json - iOS.csproj +++ /dev/null @@ -1,87 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {5F92A18F-6ED3-4BD6-AFB7-FEEF3F4DA1E0} - {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Eto.Json.IOS - Resources - Eto.Json - - - 512 - True - prompt - 4 - ..\..\.. - ..\..\Libraries - - - ..\..\BuildOutput\iOS\Debug - DEBUG; - False - full - False - - - ..\..\BuildOutput\iOS\Release - True - pdbonly - False - - - - - - - - - ..\Components\json.net-4.5.11\lib\ios\Newtonsoft.Json.dll - - - - - - - - - - - - - - - Properties\GlobalAssemblyInfo.cs - - - - - - - - {83452633-C37C-490F-852A-3ADE0A2CF0D4} - Eto - iOS - - - - - - - - - - - - - - - - 4.5.11 - False - - - \ No newline at end of file diff --git a/Source/Eto.Json/Eto.Json.csproj b/Source/Eto.Json/Eto.Json.csproj deleted file mode 100644 index 3f91e83307..0000000000 --- a/Source/Eto.Json/Eto.Json.csproj +++ /dev/null @@ -1,83 +0,0 @@ - - - - - Debug - AnyCPU - {2F2C45E0-4142-44D0-8A0C-7264C0F925B2} - Library - Eto.Json - Eto.Json - ..\ - true - - - 512 - True - prompt - 4 - ..\..\.. - ..\..\Libraries - - - ..\..\BuildOutput\Debug - DEBUG; - false - full - - - ..\..\BuildOutput\Release - true - pdbonly - - - - - - - - ..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll - - - - - - - - - - - - - - Properties\GlobalAssemblyInfo.cs - - - - - - - - - {16289D2F-044C-49EF-83E9-9391AFF8FD2B} - Eto - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Source/Eto.Json/EtoContractResolver.cs b/Source/Eto.Json/EtoContractResolver.cs deleted file mode 100644 index cc7895b99e..0000000000 --- a/Source/Eto.Json/EtoContractResolver.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using System.Reflection; - -namespace Eto.Json -{ - public class EtoContractResolver : DefaultContractResolver - { - protected override IValueProvider CreateMemberValueProvider (MemberInfo member) - { - if (member.MemberType == MemberTypes.Event) - { - return new EventValueProvider { EventInfo = (EventInfo) member }; - } - return base.CreateMemberValueProvider (member); - } - - protected override System.Collections.Generic.IList CreateProperties (Type type, MemberSerialization memberSerialization) - { - var list = base.CreateProperties (type, memberSerialization); - foreach (var eventInfo in type.GetEvents (BindingFlags.Instance | BindingFlags.Public)) { - var prop = CreateProperty(eventInfo, memberSerialization); - prop.Writable = true; - list.Add (prop); - } - - var idprop = type.GetProperty ("ID", BindingFlags.Instance | BindingFlags.Public); - if (idprop != null) { - var prop = CreateProperty(idprop, memberSerialization); - prop.PropertyName = "$name"; - prop.PropertyType = typeof(NameConverter.Info); - prop.MemberConverter = new NameConverter (); - prop.ValueProvider = new NameConverter.ValueProvider(); - list.Add (prop); - } - return list; - } - } - -} diff --git a/Source/Eto.Json/NameConverter.cs b/Source/Eto.Json/NameConverter.cs deleted file mode 100644 index aee01a6611..0000000000 --- a/Source/Eto.Json/NameConverter.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System.Reflection; -using Newtonsoft.Json.Serialization; - -namespace Eto.Json -{ - public class NameConverter : JsonConverter - { - public class Info - { - public object Instance { get; set; } - public PropertyInfo PropertyInfo { get; set; } - public FieldInfo FieldInfo { get; set; } - - public void SetValue(object value) - { - if (PropertyInfo != null) - PropertyInfo.SetValue (Instance, value, null); - else - FieldInfo.SetValue (Instance, value); - } - } - - public class ValueProvider : IValueProvider - { - public void SetValue (object target, object value) - { - var info = value as Info; - if (info != null) - info.SetValue (target); - } - - public object GetValue (object target) - { - return null; - } - } - - public override void WriteJson (JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException (); - } - - public override object ReadJson (Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var obj = JToken.ReadFrom (reader); - var id = (string)obj; - var instance = serializer.Context.Context; - if (instance != null) { - var instanceType = instance.GetType (); - - var property = instanceType.GetProperty (id, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); - if (property != null) - return new Info { - PropertyInfo = property, - Instance = instance - }; - - var field = instanceType.GetField (id, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); - if (field != null) - return new Info { - FieldInfo = field, - Instance = instance - }; - } - return null; - } - - public override bool CanConvert (Type objectType) - { - return true; - } - } -} - diff --git a/Source/Eto.Json/packages.config b/Source/Eto.Json/packages.config deleted file mode 100644 index b47d3a3ee7..0000000000 --- a/Source/Eto.Json/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Source/Eto.Mac/AppDelegate.cs b/Source/Eto.Mac/AppDelegate.cs new file mode 100644 index 0000000000..b91797f670 --- /dev/null +++ b/Source/Eto.Mac/AppDelegate.cs @@ -0,0 +1,81 @@ +using Eto.Forms; +using System.ComponentModel; +using Eto.Mac.Forms; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac +{ + [Register("EtoAppDelegate")] + public class AppDelegate : NSApplicationDelegate + { + public override bool ApplicationShouldHandleReopen(NSApplication sender, bool hasVisibleWindows) + { + if (!hasVisibleWindows) + { + var form = Application.Instance.MainForm; + if (form != null) + form.Show(); + } + return true; + } + + public override void DidBecomeActive(NSNotification notification) + { + var form = Application.Instance.MainForm; + if (form != null && !form.Visible) + form.Show(); + } + + public override void DidFinishLaunching(NSNotification notification) + { + var handler = Application.Instance.Handler as ApplicationHandler; + if (handler != null) + handler.Initialize(this); + } + + public override NSApplicationTerminateReply ApplicationShouldTerminate(NSApplication sender) + { + var args = new CancelEventArgs(); + var app = ((ApplicationHandler)Application.Instance.Handler); + var form = Application.Instance.MainForm == null ? null : Application.Instance.MainForm.Handler as IMacWindow; + if (form != null) + args.Cancel = !form.CloseWindow(ce => app.Callback.OnTerminating(app.Widget, ce)); + else + { + app.Callback.OnTerminating(app.Widget, args); + } + return args.Cancel ? NSApplicationTerminateReply.Cancel : NSApplicationTerminateReply.Now; + } + } +} + diff --git a/Source/Eto.Platform.Mac/Conversions.cg.cs b/Source/Eto.Mac/Conversions.cg.cs similarity index 79% rename from Source/Eto.Platform.Mac/Conversions.cg.cs rename to Source/Eto.Mac/Conversions.cg.cs index 3ec9536380..20a609a597 100644 --- a/Source/Eto.Platform.Mac/Conversions.cg.cs +++ b/Source/Eto.Mac/Conversions.cg.cs @@ -1,17 +1,45 @@ using System; using Eto.Drawing; -#if OSX +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; using MonoMac.CoreGraphics; -using Eto.Platform.Mac.Drawing; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Single; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if OSX +using Eto.Mac.Drawing; -namespace Eto.Platform.Mac +namespace Eto.Mac #elif IOS using MonoTouch.CoreGraphics; -using Eto.Platform.iOS.Drawing; +using Eto.iOS.Drawing; -namespace Eto.Platform.iOS +namespace Eto.iOS #endif { public static partial class Conversions @@ -29,12 +57,12 @@ static CGColorSpace CreateDeviceRGB () public static CGColor ToCGColor (this Color color) { - return new CGColor (CreateDeviceRGB (), new float[] { color.R, color.G, color.B, color.A }); + return new CGColor (CreateDeviceRGB (), new nfloat[] { color.R, color.G, color.B, color.A }); } public static Color ToEtoColor (this CGColor color) { - return new Color (color.Components [0], color.Components [1], color.Components [2], color.Alpha); + return new Color ((float)color.Components [0], (float)color.Components [1], (float)color.Components [2], (float)color.Alpha); } public static CGInterpolationQuality ToCG (this ImageInterpolation value) diff --git a/Source/Eto.Mac/Conversions.cs b/Source/Eto.Mac/Conversions.cs new file mode 100644 index 0000000000..3f34c00fb0 --- /dev/null +++ b/Source/Eto.Mac/Conversions.cs @@ -0,0 +1,389 @@ +using System; +using Eto.Drawing; +using Eto.Forms; +using Eto.Mac.Drawing; +using sd = System.Drawing; +using Eto.Mac.Forms.Printing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +using ImageIO; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +using MonoMac.ImageIO; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac +{ + public static partial class Conversions + { + public static NSColor ToNSUI(this Color color) + { + return NSColor.FromDeviceRgba(color.R, color.G, color.B, color.A); + } + + public static Color ToEto(this NSColor color) + { + if (color == null) + return Colors.Black; + //if (color.ColorSpace.ColorSpaceModel != NSColorSpaceModel.RGB) + color = color.UsingColorSpace(NSColorSpace.CalibratedRGB); + nfloat red, green, blue, alpha; + color.GetRgba(out red, out green, out blue, out alpha); + return new Color((float)red, (float)green, (float)blue, (float)alpha); + } + + public static NSRange ToNS(this Range range) + { + return new NSRange(range.Start, range.End - range.Start + 1); + } + + public static Range ToEto(this NSRange range) + { + return new Range((int)range.Location, (int)(range.Location + range.Length - 1)); + } + + public static NSImageInterpolation ToNS(this ImageInterpolation value) + { + switch (value) + { + case ImageInterpolation.Default: + return NSImageInterpolation.Default; + case ImageInterpolation.None: + return NSImageInterpolation.None; + case ImageInterpolation.Low: + return NSImageInterpolation.Low; + case ImageInterpolation.Medium: + return NSImageInterpolation.Medium; + case ImageInterpolation.High: + return NSImageInterpolation.High; + default: + throw new NotSupportedException(); + } + } + + public static ImageInterpolation ToEto(this NSImageInterpolation value) + { + switch (value) + { + case NSImageInterpolation.None: + return ImageInterpolation.None; + case NSImageInterpolation.Low: + return ImageInterpolation.Low; + case NSImageInterpolation.Medium: + return ImageInterpolation.Medium; + case NSImageInterpolation.Default: + case NSImageInterpolation.High: + return ImageInterpolation.High; + default: + throw new NotSupportedException(); + } + } + + public static NSFontTraitMask ToNS(this FontStyle style) + { + var traits = (NSFontTraitMask)0; + traits |= style.HasFlag(FontStyle.Bold) ? NSFontTraitMask.Bold : NSFontTraitMask.Unbold; + traits |= style.HasFlag(FontStyle.Italic) ? NSFontTraitMask.Italic : NSFontTraitMask.Unitalic; + //if (style.HasFlag (FontStyle.Condensed)) traits |= NSFontTraitMask.Condensed; + //if (style.HasFlag (FontStyle.Light)) traits |= NSFontTraitMask.Narrow; + return traits; + } + + public static FontStyle ToEto(this NSFontTraitMask traits) + { + var style = FontStyle.None; + if (traits.HasFlag(NSFontTraitMask.Bold)) + style |= FontStyle.Bold; + if (traits.HasFlag(NSFontTraitMask.Italic)) + style |= FontStyle.Italic; + //if (traits.HasFlag (NSFontTraitMask.Condensed)) + // style |= FontStyle.Condensed; + //if (traits.HasFlag (NSFontTraitMask.Narrow)) + // style |= FontStyle.Light; + return style; + } + + public static NSPrintingOrientation ToNS(this PageOrientation value) + { + switch (value) + { + case PageOrientation.Landscape: + return NSPrintingOrientation.Landscape; + case PageOrientation.Portrait: + return NSPrintingOrientation.Portrait; + default: + throw new NotSupportedException(); + } + } + + public static PageOrientation ToEto(this NSPrintingOrientation value) + { + switch (value) + { + case NSPrintingOrientation.Landscape: + return PageOrientation.Landscape; + case NSPrintingOrientation.Portrait: + return PageOrientation.Portrait; + default: + throw new NotSupportedException(); + } + } + + public static PointF GetLocation(NSView view, NSEvent theEvent) + { + var loc = view.ConvertPointFromView(theEvent.LocationInWindow, null); + if (!view.IsFlipped) + loc.Y = view.Frame.Height - loc.Y; + return loc.ToEto(); + } + + public static MouseEventArgs GetMouseEvent(NSView view, NSEvent theEvent, bool includeWheel) + { + var pt = Conversions.GetLocation(view, theEvent); + Keys modifiers = KeyMap.GetModifiers(theEvent); + MouseButtons buttons = theEvent.GetMouseButtons(); + SizeF? delta = null; + if (includeWheel) + delta = new SizeF((float)theEvent.DeltaX, (float)theEvent.DeltaY); + return new MouseEventArgs(buttons, modifiers, pt, delta); + } + + public static MouseButtons GetMouseButtons(this NSEvent theEvent) + { + MouseButtons buttons = MouseButtons.None; + + switch (theEvent.Type) + { + case NSEventType.LeftMouseUp: + case NSEventType.LeftMouseDown: + case NSEventType.LeftMouseDragged: + if ((theEvent.ModifierFlags & NSEventModifierMask.ControlKeyMask) > 0) + buttons |= MouseButtons.Alternate; + else + buttons |= MouseButtons.Primary; + break; + case NSEventType.RightMouseUp: + case NSEventType.RightMouseDown: + case NSEventType.RightMouseDragged: + buttons |= MouseButtons.Alternate; + break; + case NSEventType.OtherMouseUp: + case NSEventType.OtherMouseDown: + case NSEventType.OtherMouseDragged: + buttons |= MouseButtons.Middle; + break; + } + return buttons; + } + + public static CGImage ToCG(this Image image) + { + using (var imageSource = CGImageSource.FromData(image.ToNS().AsTiff())) + { + return imageSource.CreateImage(0, null); + } + } + + public static NSImage ToNS(this Image image, int? size = null) + { + if (image == null) + return null; + var source = image.Handler as IImageSource; + if (source == null) + return null; + var nsimage = source.GetImage(); + + if (size != null) + { + var rep = nsimage.BestRepresentation(new CGRect(0, 0, size.Value, size.Value), null, null); + if (rep.PixelsWide > size.Value || rep.PixelsHigh > size.Value) + { + var max = Math.Max(nsimage.Size.Width, nsimage.Size.Height); + var newsize = new CGSize((int)(size.Value * nsimage.Size.Width / max), (int)(size.Value * nsimage.Size.Height / max)); + nsimage = nsimage.Resize(newsize); + } + else + { + nsimage = new NSImage(); + nsimage.AddRepresentation(rep); + } + } + return nsimage; + } + + public static NSCellImagePosition ToNS(this ButtonImagePosition value) + { + switch (value) + { + case ButtonImagePosition.Below: + return NSCellImagePosition.ImageBelow; + case ButtonImagePosition.Overlay: + return NSCellImagePosition.ImageOverlaps; + case ButtonImagePosition.Left: + return NSCellImagePosition.ImageLeft; + case ButtonImagePosition.Right: + return NSCellImagePosition.ImageRight; + case ButtonImagePosition.Above: + return NSCellImagePosition.ImageAbove; + default: + throw new NotSupportedException(); + } + } + + public static ButtonImagePosition ToEto(this NSCellImagePosition value) + { + switch (value) + { + case NSCellImagePosition.ImageBelow: + return ButtonImagePosition.Below; + case NSCellImagePosition.ImageOverlaps: + return ButtonImagePosition.Overlay; + case NSCellImagePosition.ImageLeft: + return ButtonImagePosition.Left; + case NSCellImagePosition.ImageRight: + return ButtonImagePosition.Right; + case NSCellImagePosition.ImageAbove: + return ButtonImagePosition.Above; + default: + throw new NotSupportedException(); + } + } + + public static WindowStyle ToEtoWindowStyle(this NSWindowStyle style) + { + return style.HasFlag(NSWindowStyle.Borderless) ? WindowStyle.None : WindowStyle.Default; + } + + public static NSWindowStyle ToNS(this WindowStyle style, NSWindowStyle existing) + { + const NSWindowStyle NONE_STYLE = NSWindowStyle.Borderless; + const NSWindowStyle DEFAULT_STYLE = NSWindowStyle.Titled; + switch (style) + { + case WindowStyle.Default: + return (existing & ~NONE_STYLE) | DEFAULT_STYLE; + case WindowStyle.None: + return (existing & ~DEFAULT_STYLE) | NONE_STYLE; + default: + throw new NotSupportedException(); + } + } + + public static KeyEventArgs ToEtoKeyEventArgs(this NSEvent theEvent) + { + char keyChar = !string.IsNullOrEmpty(theEvent.Characters) ? theEvent.Characters[0] : '\0'; + Keys key = KeyMap.MapKey(theEvent.KeyCode); + KeyEventArgs kpea; + Keys modifiers = KeyMap.GetModifiers(theEvent); + key |= modifiers; + if (key != Keys.None) + { + if (((modifiers & ~(Keys.Shift | Keys.Alt)) == 0)) + kpea = new KeyEventArgs(key, KeyEventType.KeyDown, keyChar); + else + kpea = new KeyEventArgs(key, KeyEventType.KeyDown); + } + else + { + kpea = new KeyEventArgs(key, KeyEventType.KeyDown, keyChar); + } + return kpea; + } + + public static PrintSettings ToEto(this NSPrintInfo value) + { + return value == null ? null : new PrintSettings(new PrintSettingsHandler(value)); + } + + public static NSPrintInfo ToNS(this PrintSettings settings) + { + return settings == null ? null : ((PrintSettingsHandler)settings.Handler).Control; + } + + public static SizeF ToEtoSize(this NSEdgeInsets insets) + { + return new SizeF((float)(insets.Left + insets.Right), (float)(insets.Top + insets.Bottom)); + } + + public static CalendarMode ToEto(this NSDatePickerMode mode) + { + switch (mode) + { + case NSDatePickerMode.Single: + return CalendarMode.Single; + case NSDatePickerMode.Range: + return CalendarMode.Range; + default: + throw new NotSupportedException(); + } + } + + public static NSDatePickerMode ToNS(this CalendarMode mode) + { + switch (mode) + { + case CalendarMode.Single: + return NSDatePickerMode.Single; + case CalendarMode.Range: + return NSDatePickerMode.Range; + default: + throw new NotSupportedException(); + } + } + + public static HorizontalAlign ToEto(this NSTextAlignment align) + { + switch (align) + { + default: + case NSTextAlignment.Left: + return HorizontalAlign.Left; + case NSTextAlignment.Right: + return HorizontalAlign.Right; + case NSTextAlignment.Center: + return HorizontalAlign.Center; + } + } + + public static NSTextAlignment ToNS(this HorizontalAlign align) + { + switch (align) + { + case HorizontalAlign.Left: + return NSTextAlignment.Left; + case HorizontalAlign.Center: + return NSTextAlignment.Center; + case HorizontalAlign.Right: + return NSTextAlignment.Right; + default: + throw new NotSupportedException(); + } + } + } +} + diff --git a/Source/Eto.Mac/Conversions.ns.cs b/Source/Eto.Mac/Conversions.ns.cs new file mode 100644 index 0000000000..eba84cee98 --- /dev/null +++ b/Source/Eto.Mac/Conversions.ns.cs @@ -0,0 +1,45 @@ +using System; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac +{ + public static partial class Conversions + { + static readonly DateTime ReferenceDate = new DateTime (2001, 1, 1, 0, 0, 0); + + public static NSUrl ToNS (this Uri uri) + { + return uri == null ? null : new NSUrl(uri.AbsoluteUri); + } + + public static NSDate ToNS (this DateTime date) + { + return NSDate.FromTimeIntervalSinceReferenceDate ((date.ToUniversalTime () - ReferenceDate).TotalSeconds); + } + + public static NSDate ToNS (this DateTime? date) + { + return date == null ? null : date.Value.ToNS(); + } + + public static DateTime? ToEto (this NSDate date) + { + if (date == null) return null; + return new DateTime ((long)(date.SecondsSinceReferenceDate * (double)TimeSpan.TicksPerSecond + (double)ReferenceDate.Ticks), DateTimeKind.Utc).ToLocalTime (); + } + + } +} + diff --git a/Source/Eto.Platform.Mac/Conversions.sd.cs b/Source/Eto.Mac/Conversions.sd.cs similarity index 99% rename from Source/Eto.Platform.Mac/Conversions.sd.cs rename to Source/Eto.Mac/Conversions.sd.cs index 057dc24fc4..a735e9b5c2 100644 --- a/Source/Eto.Platform.Mac/Conversions.sd.cs +++ b/Source/Eto.Mac/Conversions.sd.cs @@ -2,7 +2,7 @@ using sd = System.Drawing; using Eto.Drawing; -namespace Eto.Platform +namespace Eto { public static partial class Conversions { diff --git a/Source/Eto.Mac/Drawing/BitmapHandler.cs b/Source/Eto.Mac/Drawing/BitmapHandler.cs new file mode 100644 index 0000000000..6101a41278 --- /dev/null +++ b/Source/Eto.Mac/Drawing/BitmapHandler.cs @@ -0,0 +1,296 @@ +using System; +using System.IO; +using System.Linq; +using Eto.Drawing; +using sd = System.Drawing; +using Eto.Mac.Forms; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Drawing +{ + /// + /// Bitmap data handler. + /// + /// (c) 2012-2013 by Curtis Wensley + /// See LICENSE for full terms + public class BitmapDataHandler : BitmapData + { + public BitmapDataHandler(Bitmap bitmap, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) + : base(bitmap, data, scanWidth, bitsPerPixel, controlObject) + { + } + + public static int ArgbToData(int argb) + { + return unchecked((int)(((uint)argb & 0xFF00FF00) | (((uint)argb & 0xFF) << 16) | (((uint)argb & 0xFF0000) >> 16))); + } + + public static int DataToArgb(int bitmapData) + { + return unchecked((int)(((uint)bitmapData & 0xFF00FF00) | (((uint)bitmapData & 0xFF) << 16) | (((uint)bitmapData & 0xFF0000) >> 16))); + } + + public override int TranslateArgbToData(int argb) + { + return unchecked((int)(((uint)argb & 0xFF00FF00) | (((uint)argb & 0xFF) << 16) | (((uint)argb & 0xFF0000) >> 16))); + } + + public override int TranslateDataToArgb(int bitmapData) + { + return unchecked((int)(((uint)bitmapData & 0xFF00FF00) | (((uint)bitmapData & 0xFF) << 16) | (((uint)bitmapData & 0xFF0000) >> 16))); + } + + public override bool Flipped { get { return false; } } + } + + /// + /// Bitmap handler. + /// + /// (c) 2012-2013 by Curtis Wensley + /// See LICENSE for full terms + public class BitmapHandler : ImageHandler, Bitmap.IHandler + { + NSImageRep rep; + NSBitmapImageRep bmprep; + bool alpha = true; + + public BitmapHandler() + { + } + + public BitmapHandler(NSImage image) + { + Control = image; + rep = Control.BestRepresentationForDevice(null); + bmprep = rep as NSBitmapImageRep; + } + + public void Create(string fileName) + { + if (!File.Exists(fileName)) + throw new FileNotFoundException("Icon not found", fileName); + Control = new NSImage(fileName); + rep = Control.BestRepresentationForDevice(null); + bmprep = rep as NSBitmapImageRep; + Control.Size = new CGSize(rep.PixelsWide, rep.PixelsHigh); + } + + public void Create(Stream stream) + { + Control = new NSImage(NSData.FromStream(stream)); + rep = Control.BestRepresentationForDevice(null); + bmprep = rep as NSBitmapImageRep; + Control.Size = new CGSize(rep.PixelsWide, rep.PixelsHigh); + } + + public void Create(int width, int height, PixelFormat pixelFormat) + { + switch (pixelFormat) + { + case PixelFormat.Format32bppRgb: + { + alpha = false; + const int numComponents = 4; + const int bitsPerComponent = 8; + const int bitsPerPixel = numComponents * bitsPerComponent; + const int bytesPerPixel = bitsPerPixel / 8; + int bytesPerRow = bytesPerPixel * width; + + rep = bmprep = new NSBitmapImageRep(IntPtr.Zero, width, height, bitsPerComponent, 3, false, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel); + Control = new NSImage(); + Control.AddRepresentation(rep); + break; + } + case PixelFormat.Format24bppRgb: + { + alpha = false; + const int numComponents = 3; + const int bitsPerComponent = 8; + const int bitsPerPixel = numComponents * bitsPerComponent; + const int bytesPerPixel = bitsPerPixel / 8; + int bytesPerRow = bytesPerPixel * width; + + rep = bmprep = new NSBitmapImageRep(IntPtr.Zero, width, height, bitsPerComponent, numComponents, false, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel); + Control = new NSImage(); + Control.AddRepresentation(rep); + break; + } + case PixelFormat.Format32bppRgba: + { + alpha = true; + const int numComponents = 4; + const int bitsPerComponent = 8; + const int bitsPerPixel = numComponents * bitsPerComponent; + const int bytesPerPixel = bitsPerPixel / 8; + int bytesPerRow = bytesPerPixel * width; + + rep = bmprep = new NSBitmapImageRep(IntPtr.Zero, width, height, bitsPerComponent, numComponents, true, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel); + Control = new NSImage(); + Control.AddRepresentation(rep); + break; + } + /*case PixelFormat.Format16bppRgb555: + control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 5, width, height); + break;*/ + default: + throw new ArgumentOutOfRangeException("pixelFormat", pixelFormat, "Not supported"); + } + } + + public void Create(int width, int height, Graphics graphics) + { + Create(width, height, PixelFormat.Format32bppRgba); + } + + public void Create(Image image, int width, int height, ImageInterpolation interpolation) + { + var source = image.ToNS(); + Control = source.Resize(new CGSize(width, height), interpolation); + } + + public override NSImage GetImage() + { + return Control; + } + + public BitmapData Lock() + { + return bmprep == null ? null : new BitmapDataHandler(Widget, bmprep.BitmapData, (int)bmprep.BytesPerRow, (int)bmprep.BitsPerPixel, Control); + } + + public void Unlock(BitmapData bitmapData) + { + } + + public void Save(Stream stream, ImageFormat format) + { + NSBitmapImageFileType type; + switch (format) + { + case ImageFormat.Bitmap: + type = NSBitmapImageFileType.Bmp; + break; + case ImageFormat.Gif: + type = NSBitmapImageFileType.Gif; + break; + case ImageFormat.Jpeg: + type = NSBitmapImageFileType.Jpeg; + break; + case ImageFormat.Png: + type = NSBitmapImageFileType.Png; + break; + case ImageFormat.Tiff: + type = NSBitmapImageFileType.Tiff; + break; + default: + throw new NotSupportedException(); + } + var reps = Control.Representations(); + if (reps == null) + throw new InvalidDataException(); + var newrep = reps.OfType().FirstOrDefault(); + if (newrep == null) + { + CGImage img; + img = bmprep != null ? bmprep.CGImage : Control.CGImage; + newrep = new NSBitmapImageRep(img); + } + var data = newrep.RepresentationUsingTypeProperties(type, new NSDictionary()); + var datastream = data.AsStream(); + datastream.CopyTo(stream); + stream.Flush(); + datastream.Dispose(); + } + + public override Size Size + { + get + { + /* + NSImageRep rep = this.rep; + if (rep == null) + rep = Control.BestRepresentationForDevice (null); + if (rep != null) + return new Size(rep.PixelsWide, rep.PixelsHigh); + else + */ + return Control.Size.ToEtoSize(); + } + } + + public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) + { + var sourceRect = new CGRect(source.X, (float)Control.Size.Height - source.Y - source.Height, source.Width, source.Height); + var destRect = graphics.TranslateView(destination.ToNS(), true, true); + if (alpha) + Control.Draw(destRect, sourceRect, NSCompositingOperation.SourceOver, 1, true, null); + else + Control.Draw(destRect, sourceRect, NSCompositingOperation.Copy, 1, true, null); + } + + public Bitmap Clone(Rectangle? rectangle = null) + { + if (rectangle == null) + return new Bitmap(new BitmapHandler((NSImage)Control.Copy())); + else + { + var rect = new CGRect(CGPoint.Empty, Control.Size); + var image = new NSImage(); + var cgimage = Control.AsCGImage(ref rect, null, null).WithImageInRect(rectangle.Value.ToSDRectangleF()); + image.AddRepresentation(new NSBitmapImageRep(cgimage)); + return new Bitmap(new BitmapHandler(image)); + } + } + + public Color GetPixel(int x, int y) + { + if (bmprep == null) + throw new InvalidOperationException(string.Format("Cannot get pixel data for this type of bitmap ({0})", rep.GetType())); + + return bmprep.ColorAt(x, y).ToEto(); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (rep != null) + { + rep.SafeDispose(); + rep = null; + } + } + base.Dispose(disposing); + } + } +} diff --git a/Source/Eto.Mac/Drawing/BrushHandler.cs b/Source/Eto.Mac/Drawing/BrushHandler.cs new file mode 100644 index 0000000000..976748545d --- /dev/null +++ b/Source/Eto.Mac/Drawing/BrushHandler.cs @@ -0,0 +1,21 @@ +using Eto.Drawing; + +#if OSX + +namespace Eto.Mac.Drawing +#elif IOS + +namespace Eto.iOS.Drawing +#endif +{ + /// + /// Handler for + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public abstract class BrushHandler : Brush.IHandler + { + public abstract void Apply (object control, GraphicsHandler graphics); + } +} + diff --git a/Source/Eto.Mac/Drawing/FontExtensions.cs b/Source/Eto.Mac/Drawing/FontExtensions.cs new file mode 100644 index 0000000000..6ee074b90e --- /dev/null +++ b/Source/Eto.Mac/Drawing/FontExtensions.cs @@ -0,0 +1,192 @@ +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if OSX +namespace Eto.Mac.Drawing +#elif IOS + +using MonoTouch.UIKit; +using MonoTouch.Foundation; +using MonoTouch.ObjCRuntime; +using Eto.Mac; +using NSFont = MonoTouch.UIKit.UIFont; + +namespace Eto.iOS.Drawing +#endif +{ + public static class FontExtensions + { + #if OSX + static readonly NSString ForegroundColorAttribute = NSAttributedString.ForegroundColorAttributeName; + #elif IOS + static readonly NSString ForegroundColorAttribute = UIStringAttributeKey.ForegroundColor; + static readonly Selector selSetSize = new Selector("setSize:"); + #endif + + public static NSFont ToNSFont(this Font font) + { + return font == null ? null : ((FontHandler)font.Handler).Control; + } + + public static NSDictionary Attributes(this Font font) + { + if (font != null) + { + var handler = (FontHandler)font.Handler; + return handler.Attributes; + } + return null; + } + + public static void Apply(this Font font, NSMutableAttributedString str) + { + if (font != null) + { + var handler = (FontHandler)font.Handler; + str.AddAttributes(handler.Attributes, new NSRange(0, (int)str.Length)); + } + } + + public static void Apply(this Font font, NSMutableDictionary dic) + { + if (font != null) + { + var handler = (FontHandler)font.Handler; + foreach (var item in handler.Attributes) + dic.Add(item.Key, item.Value); + } + } + + public static NSAttributedString AttributedString(this Font font, NSAttributedString attributedString) + { + if (font != null) + { + var str = attributedString as NSMutableAttributedString ?? new NSMutableAttributedString(attributedString); + font.Apply(str); + return str; + } + return attributedString; + } + + public static NSMutableAttributedString ToMutable(this NSAttributedString attributedString, string text) + { + if (attributedString != null && attributedString.Length > 0) + { + NSRange range; + return new NSMutableAttributedString(text, attributedString.GetAttributes(0, out range)); + } + + return new NSMutableAttributedString(text); + } + + public static NSMutableAttributedString AttributedString(this Font font, string text, NSAttributedString attributedString = null) + { + var mutable = attributedString.ToMutable(text); + font.Apply(mutable); + + return mutable; + } + + public static float LineHeight(this NSFont font) + { + #if OSX + return (float)layout.DefaultLineHeightForFont(font); + #elif IOS + return font.LineHeight; + #endif + /** + var leading = Math.Floor (Math.Max (0, font.Leading) + 0.5f); + var lineHeight = (float)(Math.Floor(font.Ascender + 0.5f) - Math.Floor (font.Descender + 0.5f) + leading); + + if (leading > 0) + return lineHeight; + else + return (float)(lineHeight + Math.Floor(0.2 * lineHeight + 0.5)); + /**/ + } + + static readonly NSTextStorage storage; + static readonly NSLayoutManager layout; + static readonly NSTextContainer container; + + public static NSLayoutManager SharedLayout { get { return layout; } } + + public static SizeF MeasureString(string text, Font font = null, SizeF? availableSize = null) + { + return MeasureString(font.AttributedString(text), availableSize); + } + + public static SizeF MeasureString(NSAttributedString str, SizeF? availableSize = null) + { + SetContainerSize(availableSize); + storage.SetString(str); + return layout.BoundingRectForGlyphRange(new NSRange(0, (int)str.Length), container).Size.ToEto(); + } + + public static void DrawString(NSAttributedString str, PointF point, SizeF? availableSize = null) + { + SetContainerSize(availableSize); + storage.SetString(str); + layout.DrawGlyphs(new NSRange(0, (int)str.Length), point.ToNS()); + } + + public static void DrawString(string text, PointF point, Color color, Font font = null, SizeF? availableSize = null) + { + var str = font.AttributedString(text); + str.AddAttribute(ForegroundColorAttribute, color.ToNSUI(), new NSRange(0, text.Length)); + DrawString(str, point, availableSize); + } + + static void SetContainerSize(SizeF? availableSize) + { + #if OSX + container.ContainerSize = (availableSize ?? SizeF.MaxValue).ToNS(); + #elif IOS + if (container.RespondsToSelector(selSetSize)) + container.Size = (availableSize ?? SizeF.MaxValue).ToSD(); + #endif + } + + static FontExtensions() + { + storage = new NSTextStorage(); + layout = new NSLayoutManager { UsesFontLeading = true }; + #if OSX + layout.BackgroundLayoutEnabled = false; + #endif + container = new NSTextContainer { LineFragmentPadding = 0f }; + layout.UsesFontLeading = true; + layout.AddTextContainer(container); + storage.AddLayoutManager(layout); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Mac/Drawing/FontFamilyHandler.cs b/Source/Eto.Mac/Drawing/FontFamilyHandler.cs new file mode 100644 index 0000000000..570509fe7c --- /dev/null +++ b/Source/Eto.Mac/Drawing/FontFamilyHandler.cs @@ -0,0 +1,88 @@ +using System; +using Eto.Drawing; +using System.Collections.Generic; +using System.Linq; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Drawing +{ + public class FontFamilyHandler : WidgetHandler, FontFamily.IHandler + { + public string MacName { get; set; } + + public string Name { get; set; } + + public NSFontTraitMask TraitMask { get; set; } + + public IEnumerable Typefaces + { + get + { + var descriptors = NSFontManager.SharedFontManager.AvailableMembersOfFontFamily(MacName); + return descriptors.Select(r => new FontTypeface(Widget, new FontTypefaceHandler(r))); + } + } + + public FontFamilyHandler() + { + TraitMask = (NSFontTraitMask)int.MaxValue; + } + + public FontFamilyHandler(string familyName) + { + Create(familyName); + } + + public void Create(string familyName) + { + Name = MacName = familyName; + TraitMask = (NSFontTraitMask)int.MaxValue; + + switch (familyName.ToUpperInvariant()) + { + case FontFamilies.MonospaceFamilyName: + MacName = "Courier New"; + break; + case FontFamilies.SansFamilyName: + MacName = "Helvetica"; + break; + case FontFamilies.SerifFamilyName: +#if OSX + MacName = "Times"; +#elif IOS + MacName = "Times New Roman"; +#endif + break; + case FontFamilies.CursiveFamilyName: + MacName = "Papyrus"; + TraitMask = NSFontTraitMask.Condensed | NSFontTraitMask.Unbold | NSFontTraitMask.Unitalic; + break; + case FontFamilies.FantasyFamilyName: + MacName = "Impact"; + break; + } + } + + public FontTypeface GetFace(NSFont font, NSFontTraitMask? traits) + { + var postScriptName = font.FontDescriptor.PostscriptName; + var faceHandler = Typefaces.Select(r => r.Handler).OfType().FirstOrDefault(r => r.PostScriptName == postScriptName && r.Traits == traits); + if (faceHandler == null) + faceHandler = new FontTypefaceHandler(font, traits); + return new FontTypeface(Widget, faceHandler); + } + } +} + diff --git a/Source/Eto.Mac/Drawing/FontHandler.cs b/Source/Eto.Mac/Drawing/FontHandler.cs new file mode 100644 index 0000000000..dfa89b4725 --- /dev/null +++ b/Source/Eto.Mac/Drawing/FontHandler.cs @@ -0,0 +1,318 @@ +using System; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if IOS + +using MonoTouch.UIKit; +using MonoTouch.Foundation; +using NSFont = MonoTouch.UIKit.UIFont; + +namespace Eto.iOS.Drawing + +#elif OSX + +namespace Eto.Mac.Drawing +#endif +{ + public class FontHandler : WidgetHandler, Font.IHandler + { + FontFamily family; + FontTypeface typeface; + FontStyle? style; + FontDecoration decoration; + NSDictionary _attributes; + + public FontHandler() + { + } + + public FontHandler(NSFont font) + { + Control = font; + } + + public FontHandler(NSFont font, FontStyle style) + { + Control = font; + this.style = style; + } + + public void Create(FontTypeface face, float size, FontDecoration decoration) + { + typeface = face; + family = face.Family; + Control = ((FontTypefaceHandler)face.Handler).CreateFont(size); + this.decoration = decoration; + } + + public void Create(SystemFont systemFont, float? fontSize, FontDecoration decoration) + { + switch (systemFont) + { + case SystemFont.Default: + Control = NSFont.SystemFontOfSize((nfloat)(fontSize ?? (float)NSFont.SystemFontSize)); + break; + case SystemFont.Bold: + Control = NSFont.BoldSystemFontOfSize((nfloat)(fontSize ?? (float)NSFont.SystemFontSize)); + break; + case SystemFont.Label: +#if IOS + Control = NSFont.SystemFontOfSize(fontSize ?? NSFont.LabelFontSize); +#elif OSX + Control = NSFont.LabelFontOfSize((nfloat)(fontSize ?? (float)(NSFont.LabelFontSize + 2))); // labels get a size of 12 +#endif + break; +#if OSX + case SystemFont.TitleBar: + Control = NSFont.TitleBarFontOfSize((nfloat)(fontSize ?? (float)NSFont.SystemFontSize)); + break; + case SystemFont.ToolTip: + Control = NSFont.ToolTipsFontOfSize((nfloat)(fontSize ?? (float)NSFont.SystemFontSize)); + break; + case SystemFont.MenuBar: + Control = NSFont.MenuBarFontOfSize((nfloat)(fontSize ?? (float)NSFont.SystemFontSize)); + break; + case SystemFont.Menu: + Control = NSFont.MenuFontOfSize((nfloat)(fontSize ?? (float)NSFont.SystemFontSize)); + break; + case SystemFont.Message: + Control = NSFont.MessageFontOfSize((nfloat)(fontSize ?? (float)NSFont.SystemFontSize)); + break; + case SystemFont.Palette: + Control = NSFont.PaletteFontOfSize((nfloat)(fontSize ?? (float)NSFont.SmallSystemFontSize)); + break; + case SystemFont.StatusBar: + Control = NSFont.SystemFontOfSize((nfloat)(fontSize ?? (float)NSFont.SystemFontSize)); + break; +#endif + default: + throw new NotSupportedException(); + } + this.decoration = decoration; + } + + public float LineHeight + { + get + { + return Control.LineHeight(); // LineHeight() is the extension method above + } + } + + #if OSX + NSFontTraitMask? traits; + public static NSFont CreateFont(FontFamilyHandler familyHandler, float size, NSFontTraitMask traits, int weight = 5) + { + var font = NSFontManager.SharedFontManager.FontWithFamily(familyHandler.MacName, traits, weight, size); + if (font == null) + { + if (traits.HasFlag(NSFontTraitMask.Italic)) + { + // fake italics by transforming the font + const float kRotationForItalicText = 14.0f; + var fontTransform = new NSAffineTransform(); + fontTransform.Scale(size); + var italicTransform = new NSAffineTransform(); + italicTransform.TransformStruct = Matrix.FromSkew(0, kRotationForItalicText).ToCG(); + fontTransform.AppendTransform(italicTransform); + traits &= ~NSFontTraitMask.Italic; + font = NSFontManager.SharedFontManager.FontWithFamily(familyHandler.MacName, traits, 5, size); + if (font != null) + { + font = NSFont.FromDescription(font.FontDescriptor, fontTransform); + } + } + } + return font; + } + #endif + + public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) + { + this.style = style; + this.family = family; + this.decoration = decoration; +#if OSX + var familyHandler = (FontFamilyHandler)family.Handler; + traits = style.ToNS() & familyHandler.TraitMask; + var font = CreateFont(familyHandler, size, traits.Value); + + if (font == null || font.Handle == IntPtr.Zero) + throw new ArgumentOutOfRangeException(string.Empty, string.Format("Could not allocate font with family {0}, traits {1}, size {2}", family.Name, traits, size)); +#elif IOS + string suffix = string.Empty; + var familyHandler = (FontFamilyHandler)family.Handler; + var font = familyHandler.CreateFont (size, style); + /* + var familyString = new StringBuilder(); + switch (family) + { + case FontFamily.Monospace: familyString.Append ("CourierNewPS"); suffix = "MT"; break; + default: + case FontFamily.Sans: familyString.Append ("Helvetica"); italicString = "Oblique"; break; + case FontFamily.Serif: familyString.Append ("TimesNewRomanPS"); suffix = "MT"; break; + } + bold = (style & FontStyle.Bold) != 0; + italic = (style & FontStyle.Italic) != 0; + + if (bold || italic) familyString.Append ("-"); + if (bold) familyString.Append ("Bold"); + if (italic) familyString.Append (italicString); + + familyString.Append (suffix); + var font = UIFont.FromName (familyString.ToString (), size); + */ + #endif + Control = font; + } + + public float Size + { + get { return (float)Control.PointSize; } + } + + public string FamilyName + { + get { return Control.FamilyName; } + } + + public FontFamily Family + { + get + { + if (family == null) + family = new FontFamily(new FontFamilyHandler(Control.FamilyName)); + return family; + } + } + + public FontTypeface Typeface + { + get + { + if (typeface == null) + #if IOS + typeface = ((FontFamilyHandler)Family.Handler).GetFace(Control); + #else + typeface = ((FontFamilyHandler)Family.Handler).GetFace(Control, traits); + #endif + return typeface; + } + } + + public FontStyle FontStyle + { + get + { + if (style == null) +#if OSX + style = NSFontManager.SharedFontManager.TraitsOfFont(Control).ToEto(); +#elif IOS + style = Typeface.FontStyle; +#endif + return style.Value; + } + } + + public FontDecoration FontDecoration + { + get { return decoration; } + } + + public float Ascent + { + get { return (float)Control.Ascender; } + } + + public float Descent + { + get { return (float)-Control.Descender; } + } + + public float XHeight + { +#if OSX + get { return (float)Control.XHeight; } +#elif IOS + get { return Control.xHeight; } +#endif + } + + public float Leading + { + get { return (float)Control.Leading; } + } + + public float Baseline + { + get { return Control.LineHeight() - Leading - Descent; } + } + + public NSDictionary Attributes + { + get + { + if (_attributes == null) + CreateAttributes(); + return _attributes ?? (_attributes = CreateAttributes()); + } + } + + static readonly NSObject[] attributeKeys = + { +#if OSX + NSAttributedString.FontAttributeName, + NSAttributedString.UnderlineStyleAttributeName, + NSAttributedString.StrikethroughStyleAttributeName +#elif IOS + UIStringAttributeKey.Font, + UIStringAttributeKey.UnderlineStyle, + UIStringAttributeKey.StrikethroughStyle +#endif + }; + + NSDictionary CreateAttributes() + { + return NSDictionary.FromObjectsAndKeys( + new NSObject[] + { + Control, + new NSNumber((int)(decoration.HasFlag(FontDecoration.Underline) ? NSUnderlineStyle.Single : NSUnderlineStyle.None)), + NSNumber.FromBoolean(decoration.HasFlag(FontDecoration.Strikethrough)) + }, + attributeKeys + ); + } + } +} \ No newline at end of file diff --git a/Source/Eto.Mac/Drawing/FontTypefaceHandler.cs b/Source/Eto.Mac/Drawing/FontTypefaceHandler.cs new file mode 100644 index 0000000000..dfdbf2014b --- /dev/null +++ b/Source/Eto.Mac/Drawing/FontTypefaceHandler.cs @@ -0,0 +1,101 @@ +using System; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Drawing +{ + public class FontTypefaceHandler : WidgetHandler, FontTypeface.IHandler + { + readonly string name; + + public string PostScriptName { get; private set; } + + public int Weight { get; private set; } + + public NSFontTraitMask Traits { get; private set; } + // remove when implemented in monomac + static readonly IntPtr AppKit_libraryHandler; + static NSString _NSFontFamilyAttribute; + static NSString _NSFontFaceAttribute; + + static FontTypefaceHandler() + { + AppKit_libraryHandler = Dlfcn.dlopen("/System/Library/Frameworks/AppKit.framework/AppKit", 0); + } + + public static NSString NSFontFamilyAttribute + { + get + { + if (_NSFontFamilyAttribute == null) + _NSFontFamilyAttribute = Dlfcn.GetStringConstant(AppKit_libraryHandler, "NSFontFamilyAttribute"); + return _NSFontFamilyAttribute; + } + } + + public static NSString NSFontFaceAttribute + { + get + { + if (_NSFontFaceAttribute == null) + _NSFontFaceAttribute = Dlfcn.GetStringConstant(AppKit_libraryHandler, "NSFontFaceAttribute"); + return _NSFontFaceAttribute; + } + } + + public FontTypefaceHandler(NSArray descriptor) + { + PostScriptName = (string)new NSString(descriptor.ValueAt(0)); + name = (string)new NSString(descriptor.ValueAt(1)); + Weight = new NSNumber(descriptor.ValueAt(2)).Int32Value; + Traits = (NSFontTraitMask)new NSNumber(descriptor.ValueAt(3)).Int32Value; + } + + public FontTypefaceHandler(NSFont font, NSFontTraitMask? traits = null) + { + var descriptor = font.FontDescriptor; + PostScriptName = descriptor.PostscriptName; + var manager = NSFontManager.SharedFontManager; + Weight = (int)manager.WeightOfFont(font); + Traits = traits ?? manager.TraitsOfFont(font); + name = (NSString)descriptor.FontAttributes[NSFontFaceAttribute]; + } + + public FontTypefaceHandler(string postScriptName, string name, NSFontTraitMask traits, int weight) + { + PostScriptName = postScriptName; + this.name = name; + Weight = weight; + Traits = traits; + } + + public string Name + { + get { return name; } + } + + public FontStyle FontStyle + { + get { return Traits.ToEto(); } + } + + public NSFont CreateFont(float size) + { + var family = (FontFamilyHandler)Widget.Family.Handler; + return FontHandler.CreateFont(family, size, Traits, Weight); + } + } +} + diff --git a/Source/Eto.Mac/Drawing/FontsHandler.cs b/Source/Eto.Mac/Drawing/FontsHandler.cs new file mode 100644 index 0000000000..1799858f9d --- /dev/null +++ b/Source/Eto.Mac/Drawing/FontsHandler.cs @@ -0,0 +1,52 @@ +using System; +using Eto.Drawing; +using System.Collections.Generic; +using System.Linq; +#if OSX +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Drawing +#elif IOS +using MonoTouch.UIKit; +using MonoTouch.Foundation; + +namespace Eto.iOS.Drawing +#endif +{ + public class FontsHandler : WidgetHandler, Fonts.IHandler + { + readonly string [] availableFontFamilies; + + public FontsHandler () + { +#if OSX + availableFontFamilies = NSFontManager.SharedFontManager.AvailableFontFamilies; +#elif IOS + availableFontFamilies = UIFont.FamilyNames; +#endif + } + + public IEnumerable AvailableFontFamilies + { + get { return availableFontFamilies.Select (r => new FontFamily(new FontFamilyHandler (r))); } + } + + public bool FontFamilyAvailable (string fontFamily) + { + return availableFontFamilies.Contains (fontFamily, StringComparer.InvariantCultureIgnoreCase); + } + } +} + diff --git a/Source/Eto.Mac/Drawing/GraphicsHandler.cs b/Source/Eto.Mac/Drawing/GraphicsHandler.cs new file mode 100644 index 0000000000..07889a9b18 --- /dev/null +++ b/Source/Eto.Mac/Drawing/GraphicsHandler.cs @@ -0,0 +1,686 @@ +using System; +using System.Linq; +using Eto.Drawing; +using SD = System.Drawing; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +using MonoMac; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if OSX +using Eto.Mac.Forms; + +#if XAMMAC2 +using GraphicsBase = Eto.Mac.Forms.MacBase; +#else +using GraphicsBase = Eto.Mac.Forms.MacBase; +#endif + +namespace Eto.Mac.Drawing +#elif IOS +using Eto.iOS.Forms; +using Eto.Mac; +using MonoTouch.CoreGraphics; +using MonoTouch.UIKit; +using MonoTouch.Foundation; +using NSView = MonoTouch.UIKit.UIView; +using GraphicsBase = Eto.WidgetHandler; + +namespace Eto.iOS.Drawing +#endif +{ + #if OSX + public static class GraphicsExtensions + { + [DllImport(Constants.AppKitLibrary, EntryPoint = "NSSetFocusRingStyle")] + public extern static void SetFocusRingStyle(NSFocusRingPlacement placement); + } + #endif + + /// + /// Handler for the + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class GraphicsHandler : GraphicsBase, Graphics.IHandler + { + #if OSX + NSGraphicsContext graphicsContext; + bool disposeContext; + #endif + readonly NSView view; + float height; + PixelOffsetMode pixelOffsetMode = PixelOffsetMode.None; + float offset = 0.5f; + float inverseoffset; + CGRect? clipBounds; + IGraphicsPath clipPath; + int transformSaveCount; + Stack transforms; + CGAffineTransform currentTransform = CGAffineTransform.MakeIdentity(); + static readonly CGColorSpace patternColorSpace = CGColorSpace.CreatePattern(null); + + public float Offset { get { return offset; } } + + public float InverseOffset { get { return inverseoffset; } } + + public NSView DisplayView { get; private set; } + + public CGAffineTransform CurrentTransform { get { return currentTransform; } } + + public PixelOffsetMode PixelOffsetMode + { + get { return pixelOffsetMode; } + set + { + pixelOffsetMode = value; + offset = value == PixelOffsetMode.None ? 0.5f : 0f; + inverseoffset = value == PixelOffsetMode.None ? 0f : 0.5f; + } + } + + public GraphicsHandler() + { + } + + #if OSX + + public GraphicsHandler(NSView view) + { + this.view = view; + graphicsContext = NSGraphicsContext.FromWindow(view.Window); + graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true); + disposeContext = true; + Control = graphicsContext.GraphicsPort; + + view.PostsFrameChangedNotifications = true; + AddObserver(NSView.FrameChangedNotification, FrameDidChange, view); + + // if control is in a scrollview, we need to trap when it's scrolled as well + var parent = view.Superview; + while (parent != null) + { + var scroll = parent as NSScrollView; + if (scroll != null) + { + scroll.ContentView.PostsBoundsChangedNotifications = true; + AddObserver(NSView.BoundsChangedNotification, FrameDidChange, scroll.ContentView); + } + parent = parent.Superview; + } + + SetDefaults(); + InitializeContext(view.IsFlipped); + } + + static void FrameDidChange(ObserverActionEventArgs e) + { + var h = e.Handler as GraphicsHandler; + if (h != null && h.Control != null) + { + h.RewindAll(); + + h.Control.RestoreState(); + h.Control.SaveState(); + h.InitializeContext(h.view.IsFlipped); + + h.ReplayAll(); + } + } + + public GraphicsHandler(NSView view, NSGraphicsContext graphicsContext, float height, bool flipped) + { + DisplayView = view; + this.height = height; + this.graphicsContext = flipped != graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true); + Control = this.graphicsContext.GraphicsPort; + SetDefaults(); + InitializeContext(!flipped); + } + + #elif IOS + + public GraphicsHandler(NSView view, CGContext context, float height) + { + this.DisplayView = view; + this.height = height; + this.Control = context; + + SetDefaults(); + InitializeContext(false); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + } + + #endif + protected override bool DisposeControl { get { return false; } } + + public bool IsRetained { get { return false; } } + + bool antialias; + + public bool AntiAlias + { + get { return antialias; } + set + { + antialias = value; + Control.SetShouldAntialias(value); + } + } + + float scale = 1f; + public float PointsPerPixel { get { return scale; } } + + public ImageInterpolation ImageInterpolation + { + get { return Control.InterpolationQuality.ToEto(); } + set { Control.InterpolationQuality = value.ToCG(); } + } + + public void CreateFromImage(Bitmap image) + { + var handler = image.Handler as BitmapHandler; +#if OSX + var rep = handler.Control.Representations().OfType().FirstOrDefault(); + graphicsContext = NSGraphicsContext.FromBitmap(rep); + graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true); + disposeContext = true; + Control = graphicsContext.GraphicsPort; + scale = (float)(rep.PixelsWide / handler.Control.Size.Width); +#elif IOS + var cgimage = handler.Control.CGImage; + Control = new CGBitmapContext(handler.Data.MutableBytes, cgimage.Width, cgimage.Height, cgimage.BitsPerComponent, cgimage.BytesPerRow, cgimage.ColorSpace, cgimage.BitmapInfo); + scale = cgimage.Width / handler.Control.Size.Width; +#endif + + height = image.Size.Height; + SetDefaults(); + InitializeContext(true); + } + + public void Reset() + { + // unwind all SaveState's + ResetClip(); + while (transformSaveCount > 0) + { + RestoreTransform(); + } + // initial save state + Control.RestoreState(); + } + + public void Flush() + { +#if OSX + graphicsContext.FlushGraphics(); +#endif + } + + public float ViewHeight + { + get { return (float)(view != null ? view.Bounds.Height : height); } + } + + void SetDefaults() + { + Control.InterpolationQuality = CGInterpolationQuality.High; + Control.SetAllowsSubpixelPositioning(false); + } + + void InitializeContext(bool viewFlipped) + { + Control.SaveState(); + + #if OSX + // os x has different flipped states (depending on layers, etc), so compensate to make 0,0 at the top-left + if (view != null) + { + // we have a view (drawing directly to the screen), so adjust to where it is + Control.ClipToRect(view.ConvertRectToView(view.VisibleRect(), null)); + var pos = view.ConvertPointToView(CGPoint.Empty, null); + if (!viewFlipped) + pos.Y += view.Frame.Height; + currentTransform = new CGAffineTransform(1, 0, 0, -1, (float)pos.X, (float)pos.Y); + Control.ConcatCTM(currentTransform); + } + else + { + // drawing to a bitmap or during a drawRect operation + currentTransform = new CGAffineTransform(1, 0, 0, -1, 0, viewFlipped ? ViewHeight : 0); + if (viewFlipped) + Control.ConcatCTM(currentTransform); + } + #elif IOS + if (viewFlipped) + { + // on ios, we flip the context if we're drawing on a bitmap otherwise we don't need to + currentTransform = new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight); + Control.ConcatCTM(currentTransform); + } + #endif + } + + public CGPoint TranslateView(CGPoint point, bool halfers = false, bool inverse = false) + { + if (halfers) + { + if (inverse) + { + point.X += inverseoffset; + point.Y += inverseoffset; + } + else + { + point.X += offset; + point.Y += offset; + } + } + return point; + } + + public CGRect TranslateView(CGRect rect, bool halfers = false, bool inverse = false) + { + if (halfers) + { + if (inverse) + { + rect.X += inverseoffset; + rect.Y += inverseoffset; + } + else + { + rect.X += offset; + rect.Y += offset; + } + } + return rect; + } + + void StartDrawing() + { +#if OSX + NSGraphicsContext.GlobalSaveGraphicsState(); + NSGraphicsContext.CurrentContext = graphicsContext; +#elif IOS + UIGraphics.PushContext(Control); +#endif + Control.SaveState(); + } + + void EndDrawing() + { + Control.RestoreState(); +#if OSX + NSGraphicsContext.GlobalRestoreGraphicsState(); +#elif IOS + UIGraphics.PopContext(); +#endif + } + + public void DrawLine(Pen pen, float startx, float starty, float endx, float endy) + { + StartDrawing(); + pen.Apply(this); + Control.StrokeLineSegments(new [] + { + TranslateView(new CGPoint(startx, starty), true), + TranslateView(new CGPoint(endx, endy), true) + }); + EndDrawing(); + } + + public void DrawRectangle(Pen pen, float x, float y, float width, float height) + { + StartDrawing(); + var rect = TranslateView(new CGRect(x, y, width, height), true); + pen.Apply(this); + Control.StrokeRect(rect); + EndDrawing(); + } + + public void FillRectangle(Brush brush, float x, float y, float width, float height) + { + StartDrawing(); + brush.Apply(this); + Control.FillRect(TranslateView(new CGRect(x, y, width, height), width > 1 || height > 1, true)); + EndDrawing(); + } + + public void DrawEllipse(Pen pen, float x, float y, float width, float height) + { + StartDrawing(); + var rect = TranslateView(new CGRect(x, y, width, height), true); + pen.Apply(this); + Control.StrokeEllipseInRect(rect); + EndDrawing(); + } + + public void FillEllipse(Brush brush, float x, float y, float width, float height) + { + StartDrawing(); + /* if (width == 1 || height == 1) + { + DrawLine(color, x, y, x+width-1, y+height-1); + return; + }*/ + + brush.Apply(this); + Control.FillEllipseInRect(TranslateView(new CGRect(x, y, width, height), true, true)); + EndDrawing(); + } + + public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) + { + StartDrawing(); + + var rect = TranslateView(new CGRect(x, y, width, height), true); + pen.Apply(this); + var yscale = rect.Height / rect.Width; + var centerY = rect.GetMidY(); + var centerX = rect.GetMidX(); + Control.ConcatCTM(new CGAffineTransform(1.0f, 0, 0, yscale, 0, centerY - centerY * yscale)); + Control.AddArc(centerX, centerY, rect.Width / 2, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle), sweepAngle < 0); + Control.StrokePath(); + EndDrawing(); + } + + public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) + { + StartDrawing(); + + var rect = TranslateView(new CGRect(x, y, width, height), true, true); + brush.Apply(this); + var yscale = rect.Height / rect.Width; + var centerY = rect.GetMidY(); + var centerX = rect.GetMidX(); + Control.ConcatCTM(new CGAffineTransform(1.0f, 0, 0, yscale, 0, centerY - centerY * yscale)); + Control.MoveTo(centerX, centerY); + Control.AddArc(centerX, centerY, rect.Width / 2, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle), sweepAngle < 0); + Control.AddLineToPoint(centerX, centerY); + Control.ClosePath(); + Control.FillPath(); + EndDrawing(); + } + + public void FillPath(Brush brush, IGraphicsPath path) + { + StartDrawing(); + + Control.TranslateCTM(inverseoffset, inverseoffset); + Control.BeginPath(); + Control.AddPath(path.ToCG()); + Control.ClosePath(); + brush.Apply(this); + switch (path.FillMode) + { + case FillMode.Alternate: + Control.EOFillPath(); + break; + case FillMode.Winding: + Control.FillPath(); + break; + default: + throw new NotSupportedException(); + } + EndDrawing(); + } + + public void DrawPath(Pen pen, IGraphicsPath path) + { + StartDrawing(); + + Control.TranslateCTM(offset, offset); + pen.Apply(this); + Control.BeginPath(); + Control.AddPath(path.ToCG()); + Control.StrokePath(); + + EndDrawing(); + } + + public void DrawImage(Image image, float x, float y) + { + StartDrawing(); + + var handler = (IImageHandler)image.Handler; + handler.DrawImage(this, x, y); + EndDrawing(); + } + + public void DrawImage(Image image, float x, float y, float width, float height) + { + StartDrawing(); + + var handler = (IImageHandler)image.Handler; + handler.DrawImage(this, x, y, width, height); + EndDrawing(); + } + + public void DrawImage(Image image, RectangleF source, RectangleF destination) + { + StartDrawing(); + + var handler = (IImageHandler)image.Handler; + handler.DrawImage(this, source, destination); + EndDrawing(); + } + + public void DrawText(Font font, SolidBrush brush, float x, float y, string text) + { + if (string.IsNullOrEmpty(text)) + return; + + StartDrawing(); + FontExtensions.DrawString(text, new PointF(x, y), brush.Color, font); + EndDrawing(); + } + + public SizeF MeasureString(Font font, string text) + { + StartDrawing(); + var size = FontExtensions.MeasureString(text, font); + EndDrawing(); + return size; + } + #if OSX + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (disposeContext && graphicsContext != null) + graphicsContext.FlushGraphics(); + Reset(); + if (disposeContext && graphicsContext != null) + graphicsContext.Dispose(); + } + base.Dispose(disposing); + } + #endif + public void TranslateTransform(float offsetX, float offsetY) + { + Control.TranslateCTM(offsetX, offsetY); + currentTransform = CGAffineTransform.Multiply(CGAffineTransform.MakeTranslation(offsetX, offsetY), currentTransform); + } + + public void RotateTransform(float angle) + { + angle = Conversions.DegreesToRadians(angle); + Control.RotateCTM(angle); + currentTransform = CGAffineTransform.Multiply(CGAffineTransform.MakeRotation(angle), currentTransform); + } + + public void ScaleTransform(float scaleX, float scaleY) + { + Control.ScaleCTM(scaleX, scaleY); + currentTransform = CGAffineTransform.Multiply(CGAffineTransform.MakeScale(scaleX, scaleY), currentTransform); + } + + public void MultiplyTransform(IMatrix matrix) + { + var m = matrix.ToCG(); + Control.ConcatCTM(m); + currentTransform = CGAffineTransform.Multiply(m, currentTransform); + } + + public void SaveTransform() + { + RewindClip(); + Control.SaveState(); + transformSaveCount++; + ReplayClip(); + if (transforms == null) + transforms = new Stack(); + transforms.Push(currentTransform); + } + + public void RestoreTransform() + { + if (transformSaveCount <= 0) + throw new InvalidOperationException("No saved transform"); + RewindClip(); + transformSaveCount--; + Control.RestoreState(); + ReplayClip(); + currentTransform = transforms.Pop(); + } + + public RectangleF ClipBounds + { + get { return Control.GetClipBoundingBox().ToEto(); } + } + + public void SetClip(RectangleF rectangle) + { + ResetClip(); + clipBounds = rectangle.ToNS(); + ReplayClip(); + } + + public void SetClip(IGraphicsPath path) + { + ResetClip(); + clipPath = path.Clone(); + ReplayClip(); + } + + void ReplayClip() + { + if (clipPath != null) + { + Control.SaveState(); + Control.AddPath(clipPath.ToCG()); + switch (clipPath.FillMode) + { + case FillMode.Alternate: + Control.EOClip(); + break; + case FillMode.Winding: + Control.Clip(); + break; + default: + throw new NotSupportedException(); + } + } + else if (clipBounds != null) + { + Control.SaveState(); + Control.ClipToRect(clipBounds.Value); + } + } + + void RewindClip() + { + if (clipBounds != null || clipPath != null) + { + Control.RestoreState(); + } + } + + void RewindTransform() + { + for (int i = 0; i < transformSaveCount; i++) + Control.RestoreState(); + } + + void ReplayTransform() + { + // replay transforms + if (transforms != null) + { + foreach (var transform in transforms) + { + Control.ConcatCTM(transform); + Control.SaveState(); + } + } + //Control.ConcatCTM (currentTransform); + } + + void RewindAll() + { + RewindClip(); + RewindTransform(); + } + + void ReplayAll() + { + ReplayTransform(); + ReplayClip(); + } + + public void ResetClip() + { + RewindClip(); + clipBounds = null; + clipPath = null; + } + + public void Clear(SolidBrush brush) + { + var rect = Control.GetClipBoundingBox(); + Control.ClearRect(rect); + if (brush != null) + FillRectangle(brush, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height); + } + + public void SetFillColorSpace() + { + Control.SetFillColorSpace(patternColorSpace); + } + } +} diff --git a/Source/Eto.Mac/Drawing/GraphicsPathHandler.cs b/Source/Eto.Mac/Drawing/GraphicsPathHandler.cs new file mode 100644 index 0000000000..bf6eaa2405 --- /dev/null +++ b/Source/Eto.Mac/Drawing/GraphicsPathHandler.cs @@ -0,0 +1,302 @@ +using System; +using Eto.Drawing; +using System.Collections.Generic; +using sd = System.Drawing; + +#if OSX +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +using Eto.Mac; +namespace Eto.Mac.Drawing +#elif IOS +using MonoTouch.CoreGraphics; +using Eto.iOS; + +namespace Eto.iOS.Drawing +#endif +{ + + /// + /// Handler for + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class GraphicsPathHandler : GraphicsPath.IHandler + { + public CGPath Control { get; set; } + bool startFigure = true; + PointF? startPoint; + IMatrix transform; + bool isFirstFigure = true; + bool firstFigureClosed; + + public GraphicsPathHandler () + { + Control = new CGPath (); + } + + public GraphicsPathHandler(CGPath path) + { + Control = path; + } + + public void MoveTo (float x, float y) + { + Control.MoveToPoint (x, y); + if (startPoint == null) + startPoint = new PointF(x, y); + startFigure = false; + } + + public void LineTo (float x, float y) + { + Control.AddLineToPoint (x, y); + } + + void ConnectTo (PointF point) + { + ConnectTo (point.X, point.Y); + } + + void ConnectTo (float x, float y) + { + if (Control.IsEmpty || startFigure) + MoveTo (x, y); + else + LineTo (x, y); + } + + public void AddLine (float startX, float startY, float endX, float endY) + { + ConnectTo (startX, startY); + LineTo (endX, endY); + } + + public void AddLines (IEnumerable points) + { + var enumerator = points.GetEnumerator (); + if (!enumerator.MoveNext ()) + return; + ConnectTo(enumerator.Current); + while (enumerator.MoveNext ()) + { + var point = enumerator.Current; + Control.AddLineToPoint(point.X, point.Y); + } + } + + public void AddRectangle (float x, float y, float width, float height) + { + Control.AddRect (new sd.RectangleF(x, y, width, height)); + startFigure = true; + isFirstFigure = false; + } + + public void AddArc (float x, float y, float width, float height, float startAngle, float sweepAngle) + { + var yscale = height / width; + var centerY = y + height / 2; + var affine = new CGAffineTransform (1.0f, 0, 0, yscale, 0, centerY - centerY * yscale); + + if (startFigure) { + // degrees to radians conversion + double startRadians = startAngle * Math.PI / 180.0; + + // x and y radius + double dx = width / 2; + double dy = height / 2; + + // determine the start point + double xs = x + dx + (Math.Cos (startRadians) * dx); + double ys = y + dy + (Math.Sin (startRadians) * dy); + + MoveTo ((float)xs, (float)ys); + } + + Control.AddArc (affine, x+ width / 2, centerY, width / 2, Conversions.DegreesToRadians (startAngle), Conversions.DegreesToRadians (startAngle + sweepAngle), sweepAngle < 0); + } + + public void AddBezier (PointF start, PointF control1, PointF control2, PointF end) + { + ConnectTo (start); + this.AddCurveToPoint (control1, control2, end); + } + + /// + /// Check points early. If an invalid point is passed to AddCurveToPoint, + /// iOS crashes with a SIGABRT leading to a long debugging experience. + /// This provides early diagnostics. + /// + /// + private void Check(float f) + { + if (float.IsInfinity(f) || float.IsNaN(f)) + throw new InvalidOperationException("Invalid point specified to AddCurveToPoint"); + } + + private void Check(PointF p) + { + Check(p.X); + Check(p.Y); + } + + private void AddCurveToPoint(PointF point1, PointF point2, PointF point3) + { + Check(point1); + Check(point2); + Check(point3); + Control.AddCurveToPoint(point1.ToSD(), point2.ToSD(), point3.ToSD()); + } + + public void AddPath (IGraphicsPath path, bool connect = false) + { + if (path.IsEmpty) + return; + + var handler = path.ToHandler (); + if (connect && handler.startPoint != null && !handler.firstFigureClosed) { + var first = true; + handler.Control.Apply (element => { + switch (element.Type) { + case CGPathElementType.AddCurveToPoint: + if (first) + ConnectTo (element.Point3.ToEto()); + this.AddCurveToPoint(element.Point1.ToEto(), element.Point2.ToEto(), element.Point3.ToEto()); + break; + case CGPathElementType.AddLineToPoint: + if (first) + ConnectTo (element.Point1.ToEto()); + Control.AddLineToPoint(element.Point1); + break; + case CGPathElementType.AddQuadCurveToPoint: + if (first) + ConnectTo (element.Point2.ToEto()); + Control.AddQuadCurveToPoint (element.Point1.X, element.Point1.Y, element.Point2.X, element.Point2.Y); + break; + case CGPathElementType.CloseSubpath: + Control.CloseSubpath (); + break; + case CGPathElementType.MoveToPoint: + if (first) + ConnectTo (element.Point1.ToEto()); + else + Control.MoveToPoint (element.Point1); + break; + } + first = false; + }); + } + else { + Control.AddPath(handler.Control); + } + startFigure = handler.startFigure; + } + + public void Transform (IMatrix matrix) + { + if (transform == null) + transform = matrix; + else + transform.Prepend (matrix); + var path = new CGPath (); + path.AddPath (matrix.ToCG (), Control); + Control = path; + } + + public void CloseFigure () + { + Control.CloseSubpath (); + startFigure = true; + firstFigureClosed |= isFirstFigure; + isFirstFigure = false; + } + + public void StartFigure () + { + startFigure = true; + isFirstFigure = false; + } + + public void AddEllipse (float x, float y, float width, float height) + { + #if XAMMAC || XAMMAC2 + Control.AddEllipseInRect(new CGRect(x, y, width, height)); + #else + Control.AddElipseInRect (new sd.RectangleF (x, y, width, height)); + #endif + startFigure = true; + isFirstFigure = false; + } + + public void AddCurve (IEnumerable points, float tension = 0.5f) + { + points = SplineHelper.SplineCurve (points, tension); + SplineHelper.Draw (points, ConnectTo, (c1, c2, end) => this.AddCurveToPoint(c1, c2, end)); + } + + public RectangleF Bounds + { + get { return Control.PathBoundingBox.ToEto(); } + } + + public bool IsEmpty + { + get { return Control.IsEmpty; } + } + + public PointF CurrentPoint + { + get { return Control.CurrentPoint.ToEto(); } + } + + public object ControlObject + { + get { return this; } + } + + public void Dispose () + { + Control.Dispose (); + } + + FillMode fillMode = FillMode.Alternate; + public FillMode FillMode + { + get { return fillMode; } + set { fillMode = value;} + } + + public IGraphicsPath Clone () + { + return new GraphicsPathHandler (new CGPath (Control)); + } + } +} + diff --git a/Source/Eto.Mac/Drawing/IconHandler.cs b/Source/Eto.Mac/Drawing/IconHandler.cs new file mode 100644 index 0000000000..fa02c095a7 --- /dev/null +++ b/Source/Eto.Mac/Drawing/IconHandler.cs @@ -0,0 +1,79 @@ +using System.IO; +using Eto.Drawing; +using sd = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Drawing +{ + public class IconHandler : ImageHandler, Icon.IHandler + { + public IconHandler() + { + } + + public IconHandler(NSImage image) + { + Control = image; + } + + public void Create(Stream stream) + { + var data = NSData.FromStream(stream); + Control = new NSImage(data); + } + + public void Create(string fileName) + { + if (!File.Exists(fileName)) + throw new FileNotFoundException("Icon not found", fileName); + Control = new NSImage(fileName); + } + + public override Size Size + { + get { return Control.Size.ToEtoSize(); } + } + + public override NSImage GetImage() + { + return Control; + } + + public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) + { + var sourceRect = new CGRect(source.X, (float)Control.Size.Height - source.Y - source.Height, source.Width, source.Height); + var destRect = graphics.TranslateView(destination.ToNS(), true, true); + Control.Draw(destRect, sourceRect, NSCompositingOperation.SourceOver, 1, true, null); + } + } +} diff --git a/Source/Eto.Mac/Drawing/ImageHandler.cs b/Source/Eto.Mac/Drawing/ImageHandler.cs new file mode 100644 index 0000000000..c3627b765c --- /dev/null +++ b/Source/Eto.Mac/Drawing/ImageHandler.cs @@ -0,0 +1,86 @@ +using Eto.Drawing; +using Eto.Mac.Forms; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Drawing +{ + interface IImageSource + { + NSImage GetImage(); + } + + interface IImageHandler : IImageSource + { + void DrawImage(GraphicsHandler graphics, float x, float y); + + void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height); + + void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination); + } + + public abstract class ImageHandler : WidgetHandler, Image.IHandler, IImageHandler + where TControl: class + where TWidget: Image + { + public abstract Size Size { get; } + + public abstract NSImage GetImage(); + + public virtual void DrawImage(GraphicsHandler graphics, float x, float y) + { + DrawImage(graphics, x, y, Size.Width, Size.Height); + } + + public virtual void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height) + { + DrawImage(graphics, new RectangleF(PointF.Empty, Size), new RectangleF(x, y, width, height)); + } + + public abstract void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination); + + protected override void Dispose(bool disposing) + { + // HACK: Remove when monomac/xammac's Dispose() actually works! + if (disposing && DisposeControl) + { + var obj = Control as NSObject; + if (obj != null) + { + obj.SafeDispose(); + Control = null; + } + } + base.Dispose(disposing); + } + } +} diff --git a/Source/Eto.Mac/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Mac/Drawing/IndexedBitmapHandler.cs new file mode 100644 index 0000000000..d93a8261a6 --- /dev/null +++ b/Source/Eto.Mac/Drawing/IndexedBitmapHandler.cs @@ -0,0 +1,199 @@ +using System; +using System.Runtime.InteropServices; +using Eto.Drawing; +using System.Linq; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Drawing +{ + public class IndexedBitmapDataHandler : BitmapData + { + public IndexedBitmapDataHandler(Image image, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) + : base(image, data, scanWidth, bitsPerPixel, controlObject) + { + } + + public override int TranslateArgbToData(int argb) + { + return argb; + } + + public override int TranslateDataToArgb(int bitmapData) + { + return bitmapData; + } + } + + public class IndexedBitmapHandler : ImageHandler, IndexedBitmap.IHandler + { + Size size; + int bytesPerRow; + int bitsPerPixel; + int[] colors; + BitmapHandler bmp; + IntPtr ptr; + + public int RowStride + { + get { return bytesPerRow; } + } + + public override Size Size + { + get { return size; } + } + + public void Create(int width, int height, int bitsPerPixel) + { + this.bitsPerPixel = bitsPerPixel; + bytesPerRow = width * bitsPerPixel / 8; + int colorCount = (int)Math.Pow(2, bitsPerPixel); + colors = new int[colorCount]; + for (int i=0; i Color.FromArgb(BitmapDataHandler.DataToArgb(r)))); + } + set + { + if (value.Count != colors.Length) + throw new ArgumentException("Input palette must have the same colors as the output"); + for (int i=0; i size.Width || source.Bottom > size.Height) + throw new Exception("Source rectangle exceeds image size"); + + // we have to draw to a temporary bitmap pixel by pixel + var bd = bmp.Lock(); + unsafe + { + var dest = (byte*)bd.Data; + var src = (byte*)ptr; + var scany = size.Width; + + dest += source.Top * bd.ScanWidth; + dest += source.Left * bd.BytesPerPixel; + + src += source.Top * scany; + src += source.Left; + + int bottom = source.Bottom; + int right = source.Right; + int left = source.Left; + scany = scany - (right - left); + for (int y=source.Top; y < bottom; y++) + { + var destrow = (int*)dest; + for (int x=left; x < right; x++) + { + *destrow = colors[*src]; + destrow++; + src++; + } + dest += bd.ScanWidth; + src += scany; + } + } + bmp.Unlock(bd); + } + + public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) + { + CopyTo(bmp, Rectangle.Truncate(source)); + bmp.DrawImage(graphics, source, destination); + } + + protected override void Dispose(bool disposing) + { + if (disposing && bmp != null) + { + bmp.Dispose(); + bmp = null; + } + if (ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptr); + ptr = IntPtr.Zero; + } + base.Dispose(disposing); + } + } +} diff --git a/Source/Eto.Mac/Drawing/LinearGradientBrushHandler.cs b/Source/Eto.Mac/Drawing/LinearGradientBrushHandler.cs new file mode 100644 index 0000000000..6d1e7ad222 --- /dev/null +++ b/Source/Eto.Mac/Drawing/LinearGradientBrushHandler.cs @@ -0,0 +1,213 @@ +using System; +using Eto.Drawing; +using sd = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if OSX + +namespace Eto.Mac.Drawing +#else +using Eto.Mac; +using MonoTouch.CoreGraphics; +using MonoTouch.ImageIO; + +namespace Eto.iOS.Drawing +#endif +{ + /// + /// Handler for + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class LinearGradientBrushHandler : BrushHandler, LinearGradientBrush.IHandler + { + class BrushObject + { + CGAffineTransform transform = CGAffineTransform.MakeIdentity(); + CGAffineTransform viewTransform = CGAffineTransform.MakeIdentity(); + readonly nfloat[] alpha = { 1 }; + CGPattern pattern; + GradientWrapMode wrap; + CGSize tileSize; + CGSize sectionSize; + + public CGGradient InverseGradient { get; set; } + + public CGGradient Gradient { get; set; } + + public CGPoint StartPoint { get; set; } + + public CGPoint EndPoint { get; set; } + + public GradientWrapMode Wrap + { + get { return wrap; } + set + { + wrap = value; + pattern = null; + } + } + + public void Apply(GraphicsHandler graphics) + { + graphics.SetFillColorSpace(); + + #if OSX + if (graphics.DisplayView != null) + { + // adjust for position of the current view relative to the window + var pos = graphics.DisplayView.ConvertPointToView(CGPoint.Empty, null); + graphics.Control.SetPatternPhase(new CGSize(pos.X, pos.Y)); + } + #endif + + // make current transform apply to the pattern + var currentTransform = graphics.CurrentTransform; + if (pattern == null || viewTransform != currentTransform) + { + viewTransform = currentTransform; + SetPattern(); + } + + graphics.Control.SetFillPattern(pattern, alpha); + } + + public float Opacity + { + get { return (float)alpha[0]; } + set { alpha[0] = value; } + } + + public CGAffineTransform Transform + { + get { return transform; } + set + { + transform = value; + pattern = null; + } + } + + void DrawPattern(CGContext context) + { + var start = new CGPoint(0, 0); + var end = start + sectionSize; + + context.ClipToRect(new CGRect(start, tileSize).Inset(-4, -4)); + + if (Wrap == GradientWrapMode.Reflect) + { + for (int i = 0; i < 2; i++) + { + context.DrawLinearGradient(Gradient, start, end, 0); + context.DrawLinearGradient(InverseGradient, end, end + sectionSize, 0); + start = start + sectionSize + sectionSize; + end = end + sectionSize + sectionSize; + } + } + else + { + for (int i = 0; i < 2; i++) + { + context.DrawLinearGradient(Gradient, start, end, 0); + start = start + sectionSize; + end = end + sectionSize; + } + } + } + + void SetPattern() + { + sectionSize = new CGSize((EndPoint.X - StartPoint.X) + 1, (EndPoint.Y - StartPoint.Y) + 1); + if (Wrap == GradientWrapMode.Reflect) + tileSize = new CGSize(sectionSize.Width * 4, sectionSize.Height * 4); + else + tileSize = new CGSize(sectionSize.Width * 2, sectionSize.Height * 2); + var rect = new CGRect(StartPoint, tileSize); + var t = CGAffineTransform.Multiply(transform, viewTransform); + pattern = new CGPattern(rect, t, rect.Width, rect.Height, CGPatternTiling.NoDistortion, true, DrawPattern); + } + } + + public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint) + { + return new BrushObject + { + Gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor [] + { + startColor.ToCGColor(), + endColor.ToCGColor() + }), + InverseGradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor [] + { + endColor.ToCGColor(), + startColor.ToCGColor() + }), + StartPoint = startPoint.ToNS(), + EndPoint = endPoint.ToNS() + }; + } + + public object Create(RectangleF rectangle, Color startColor, Color endColor, float angle) + { + return null; + } + + public IMatrix GetTransform(LinearGradientBrush widget) + { + return ((BrushObject)widget.ControlObject).Transform.ToEto(); + } + + public void SetTransform(LinearGradientBrush widget, IMatrix transform) + { + ((BrushObject)widget.ControlObject).Transform = transform.ToCG(); + } + + public GradientWrapMode GetGradientWrap(LinearGradientBrush widget) + { + return ((BrushObject)widget.ControlObject).Wrap; + } + + public void SetGradientWrap(LinearGradientBrush widget, GradientWrapMode gradientWrap) + { + ((BrushObject)widget.ControlObject).Wrap = gradientWrap; + } + + public override void Apply(object control, GraphicsHandler graphics) + { + ((BrushObject)control).Apply(graphics); + } + } +} + diff --git a/Source/Eto.Mac/Drawing/MatrixHandler.cs b/Source/Eto.Mac/Drawing/MatrixHandler.cs new file mode 100644 index 0000000000..172f02dec4 --- /dev/null +++ b/Source/Eto.Mac/Drawing/MatrixHandler.cs @@ -0,0 +1,179 @@ +using System; +using Eto.Drawing; +using SD = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if OSX + +namespace Eto.Mac.Drawing +#elif IOS +using MonoTouch.CoreGraphics; + +namespace Eto.iOS.Drawing +#endif +{ + /// + /// Handler for + /// + /// (c) 2012-2013 by Curtis Wensley + /// See LICENSE for full terms + public class MatrixHandler : Matrix.IHandler + { + CGAffineTransform control; + + public CGAffineTransform Control { get { return control; } } + + public MatrixHandler () + { + } + + public MatrixHandler (CGAffineTransform matrix) + { + control = matrix; + } + + public void Create () + { + control = CGAffineTransform.MakeIdentity (); + } + + public void Create (float xx, float yx, float xy, float yy, float dx, float dy) + { + control = new CGAffineTransform (xx, yx, xy, yy, dx, dy); + } + + public float[] Elements + { + get + { + return new float[] { + (float)control.xx, + (float)control.yx, + (float)control.xy, + (float)control.yy, + (float)control.x0, + (float)control.y0 + }; + } + } + + public float X0 { get { return (float)control.x0; } set { control.x0 = value; } } + + public float Y0 { get { return (float)control.y0; } set { control.y0 = value; } } + + public float Xx { get { return (float)control.xx; } set { control.xx = value; } } + + public float Xy { get { return (float)control.xy; } set { control.xy = value; } } + + public float Yx { get { return (float)control.yx; } set { control.yx = value; } } + + public float Yy { get { return (float)control.yy; } set { control.yy = value; } } + + public void Rotate (float angle) + { + control = CGAffineTransform.Multiply (CGAffineTransform.MakeRotation (Conversions.DegreesToRadians (angle)), control); + } + + public void RotateAt (float angle, float centerX, float centerY) + { + angle = Conversions.DegreesToRadians (angle); + var sina = (float)Math.Sin (angle); + var cosa = (float)Math.Cos (angle); + var matrix = new CGAffineTransform(cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa); + control = CGAffineTransform.Multiply (matrix, control); + } + + public void Translate (float x, float y) + { + control = CGAffineTransform.Multiply (CGAffineTransform.MakeTranslation (x, y), control); + } + + public void Scale (float scaleX, float scaleY) + { + control = CGAffineTransform.Multiply (CGAffineTransform.MakeScale (scaleX, scaleY), control); + } + + public void ScaleAt (float scaleX, float scaleY, float centerX, float centerY) + { + var matrix = new CGAffineTransform(scaleX, 0f, 0f, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); + control = CGAffineTransform.Multiply (matrix, control); + } + + public void Skew (float skewX, float skewY) + { + var matrix = new CGAffineTransform (1, (float)Math.Tan (Conversions.DegreesToRadians (skewX)), (float)Math.Tan (Conversions.DegreesToRadians (skewY)), 1, 0, 0); + control = CGAffineTransform.Multiply (matrix, control); + } + + public void Append (IMatrix matrix) + { + var affineMatrix = (CGAffineTransform)matrix.ControlObject; + control.Multiply (affineMatrix); + } + + public void Prepend (IMatrix matrix) + { + var affineMatrix = (CGAffineTransform)matrix.ControlObject; + control = CGAffineTransform.Multiply (affineMatrix, control); + } + + public void Invert () + { + control = control.Invert (); + } + + public PointF TransformPoint (Point p) + { + return control.TransformPoint(p.ToSDPointF()).ToEto(); + } + + public PointF TransformPoint (PointF p) + { + return control.TransformPoint(p.ToSD()).ToEto(); + } + + public object ControlObject + { + get { return control; } + } + + public IMatrix Clone () + { + return new MatrixHandler (control); + } + + public void Dispose() + { + } + } +} diff --git a/Source/Eto.Mac/Drawing/PenHandler.cs b/Source/Eto.Mac/Drawing/PenHandler.cs new file mode 100644 index 0000000000..882be236ad --- /dev/null +++ b/Source/Eto.Mac/Drawing/PenHandler.cs @@ -0,0 +1,212 @@ +using System; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if XAMMAC2 +using nnfloat = System.nfloat; +#else +using nnfloat = System.Single; +#endif + + +#if OSX + +namespace Eto.Mac.Drawing +#elif IOS +using MonoTouch.CoreGraphics; + +namespace Eto.iOS.Drawing +#endif +{ + /// + /// Pen handler + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class PenHandler : Pen.IHandler + { + class PenControl { + nnfloat[] cgdashes; + DashStyle dashStyle; + CGLineCap lineCap; + float thickness; + float cgoffset; + + public CGColor Color { get; set; } + + public float Thickness + { + get { return thickness; } + set { + thickness = value; + SetDashStyle (); + } + } + + public CGLineJoin LineJoin { get; set; } + + public CGLineCap LineCap + { + get { return lineCap; } + set { + lineCap = value; + SetDashStyle (); + } + } + + public float MiterLimit { get; set; } + + public DashStyle DashStyle + { + get { return dashStyle; } + set { + dashStyle = value; + SetDashStyle (); + } + } + + void SetDashStyle () + { + if (DashStyle == null || DashStyle.IsSolid) { + cgdashes = null; + } else { + // TODO: this is not quite perfect for Square/Round for small thicknesses + + var dashes = DashStyle.Dashes; + cgoffset = DashStyle.Offset * Thickness; + + if (LineCap == CGLineCap.Butt) + cgdashes = Array.ConvertAll (dashes, x => (nnfloat)(x * Thickness)); + else { + if (Math.Abs(Thickness - 1) < 0.01f) + cgoffset += Thickness / 2; + cgdashes = new nnfloat[dashes.Length]; + for (int i = 0; i < cgdashes.Length; i++) { + var dash = dashes [i] * Thickness; + if ((i % 2) == 1) { + // gap must include square/round thickness + dash += Thickness; + } else { + // dash must exclude square/round thickness + dash -= Thickness; + } + cgdashes [i] = dash; + } + } + } + } + + public void Apply (GraphicsHandler graphics) + { + graphics.Control.SetStrokeColor (Color); + graphics.Control.SetLineCap (LineCap); + graphics.Control.SetLineJoin (LineJoin); + graphics.Control.SetLineWidth (Thickness); + graphics.Control.SetMiterLimit (MiterLimit); + if (cgdashes != null) + graphics.Control.SetLineDash (cgoffset, cgdashes); + } + } + + public object Create (Color color, float thickness) + { + return new PenControl { + Color = color.ToCGColor (), + Thickness = thickness, + MiterLimit = 10f, + LineCap = PenLineCap.Square.ToCG () + }; + } + + public Color GetColor (Pen widget) + { + return ((PenControl)widget.ControlObject).Color.ToEtoColor (); + } + + public void SetColor (Pen widget, Color color) + { + ((PenControl)widget.ControlObject).Color = color.ToCGColor (); + } + + public float GetThickness (Pen widget) + { + return ((PenControl)widget.ControlObject).Thickness; + } + + public void SetThickness (Pen widget, float thickness) + { + ((PenControl)widget.ControlObject).Thickness = thickness; + } + + public PenLineJoin GetLineJoin (Pen widget) + { + return ((PenControl)widget.ControlObject).LineJoin.ToEto (); + } + + public void SetLineJoin (Pen widget, PenLineJoin lineJoin) + { + ((PenControl)widget.ControlObject).LineJoin = lineJoin.ToCG (); + } + + public PenLineCap GetLineCap (Pen widget) + { + return ((PenControl)widget.ControlObject).LineCap.ToEto (); + } + + public void SetLineCap (Pen widget, PenLineCap lineCap) + { + ((PenControl)widget.ControlObject).LineCap = lineCap.ToCG (); + } + + public float GetMiterLimit (Pen widget) + { + return ((PenControl)widget.ControlObject).MiterLimit; + } + + public void SetMiterLimit (Pen widget, float miterLimit) + { + ((PenControl)widget.ControlObject).MiterLimit = miterLimit; + } + + public void SetDashStyle (Pen widget, DashStyle dashStyle) + { + ((PenControl)widget.ControlObject).DashStyle = dashStyle; + } + + public void Apply (Pen widget, GraphicsHandler graphics) + { + ((PenControl)widget.ControlObject).Apply (graphics); + } + } +} + diff --git a/Source/Eto.Mac/Drawing/SolidBrushHandler.cs b/Source/Eto.Mac/Drawing/SolidBrushHandler.cs new file mode 100644 index 0000000000..28825587f9 --- /dev/null +++ b/Source/Eto.Mac/Drawing/SolidBrushHandler.cs @@ -0,0 +1,53 @@ +using Eto.Drawing; + +#if OSX +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Drawing +#elif IOS +using MonoTouch.CoreGraphics; + +namespace Eto.iOS.Drawing +#endif +{ + /// + /// Handler for + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class SolidBrushHandler : BrushHandler, SolidBrush.IHandler + { + public override void Apply (object control, GraphicsHandler graphics) + { + graphics.Control.SetFillColor ((CGColor)control); + } + + public Color GetColor (SolidBrush widget) + { + return ((CGColor)widget.ControlObject).ToEtoColor (); + } + + public void SetColor (SolidBrush widget, Color color) + { + widget.ControlObject = color.ToCGColor (); + } + + object SolidBrush.IHandler.Create (Color color) + { + return color.ToCGColor (); + } + } +} + diff --git a/Source/Eto.Platform.Mac/Drawing/SplineHelper.cs b/Source/Eto.Mac/Drawing/SplineHelper.cs similarity index 97% rename from Source/Eto.Platform.Mac/Drawing/SplineHelper.cs rename to Source/Eto.Mac/Drawing/SplineHelper.cs index d99bc4dada..014615f79f 100644 --- a/Source/Eto.Platform.Mac/Drawing/SplineHelper.cs +++ b/Source/Eto.Mac/Drawing/SplineHelper.cs @@ -3,12 +3,12 @@ using Eto.Drawing; using System.Collections.Generic; -namespace Eto.Platform +namespace Eto { /// /// Helper methods to calculate points of a spline /// - /// (c) 2012 by Curtis Wensley + /// (c) 2012-2014 by Curtis Wensley /// See LICENSE for full terms public static class SplineHelper { diff --git a/Source/Eto.Mac/Drawing/TextureBrushHandler.cs b/Source/Eto.Mac/Drawing/TextureBrushHandler.cs new file mode 100644 index 0000000000..82e53e3ad8 --- /dev/null +++ b/Source/Eto.Mac/Drawing/TextureBrushHandler.cs @@ -0,0 +1,168 @@ +using System; +using Eto.Drawing; +using sd = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if OSX + +namespace Eto.Mac.Drawing +#else +using MonoTouch.CoreGraphics; +using MonoTouch.ImageIO; + +namespace Eto.iOS.Drawing +#endif +{ + /// + /// Handler for + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class TextureBrushHandler : BrushHandler, TextureBrush.IHandler + { + class BrushObject + { + CGImage image; + CGAffineTransform transform = CGAffineTransform.MakeIdentity(); + CGAffineTransform viewTransform = CGAffineTransform.MakeIdentity(); + readonly nfloat[] alpha = { 1 }; + CGPattern pattern; + + public void Apply(GraphicsHandler graphics) + { + graphics.SetFillColorSpace(); + + #if OSX + if (graphics.DisplayView != null) + { + // adjust for position of the current view relative to the window + var pos = graphics.DisplayView.ConvertPointToView(CGPoint.Empty, null); + graphics.Control.SetPatternPhase(new CGSize(pos.X, pos.Y)); + } + #endif + + // make current transform apply to the pattern + var currentTransform = graphics.CurrentTransform; + if (pattern == null || viewTransform != currentTransform) + { + viewTransform = currentTransform; + SetPattern(); + } + + graphics.Control.SetFillPattern(pattern, alpha); + } + + public CGImage Image + { + get { return image; } + set + { + image = value; + ClearPattern(); + } + } + + public float Opacity + { + get { return (float)alpha[0]; } + set { alpha[0] = value; } + } + + public CGAffineTransform Transform + { + get { return transform; } + set + { + transform = value; + ClearPattern(); + } + } + + void ClearPattern() + { + if (pattern != null) + pattern.Dispose(); + pattern = null; + } + + void DrawPattern(CGContext context) + { + var destRect = new CGRect(0, 0, image.Width, image.Height); + context.ConcatCTM(new CGAffineTransform(1, 0, 0, -1, 0, image.Height)); + context.DrawImage(destRect, image); + } + + void SetPattern() + { + var t = CGAffineTransform.Multiply(transform, viewTransform); + ClearPattern(); + pattern = new CGPattern(new CGRect(0, 0, image.Width, image.Height), t, image.Width, image.Height, CGPatternTiling.NoDistortion, true, DrawPattern); + } + } + + public object Create(Image image, float opacity) + { + return new BrushObject + { + Image = image.ToCG(), + Opacity = opacity + }; + } + + public IMatrix GetTransform(TextureBrush widget) + { + return ((BrushObject)widget.ControlObject).Transform.ToEto(); + } + + public void SetTransform(TextureBrush widget, IMatrix transform) + { + ((BrushObject)widget.ControlObject).Transform = transform.ToCG(); + } + + public override void Apply(object control, GraphicsHandler graphics) + { + ((BrushObject)control).Apply(graphics); + } + + public float GetOpacity(TextureBrush widget) + { + return ((BrushObject)widget.ControlObject).Opacity; + } + + public void SetOpacity(TextureBrush widget, float opacity) + { + ((BrushObject)widget.ControlObject).Opacity = opacity; + } + } +} + diff --git a/Source/Eto.Mac/Eto.Mac - Pcl.csproj b/Source/Eto.Mac/Eto.Mac - Pcl.csproj new file mode 100644 index 0000000000..4c97c55b14 --- /dev/null +++ b/Source/Eto.Mac/Eto.Mac - Pcl.csproj @@ -0,0 +1,234 @@ + + + + Debug + AnyCPU + {3E7995E0-C9EB-11E3-9C1A-0800200C9A66} + Library + Eto.Mac + v4.5 + Eto.Mac + + + $(DefineConstants);OSX;DESKTOP;MONOMAC + false + true + + + full + ..\..\BuildOutput\Pcl\Debug\ + DEBUG;OSX;DESKTOP;MONOMAC + prompt + 4 + false + true + + + pdbonly + true + ..\..\BuildOutput\Pcl\Release\ + prompt + 4 + false + OSX;DESKTOP;MONOMAC + true + + + ..\..\.. + + + + + ..\..\Libraries\MonoMac\MonoMac.dll + + + + + + + + + + + + + + + + + Code + + + Code + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + + + PlatformDetect.cs + + + + + + + + + + + + MonoMac-License.txt + PreserveNewest + + + + + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + \ No newline at end of file diff --git a/Source/Eto.Mac/Eto.Mac.csproj b/Source/Eto.Mac/Eto.Mac.csproj new file mode 100644 index 0000000000..7c858e2387 --- /dev/null +++ b/Source/Eto.Mac/Eto.Mac.csproj @@ -0,0 +1,228 @@ + + + + Debug + AnyCPU + {9DD10DFF-5AB3-4E66-B798-CA17911A61E4} + Library + Eto.Mac + Eto.Mac + + + $(DefineConstants);OSX;DESKTOP;MONOMAC + false + true + + + full + ..\..\BuildOutput\Debug\ + DEBUG;OSX;DESKTOP;MONOMAC + prompt + 4 + false + true + + + pdbonly + true + ..\..\BuildOutput\Release\ + prompt + 4 + false + OSX;DESKTOP;MONOMAC + true + + + ..\..\.. + + + + + ..\..\Libraries\MonoMac\MonoMac.dll + + + + + + + + + + + + + + + + + Code + + + Code + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {16289D2F-044C-49EF-83E9-9391AFF8FD2B} + Eto + + + + + MonoMac-License.txt + PreserveNewest + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Eto.Mac/Eto.Mac64 - Pcl.csproj b/Source/Eto.Mac/Eto.Mac64 - Pcl.csproj new file mode 100644 index 0000000000..e8fd50d593 --- /dev/null +++ b/Source/Eto.Mac/Eto.Mac64 - Pcl.csproj @@ -0,0 +1,234 @@ + + + + Debug + AnyCPU + {55DAB390-1CFC-11E4-8C21-0800200C9A66} + Library + Eto.Mac + v4.5 + Eto.Mac64 + + + $(DefineConstants);OSX;DESKTOP;MONOMAC;Mac64 + false + true + + + full + ..\..\BuildOutput\Pcl\Debug\ + DEBUG;OSX;DESKTOP;MONOMAC;Mac64 + prompt + 4 + false + true + + + pdbonly + true + ..\..\BuildOutput\Pcl\Release\ + prompt + 4 + false + OSX;DESKTOP;MONOMAC;Mac64 + true + + + ..\..\.. + + + + + ..\..\Libraries\MonoMac64\MonoMac.dll + + + + + + + + + + + + + + + + + Code + + + Code + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + + + PlatformDetect.cs + + + + + + + + + + + + MonoMac-License.txt + PreserveNewest + + + + + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + \ No newline at end of file diff --git a/Source/Eto.Mac/Eto.Mac64.csproj b/Source/Eto.Mac/Eto.Mac64.csproj new file mode 100644 index 0000000000..31bfb6f5e5 --- /dev/null +++ b/Source/Eto.Mac/Eto.Mac64.csproj @@ -0,0 +1,231 @@ + + + + Debug + AnyCPU + {75EADBA0-15B4-11E4-8C21-0800200C9A66} + Library + Eto.Mac + Eto.Mac64 + + + $(DefineConstants);OSX;DESKTOP;MONOMAC;MAC64 + false + true + + + full + ..\..\BuildOutput\Debug\ + DEBUG;OSX;DESKTOP;MONOMAC;Mac64 + prompt + 4 + false + true + + + pdbonly + true + ..\..\BuildOutput\Release\ + prompt + 4 + false + OSX;DESKTOP;MONOMAC;Mac64 + true + + + ..\..\.. + + + + + ..\..\Libraries\MonoMac64\MonoMac.dll + False + + + + + + + + + + + + + Code + + + + + + + Code + + + Code + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {16289D2F-044C-49EF-83E9-9391AFF8FD2B} + Eto + + + + + MonoMac-License.txt + PreserveNewest + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Eto.Mac/Eto.XamMac - Pcl.csproj b/Source/Eto.Mac/Eto.XamMac - Pcl.csproj new file mode 100644 index 0000000000..cfb6551900 --- /dev/null +++ b/Source/Eto.Mac/Eto.XamMac - Pcl.csproj @@ -0,0 +1,234 @@ + + + + Debug + AnyCPU + {BF405A10-C9EB-11E3-9C1A-0800200C9A66} + {42C0BBD9-55CE-4FC1-8D90-A7348ABAFB23};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Eto.Mac + v4.5 + Eto.XamMac + + + full + false + ..\..\BuildOutput\Pcl\Debug\ + DEBUG;OSX;DESKTOP;XAMMAC + prompt + 4 + False + True + True + false + false + false + false + false + + + pdbonly + true + ..\..\BuildOutput\Pcl\Release\ + prompt + 4 + false + true + OSX;DESKTOP;XAMMAC + True + false + false + false + false + false + + + + $(XamarinMacLibPath) + + + + + + + + + + + + + + + + + + Code + + + Code + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + + + PlatformDetect.cs + + + + + + + + + + + + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + \ No newline at end of file diff --git a/Source/Eto.Mac/Eto.XamMac.csproj b/Source/Eto.Mac/Eto.XamMac.csproj new file mode 100644 index 0000000000..5f60da726f --- /dev/null +++ b/Source/Eto.Mac/Eto.XamMac.csproj @@ -0,0 +1,228 @@ + + + + Debug + AnyCPU + {15490F6C-C579-4A86-AD16-8D9B5B41EB87} + {42C0BBD9-55CE-4FC1-8D90-A7348ABAFB23};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Eto.Mac + Eto.XamMac + + + full + false + ..\..\BuildOutput\Debug\ + DEBUG;OSX;DESKTOP;XAMMAC + prompt + 4 + False + True + True + false + false + false + false + false + + + pdbonly + true + ..\..\BuildOutput\Release\ + prompt + 4 + false + true + OSX;DESKTOP;XAMMAC + True + false + false + false + false + false + + + + $(XamarinMacLibPath) + + + + + + + + + + + + + + + + + + Code + + + Code + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {16289D2F-044C-49EF-83E9-9391AFF8FD2B} + Eto + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Eto.Mac/Eto.XamMac2 - Pcl.csproj b/Source/Eto.Mac/Eto.XamMac2 - Pcl.csproj new file mode 100644 index 0000000000..1ab2681e23 --- /dev/null +++ b/Source/Eto.Mac/Eto.XamMac2 - Pcl.csproj @@ -0,0 +1,232 @@ + + + + Debug + AnyCPU + {856E8C70-2702-11E4-8C21-0800200C9A66} + {A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Eto.Mac + v2.0 + Eto.XamMac2 + Xamarin.Mac + + + full + false + ..\..\BuildOutput\Pcl\Debug\ + DEBUG;OSX;DESKTOP;XAMMAC;XAMMAC2 + prompt + 4 + False + True + True + false + false + false + false + false + + + pdbonly + true + ..\..\BuildOutput\Pcl\Release\ + prompt + 4 + false + true + OSX;DESKTOP;XAMMAC;XAMMAC2 + True + false + false + false + false + false + + + + + + + + + + + + + + + + + + Code + + + Code + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + + + PlatformDetect.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + {35EF0A4E-2A1A-492C-8BED-106774EA09F2} + Eto - Pcl + + + + \ No newline at end of file diff --git a/Source/Eto.Platform.Mac/EtoBundle.cs b/Source/Eto.Mac/EtoBundle.cs similarity index 79% rename from Source/Eto.Platform.Mac/EtoBundle.cs rename to Source/Eto.Mac/EtoBundle.cs index c8c226ff22..59cfeeb360 100644 --- a/Source/Eto.Platform.Mac/EtoBundle.cs +++ b/Source/Eto.Mac/EtoBundle.cs @@ -1,8 +1,19 @@ using System; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; using MonoMac.Foundation; +using MonoMac.CoreGraphics; using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif -namespace Eto.Platform.Mac +namespace Eto.Mac { public static class EtoBundle { diff --git a/Source/Eto.Mac/EtoEnvironmentHandler.cs b/Source/Eto.Mac/EtoEnvironmentHandler.cs new file mode 100644 index 0000000000..a7c113b27d --- /dev/null +++ b/Source/Eto.Mac/EtoEnvironmentHandler.cs @@ -0,0 +1,58 @@ +using System; +using System.Linq; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac +{ + public class EtoEnvironmentHandler : WidgetHandler, EtoEnvironment.IHandler + { + static void Convert (EtoSpecialFolder folder, out NSSearchPathDirectory dir, out NSSearchPathDomain domain) + { + switch (folder) { + case EtoSpecialFolder.ApplicationSettings: + dir = NSSearchPathDirectory.ApplicationSupportDirectory; + domain = NSSearchPathDomain.User; + break; + case EtoSpecialFolder.Documents: + dir = NSSearchPathDirectory.DocumentDirectory; + domain = NSSearchPathDomain.User; + break; + default: + throw new NotSupportedException (); + } + } + + public string GetFolderPath (EtoSpecialFolder folder) + { + NSSearchPathDirectory dir; + NSSearchPathDomain domain; + switch (folder) { + case EtoSpecialFolder.ApplicationResources: + return NSBundle.MainBundle.ResourcePath; + case EtoSpecialFolder.ApplicationSettings: + Convert (folder, out dir, out domain); + var path = NSSearchPath.GetDirectories (dir, domain).FirstOrDefault (); + path = System.IO.Path.Combine (path, NSBundle.MainBundle.BundleIdentifier); + if (!System.IO.Directory.Exists (path)) + System.IO.Directory.CreateDirectory (path); + return path; + default: + Convert (folder, out dir, out domain); + return NSSearchPath.GetDirectories (dir, domain).FirstOrDefault (); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Actions/MacCommand.cs b/Source/Eto.Mac/Forms/Actions/MacCommand.cs new file mode 100644 index 0000000000..3e27e22b46 --- /dev/null +++ b/Source/Eto.Mac/Forms/Actions/MacCommand.cs @@ -0,0 +1,30 @@ +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Actions +{ + public class MacCommand : Command + { + public Selector Selector { get; private set; } + + public MacCommand(string id, string text, string selector) + { + ID = id; + MenuText = ToolBarText = text; + Selector = new Selector(selector); + } + } +} + diff --git a/Source/Eto.Mac/Forms/ApplicationHandler.cs b/Source/Eto.Mac/Forms/ApplicationHandler.cs new file mode 100644 index 0000000000..bb28da8e38 --- /dev/null +++ b/Source/Eto.Mac/Forms/ApplicationHandler.cs @@ -0,0 +1,211 @@ +using System; +using Eto.Forms; +using Eto.Mac.Forms.Actions; +using System.Collections.Generic; +using System.Linq; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; + +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; + +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; + +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms +{ + public class ApplicationHandler : WidgetHandler, Application.IHandler + { + bool attached; + + internal static bool QueueResizing { get; set; } + + public NSApplicationDelegate AppDelegate { get; set; } + + public bool AddFullScreenMenuItem { get; set; } + + public bool AllowClosingMainForm { get; set; } + + public static ApplicationHandler Instance + { + get { return Application.Instance == null ? null : Application.Instance.Handler as ApplicationHandler; } + } + + public string BadgeLabel + { + get + { + var badgeLabel = Control.DockTile.BadgeLabel; + return string.IsNullOrEmpty(badgeLabel) ? null : badgeLabel; + } + set + { + Control.DockTile.BadgeLabel = value ?? string.Empty; + } + } + + public bool ShouldCloseForm(Window window, bool wasClosed) + { + if (ReferenceEquals(window, Widget.MainForm)) + { + if (AllowClosingMainForm && wasClosed) + Widget.MainForm = null; + return AllowClosingMainForm; + } + + return true; + } + + public ApplicationHandler() + { + Control = NSApplication.SharedApplication; + } + + static void restart_WillTerminate(object sender, EventArgs e) + { + // re-open after we terminate + var args = new string[] + { + "-c", + "open \"$1\"", + string.Empty, + NSBundle.MainBundle.BundlePath + }; + NSTask.LaunchFromPath("/bin/sh", args); + } + + public void Invoke(Action action) + { + var thread = NSThread.Current; + if (thread != null && thread.IsMainThread) + action(); + else + { + Control.InvokeOnMainThread(() => action()); + } + } + + public void AsyncInvoke(Action action) + { + Control.BeginInvokeOnMainThread(() => action()); + } + + public void Restart() + { + NSApplication.SharedApplication.WillTerminate += restart_WillTerminate; + NSApplication.SharedApplication.Terminate(AppDelegate); + + // only get here if cancelled, remove event to restart + NSApplication.SharedApplication.WillTerminate -= restart_WillTerminate; + } + + public void RunIteration() + { + NSApplication.SharedApplication.NextEvent(NSEventMask.AnyEvent, NSDate.DistantFuture, NSRunLoop.NSDefaultRunLoopMode, true); + } + + public void Attach(object context) + { + attached = true; + } + + public void OnMainFormChanged() + { + } + + public void Run() + { + if (!attached) + { + EtoBundle.Init(); + + if (Control.Delegate == null) + Control.Delegate = AppDelegate ?? new AppDelegate(); + NSApplication.Main(new string[0]); + } + else + Initialize(Control.Delegate); + } + + public void Initialize(NSApplicationDelegate appdelegate) + { + AppDelegate = appdelegate; + Callback.OnInitialized(Widget, EventArgs.Empty); + } + + public void Quit() + { + NSApplication.SharedApplication.Terminate(AppDelegate); + } + + public bool QuitIsSupported { get { return true; } } + + public void Open(string url) + { + NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(url)); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Application.TerminatingEvent: + // handled by app delegate + break; + default: + base.AttachEvent(id); + break; + } + } + + public void EnableFullScreen() + { + if (Control.RespondsToSelector(new Selector("setPresentationOptions:"))) + { + AddFullScreenMenuItem = true; + } + } + + public Keys CommonModifier + { + get + { + return Keys.Application; + } + } + + public Keys AlternateModifier + { + get + { + return Keys.Alt; + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Cells/CellHandler.cs b/Source/Eto.Mac/Forms/Cells/CellHandler.cs new file mode 100644 index 0000000000..c8f98cc66f --- /dev/null +++ b/Source/Eto.Mac/Forms/Cells/CellHandler.cs @@ -0,0 +1,114 @@ +using Eto.Forms; +using Eto.Drawing; +using System; +using Eto.Mac.Forms.Controls; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Cells +{ + public interface ICellHandler + { + NSCell Control { get; } + + Eto.Platform Platform { get; } + + IDataColumnHandler ColumnHandler { get; set; } + + NSObject GetObjectValue (object dataItem); + + void SetObjectValue (object dataItem, NSObject val); + + nfloat GetPreferredSize (object value, CGSize cellSize, int row, object dataItem); + + void HandleEvent (string handler, bool defaultEvent = false); + + void SetBackgroundColor (NSCell cell, Color color); + + Color GetBackgroundColor (NSCell cell); + + void SetForegroundColor (NSCell cell, Color color); + + Color GetForegroundColor (NSCell cell); + + bool Editable { get; set; } + } + + public abstract class CellHandler : MacObject, Cell.IHandler, ICellHandler + where TControl: NSCell + where TWidget: Cell + { + public IDataColumnHandler ColumnHandler { get; set; } + NSCell copy; + + NSCell ICellHandler.Control { + get { return Control; } + } + + public virtual bool Editable { + get { return Control.Editable; } + set { + Control.Enabled = Control.Editable = value; + } + } + + public virtual NSObject GetObjectValue (object dataItem) + { + return null; + } + + Eto.Platform ICellHandler.Platform + { + get { return Widget.Platform; } + } + + public abstract void SetBackgroundColor (NSCell cell, Color color); + + public abstract Color GetBackgroundColor (NSCell cell); + + public abstract void SetForegroundColor (NSCell cell, Color color); + + public abstract Color GetForegroundColor (NSCell cell); + + public abstract void SetObjectValue (object dataItem, NSObject value); + + public abstract nfloat GetPreferredSize (object value, CGSize cellSize, NSCell cell); + + public nfloat GetPreferredSize (object value, CGSize cellSize, int row, object dataItem) + { + if (copy == null) + copy = Control.Copy () as NSCell; + ColumnHandler.DataViewHandler.OnCellFormatting (ColumnHandler.Widget, dataItem, row, copy); + return GetPreferredSize (value, cellSize, copy); + } + + } +} + diff --git a/Source/Eto.Mac/Forms/Cells/CheckBoxCellHandler.cs b/Source/Eto.Mac/Forms/Cells/CheckBoxCellHandler.cs new file mode 100644 index 0000000000..779196ad00 --- /dev/null +++ b/Source/Eto.Mac/Forms/Cells/CheckBoxCellHandler.cs @@ -0,0 +1,132 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Cells +{ + public class CheckBoxCellHandler : CellHandler, CheckBoxCell.IHandler + { + public class EtoCell : NSButtonCell, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public EtoCell () + { + } + + public EtoCell (IntPtr handle) : base(handle) + { + } + + [Export("copyWithZone:")] + NSObject CopyWithZone (IntPtr zone) + { + var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr (SuperHandle, MacCommon.CopyWithZoneHandle, zone); + return new EtoCell (ptr) { Handler = Handler }; + } + } + + public CheckBoxCellHandler () + { + Control = new EtoCell { Handler = this }; + Control.Title = string.Empty; + Control.SetButtonType (NSButtonType.Switch); + } + + public override void SetBackgroundColor (NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.BackgroundColor = color.ToNSUI (); + } + + public override Color GetBackgroundColor (NSCell cell) + { + var c = (EtoCell)cell; + return c.BackgroundColor.ToEto (); + } + + public override void SetForegroundColor (NSCell cell, Color color) + { + } + + public override Color GetForegroundColor (NSCell cell) + { + return Colors.Transparent; + } + + + public override void SetObjectValue (object dataItem, NSObject value) + { + if (Widget.Binding != null) { + var num = value as NSNumber; + if (num != null) { + var state = (NSCellStateValue)num.Int32Value; + bool? boolValue; + switch (state) { + default: + boolValue = null; + break; + case NSCellStateValue.On: + boolValue = true; + break; + case NSCellStateValue.Off: + boolValue = false; + break; + } + Widget.Binding.SetValue(dataItem, boolValue); + } + } + } + + public override NSObject GetObjectValue (object dataItem) + { + if (Widget.Binding != null) { + NSCellStateValue state = NSCellStateValue.Off; + var val = Widget.Binding.GetValue(dataItem); + state = val != null ? val.Value ? NSCellStateValue.On : NSCellStateValue.Off : NSCellStateValue.Mixed; + return new NSNumber((int)state); + } + return new NSNumber ((int)NSCellStateValue.Off); + } + + public override nfloat GetPreferredSize (object value, CGSize cellSize, NSCell cell) + { + return 25; + } + } +} + diff --git a/Source/Eto.Mac/Forms/Cells/ComboBoxCellHandler.cs b/Source/Eto.Mac/Forms/Cells/ComboBoxCellHandler.cs new file mode 100644 index 0000000000..3e2306260e --- /dev/null +++ b/Source/Eto.Mac/Forms/Cells/ComboBoxCellHandler.cs @@ -0,0 +1,212 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using System.Linq; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Cells +{ + public class ComboBoxCellHandler : CellHandler, ComboBoxCell.IHandler + { + CollectionHandler collection; + + public class EtoCell : NSPopUpButtonCell, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public EtoCell() + { + } + + public EtoCell(IntPtr handle) : base(handle) + { + } + + public NSColor TextColor { get; set; } + + public bool DrawsBackground { get; set; } + + [Export("copyWithZone:")] + NSObject CopyWithZone(IntPtr zone) + { + var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr(SuperHandle, MacCommon.CopyWithZoneHandle, zone); + return new EtoCell(ptr) { Handler = Handler }; + } + + public override void DrawBorderAndBackground(CGRect cellFrame, NSView controlView) + { + if (DrawsBackground) + { + var nscontext = NSGraphicsContext.CurrentContext; + var context = nscontext.GraphicsPort; + + context.SetFillColor(BackgroundColor.CGColor); + context.FillRect(cellFrame); + } + + base.DrawBorderAndBackground(cellFrame, controlView); + } + + public override CGRect DrawTitle(NSAttributedString title, CGRect frame, NSView controlView) + { + if (TextColor != null) + { + var newtitle = (NSMutableAttributedString)title.MutableCopy(); + var range = new NSRange(0, (int)title.Length); + newtitle.RemoveAttribute(NSAttributedString.ForegroundColorAttributeName, range); + newtitle.AddAttribute(NSAttributedString.ForegroundColorAttributeName, TextColor, range); + title = newtitle; + } + var rect = base.DrawTitle(title, frame, controlView); + return rect; + } + } + + class CollectionHandler : EnumerableChangedHandler + { + public ComboBoxCellHandler Handler { get; set; } + ILookup indexLookupByKey; + + public ILookup IndexLookup + { + get { return indexLookupByKey ?? (indexLookupByKey = Collection.ToLookup(e => Handler.Widget.ComboKeyBinding.GetValue(e), e => IndexOf(e))); } + } + + public override void AddItem(object item) + { + var menu = Handler.Control.Menu; + var textBinding = Handler.Widget.ComboTextBinding; + menu.AddItem(new NSMenuItem(textBinding.GetValue(item))); + indexLookupByKey = null; + } + + public override void InsertItem(int index, object item) + { + var menu = Handler.Control.Menu; + var textBinding = Handler.Widget.ComboTextBinding; + menu.InsertItem(new NSMenuItem(textBinding.GetValue(item)), index); + indexLookupByKey = null; + } + + public override void RemoveItem(int index) + { + var menu = Handler.Control.Menu; + menu.RemoveItemAt(index); + indexLookupByKey = null; + } + + public override void RemoveAllItems() + { + Handler.Control.RemoveAllItems(); + indexLookupByKey = null; + } + } + + public ComboBoxCellHandler() + { + Control = new EtoCell { Handler = this, ControlSize = NSControlSize.Regular, Bordered = false }; + Control.Title = string.Empty; + } + + public override void SetBackgroundColor(NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.BackgroundColor = color.ToNSUI(); + c.DrawsBackground = color != Colors.Transparent; + } + + public override Color GetBackgroundColor(NSCell cell) + { + var c = (EtoCell)cell; + return c.BackgroundColor.ToEto(); + } + + public override void SetForegroundColor(NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.TextColor = color.ToNSUI(); + } + + public override Color GetForegroundColor(NSCell cell) + { + var c = (EtoCell)cell; + return c.TextColor.ToEto(); + } + + public IEnumerable DataStore + { + get { return collection != null ? collection.Collection : null; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler { Handler = this }; + collection.Register(value); + } + } + + public override void SetObjectValue(object dataItem, NSObject value) + { + if (Widget.Binding != null) + { + var row = ((NSNumber)value).Int32Value; + var item = collection.ElementAt(row); + var itemValue = item != null ? Widget.ComboKeyBinding.GetValue(item) : null; + Widget.Binding.SetValue(dataItem, itemValue); + } + } + + public override NSObject GetObjectValue(object dataItem) + { + if (Widget.Binding != null) + { + var val = Widget.Binding.GetValue(dataItem); + var key = Convert.ToString(val); + var lookup = collection.IndexLookup[key].ToArray(); + var index = lookup.Length > 0 ? lookup[0] : -1; + return new NSNumber(index); + } + return null; + } + + public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) + { + return 100; + } + } +} + diff --git a/Source/Eto.Mac/Forms/Cells/DrawableCellHandler.cs b/Source/Eto.Mac/Forms/Cells/DrawableCellHandler.cs new file mode 100644 index 0000000000..58c14e1f84 --- /dev/null +++ b/Source/Eto.Mac/Forms/Cells/DrawableCellHandler.cs @@ -0,0 +1,175 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using sd = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + + +namespace Eto.Mac.Forms.Cells +{ + public class DrawableCellHandler : CellHandler, DrawableCell.IHandler + { + public class EtoCellValue : NSObject + { + public object Item { get; set; } + + public EtoCellValue() + { + } + + public EtoCellValue(IntPtr handle) : base(handle) + { + } + + [Export("copyWithZone:")] + NSObject CopyWithZone(IntPtr zone) + { + var val = new EtoCellValue { Item = Item }; + val.DangerousRetain(); + return val; + } + } + + public class EtoCell : NSCell, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public DrawableCellHandler Handler + { + get { return (DrawableCellHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public EtoCell() + { + } + + public EtoCell(IntPtr handle) : base(handle) + { + } + + public Color BackgroundColor { get; set; } + + public bool DrawsBackground { get; set; } + + // TODO: Mac64 + #if !Mac64 && !XAMMAC2 + public override CGSize CellSizeForBounds(CGRect bounds) + { + return CGSize.Empty; + } + #endif + + [Export("copyWithZone:")] + NSObject CopyWithZone(IntPtr zone) + { + var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr( + SuperHandle, + MacCommon.CopyWithZoneHandle, + zone + ); + return new EtoCell(ptr) { Handler = Handler }; + } + + public override void DrawInteriorWithFrame(CGRect cellFrame, NSView inView) + { + var nscontext = NSGraphicsContext.CurrentContext; + + if (DrawsBackground) + { + var context = nscontext.GraphicsPort; + context.SetFillColor(BackgroundColor.ToCGColor()); + context.FillRect(cellFrame); + } + + var handler = Handler; + var graphicsHandler = new GraphicsHandler(null, nscontext, (float)cellFrame.Height, flipped: true); + using (var graphics = new Graphics(graphicsHandler)) + { + var state = Highlighted ? DrawableCellStates.Selected : DrawableCellStates.None; + var item = ObjectValue as EtoCellValue; + var args = new DrawableCellPaintEventArgs(graphics, cellFrame.ToEto(), state, item != null ? item.Item : null); + handler.Callback.OnPaint(handler.Widget, args); + } + } + } + + public override bool Editable + { + get { return base.Editable; } + set { Control.Editable = value; } + } + + public DrawableCellHandler() + { + Control = new EtoCell { Handler = this, Enabled = true }; + } + + public override void SetBackgroundColor(NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.BackgroundColor = color; + c.DrawsBackground = color != Colors.Transparent; + } + + public override Color GetBackgroundColor(NSCell cell) + { + return ((EtoCell)cell).BackgroundColor; + } + + public override void SetForegroundColor(NSCell cell, Color color) + { + } + + public override Color GetForegroundColor(NSCell cell) + { + return Colors.Transparent; + } + + public override NSObject GetObjectValue(object dataItem) + { + return new EtoCellValue { Item = dataItem }; + } + + public override void SetObjectValue(object dataItem, NSObject value) + { + } + + public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) + { + return 10f; + } + } +} + diff --git a/Source/Eto.Mac/Forms/Cells/ImageTextCellHandler.cs b/Source/Eto.Mac/Forms/Cells/ImageTextCellHandler.cs new file mode 100644 index 0000000000..5ecdfdca2a --- /dev/null +++ b/Source/Eto.Mac/Forms/Cells/ImageTextCellHandler.cs @@ -0,0 +1,160 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using Eto.Mac.Forms.Controls; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Cells +{ + public class ImageTextCellHandler : CellHandler, ImageTextCell.IHandler + { + public class EtoCell : MacImageListItemCell, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public NSImageInterpolation ImageInterpolation { get; set; } + + public EtoCell() + { + } + + public EtoCell(IntPtr handle) : base(handle) + { + } + + [Export("copyWithZone:")] + NSObject CopyWithZone(IntPtr zone) + { + var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr(SuperHandle, MacCommon.CopyWithZoneHandle, zone); + return new EtoCell(ptr) { Handler = Handler }; + } + + public override void DrawInteriorWithFrame(CGRect cellFrame, NSView inView) + { + var nscontext = NSGraphicsContext.CurrentContext; + nscontext.ImageInterpolation = ImageInterpolation; + base.DrawInteriorWithFrame(cellFrame, inView); + } + } + + public ImageTextCellHandler() + { + Control = new EtoCell + { + Handler = this, + UsesSingleLineMode = true + }; + } + + public override void SetBackgroundColor(NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.BackgroundColor = color.ToNSUI(); + c.DrawsBackground = color != Colors.Transparent; + } + + public override Color GetBackgroundColor(NSCell cell) + { + var c = (EtoCell)cell; + return c.BackgroundColor.ToEto(); + } + + public override void SetForegroundColor(NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.TextColor = color.ToNSUI(); + } + + public override Color GetForegroundColor(NSCell cell) + { + var c = (EtoCell)cell; + return c.TextColor.ToEto(); + } + + public override NSObject GetObjectValue(object dataItem) + { + var result = new MacImageData(); + if (Widget.TextBinding != null) + { + result.Text = (NSString)Convert.ToString(Widget.TextBinding.GetValue(dataItem)); + } + if (Widget.ImageBinding != null) + { + var image = Widget.ImageBinding.GetValue(dataItem) as Image; + result.Image = image != null ? ((IImageSource)image.Handler).GetImage() : null; + } + else + result.Image = null; + return result; + } + + public override void SetObjectValue(object dataItem, NSObject value) + { + if (Widget.TextBinding != null) + { + var str = value as NSString; + if (str != null) + Widget.TextBinding.SetValue(dataItem, str.ToString()); + else + Widget.TextBinding.SetValue(dataItem, null); + } + } + + public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) + { + var val = value as MacImageData; + if (val == null) + return 0; + + var font = cell.Font ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize); + var str = val.Text; + var attrs = NSDictionary.FromObjectAndKey(font, NSAttributedString.FontAttributeName); + + var size = str.StringSize(attrs).Width + 4 + 16 + MacImageListItemCell.ImagePadding * 2; // for border + image + return (float)size; + + } + + public ImageInterpolation ImageInterpolation + { + get { return Control.ImageInterpolation.ToEto(); } + set { Control.ImageInterpolation = value.ToNS(); } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Cells/ImageViewCellHandler.cs b/Source/Eto.Mac/Forms/Cells/ImageViewCellHandler.cs new file mode 100644 index 0000000000..5d14cd4c2f --- /dev/null +++ b/Source/Eto.Mac/Forms/Cells/ImageViewCellHandler.cs @@ -0,0 +1,159 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Cells +{ + public class ImageViewCellHandler : CellHandler, ImageViewCell.IHandler + { + public class EtoCell : NSImageCell, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public EtoCell() + { + } + + public EtoCell(IntPtr handle) : base(handle) + { + } + + public Color BackgroundColor { get; set; } + + public bool DrawsBackground { get; set; } + + public NSImageInterpolation ImageInterpolation { get; set; } + + [Export("copyWithZone:")] + NSObject CopyWithZone(IntPtr zone) + { + var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr( + SuperHandle, + MacCommon.CopyWithZoneHandle, + zone + ); + return new EtoCell(ptr) { Handler = Handler }; + } + + public override void DrawInteriorWithFrame(CGRect cellFrame, NSView inView) + { + var nscontext = NSGraphicsContext.CurrentContext; + + if (DrawsBackground) + { + var context = nscontext.GraphicsPort; + context.SetFillColor(BackgroundColor.ToCGColor()); + context.FillRect(cellFrame); + } + + nscontext.ImageInterpolation = ImageInterpolation; + + base.DrawInteriorWithFrame(cellFrame, inView); + } + } + + public override bool Editable + { + get { return base.Editable; } + set { Control.Editable = value; } + } + + public ImageViewCellHandler() + { + Control = new EtoCell { Handler = this, Enabled = true }; + } + + public override void SetBackgroundColor(NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.BackgroundColor = color; + c.DrawsBackground = color != Colors.Transparent; + } + + public override Color GetBackgroundColor(NSCell cell) + { + var c = (EtoCell)cell; + return c.BackgroundColor; + } + + public override void SetForegroundColor(NSCell cell, Color color) + { + } + + public override Color GetForegroundColor(NSCell cell) + { + return Colors.Transparent; + } + + public override NSObject GetObjectValue(object dataItem) + { + if (Widget.Binding != null) + { + var img = Widget.Binding.GetValue(dataItem) as Image; + if (img != null) + { + var imgHandler = ((IImageSource)img.Handler); + return imgHandler.GetImage(); + } + } + return new NSImage(); + } + + public override void SetObjectValue(object dataItem, NSObject value) + { + } + + public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) + { + var img = value as Image; + if (img != null) + { + return (float)(cellSize.Height / (float)img.Size.Height * (float)img.Size.Width); + } + return 16; + } + + public ImageInterpolation ImageInterpolation + { + get { return Control.ImageInterpolation.ToEto(); } + set { Control.ImageInterpolation = value.ToNS(); } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Cells/TextBoxCellHandler.cs b/Source/Eto.Mac/Forms/Cells/TextBoxCellHandler.cs new file mode 100644 index 0000000000..cd80aa9bc4 --- /dev/null +++ b/Source/Eto.Mac/Forms/Cells/TextBoxCellHandler.cs @@ -0,0 +1,130 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Cells +{ + public class TextBoxCellHandler : CellHandler, TextBoxCell.IHandler + { + public class EtoCell : NSTextFieldCell, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public EtoCell () + { + } + + public EtoCell (IntPtr handle) : base(handle) + { + } + + [Export("copyWithZone:")] + NSObject CopyWithZone (IntPtr zone) + { + var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr (SuperHandle, MacCommon.CopyWithZoneHandle, zone); + return new EtoCell (ptr) { Handler = Handler }; + } + } + + public TextBoxCellHandler () + { + Control = new EtoCell { + Handler = this, + UsesSingleLineMode = true, + Wraps = false, + Scrollable = true + }; + } + + public override void SetBackgroundColor (NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.BackgroundColor = color.ToNSUI (); + c.DrawsBackground = color != Colors.Transparent; + } + + public override Color GetBackgroundColor (NSCell cell) + { + var c = (EtoCell)cell; + return c.BackgroundColor.ToEto (); + } + + public override void SetForegroundColor (NSCell cell, Color color) + { + var c = (EtoCell)cell; + c.TextColor = color.ToNSUI (); + } + + public override Color GetForegroundColor (NSCell cell) + { + var c = (EtoCell)cell; + return c.TextColor.ToEto (); + } + + public override NSObject GetObjectValue (object dataItem) + { + if (Widget.Binding != null) + { + var val = Widget.Binding.GetValue(dataItem); + return val != null ? new NSString(Convert.ToString(val)) : null; + } + return null; + } + + public override void SetObjectValue (object dataItem, NSObject value) + { + if (Widget.Binding != null) { + var str = value as NSString; + if (str != null) + Widget.Binding.SetValue (dataItem, str.ToString()); + else + Widget.Binding.SetValue (dataItem, null); + } + } + + public override nfloat GetPreferredSize (object value, CGSize cellSize, NSCell cell) + { + var font = cell.Font ?? NSFont.BoldSystemFontOfSize (NSFont.SystemFontSize); + var str = new NSString (Convert.ToString (value)); + var attrs = NSDictionary.FromObjectAndKey (font, NSAttributedString.FontAttributeName); + return (float)str.StringSize (attrs).Width + 8; // for border + + } + } +} + diff --git a/Source/Eto.Mac/Forms/ClipboardHandler.cs b/Source/Eto.Mac/Forms/ClipboardHandler.cs new file mode 100644 index 0000000000..52c01b0125 --- /dev/null +++ b/Source/Eto.Mac/Forms/ClipboardHandler.cs @@ -0,0 +1,98 @@ +using System; +using Eto.Forms; +using System.IO; +using Eto.Mac.Drawing; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + public class ClipboardHandler : WidgetHandler, Clipboard.IHandler + { + public ClipboardHandler () + { + Control = NSPasteboard.GeneralPasteboard; + } + + public void SetData (byte[] value, string type) + { + Control.SetDataForType (NSData.FromArray (value), type); + } + + public string Html + { + set { Control.SetStringForType (value, NSPasteboard.NSHtmlType); } + get { return Control.GetStringForType (NSPasteboard.NSHtmlType); } + } + + public void SetString (string value, string type) + { + Control.SetStringForType (value, type); + } + + public string Text + { + set { Control.SetStringForType (value, NSPasteboard.NSStringType); } + get { return Control.GetStringForType (NSPasteboard.NSStringType); } + } + + public Image Image + { + set { + var handler = value.Handler as BitmapHandler; + if (handler != null) { + var data = handler.Control.AsTiff (); + Control.SetDataForType (data, NSPasteboard.NSTiffType); + } + } + get { + var image = new NSImage(Control); + if (image.Handle == IntPtr.Zero) return null; + return new Bitmap(new BitmapHandler(image)); + } + } + + public unsafe byte[] GetData (string type) + { + var availableType = Control.GetAvailableTypeFromArray(new string[] { type }); + + if (availableType != null) + { + var data = Control.GetDataForType(availableType); + var bytes = new byte[data.Length]; + var stream = new UnmanagedMemoryStream((byte*)data.Bytes, (long)data.Length); + stream.Read(bytes, 0, (int)data.Length); + return bytes; + } + return null; + } + + public string GetString (string type) + { + return Control.GetStringForType (type); + } + + public string[] Types { + get { return Control.Types; } + } + + public void Clear () + { + Control.ClearContents (); + } + + } +} + diff --git a/Source/Eto.Mac/Forms/ColorDialogHandler.cs b/Source/Eto.Mac/Forms/ColorDialogHandler.cs new file mode 100644 index 0000000000..16eb8be51d --- /dev/null +++ b/Source/Eto.Mac/Forms/ColorDialogHandler.cs @@ -0,0 +1,117 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + interface IColorDialogHandler + { + Color Color { get; set; } + ColorDialog Widget { get; } + NSColorPanel Control { get; } + ColorDialog.ICallback Callback { get; } + } + + class ColorHandler : NSWindowDelegate + { + public static ColorHandler Instance { get; set; } + WeakReference handler; + public IColorDialogHandler Handler { get { return (IColorDialogHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [Export("changeColor:")] + public void ChangeColor(NSColorPanel panel) + { + Handler.Color = panel.Color.UsingColorSpace (NSColorSpace.DeviceRGB).ToEto (); + Handler.Callback.OnColorChanged(Handler.Widget, EventArgs.Empty); + } + + public override void WillClose (NSNotification notification) + { + Handler.Control.SetTarget (null); + Handler.Control.SetAction (null); + ColorHandler.Instance = null; + } + + [Export("modalClosed:")] + public void ModalClosed(NSNotification notification) + { + NSColorPanel.SharedColorPanel.PerformClose (this); + NSNotificationCenter.DefaultCenter.RemoveObserver (this); + } + } + + public class ColorDialogHandler : MacObject, ColorDialog.IHandler, IColorDialogHandler + { + public ColorDialogHandler() + { + Control = NSColorPanel.SharedColorPanel; + this.Color = Colors.White; + } + + public Color Color { get; set; } + + #region IDialog implementation + + public DialogResult ShowDialog (Window parent) + { + //Control = new NSColorPanel(); + NSWindow parentWindow; + //Console.WriteLine ("Parent: {0}. {1}, {2}", parent, parent.ControlObject, NSApplication.SharedApplication.ModalWindow); + if (parent != null) { + parentWindow = parent.ParentWindow.ControlObject as NSWindow ?? NSApplication.SharedApplication.KeyWindow; + if (parentWindow != null) + Control.ParentWindow = parentWindow; + } + else parentWindow = NSApplication.SharedApplication.KeyWindow; + + ColorHandler.Instance = new ColorHandler{ Handler = this }; + Control.Delegate = ColorHandler.Instance; + Control.SetTarget (null); + Control.SetAction (null); + Control.Color = Color.ToNSUI (); + + Control.SetTarget (ColorHandler.Instance); + Control.SetAction (new Selector("changeColor:")); + + //Control.Continuous = false; + bool isModal = false; + if (parentWindow != null) { + if (parentWindow == NSApplication.SharedApplication.ModalWindow) + { + //Control.WorksWhenModal = true; + //Control.ParentWindow = parentWindow; + NSNotificationCenter.DefaultCenter.AddObserver(ColorHandler.Instance, new Selector("modalClosed:"), new NSString("NSWindowWillCloseNotification"), parentWindow); + isModal = true; + } + } + + + // work around for modal dialogs wanting to show the color panel.. only works when the panel is key + + //if (isModal) Control.MakeKeyAndOrderFront (parentWindow); + //else Control.OrderFront (parentWindow); + NSApplication.SharedApplication.OrderFrontColorPanel (parentWindow); + if (isModal) Control.MakeKeyWindow(); + //Control.OrderFront (parentWindow); + + + return DialogResult.None; // signal that we are returning right away! + } + + #endregion + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/ButtonHandler.cs b/Source/Eto.Mac/Forms/Controls/ButtonHandler.cs new file mode 100644 index 0000000000..33dd791606 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/ButtonHandler.cs @@ -0,0 +1,254 @@ +using System; +using SD = System.Drawing; +using Eto.Drawing; +using Eto.Forms; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + /// + /// Button handler. + /// + /// (c) 2012-2013 by Curtis Wensley + /// See LICENSE for full terms + public class ButtonHandler : MacButton, Button.IHandler + { + Image image; + ButtonImagePosition imagePosition; + static readonly Size originalSize; + + public static int MinimumWidth = 80; + + public class EtoButtonCell : NSButtonCell + { + public Color? Color { get; set; } + + public override void DrawBezelWithFrame(CGRect frame, NSView controlView) + { + if (Color != null) + { + MacEventView.Colourize(controlView, Color.Value, delegate + { + base.DrawBezelWithFrame(frame, controlView); + }); + } + else + base.DrawBezelWithFrame(frame, controlView); + } + } + + class EtoButton : NSButton, IMacControl + { + bool setBezel = true; + public WeakReference WeakHandler { get; set; } + + public ButtonHandler Handler + { + get { return (ButtonHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public override void SizeToFit() + { + setBezel = false; + base.SizeToFit(); + + if (Handler.AutoSize) + { + var size = Frame.Size; + size.Width = (nfloat)Math.Max(size.Width, MinimumWidth); + SetFrameSize(size); + } + setBezel = true; + } + + public override void SetFrameSize(CGSize newSize) + { + base.SetFrameSize(newSize); + if (setBezel) + Handler.SetBezel(); + } + } + + static ButtonHandler() + { + // store the normal size for a rounded button, so we can determine what style to give it based on actual size + var b = new NSButton { BezelStyle = NSBezelStyle.Rounded }; + b.SizeToFit(); + originalSize = b.Frame.Size.ToEtoSize(); + } + + public ButtonHandler() + { + Control = new EtoButton + { + Handler = this, + Cell = new EtoButtonCell (), + Title = string.Empty, + BezelStyle = NSBezelStyle.Rounded, + ImagePosition = NSCellImagePosition.ImageLeft + }; + Control.SetButtonType(NSButtonType.MomentaryPushIn); + Control.Activated += HandleActivated; + } + + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + SetBezel(); + } + + static void HandleActivated(object sender, EventArgs e) + { + var handler = GetHandler(sender) as ButtonHandler; + if (handler != null) + { + handler.Callback.OnClick(handler.Widget, EventArgs.Empty); + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + default: + base.AttachEvent(id); + break; + } + } + + public override Color BackgroundColor + { + get + { + var cell = (EtoButtonCell)Control.Cell; + return cell.Color ?? Colors.Transparent; + } + set + { + var cell = (EtoButtonCell)Control.Cell; + cell.Color = value.A > 0 ? (Color?)value : null; + Control.SetNeedsDisplay(); + } + } + + public Image Image + { + get { return image; } + set + { + var oldSize = GetPreferredSize(Size.MaxValue); + image = value; + Control.Image = image.ToNS(); + SetBezel(); + LayoutIfNeeded(oldSize); + } + } + + public override Size Size + { + get { return base.Size; } + set + { + base.Size = value; + SetBezel(); + } + } + + /// + /// Gets the bezel style of the button based on its size and image position + /// + NSBezelStyle GetBezelStyle() + { + var size = Control.Frame.Size.ToEtoSize(); + if (size.Width == 0 || size.Height == 0) + return Control.BezelStyle; + if (size.Height < 22 || size.Width < 22) + return NSBezelStyle.SmallSquare; + if (size.Height > originalSize.Height) + return NSBezelStyle.RegularSquare; + if (Image == null) + return NSBezelStyle.Rounded; + if (image.Size.Height > 18) + return NSBezelStyle.RegularSquare; + switch (Control.ImagePosition) + { + case NSCellImagePosition.ImageAbove: + case NSCellImagePosition.ImageBelow: + if (!string.IsNullOrEmpty(Text)) + return NSBezelStyle.RegularSquare; + break; + } + return NSBezelStyle.Rounded; + } + + void SetBezel() + { + Control.BezelStyle = GetBezelStyle(); + } + + public override string Text + { + get { return base.Text; } + set + { + base.Text = value; + SetImagePosition(); + } + } + + void SetImagePosition() + { + var position = imagePosition.ToNS(); + if ((position == NSCellImagePosition.ImageAbove || position == NSCellImagePosition.ImageBelow) && string.IsNullOrEmpty(Text)) + position = NSCellImagePosition.ImageOnly; + Control.ImagePosition = position; + SetBezel(); + } + + public ButtonImagePosition ImagePosition + { + get { return imagePosition; } + set + { + if (imagePosition != value) + { + var oldSize = GetPreferredSize(Size.MaxValue); + imagePosition = value; + SetImagePosition(); + LayoutIfNeeded(oldSize); + } + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/CalendarHandler.cs b/Source/Eto.Mac/Forms/Controls/CalendarHandler.cs new file mode 100644 index 0000000000..ec7a502acd --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/CalendarHandler.cs @@ -0,0 +1,165 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class CalendarHandler : MacControl, Calendar.IHandler + { + public class EtoDatePicker : NSDatePicker, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public CalendarHandler Handler + { + get { return (CalendarHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public CalendarHandler() + { + Control = new EtoDatePicker + { + Handler = this, + TimeZone = NSTimeZone.LocalTimeZone, + Calendar = NSCalendar.CurrentCalendar, + Bezeled = false, + DateValue = DateTime.Today, + DatePickerStyle = NSDatePickerStyle.ClockAndCalendar, + DatePickerElements = NSDatePickerElementFlags.YearMonthDateDay + }; + Control.Activated += HandleActivated; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Calendar.SelectedDateChangedEvent: + case Calendar.SelectedRangeChangedEvent: + // handled by delegate + break; + default: + base.AttachEvent(id); + break; + } + } + + Range lastRange; + + void HandleActivated(object sender, EventArgs e) + { + var range = SelectedRange; + if (range != lastRange) + { + var lastDate = lastRange.Start; + lastRange = range; + if (SelectedDate != lastDate) + Callback.OnSelectedDateChanged(Widget, EventArgs.Empty); + + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + } + + public DateTime MinDate + { + get { return Control.MinDate.ToEto() ?? DateTime.MinValue; } + set + { + var range = SelectedRange; + var date = SelectedDate; + Control.MinDate = value.ToNS(); + if (date != SelectedDate) + Callback.OnSelectedDateChanged(Widget, EventArgs.Empty); + if (range != SelectedRange) + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + } + + public DateTime MaxDate + { + get { return Control.MaxDate.ToEto() ?? DateTime.MaxValue; } + set + { + var range = SelectedRange; + var date = SelectedDate; + Control.MaxDate = value.ToNS(); + if (date != SelectedDate) + Callback.OnSelectedDateChanged(Widget, EventArgs.Empty); + if (range != SelectedRange) + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + } + + public DateTime SelectedDate + { + get + { + return Control.DateValue.ToEto() ?? DateTime.Today; + } + set + { + if (value != SelectedDate) + { + Control.DateValue = value.ToNS(); + Callback.OnSelectedDateChanged(Widget, EventArgs.Empty); + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + } + } + + public Range SelectedRange + { + get + { + var val = Control.DateValue.ToEto(); + if (val != null) + { + var date = val.Value; + if (Mode == CalendarMode.Single) + return new Range(date); + return new Range(date, date + TimeSpan.FromSeconds(Control.TimeInterval)); + } + return new Range(DateTime.Today); + } + set + { + var old = SelectedRange; + if (value != old) + { + // don't validate otherwise the new value gets overridden when null + Control.DateValue = value.Start.ToNS(); + Control.TimeInterval = value.Interval().TotalSeconds; + if (old.Start != value.Start) + Callback.OnSelectedDateChanged(Widget, EventArgs.Empty); + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + } + } + + public CalendarMode Mode + { + get { return Control.DatePickerMode.ToEto(); } + set + { + var triggerChange = Control.TimeInterval > 0; + Control.DatePickerMode = value.ToNS(); + if (triggerChange || Control.TimeInterval > 0) + Callback.OnSelectedRangeChanged(Widget, EventArgs.Empty); + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Mac/Forms/Controls/CheckBoxHandler.cs b/Source/Eto.Mac/Forms/Controls/CheckBoxHandler.cs new file mode 100644 index 0000000000..24b8c6e4b4 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/CheckBoxHandler.cs @@ -0,0 +1,94 @@ +using System; +using Eto.Forms; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class CheckBoxHandler : MacButton, CheckBox.IHandler + { + public class EtoCheckBoxButton : NSButton, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public CheckBoxHandler() + { + Control = new EtoCheckBoxButton { Handler = this, Title = string.Empty }; + Control.SetButtonType(NSButtonType.Switch); + Control.Activated += HandleActivated; + } + + static void HandleActivated(object sender, EventArgs e) + { + var handler = GetHandler(sender) as CheckBoxHandler; + handler.Callback.OnCheckedChanged(handler.Widget, EventArgs.Empty); + } + + public bool? Checked + { + get + { + switch (Control.State) + { + case NSCellStateValue.On: + return true; + case NSCellStateValue.Off: + return false; + default: + return null; + } + } + set + { + if (value == null) + Control.State = ThreeState ? NSCellStateValue.Mixed : NSCellStateValue.Off; + else if (value.Value) + Control.State = NSCellStateValue.On; + else + Control.State = NSCellStateValue.Off; + } + } + + public bool ThreeState + { + get { return Control.AllowsMixedState; } + set { Control.AllowsMixedState = value; } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/ColorPickerHandler.cs b/Source/Eto.Mac/Forms/Controls/ColorPickerHandler.cs new file mode 100644 index 0000000000..4edddc8079 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/ColorPickerHandler.cs @@ -0,0 +1,66 @@ +using System; +using sd = System.Drawing; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using System.Text.RegularExpressions; +using System.Linq; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class ColorPickerHandler : MacControl, ColorPicker.IHandler + { + public class EtoColorWell : NSColorWell, IMacControl + { + public WeakReference WeakHandler { get; set; } + } + + public ColorPickerHandler() + { + Control = new EtoColorWell { WeakHandler = new WeakReference(this) }; + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + return new SizeF(44, 23); + } + + static NSString keyColor = new NSString("color"); + + public override void AttachEvent(string id) + { + switch (id) + { + case ColorPicker.ColorChangedEvent: + AddControlObserver(keyColor, args => + { + var handler = (ColorPickerHandler)args.Handler; + handler.Callback.OnColorChanged(handler.Widget, EventArgs.Empty); + }); + break; + default: + base.AttachEvent(id); + break; + } + } + + public Color Color + { + get { return Control.Color.ToEto(); } + set { Control.Color = value.ToNSUI(); } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/ComboBoxHandler.cs b/Source/Eto.Mac/Forms/Controls/ComboBoxHandler.cs new file mode 100644 index 0000000000..335e42d719 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/ComboBoxHandler.cs @@ -0,0 +1,281 @@ +using System; +using SD = System.Drawing; +using Eto.Forms; +using System.Linq; +using System.Collections.Generic; +using System.Collections; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class ComboBoxHandler : MacControl, ComboBox.IHandler + { + int lastSelected = -1; + CollectionHandler collection; + + public class EtoComboBox : NSComboBox, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public ComboBoxHandler() + { + Control = new EtoComboBox + { + Handler = this, + StringValue = string.Empty, + Editable = true, + VisibleItems = 20 + }; + AddObserver(NSComboBox.SelectionIsChangingNotification, SelectionDidChange); + Control.Changed += HandleChanged; + } + + static void HandleChanged(object sender, EventArgs e) + { + var handler = GetHandler(sender) as ComboBoxHandler; + if (handler != null) + { + handler.Callback.OnTextChanged(handler.Widget, EventArgs.Empty); + Application.Instance.AsyncInvoke(() => + { + if (handler.SelectedIndex != handler.lastSelected) + { + handler.Callback.OnSelectedIndexChanged(handler.Widget, EventArgs.Empty); + handler.lastSelected = handler.SelectedIndex; + } + }); + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case ComboBox.TextChangedEvent: + // handled automatically + break; + default: + base.AttachEvent(id); + break; + } + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + var size = base.GetNaturalSize(availableSize); + return new SizeF(Math.Max(size.Width, 100), size.Height); + } + + static void SelectionDidChange(ObserverActionEventArgs e) + { + var handler = e.Handler as ComboBoxHandler; + if (handler != null) + { + Application.Instance.AsyncInvoke(() => + { + handler.Callback.OnSelectedIndexChanged(handler.Widget, EventArgs.Empty); + Application.Instance.AsyncInvoke(() => handler.Callback.OnTextChanged(handler.Widget, EventArgs.Empty)); + }); + } + } + + class CollectionHandler : EnumerableChangedHandler + { + public ComboBoxHandler Handler { get; set; } + + public override void AddRange(IEnumerable items) + { + var oldIndex = Handler.Control.SelectedIndex; + var binding = Handler.Widget.TextBinding; + foreach (var item in items.Select(r => binding.GetValue(r))) + { + Handler.Control.Add(NSObject.FromObject(item)); + } + Handler.LayoutIfNeeded(); + } + + public override void AddItem(object item) + { + var binding = Handler.Widget.TextBinding; + Handler.Control.Add(NSObject.FromObject(binding.GetValue(item))); + Handler.LayoutIfNeeded(); + } + + public override void InsertItem(int index, object item) + { + var binding = Handler.Widget.TextBinding; + Handler.Control.Insert(NSObject.FromObject(binding.GetValue(item)), index); + Handler.LayoutIfNeeded(); + } + + public override void RemoveItem(int index) + { + var selected = Handler.SelectedIndex; + Handler.Control.RemoveAt(index); + if (selected == index) + { + Handler.Control.StringValue = string.Empty; + Handler.SelectedIndex = -1; + // when removing the last item, we don't get a change event here + if (index == Count) + Handler.Callback.OnSelectedIndexChanged(Handler.Widget, EventArgs.Empty); + } + Handler.LayoutIfNeeded(); + } + + public override void RemoveAllItems() + { + var change = Handler.SelectedIndex != -1; + Handler.Control.RemoveAll(); + if (change) + { + Handler.Control.StringValue = string.Empty; + Handler.SelectedIndex = -1; + } + Handler.LayoutIfNeeded(); + } + } + + public IEnumerable DataStore + { + get { return collection == null ? null : collection.Collection; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler { Handler = this }; + collection.Register(value); + } + } + + public int SelectedIndex + { + get { return (int)Control.SelectedIndex; } + set + { + var selectedIndex = SelectedIndex; + var lastText = Text; + if (value == -1) + { + if (selectedIndex != -1) + { + Control.DeselectItem(Control.SelectedIndex); + Control.StringValue = string.Empty; + } + } + else + Control.SelectItem(value); + if (value != selectedIndex) + { + Callback.OnSelectedIndexChanged(Widget, EventArgs.Empty); + } + if (lastText != Text) + { + Callback.OnTextChanged(Widget, EventArgs.Empty); + } + } + } + + public override Color BackgroundColor + { + get { return ((NSComboBoxCell)Control.Cell).BackgroundColor.ToEto(); } + set + { + if (value != BackgroundColor) + { + ((NSComboBoxCell)Control.Cell).BackgroundColor = value.ToNSUI(); + Control.SetNeedsDisplay(); + } + } + } + + public Color TextColor + { + get { return ((NSComboBoxCell)Control.Cell).TextColor.ToEto(); } + set + { + if (value != TextColor) + { + ((NSComboBoxCell)Control.Cell).TextColor = value.ToNSUI(); + Control.SetNeedsDisplay(); + } + } + } + + public string Text + { + get { return Control.StringValue; } + set + { + if (Text != value) + { + Control.StringValue = value ?? string.Empty; + if (collection != null) + { + var binding = Widget.TextBinding; + var item = collection.Collection.FirstOrDefault(r => binding.GetValue(r) == value); + var index = item != null ? collection.IndexOf(item) : -1; + + SelectedIndex = index; + } + + } + } + } + + public bool ReadOnly + { + get { return !Control.Editable; } + set + { + Control.Editable = !value; + if (Control.Window != null) + Control.Window.MakeFirstResponder(null); // allows editing if currently focussed, so remove focus + } + } + + public bool AutoComplete + { + get { return Control.Completes; } + set { Control.Completes = value; } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/DateTimePickerHandler.cs b/Source/Eto.Mac/Forms/Controls/DateTimePickerHandler.cs new file mode 100644 index 0000000000..5144d6ebac --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/DateTimePickerHandler.cs @@ -0,0 +1,210 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class DateTimePickerHandler : MacControl, DateTimePicker.IHandler + { + DateTime? curValue; + DateTimePickerMode mode; + + public class EtoDatePicker : NSDatePicker, IMacControl + { + public override void DrawRect(CGRect dirtyRect) + { + if (Handler.curValue != null) + base.DrawRect(dirtyRect); + else + { + // paint with no elements visible + var old = DatePickerElements; + DatePickerElements = 0; + base.DrawRect(dirtyRect); + DatePickerElements = old; + } + } + + public WeakReference WeakHandler { get; set; } + + public DateTimePickerHandler Handler + { + get { return (DateTimePickerHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public DateTimePickerHandler() + { + Control = new EtoDatePicker + { + Handler = this, + TimeZone = NSTimeZone.LocalTimeZone, + Calendar = NSCalendar.CurrentCalendar, + DateValue = DateTime.Now.ToNS() + }; + #pragma warning disable 612,618 + this.Mode = DateTimePicker.DefaultMode; + #pragma warning restore 612,618 + // apple+backspace clears the value + Control.ValidateProposedDateValue += HandleValidateProposedDateValue; + } + + protected override void Initialize() + { + base.Initialize(); + Widget.KeyDown += HandleKeyDown; + // when clicking, set the value if it is null + Widget.MouseDown += HandleMouseDown; + } + + static void HandleKeyDown(object sender, KeyEventArgs e) + { + var handler = (DateTimePickerHandler)((Control)sender).Handler; + if (!e.Handled) + { + if (e.KeyData == (Keys.Application | Keys.Backspace)) + { + handler.curValue = null; + handler.Callback.OnValueChanged(handler.Widget, EventArgs.Empty); + handler.Control.NeedsDisplay = true; + } + } + } + + static void HandleMouseDown(object sender, MouseEventArgs e) + { + var handler = (DateTimePickerHandler)((Control)sender).Handler; + if (e.Buttons == MouseButtons.Primary) + { + if (handler.curValue == null) + { + handler.curValue = handler.Control.DateValue.ToEto(); + handler.Callback.OnValueChanged(handler.Widget, EventArgs.Empty); + handler.Control.NeedsDisplay = true; + } + } + } + + static void HandleValidateProposedDateValue(object sender, NSDatePickerValidatorEventArgs e) + { + var datePickerCell = (NSDatePickerCell)sender; + var handler = GetHandler(datePickerCell.ControlView) as DateTimePickerHandler; + var date = e.ProposedDateValue.ToEto(); + if (date != handler.Control.DateValue.ToEto()) + { + handler.curValue = date; + handler.Callback.OnValueChanged(handler.Widget, EventArgs.Empty); + } + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + return SizeF.Max(new Size(mode == DateTimePickerMode.DateTime ? 180 : 120, 10), base.GetNaturalSize(availableSize)); + } + + public DateTimePickerMode Mode + { + get { return mode; } + set + { + mode = value; + switch (mode) + { + case DateTimePickerMode.Date: + Control.DatePickerElements = NSDatePickerElementFlags.YearMonthDateDay; + break; + case DateTimePickerMode.Time: + Control.DatePickerElements = NSDatePickerElementFlags.HourMinuteSecond; + break; + case DateTimePickerMode.DateTime: + Control.DatePickerElements = NSDatePickerElementFlags.YearMonthDateDay | NSDatePickerElementFlags.HourMinuteSecond; + break; + default: + throw new NotSupportedException(); + } + } + } + + public DateTime MinDate + { + get { return Control.MinDate.ToEto() ?? DateTime.MinValue; } + set { Control.MinDate = value.ToNS(); } + } + + public DateTime MaxDate + { + get { return Control.MaxDate.ToEto() ?? DateTime.MaxValue; } + set { Control.MaxDate = value.ToNS(); } + } + + public DateTime? Value + { + get + { + return curValue; + } + set + { + if (value != curValue) + { + curValue = value; + // don't validate otherwise the new value gets overridden when null + Control.ValidateProposedDateValue -= HandleValidateProposedDateValue; + Control.DateValue = (value ?? DateTime.Now).ToNS(); + Control.ValidateProposedDateValue += HandleValidateProposedDateValue; + Callback.OnValueChanged(Widget, EventArgs.Empty); + } + } + } + + public Color TextColor + { + get { return Control.TextColor.ToEto(); } + set { Control.TextColor = value.ToNSUI(); } + } + + protected override void SetBackgroundColor(Color? color) + { + if (color != null) + { + Control.Cell.BackgroundColor = color.Value.ToNSUI(); + Control.Cell.DrawsBackground = true; + } + else + { + Control.Cell.BackgroundColor = NSColor.ControlBackground; + Control.Cell.DrawsBackground = true; + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/DrawableHandler.cs b/Source/Eto.Mac/Forms/Controls/DrawableHandler.cs new file mode 100644 index 0000000000..70dec7efae --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/DrawableHandler.cs @@ -0,0 +1,149 @@ +using sd = System.Drawing; +using Eto.Drawing; +using Eto.Forms; +using Eto.Mac.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class DrawableHandler : MacPanel, Drawable.IHandler + { + Brush backgroundBrush; + Color backgroundColor; + + public bool SupportsCreateGraphics { get { return true; } } + + public override NSView ContainerControl { get { return Control; } } + + public class EtoDrawableView : MacEventView + { + Drawable Drawable + { + get { return Widget as Drawable; } + } + + public override void DrawRect(CGRect dirtyRect) + { + var drawable = Drawable; + if (drawable == null) + return; + if (!IsFlipped) + dirtyRect.Y = Frame.Height - dirtyRect.Y - dirtyRect.Height; + if (dirtyRect.X % 1.0f > 0f) + dirtyRect.Width += 1; + if (dirtyRect.Y % 1.0f > 0f) + dirtyRect.Height += 1; + ApplicationHandler.QueueResizing = true; + drawable.Update(Rectangle.Ceiling(dirtyRect.ToEto())); + ApplicationHandler.QueueResizing = false; + } + + public bool CanFocus { get; set; } + + public override bool AcceptsFirstResponder() + { + return CanFocus; + } + + public override bool AcceptsFirstMouse(NSEvent theEvent) + { + return CanFocus; + } + } + + public Graphics CreateGraphics() + { + return new Graphics(new GraphicsHandler(Control)); + } + + public override bool Enabled { get; set; } + + public override Color BackgroundColor + { + get { return backgroundColor; } + set + { + if (backgroundColor != value) + { + backgroundColor = value; + backgroundBrush = backgroundColor.A > 0 ? new SolidBrush(backgroundColor) : null; + Invalidate(); + } + } + } + + public void Create() + { + Enabled = true; + Control = new EtoDrawableView { Handler = this }; + } + + public void Create(bool largeCanvas) + { + Create(); + } + + public bool CanFocus + { + get { return Control.CanFocus; } + set { Control.CanFocus = value; } + } + + public override void Invalidate() + { + if (!NeedsQueue(Invalidate)) + base.Invalidate(); + } + + public override void Invalidate(Rectangle rect) + { + if (!NeedsQueue(() => Invalidate(rect))) + base.Invalidate(rect); + } + + public void Update(Rectangle rect) + { + var context = NSGraphicsContext.CurrentContext; + if (context != null) + { + var handler = new GraphicsHandler(Control, context, (float)Control.Frame.Height, Control.IsFlipped); + using (var graphics = new Graphics(handler)) + { + if (backgroundBrush != null) + graphics.FillRectangle(backgroundBrush, rect); + + var widget = Widget; + if (widget != null) + Callback.OnPaint(widget, new PaintEventArgs(graphics, rect)); + } + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/DropDownHandler.cs b/Source/Eto.Mac/Forms/Controls/DropDownHandler.cs new file mode 100644 index 0000000000..d08be2b99e --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/DropDownHandler.cs @@ -0,0 +1,231 @@ +using System; +using SD = System.Drawing; +using Eto.Forms; +using System.Linq; +using System.Collections.Generic; +using System.Collections; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class DropDownHandler : MacControl, DropDown.IHandler + { + CollectionHandler collection; + + public class EtoPopUpButtonCell : NSPopUpButtonCell + { + NSDictionary textAttributes; + Color? textColor; + + public Color? Color { get; set; } + + public Color? TextColor + { + get { return textColor; } + set + { + textColor = value; + textAttributes = textColor != null ? NSDictionary.FromObjectAndKey(textColor.Value.ToNSUI(), NSAttributedString.ForegroundColorAttributeName) : null; + } + } + + public override void DrawBezelWithFrame(CGRect frame, NSView controlView) + { + if (Color != null) + { + MacEventView.Colourize(controlView, Color.Value, delegate + { + base.DrawBezelWithFrame(frame, controlView); + }); + } + else + base.DrawBezelWithFrame(frame, controlView); + } + + public override CGRect DrawTitle(NSAttributedString title, CGRect frame, NSView controlView) + { + if (textAttributes != null) + { + var str = new NSMutableAttributedString(title); + str.AddAttributes(textAttributes, new NSRange(0, title.Length)); + title = str; + } + return base.DrawTitle(title, frame, controlView); + } + } + + public class EtoPopUpButton : NSPopUpButton, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public DropDownHandler() + { + Control = new EtoPopUpButton { Handler = this, Cell = new EtoPopUpButtonCell() }; + Control.Activated += HandleActivated; + } + + static void HandleActivated(object sender, EventArgs e) + { + var handler = GetHandler(sender) as DropDownHandler; + handler.Callback.OnSelectedIndexChanged(handler.Widget, EventArgs.Empty); + } + + class CollectionHandler : EnumerableChangedHandler + { + public DropDownHandler Handler { get; set; } + + public override int IndexOf(object item) + { + var binding = Handler.Widget.TextBinding; + return (int)Handler.Control.Menu.IndexOf(binding.GetValue(item)); + } + + public override void AddRange(IEnumerable items) + { + var oldIndex = Handler.Control.IndexOfSelectedItem; + var binding = Handler.Widget.TextBinding; + foreach (var item in items.Select(r => binding.GetValue(r))) + { + Handler.Control.Menu.AddItem(new NSMenuItem(item)); + } + if (oldIndex == -1) + Handler.Control.SelectItem(-1); + Handler.LayoutIfNeeded(); + } + + public override void AddItem(object item) + { + var oldIndex = Handler.Control.IndexOfSelectedItem; + var binding = Handler.Widget.TextBinding; + Handler.Control.Menu.AddItem(new NSMenuItem(Convert.ToString(binding.GetValue(item)))); + if (oldIndex == -1) + Handler.Control.SelectItem(-1); + Handler.LayoutIfNeeded(); + } + + public override void InsertItem(int index, object item) + { + var oldIndex = Handler.Control.IndexOfSelectedItem; + var binding = Handler.Widget.TextBinding; + Handler.Control.Menu.InsertItem(new NSMenuItem(Convert.ToString(binding.GetValue(item))), index); + if (oldIndex == -1) + Handler.Control.SelectItem(-1); + Handler.LayoutIfNeeded(); + } + + public override void RemoveItem(int index) + { + var selected = Handler.SelectedIndex; + Handler.Control.RemoveItem(index); + Handler.LayoutIfNeeded(); + if (Handler.Widget.Loaded && selected == index) + { + Handler.Control.SelectItem(-1); + Handler.Callback.OnSelectedIndexChanged(Handler.Widget, EventArgs.Empty); + } + } + + public override void RemoveAllItems() + { + var change = Handler.SelectedIndex != -1; + Handler.Control.RemoveAllItems(); + Handler.LayoutIfNeeded(); + if (Handler.Widget.Loaded && change) + { + Handler.Control.SelectItem(-1); + Handler.Callback.OnSelectedIndexChanged(Handler.Widget, EventArgs.Empty); + } + } + } + + public IEnumerable DataStore + { + get { return collection == null ? null : collection.Collection; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler { Handler = this }; + collection.Register(value); + } + } + + public int SelectedIndex + { + get { return (int)Control.IndexOfSelectedItem; } + set + { + if (value != SelectedIndex) + { + Control.SelectItem(value); + if (Widget.Loaded) + Callback.OnSelectedIndexChanged(Widget, EventArgs.Empty); + } + } + } + + public override Color BackgroundColor + { + get { return ((EtoPopUpButtonCell)Control.Cell).Color ?? Colors.Transparent; } + set + { + if (value != BackgroundColor) + { + ((EtoPopUpButtonCell)Control.Cell).Color = value; + Control.SetNeedsDisplay(); + } + } + } + + public Color TextColor + { + get { return ((EtoPopUpButtonCell)Control.Cell).TextColor ?? NSColor.ControlText.ToEto(); } + set + { + if (value != TextColor) + { + ((EtoPopUpButtonCell)Control.Cell).TextColor = value; + Control.SetNeedsDisplay(); + } + } + } + } +} \ No newline at end of file diff --git a/Source/Eto.Mac/Forms/Controls/GridColumnHandler.cs b/Source/Eto.Mac/Forms/Controls/GridColumnHandler.cs new file mode 100644 index 0000000000..605c16deb0 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/GridColumnHandler.cs @@ -0,0 +1,257 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using Eto.Mac.Forms.Cells; + + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public interface IDataViewHandler + { + bool ShowHeader { get; } + + NSTableView Table { get; } + + object GetItem(int row); + + int RowCount { get; } + + CGRect GetVisibleRect(); + + void OnCellFormatting(GridColumn column, object item, int row, NSCell cell); + } + + public interface IDataColumnHandler + { + void Setup(int column); + + NSObject GetObjectValue(object dataItem); + + void SetObjectValue(object dataItem, NSObject val); + + GridColumn Widget { get; } + + IDataViewHandler DataViewHandler { get; } + + void Resize(bool force = false); + + void Loaded(IDataViewHandler handler, int column); + } + + public class GridColumnHandler : MacObject, GridColumn.IHandler, IDataColumnHandler + { + Cell dataCell; + Font font; + + public IDataViewHandler DataViewHandler { get; private set; } + + public int Column { get; private set; } + + public GridColumnHandler() + { + Control = new NSTableColumn(); + Control.ResizingMask = NSTableColumnResizing.None; + Sortable = false; + HeaderText = string.Empty; + Editable = false; + AutoSize = true; + DataCell = new TextBoxCell(); + } + + public void Loaded(IDataViewHandler handler, int column) + { + Column = column; + DataViewHandler = handler; + } + + public void Resize(bool force = false) + { + var handler = DataViewHandler; + if (AutoSize && handler != null) + { + var width = Control.DataCell.CellSize.Width; + var outlineView = handler.Table as NSOutlineView; + if (handler.ShowHeader) + width = (nfloat)Math.Max(Control.HeaderCell.CellSize.Width, width); + + if (dataCell != null) + { + /* Auto size based on visible cells only */ + var rect = handler.GetVisibleRect(); + var range = handler.Table.RowsInRect(rect); + + var cellSize = Control.DataCell.CellSize; + var dataCellHandler = ((ICellHandler)dataCell.Handler); + for (var i = range.Location; i < range.Location + range.Length; i++) + { + var cellWidth = GetRowWidth(dataCellHandler, (int)i, cellSize) + 4; + if (outlineView != null && Column == 0) + { + cellWidth += (float)((outlineView.LevelForRow((nint)i) + 1) * outlineView.IndentationPerLevel); + } + width = (nfloat)Math.Max(width, cellWidth); + } + } + if (force || width > Control.Width) + Control.Width = width; + } + } + + protected virtual nfloat GetRowWidth(ICellHandler cell, int row, CGSize cellSize) + { + var item = DataViewHandler.GetItem(row); + var val = GetObjectValue(item); + return cell.GetPreferredSize(val, cellSize, row, item); + } + + public string HeaderText + { + get { return Control.HeaderCell.StringValue; } + set { Control.HeaderCell.StringValue = value; } + } + + public bool Resizable + { + get + { + return Control.ResizingMask.HasFlag(NSTableColumnResizing.UserResizingMask); + } + set + { + if (value) + Control.ResizingMask |= NSTableColumnResizing.UserResizingMask; + else + Control.ResizingMask &= ~NSTableColumnResizing.UserResizingMask; + } + } + + public bool AutoSize + { + get; + set; + } + + public bool Sortable { get; set; } + + public bool Editable + { + get + { + return Control.Editable; + } + set + { + Control.Editable = value; + if (dataCell != null) + { + var cellHandler = (ICellHandler)dataCell.Handler; + cellHandler.Editable = value; + } + } + } + + public int Width + { + get { return (int)Control.Width; } + set { Control.Width = value; } + } + + public bool Visible + { + get { return !Control.Hidden; } + set { Control.Hidden = !value; } + } + + public Cell DataCell + { + get { return dataCell; } + set + { + dataCell = value; + if (dataCell != null) + { + var editable = Editable; + var cellHandler = (ICellHandler)dataCell.Handler; + Control.DataCell = cellHandler.Control; + cellHandler.ColumnHandler = this; + cellHandler.Editable = editable; + } + else + Control.DataCell = null; + } + } + + public void Setup(int column) + { + Column = column; + Control.Identifier = new NSString(column.ToString()); + } + + public NSObject GetObjectValue(object dataItem) + { + return ((ICellHandler)dataCell.Handler).GetObjectValue(dataItem); + } + + public void SetObjectValue(object dataItem, NSObject val) + { + ((ICellHandler)dataCell.Handler).SetObjectValue(dataItem, val); + } + + GridColumn IDataColumnHandler.Widget + { + get { return Widget; } + } + + public Font Font + { + get + { + if (font == null) + font = new Font(new FontHandler(Control.DataCell.Font)); + return font; + } + set + { + font = value; + if (font != null) + { + var fontHandler = (FontHandler)font.Handler; + Control.DataCell.Font = fontHandler.Control; + } + else + Control.DataCell.Font = null; + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/GridHandler.cs b/Source/Eto.Mac/Forms/Controls/GridHandler.cs new file mode 100644 index 0000000000..8fa0e9b6a6 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/GridHandler.cs @@ -0,0 +1,463 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using Eto.Mac.Forms.Menu; +using System.Linq; +using Eto.Drawing; +using Eto.Mac.Drawing; +using sd = System.Drawing; +using Eto.Mac.Forms.Cells; + + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using nnint = System.Int32; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +using nnint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +using nnint = System.Int32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public interface IGridHandler + { + Grid Widget { get; } + + NSTableView Table { get; } + + bool AutoSizeColumns(); + } + + class EtoGridScrollView : NSScrollView + { + WeakReference handler; + + public IGridHandler Handler { get { return (IGridHandler)handler.Target; } set { handler = new WeakReference(value); } } + + bool autoSized; + + public override void SetFrameSize(CGSize newSize) + { + base.SetFrameSize(newSize); + + if (!autoSized) + { + autoSized = Handler.AutoSizeColumns(); + } + } + } + + class EtoTableHeaderView : NSTableHeaderView + { + WeakReference handler; + + public IGridHandler Handler { get { return (IGridHandler)handler.Target; } set { handler = new WeakReference(value); } } + + static readonly Selector selConvertPointFromBacking = new Selector("convertPointFromBacking:"); + + #if Mac64 + CGPoint ConvertPointFromBacking(CGPoint point) + { + return base.ConvertNSPointromBacking(point); + } + #endif + + public override void MouseDown(NSEvent theEvent) + { + var point = theEvent.LocationInWindow; + + if (RespondsToSelector(selConvertPointFromBacking)) + point = ConvertPointFromBacking(point); + else + point = ConvertPointFromBase(point); + var col = GetColumn(point); + if (col >= 0) + { + var column = Handler.Widget.Columns[(int)col]; + if (!column.Sortable) + return; + } + base.MouseDown(theEvent); + } + } + + class MacCellFormatArgs : GridCellFormatEventArgs + { + Font font; + + public ICellHandler CellHandler { get { return Column.DataCell.Handler as ICellHandler; } } + + public NSCell Cell { get; private set; } + + public MacCellFormatArgs(GridColumn column, object item, int row, NSCell cell) + : base(column, item, row) + { + this.Cell = cell; + } + + public override Font Font + { + get + { + return font ?? (font = new Font(new FontHandler(Cell.Font))); + } + set + { + font = value; + Cell.Font = font != null ? ((FontHandler)font.Handler).Control : null; + } + } + + public override Color BackgroundColor + { + get { return CellHandler.GetBackgroundColor(Cell); } + set { CellHandler.SetBackgroundColor(Cell, value); } + } + + public override Color ForegroundColor + { + get { return CellHandler.GetForegroundColor(Cell); } + set { CellHandler.SetForegroundColor(Cell, value); } + } + } + + public abstract class GridHandler : MacControl, Grid.IHandler, IDataViewHandler, IGridHandler + where TControl: NSTableView + where TWidget: Grid + where TCallback: Grid.ICallback + { + ColumnCollection columns; + ContextMenu contextMenu; + + protected int SuppressSelectionChanged { get; set; } + + protected bool IsAutoSizingColumns { get; private set; } + + public NSTableView Table + { + get { return Control; } + } + + public NSScrollView ScrollView { get; private set; } + + public override NSView ContainerControl { get { return ScrollView; } } + + protected virtual void PreUpdateColumn(int index) + { + } + + protected virtual void UpdateColumns() + { + } + + public GridColumnHandler GetColumn(NSTableColumn tableColumn) + { + var str = tableColumn.Identifier; + if (!string.IsNullOrEmpty(str)) + { + int col; + if (int.TryParse(str, out col)) + { + return GetColumn(col); + } + } + return null; + } + + public GridColumnHandler GetColumn(int column) + { + return Widget.Columns[column].Handler as GridColumnHandler; + //return Widget.Columns.Select (r => r.Handler as GridColumnHandler).First (r => r.Column == column); + } + + class ColumnCollection : EnumerableChangedHandler + { + public GridHandler Handler { get; set; } + + public override void AddItem(GridColumn item) + { + var colhandler = (GridColumnHandler)item.Handler; + Handler.Control.AddColumn(colhandler.Control); + colhandler.Setup((int)(Handler.Control.ColumnCount - 1)); + + Handler.UpdateColumns(); + } + + public override void InsertItem(int index, GridColumn item) + { + var outline = Handler.Control; + var columns = new List(outline.TableColumns()); + Handler.PreUpdateColumn(index); + for (int i = index; i < columns.Count; i++) + { + outline.RemoveColumn(columns[i]); + } + var colhandler = (GridColumnHandler)item.Handler; + columns.Insert(index, colhandler.Control); + outline.AddColumn(colhandler.Control); + colhandler.Setup(index); + for (int i = index + 1; i < columns.Count; i++) + { + var col = columns[i]; + var colHandler = Handler.GetColumn(i); + colHandler.Setup(i); + outline.AddColumn(col); + } + Handler.UpdateColumns(); + } + + public override void RemoveItem(int index) + { + var outline = Handler.Control; + var columns = new List(outline.TableColumns()); + Handler.PreUpdateColumn(index); + for (int i = index; i < columns.Count; i++) + { + outline.RemoveColumn(columns[i]); + } + columns.RemoveAt(index); + for (int i = index; i < columns.Count; i++) + { + var col = columns[i]; + var colHandler = Handler.GetColumn(i); + colHandler.Setup(i); + outline.AddColumn(col); + } + Handler.UpdateColumns(); + } + + public override void RemoveAllItems() + { + Handler.PreUpdateColumn(0); + foreach (var col in Handler.Control.TableColumns ()) + Handler.Control.RemoveColumn(col); + Handler.UpdateColumns(); + } + } + + protected GridHandler() + { + ScrollView = new EtoGridScrollView + { + Handler = this, + HasVerticalScroller = true, + HasHorizontalScroller = true, + AutohidesScrollers = true, + BorderType = NSBorderType.BezelBorder, + }; + ScrollView.ContentView.PostsBoundsChangedNotifications = true; + this.AddObserver(NSView.BoundsChangedNotification, HandleScrolled, ScrollView.ContentView); + } + + static void HandleScrolled(ObserverActionEventArgs e) + { + var handler = (GridHandler)e.Handler; + handler.AutoSizeColumns(); + } + + public override void AttachEvent(string id) + { + switch (id) + { + default: + base.AttachEvent(id); + break; + } + } + + protected override void Initialize() + { + base.Initialize(); + columns = new ColumnCollection { Handler = this }; + columns.Register(Widget.Columns); + + Control.HeaderView = new EtoTableHeaderView { Handler = this }; + ScrollView.DocumentView = Control; + } + + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + + int i = 0; + IsAutoSizingColumns = true; + foreach (var col in Widget.Columns.Select(r => r.Handler).OfType()) + { + col.Loaded(this, i++); + col.Resize(true); + } + IsAutoSizingColumns = false; + } + + public bool AutoSizeColumns() + { + if (Widget.Loaded) + { + var rect = Table.VisibleRect(); + if (rect.Width > 0 || rect.Height > 0) + { + IsAutoSizingColumns = true; + foreach (var col in Widget.Columns.Select(r => r.Handler).OfType()) + { + col.Resize(); + } + IsAutoSizingColumns = false; + return true; + } + } + return false; + } + + public bool ShowHeader + { + get + { + return Control.HeaderView != null; + } + set + { + if (value && Control.HeaderView == null) + { + Control.HeaderView = new EtoTableHeaderView { Handler = this }; + } + else if (!value && Control.HeaderView != null) + { + Control.HeaderView = null; + } + } + } + + public bool AllowColumnReordering + { + get { return Control.AllowsColumnReordering; } + set { Control.AllowsColumnReordering = value; } + } + + public ContextMenu ContextMenu + { + get { return contextMenu; } + set + { + contextMenu = value; + Control.Menu = contextMenu != null ? ((ContextMenuHandler)contextMenu.Handler).Control : null; + } + } + + public bool AllowMultipleSelection + { + get { return Control.AllowsMultipleSelection; } + set { Control.AllowsMultipleSelection = value; } + } + + public IEnumerable SelectedRows + { + get + { + var rows = Control.SelectedRows; + if (rows != null && rows.Count > 0) + return rows.Select(r => (int)r); + return Enumerable.Empty(); + } + set + { + SuppressSelectionChanged++; + UnselectAll(); + var indexes = NSIndexSet.FromArray(value.ToArray()); + Control.SelectRows(indexes, AllowMultipleSelection); + SuppressSelectionChanged--; + if (SuppressSelectionChanged == 0) + Callback.OnSelectionChanged(Widget, EventArgs.Empty); + } + } + + public void SelectAll() + { + Control.SelectAll(Control); + } + + public void SelectRow(int row) + { + Control.SelectRow((nnint)row, AllowMultipleSelection); + } + + public void UnselectRow(int row) + { + Control.DeselectRow(row); + } + + public void UnselectAll() + { + Control.DeselectAll(Control); + } + + public void BeginEdit(int row, int column) + { + Control.SelectRow((nnint)row, false); + Control.EditColumn((nint)column, (nint)row, new NSEvent(), true); + } + + public int RowHeight + { + get { return (int)Control.RowHeight; } + set { Control.RowHeight = value; } + } + + public abstract object GetItem(int row); + + public virtual int RowCount + { + get { return (int)Control.RowCount; } + } + + Grid IGridHandler.Widget + { + get { return Widget; } + } + + public CGRect GetVisibleRect() + { + var rect = ScrollView.VisibleRect(); + var loc = ScrollView.ContentView.Bounds.Location; + return new CGRect(rect.X + loc.X, rect.Y + loc.Y, rect.Width, rect.Height); + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + var width = Widget.Columns.Sum(r => r.Width); + if (width == 0) + width = 100; + var height = RowHeight * 4; + return new Size(width, height); + } + + public void OnCellFormatting(GridColumn column, object item, int row, NSCell cell) + { + Callback.OnCellFormatting(Widget, new MacCellFormatArgs(column, item, row, cell)); + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/GridViewHandler.cs b/Source/Eto.Mac/Forms/Controls/GridViewHandler.cs new file mode 100644 index 0000000000..99dfbe5257 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/GridViewHandler.cs @@ -0,0 +1,341 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using Eto.Drawing; +using sd = System.Drawing; +using System.Collections; +using System.Linq; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class GridViewHandler : GridHandler, GridView.IHandler + { + CollectionHandler collection; + + public class EtoTableView : NSTableView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public GridViewHandler Handler + { + get { return (GridViewHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + /// + /// The area to the right and below the rows is not filled with the background + /// color. This fixes that. See http://orangejuiceliberationfront.com/themeing-nstableview/ + /// + public override void DrawBackground(CGRect clipRect) + { + var backgroundColor = Handler.BackgroundColor; + if (backgroundColor != Colors.Transparent) + { + backgroundColor.ToNSUI().Set(); + NSGraphics.RectFill(clipRect); + } + else + base.DrawBackground(clipRect); + } + } + + class EtoTableViewDataSource : NSTableViewDataSource + { + WeakReference handler; + + public GridViewHandler Handler { get { return (GridViewHandler)(handler != null ? handler.Target : null); } set { handler = new WeakReference(value); } } + + public override nint GetRowCount(NSTableView tableView) + { + return (Handler.collection != null && Handler.collection.Collection != null) ? Handler.collection.Count : 0; + } + + public override NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, nint row) + { + var item = Handler.collection.ElementAt((int)row); + var colHandler = Handler.GetColumn(tableColumn); + return colHandler == null ? null : colHandler.GetObjectValue(item); + } + + public override void SetObjectValue(NSTableView tableView, NSObject theObject, NSTableColumn tableColumn, nint row) + { + var item = Handler.collection.ElementAt((int)row); + var colHandler = Handler.GetColumn(tableColumn); + if (colHandler != null) + { + colHandler.SetObjectValue(item, theObject); + + Handler.Callback.OnCellEdited(Handler.Widget, new GridViewCellEventArgs(colHandler.Widget, (int)row, colHandler.Column, item)); + } + } + } + + class EtoTableDelegate : NSTableViewDelegate + { + WeakReference handler; + + public GridViewHandler Handler { get { return (GridViewHandler)(handler != null ? handler.Target : null); } set { handler = new WeakReference(value); } } + + public override bool ShouldEditTableColumn(NSTableView tableView, NSTableColumn tableColumn, nint row) + { + var colHandler = Handler.GetColumn(tableColumn); + var item = Handler.collection.ElementAt((int)row); + var args = new GridViewCellEventArgs(colHandler.Widget, (int)row, colHandler.Column, item); + Handler.Callback.OnCellEditing(Handler.Widget, args); + return true; + } + + public override void SelectionDidChange(NSNotification notification) + { + if (Handler.SuppressSelectionChanged == 0) + { + Handler.Callback.OnSelectionChanged(Handler.Widget, EventArgs.Empty); + } + } + + public override void DidClickTableColumn(NSTableView tableView, NSTableColumn tableColumn) + { + var colHandler = Handler.GetColumn(tableColumn); + Handler.Callback.OnColumnHeaderClick(Handler.Widget, new GridColumnEventArgs(colHandler.Widget)); + } + + public override void WillDisplayCell(NSTableView tableView, NSObject cell, NSTableColumn tableColumn, nint row) + { + var colHandler = Handler.GetColumn(tableColumn); + var item = Handler.GetItem((int)row); + Handler.OnCellFormatting(colHandler.Widget, item, (int)row, cell as NSCell); + + } + + public override void ColumnDidResize(NSNotification notification) + { + if (!Handler.IsAutoSizingColumns) + { + // when the user resizes the column, don't autosize anymore when data/scroll changes + var column = notification.UserInfo["NSTableColumn"] as NSTableColumn; + if (column != null) + { + var colHandler = Handler.GetColumn(column); + colHandler.AutoSize = false; + } + } + } + } + + public bool ShowCellBorders + { + get { return Control.IntercellSpacing.Width > 0 || Control.IntercellSpacing.Height > 0; } + set { Control.IntercellSpacing = value ? new CGSize(1, 1) : CGSize.Empty; } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Grid.CellEditingEvent: + // handled by delegate + /* following should work, but internal delegate to trigger event does not work + table.ShouldEditTableColumn = (tableView, tableColumn, row) => { + var id = tableColumn.Identifier as EtoGridColumnIdentifier; + var item = store.GetItem (row); + var args = new GridViewCellArgs(id.Handler.Widget, row, id.Handler.Column, item); + this.Widget.OnBeginCellEdit (args); + return true; + };*/ + break; + case Grid.CellEditedEvent: + // handled after object value is set + break; + case Grid.SelectionChangedEvent: + /* handled by delegate, for now + table.SelectionDidChange += delegate { + Widget.OnSelectionChanged (EventArgs.Empty); + };*/ + break; + case Grid.ColumnHeaderClickEvent: + /* + table.DidClickTableColumn += delegate(object sender, NSTableViewTableEventArgs e) { + var column = Handler.Widget.Columns.First (r => object.ReferenceEquals (r.ControlObject, tableColumn)); + Handler.Widget.OnHeaderClick (new GridColumnEventArgs (column)); + }; + */ + break; + case Grid.CellFormattingEvent: + break; + case GridView.CellDoubleClickEvent: + Control.DoubleClick += (sender, e) => + { + int rowIndex; + if ((rowIndex = (int)Control.ClickedRow) >= 0) + { + var columnIndex = (int)Control.ClickedColumn; + var item = GetItem(rowIndex); + var column = columnIndex == -1 ? null : Widget.Columns[columnIndex]; + Callback.OnCellDoubleClick(Widget, new GridViewCellEventArgs(column, rowIndex, columnIndex, item)); + } + }; + break; + default: + base.AttachEvent(id); + break; + } + } + + public GridViewHandler() + { + Control = new EtoTableView + { + Handler = this, + FocusRingType = NSFocusRingType.None, + DataSource = new EtoTableViewDataSource { Handler = this }, + Delegate = new EtoTableDelegate { Handler = this }, + ColumnAutoresizingStyle = NSTableViewColumnAutoresizingStyle.None + }; + } + + public IEnumerable SelectedItems + { + get + { + if (collection != null) + { + foreach (var row in SelectedRows) + yield return collection.ElementAt(row); + } + } + } + + class CollectionHandler : EnumerableChangedHandler + { + public GridViewHandler Handler { get; set; } + + public override void AddRange(IEnumerable items) + { + Handler.Control.ReloadData(); + Handler.AutoSizeColumns(); + } + + static Selector selInsertRowsWithAnimation = new Selector("insertRowsAtIndexes:withAnimation:"); + static Selector selRemoveRowsWithAnimation = new Selector("removeRowsAtIndexes:withAnimation:"); + + public override void AddItem(object item) + { + if (Handler.Control.RespondsToSelector(selInsertRowsWithAnimation)) + { + Handler.Control.BeginUpdates(); + Handler.Control.InsertRows(new NSIndexSet(Count), NSTableViewAnimation.SlideDown); + Handler.Control.EndUpdates(); + } + else + Handler.Control.ReloadData(); + + Handler.AutoSizeColumns(); + } + + public override void InsertItem(int index, object item) + { + if (Handler.Control.RespondsToSelector(selInsertRowsWithAnimation)) + { + Handler.Control.BeginUpdates(); + Handler.Control.InsertRows(new NSIndexSet(index), NSTableViewAnimation.SlideDown); + Handler.Control.EndUpdates(); + } + else + { + var rows = Handler.SelectedRows.Select(r => r >= index ? r + 1 : r).ToArray(); + Handler.SuppressSelectionChanged++; + Handler.Control.ReloadData(); + Handler.SelectedRows = rows; + Handler.SuppressSelectionChanged--; + } + + Handler.AutoSizeColumns(); + } + + public override void RemoveItem(int index) + { + if (Handler.Control.RespondsToSelector(selRemoveRowsWithAnimation)) + { + Handler.Control.BeginUpdates(); + Handler.Control.RemoveRows(new NSIndexSet(index), NSTableViewAnimation.SlideUp); + Handler.Control.EndUpdates(); + } + else + { + // need to adjust selected rows to shift them up + bool isSelected = false; + var rows = Handler.SelectedRows.Where(r => + { + if (r != index) + return true; + isSelected = true; + return false; + }).Select(r => r > index ? r - 1 : r).ToArray(); + Handler.SuppressSelectionChanged++; + Handler.Control.ReloadData(); + Handler.SelectedRows = rows; + Handler.SuppressSelectionChanged--; + // item being removed was selected, so trigger change + if (isSelected) + Handler.Callback.OnSelectionChanged(Handler.Widget, EventArgs.Empty); + } + + Handler.AutoSizeColumns(); + } + + public override void RemoveAllItems() + { + Handler.Control.ReloadData(); + Handler.AutoSizeColumns(); + } + } + + public IEnumerable DataStore + { + get { return collection != null ? collection.Collection : null; } + set + { + if (collection != null) + collection.Unregister(); + collection = new CollectionHandler{ Handler = this }; + collection.Register(value); + if (Widget.Loaded) + AutoSizeColumns(); + } + } + + public override object GetItem(int row) + { + return collection.ElementAt(row); + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/GroupBoxHandler.cs b/Source/Eto.Mac/Forms/Controls/GroupBoxHandler.cs new file mode 100644 index 0000000000..893fee8bf1 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/GroupBoxHandler.cs @@ -0,0 +1,130 @@ +using System; +using Eto.Forms; +using SD = System.Drawing; +using Eto.Drawing; +using Eto.Mac.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class GroupBoxHandler : MacPanel, GroupBox.IHandler + { + Font font; + + public class EtoBox : NSBox, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public GroupBoxHandler() + { + Control = new EtoBox { Handler = this }; + Control.Title = string.Empty; + Control.ContentView = new NSView(); + Enabled = true; + } + + public override NSView ContainerControl + { + get { return Control; } + } + + public override NSView ContentControl + { + get { return (NSView)Control.ContentView; } + } + + public override bool Enabled { get; set; } + + public override Size ClientSize + { + get + { + var view = Control.ContentView as NSView; + return view.Frame.Size.ToEtoSize(); + } + set + { + Control.SetFrameFromContentFrame(new CGRect(0, 0, value.Width, value.Height)); + } + } + + public Font Font + { + get + { + return font ?? (font = new Font(new FontHandler(Control.TitleFont))); + } + set + { + font = value; + Control.TitleFont = font == null ? null : ((FontHandler)font.Handler).Control; + LayoutIfNeeded(); + } + } + + public virtual string Text + { + get { return Control.Title; } + set { Control.Title = value; } + } + + public override SizeF GetPreferredSize(SizeF availableSize) + { + return base.GetPreferredSize(availableSize) + new SizeF(14, (float)TitleCell.CellSize.Height * 1.1f + 6); + } + + public override void SetContentSize(CGSize contentSize) + { + Control.SetFrameFromContentFrame(new CGRect(0, 0, contentSize.Width, contentSize.Height)); + } + + NSTextFieldCell TitleCell { get { return (NSTextFieldCell)Control.TitleCell; } } + + public Color TextColor + { + get { return TitleCell.TextColor.ToEto(); } + set + { + TitleCell.TextColor = value.ToNSUI(); + Control.SetNeedsDisplay(); + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/ImageViewHandler.cs b/Source/Eto.Mac/Forms/Controls/ImageViewHandler.cs new file mode 100644 index 0000000000..6716abd65d --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/ImageViewHandler.cs @@ -0,0 +1,75 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class ImageViewHandler : MacControl, ImageView.IHandler + { + Image image; + + public class EtoImageView : NSImageView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public ImageViewHandler () + { + Control = new EtoImageView { Handler = this, ImageScaling = NSImageScale.ProportionallyUpOrDown }; + } + + protected override SizeF GetNaturalSize (SizeF availableSize) + { + return image == null ? Size.Empty : image.Size; + } + + public Image Image { + get { + return image; + } + set { + image = value; + Control.Image = image == null ? null : ((IImageSource)value.Handler).GetImage(); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/LabelHandler.cs b/Source/Eto.Mac/Forms/Controls/LabelHandler.cs new file mode 100644 index 0000000000..3b47dfb4b1 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/LabelHandler.cs @@ -0,0 +1,53 @@ +using System; +using sd = System.Drawing; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using System.Text.RegularExpressions; +using System.Linq; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if XAMMAC2 +using nnint = System.nint; +#elif Mac64 +using nnint = System.UInt64; +#else +using nnint = System.Int32; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class LabelHandler : MacLabel, Label.IHandler + { + } +} diff --git a/Source/Eto.Mac/Forms/Controls/LinkButtonHandler.cs b/Source/Eto.Mac/Forms/Controls/LinkButtonHandler.cs new file mode 100644 index 0000000000..fd305d1fa8 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/LinkButtonHandler.cs @@ -0,0 +1,185 @@ +using System; +using SD = System.Drawing; +using Eto.Drawing; +using Eto.Forms; +using Eto.Mac.Drawing; +using System.Runtime.InteropServices; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + /// + /// LinkButton handler. + /// + /// (c) 2012-2014 by Curtis Wensley + /// See LICENSE for full terms + public class LinkButtonHandler : MacLabel, LinkButton.IHandler + { + static readonly object HoverFontKey = new object(); + static readonly object NormalFontKey = new object(); + + Font HoverFont + { + get { return Widget.Properties.Get(HoverFontKey); } + set { Widget.Properties[HoverFontKey] = value; } + } + + Font NormalFont + { + get { return Widget.Properties.Get(NormalFontKey) ?? Font; } + set { Widget.Properties[NormalFontKey] = value; } + } + + public class EtoLinkLabel : EtoLabel + { + new LinkButtonHandler Handler { get { return (LinkButtonHandler)base.Handler; } set { base.Handler = value; } } + + public override bool AcceptsFirstResponder() + { + return Handler.Enabled; + } + + public override void DrawRect(CGRect dirtyRect) + { + if (Handler.HasFocus) + { + NSGraphicsContext.CurrentContext.SaveGraphicsState(); + GraphicsExtensions.SetFocusRingStyle(NSFocusRingPlacement.RingOnly); + NSGraphics.RectFill(this.Bounds); + NSGraphicsContext.CurrentContext.RestoreGraphicsState(); + } + + base.DrawRect(dirtyRect); + } + } + + protected override void Initialize() + { + base.Initialize(); + + TextColor = NSColor.Blue.ToEto(); + Cursor = Cursors.Pointer; + Widget.MouseEnter += HandleMouseEnter; + Widget.MouseLeave += HandleMouseLeave; + SetFonts(); + Font = NormalFont; + } + + public override Cursor CurrentCursor + { + get { return Enabled ? Cursor : null; } + } + + protected override NSColor CurrentColor + { + get { return Enabled ? TextColor.ToNSUI() : DisabledTextColor.ToNSUI(); } + } + + protected override EtoLinkLabel CreateLabel() + { + return new EtoLinkLabel + { + Handler = this, + Cell = new EtoLabelFieldCell(), + DrawsBackground = false, + FocusRingType = NSFocusRingType.Exterior, + Bordered = false, + Bezeled = false, + Editable = false, + Selectable = false, + Alignment = NSTextAlignment.Left, + }; + } + + public override Font Font + { + get { return base.Font; } + set + { + base.Font = value; + SetFonts(); + } + } + + void SetFonts() + { + //HoverFont = new Font(Font.Typeface, Font.Size, FontDecoration.Underline); + //NormalFont = new Font(Font.Typeface, Font.Size); + base.Font = new Font(Font.Typeface, Font.Size, FontDecoration.Underline); + } + + void HandleMouseLeave(object sender, MouseEventArgs e) + { + Font = NormalFont; + } + + void HandleMouseEnter(object sender, MouseEventArgs e) + { + if (Enabled && HoverFont != null) + Font = HoverFont; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case LinkButton.ClickEvent: + Widget.MouseDown += (sender, e) => + { + if (Enabled && e.Buttons == MouseButtons.Primary) + { + Callback.OnClick(Widget, EventArgs.Empty); + e.Handled = true; + } + }; + break; + default: + base.AttachEvent(id); + break; + } + } + + static readonly object DisabledTextColorKey = new object(); + + public Color DisabledTextColor + { + get { return Widget.Properties.Get(DisabledTextColorKey) ?? NSColor.DisabledControlText.ToEto(); } + set + { + if (value != DisabledTextColor) + { + Widget.Properties[DisabledTextColorKey] = value; + + } + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/ListBoxHandler.cs b/Source/Eto.Mac/Forms/Controls/ListBoxHandler.cs new file mode 100644 index 0000000000..279d80fac9 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/ListBoxHandler.cs @@ -0,0 +1,290 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using Eto.Mac.Forms.Controls; +using Eto.Drawing; +using Eto.Mac.Drawing; +using System.Collections; +using System.Linq; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using nnint = System.Int32; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +using nnint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +using nnint = System.Int32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class EtoScrollView : NSScrollView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler { get { return WeakHandler.Target; } set { WeakHandler = new WeakReference(value); } } + } + + public class ListBoxHandler : MacControl, ListBox.IHandler + { + readonly NSScrollView scroll; + readonly CollectionHandler collection; + readonly MacImageListItemCell cell; + + public override NSView ContainerControl + { + get { return scroll; } + } + + public NSScrollView Scroll + { + get { return scroll; } + } + + class DataSource : NSTableViewDataSource + { + WeakReference handler; + + public ListBoxHandler Handler { get { return (ListBoxHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, nint row) + { + var w = Handler.Widget; + var item = Handler.collection.ElementAt((int)row); + return new MacImageData + { + Text = new NSString(Convert.ToString(w.TextBinding.GetValue(item))), + Image = w.ImageBinding != null ? ((Image)w.ImageBinding.GetValue(item)).ToNS() : null + }; + } + + public override nint GetRowCount(NSTableView tableView) + { + return Handler.collection.Collection == null ? 0 : Handler.collection.Collection.Count(); + } + } + + class Delegate : NSTableViewDelegate + { + WeakReference handler; + + public ListBoxHandler Handler { get { return (ListBoxHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override bool ShouldSelectRow(NSTableView tableView, nint row) + { + return true; + } + + public override void SelectionDidChange(NSNotification notification) + { + Handler.Callback.OnSelectedIndexChanged(Handler.Widget, EventArgs.Empty); + } + } + + class EtoListBoxTableView : NSTableView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public ListBoxHandler Handler + { + get { return (ListBoxHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public override NSMenu MenuForEvent(NSEvent theEvent) + { + if (Handler.ContextMenu != null) + return Handler.ContextMenu.ControlObject as NSMenu; + return base.MenuForEvent(theEvent); + } + } + + public override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + + if (!e.Handled && e.Key == Keys.Enter) + { + Callback.OnActivated(Widget, EventArgs.Empty); + e.Handled = true; + } + } + + public ContextMenu ContextMenu + { + get; + set; + } + + public override bool Enabled + { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + + public ListBoxHandler() + { + collection = new CollectionHandler { Handler = this }; + Control = new EtoListBoxTableView { Handler = this }; + + var col = new NSTableColumn(); + col.ResizingMask = NSTableColumnResizing.Autoresizing; + col.Editable = false; + cell = new MacImageListItemCell(); + cell.Wraps = false; + col.DataCell = cell; + Control.AddColumn(col); + + Control.DataSource = new DataSource { Handler = this }; + Control.HeaderView = null; + Control.DoubleClick += HandleDoubleClick; + Control.Delegate = new Delegate { Handler = this }; + + scroll = new EtoScrollView { Handler = this }; + scroll.AutoresizesSubviews = true; + scroll.DocumentView = Control; + scroll.HasVerticalScroller = true; + scroll.HasHorizontalScroller = true; + scroll.AutohidesScrollers = true; + scroll.BorderType = NSBorderType.BezelBorder; + } + + protected override void Initialize() + { + base.Initialize(); + HandleEvent(Eto.Forms.Control.KeyDownEvent); + } + + static void HandleDoubleClick(object sender, EventArgs e) + { + var handler = GetHandler(sender) as ListBoxHandler; + if (handler != null) + handler.Callback.OnActivated(handler.Widget, EventArgs.Empty); + } + + public override Font Font + { + get + { + if (font == null) + font = new Font(new FontHandler(Control.Font)); + return font; + } + set + { + font = value; + if (font != null) + { + var fontHandler = (FontHandler)font.Handler; + cell.Font = fontHandler.Control; + Control.RowHeight = fontHandler.LineHeight; + } + else + cell.Font = NSFont.SystemFontOfSize(NSFont.SystemFontSize); + } + } + + class CollectionHandler : EnumerableChangedHandler + { + public ListBoxHandler Handler { get; set; } + + public override void AddRange(IEnumerable items) + { + Handler.Control.ReloadData(); + } + + public override void AddItem(object item) + { + Handler.Control.ReloadData(); + } + + public override void InsertItem(int index, object item) + { + Handler.Control.ReloadData(); + } + + public override void RemoveItem(int index) + { + Handler.Control.ReloadData(); + } + + public override void RemoveAllItems() + { + Handler.Control.ReloadData(); + } + } + + public IEnumerable DataStore + { + get { return collection.Collection; } + set + { + if (collection.Collection != null) + collection.Unregister(); + collection.Register(value); + } + } + + public int SelectedIndex + { + get { return (int)Control.SelectedRow; } + set + { + if (value == -1) + Control.DeselectAll(Control); + else + { + Control.SelectRow((nnint)value, false); + Control.ScrollRowToVisible(value); + } + } + } + + public override void Focus() + { + if (Control.Window != null) + Control.Window.MakeFirstResponder(Control); + else + base.Focus(); + } + + public override Color BackgroundColor + { + get { return Control.BackgroundColor.ToEto(); } + set { Control.BackgroundColor = value.ToNSUI(); } + } + + public Color TextColor + { + get { return cell.TextColor.ToEto(); } + set + { + cell.TextColor = value.ToNSUI(); + Control.SetNeedsDisplay(); + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/MacButton.cs b/Source/Eto.Mac/Forms/Controls/MacButton.cs new file mode 100644 index 0000000000..ae192e4d2b --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/MacButton.cs @@ -0,0 +1,70 @@ +using Eto.Forms; +using Eto.Drawing; + + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreText; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreText; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public abstract class MacButton : MacControl, TextControl.IHandler + where TControl: NSButton + where TWidget: Control + where TCallback: Control.ICallback + { + static readonly object textKey = new object(); + + public virtual string Text + { + get { return Widget.Properties.Get(textKey); } + set + { + Widget.Properties[textKey] = value; + var oldSize = GetPreferredSize(Size.MaxValue); + SetText(value); + LayoutIfNeeded(oldSize); + } + } + + static readonly object textColorKey = new object(); + + public virtual Color TextColor + { + get { return Widget.Properties.Get(textColorKey) ?? NSColor.ControlText.ToEto(); } + set { + if (value != TextColor) + { + Widget.Properties[textColorKey] = value; + SetText(Text); + } + } + } + + void SetText(string text) + { + Control.SetTitleWithMnemonic(text ?? string.Empty); + var color = Widget.Properties.Get(textColorKey); + if (color != null) + { + var attr = NSDictionary.FromObjectAndKey(color.Value.ToNSUI(), NSAttributedString.ForegroundColorAttributeName); + var str = new NSMutableAttributedString(Control.AttributedTitle); + str.AddAttributes(attr, new NSRange(0, str.Length)); + Control.AttributedTitle = str; + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/MacControl.cs b/Source/Eto.Mac/Forms/Controls/MacControl.cs new file mode 100644 index 0000000000..83aeb45156 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/MacControl.cs @@ -0,0 +1,54 @@ +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using sd = System.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public abstract class MacControl : MacView + where TControl: NSControl + where TWidget: Control + where TCallback: Control.ICallback + { + internal Font font; + + public override NSView ContainerControl { get { return Control; } } + + public override bool Enabled + { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + + public virtual Font Font + { + get + { + if (font == null) + font = new Font(new FontHandler(Control.Font)); + return font; + } + set + { + font = value; + Control.Font = font.ToNSFont(); + Control.AttributedStringValue = font.AttributedString(Control.AttributedStringValue); + LayoutIfNeeded(); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/MacEventView.cs b/Source/Eto.Mac/Forms/Controls/MacEventView.cs new file mode 100644 index 0000000000..ab8f0a8c34 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/MacEventView.cs @@ -0,0 +1,128 @@ +using System; +using SD = System.Drawing; +using Eto.Forms; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class MacEventView : NSView, IMacControl + { + static readonly NSString CIOutputImage = new NSString("outputImage"); + static readonly Selector selConvertSizeToBacking = new Selector("convertSizeToBacking:"); + + public static void Colourize(NSView control, Color color, Action drawAction) + { + var size = control.Frame.Size; + if (size.Width <= 0 || size.Height <= 0) + return; + var image = new NSImage(size); + + image.LockFocusFlipped(!control.IsFlipped); + drawAction(); + image.UnlockFocus(); + + var ciImage = CIImage.FromCGImage(image.CGImage); + + CGSize realSize; + if (control.RespondsToSelector(selConvertSizeToBacking)) + realSize = control.ConvertSizeToBacking(size); + else + realSize = control.ConvertSizeToBase(size); + + var filter2 = new CIColorControls(); + filter2.SetDefaults(); + filter2.Image = ciImage; + filter2.Saturation = 0.0f; + ciImage = (CIImage)filter2.ValueForKey(CIOutputImage); + + var filter3 = new CIColorMatrix(); + filter3.SetDefaults(); + filter3.Image = ciImage; + filter3.RVector = new CIVector(0, color.R, 0); + filter3.GVector = new CIVector(color.G, 0, 0); + filter3.BVector = new CIVector(0, 0, color.B); + ciImage = (CIImage)filter3.ValueForKey(CIOutputImage); + + // create separate context so we can force using the software renderer, which is more than fast enough for this + var ciContext = CIContext.FromContext(NSGraphicsContext.CurrentContext.GraphicsPort, new CIContextOptions { UseSoftwareRenderer = true }); + ciContext.DrawImage(ciImage, new CGRect(CGPoint.Empty, size), new CGRect(CGPoint.Empty, realSize)); + } + + public WeakReference WeakHandler { get; set; } + + public IMacViewHandler Handler + { + get { return (IMacViewHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public Control Widget + { + get { return Handler == null ? null : Handler.Widget; } + } + + public static bool KeyDown(Control control, NSEvent theEvent) + { + if (control != null) + { + var handler = control.Handler as IMacViewHandler; + var kpea = theEvent.ToEtoKeyEventArgs(); + handler.OnKeyDown(kpea); + return kpea.Handled; + } + return false; + } + + public static bool KeyUp(Control control, NSEvent theEvent) + { + if (control != null) + { + var handler = control.Handler as IMacViewHandler; + var kpea = theEvent.ToEtoKeyEventArgs(); + handler.Callback.OnKeyUp(control, kpea); + return kpea.Handled; + } + return false; + } + + public override void ResetCursorRects() + { + var cursor = Handler.CurrentCursor; + if (cursor != null) + { + AddCursorRect(new CGRect(CGPoint.Empty, Frame.Size), cursor.ControlObject as NSCursor); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/MacImageAndTextCell.cs b/Source/Eto.Mac/Forms/Controls/MacImageAndTextCell.cs new file mode 100644 index 0000000000..d160a1d5f9 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/MacImageAndTextCell.cs @@ -0,0 +1,250 @@ +using System; +using SD = System.Drawing; +using Eto.Forms; +using Eto.Mac.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class MacImageData : NSObject, ICloneable + { + public MacImageData() + { + } + + public MacImageData(IListItem item) + { + SetItem(item); + } + + public MacImageData(IntPtr handle) + : base(handle) + { + } + + public MacImageData(MacImageData value) + { + this.Text = value.Text; + this.Image = value.Image; + } + + public override string Description + { + get { return (string)Text ?? string.Empty; } + } + + public NSImage Image { get; set; } + + public NSString Text { get; set; } + + + public void SetItem(IListItem value) + { + var imgitem = value as IImageListItem; + if (imgitem != null && imgitem.Image != null) + Image = ((IImageSource)imgitem.Image.Handler).GetImage(); + Text = (NSString)value.Text; + } + + [Export("copyWithZone:")] + public virtual NSObject CopyWithZone(IntPtr zone) + { + var clone = (MacImageData)Clone(); + clone.DangerousRetain(); + return clone; + } + + #region ICloneable implementation + + public virtual object Clone() + { + return new MacImageData(this); + } + + #endregion + } + + public class MacImageListItemCell : NSTextFieldCell + { + public const int ImagePadding = 2; + NSShadow textShadow; + NSShadow textHighlightShadow; + NSColor groupColor = NSColor.FromCalibratedRgba(0x6F / (float)0xFF, 0x7E / (float)0xFF, 0x8B / (float)0xFF, 1.0F); + //light shade: NSColor.FromCalibratedRgba (0x82 / (float)0xFF, 0x90 / (float)0xFF, 0x9D / (float)0xFF, 1.0F); + + static readonly IntPtr selDrawInRectFromRectOperationFractionRespectFlippedHints = Selector.GetHandle("drawInRect:fromRect:operation:fraction:respectFlipped:hints:"); + + + public MacImageListItemCell() + { + } + + public NSColor GroupColor + { + get { return groupColor; } + set { groupColor = value; } + } + + public bool UseTextShadow + { + get; + set; + } + + public void SetGroupItem(bool isGroupItem, NSTableView tableView, float? groupSize = null, float? normalSize = null) + { + if (isGroupItem) + Font = NSFont.BoldSystemFontOfSize(groupSize ?? (float)NSFont.SystemFontSize); + else if (Highlighted) + Font = NSFont.BoldSystemFontOfSize(normalSize ?? (float)NSFont.SystemFontSize); + else + Font = NSFont.SystemFontOfSize(normalSize ?? (float)NSFont.SystemFontSize); + + if (Highlighted) + TextColor = NSColor.Highlight; + else if (!tableView.Window.IsKeyWindow) + TextColor = NSColor.DisabledControlText; + else if (isGroupItem) + TextColor = GroupColor; + else + TextColor = NSColor.ControlText; + + } + + public NSShadow TextShadow + { + get + { + if (textShadow == null) + { + textShadow = new NSShadow(); + textShadow.ShadowColor = NSColor.FromDeviceWhite(1F, 0.5F); + textShadow.ShadowOffset = new CGSize(0F, -1.0F); + textShadow.ShadowBlurRadius = 0F; + } + return textShadow; + } + set { textShadow = value; } + } + + public NSShadow TextHighlightShadow + { + get + { + if (textHighlightShadow == null) + { + textHighlightShadow = new NSShadow(); + textHighlightShadow.ShadowColor = NSColor.FromDeviceWhite(0F, 0.5F); + textHighlightShadow.ShadowOffset = new CGSize(0F, -1.0F); + textHighlightShadow.ShadowBlurRadius = 2F; + } + return textHighlightShadow; + } + set { textShadow = value; } + } + + public MacImageListItemCell(IntPtr handle) + : base(handle) + { + } + + // TODO: Mac64 + #if !Mac64 && !XAMMAC2 + public override CGSize CellSizeForBounds(CGRect bounds) + { + var size = base.CellSizeForBounds(bounds); + var data = ObjectValue as MacImageData; + if (data != null && data.Image != null) + { + var imageSize = data.Image.Size; + var newHeight = Math.Min(imageSize.Height, size.Height); + var newWidth = imageSize.Width * newHeight / imageSize.Height; + size.Width += (nfloat)(newWidth + ImagePadding); + } + size.Width = (nfloat)Math.Min(size.Width, bounds.Width); + return size; + } + #endif + + public override void DrawInteriorWithFrame(CGRect cellFrame, NSView inView) + { + var data = ObjectValue as MacImageData; + if (data != null) + { + + if (data.Image != null) + { + var imageSize = data.Image.Size; + if (imageSize.Width > 0 && imageSize.Height > 0) + { + var newHeight = (nfloat)Math.Min(imageSize.Height, cellFrame.Height); + var newWidth = (nfloat)(imageSize.Width * newHeight / imageSize.Height); + + var imageRect = new CGRect(cellFrame.X, cellFrame.Y, newWidth, newHeight); + imageRect.Y += (cellFrame.Height - newHeight) / 2; + + if (data.Image.RespondsToSelector(new Selector(selDrawInRectFromRectOperationFractionRespectFlippedHints))) + // 10.6+ + data.Image.Draw(imageRect, new CGRect(CGPoint.Empty, data.Image.Size), NSCompositingOperation.SourceOver, 1, true, null); + else + { + // 10.5- + #pragma warning disable 618 + data.Image.Flipped = ControlView.IsFlipped; + #pragma warning restore 618 + data.Image.Draw(imageRect, new CGRect(CGPoint.Empty, data.Image.Size), NSCompositingOperation.SourceOver, 1); + } + cellFrame.Width -= newWidth + ImagePadding; + cellFrame.X += newWidth + ImagePadding; + } + } + } + + var titleSize = AttributedStringValue.Size; + + // test to see if the text height is bigger then the cell, if it is, + // don't try to center it or it will be pushed up out of the cell! + if (titleSize.Height < cellFrame.Size.Height) + { + cellFrame.Y = cellFrame.Y + (cellFrame.Size.Height - titleSize.Height) / 2; + } + + if (UseTextShadow) + { + var str = new NSMutableAttributedString(StringValue); + str.AddAttribute(NSAttributedString.ShadowAttributeName, Highlighted ? TextHighlightShadow : TextShadow, new NSRange(0, (int)str.Length)); + AttributedStringValue = str; + } + + base.DrawInteriorWithFrame(cellFrame, inView); + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/MacLabel.cs b/Source/Eto.Mac/Forms/Controls/MacLabel.cs new file mode 100644 index 0000000000..2787ed2a22 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/MacLabel.cs @@ -0,0 +1,337 @@ +using System; +using sd = System.Drawing; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using System.Text.RegularExpressions; +using System.Linq; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if XAMMAC2 +using nnint = System.nint; +#elif Mac64 +using nnint = System.UInt64; +#else +using nnint = System.Int32; +#endif + +namespace Eto.Mac.Forms.Controls +{ + + public class EtoLabelFieldCell : NSTextFieldCell + { + public VerticalAlign VerticalAlign { get; set; } + + public override CGRect DrawingRectForBounds(CGRect theRect) + { + var rect = base.DrawingRectForBounds(theRect); + var titleSize = CellSizeForBounds(theRect); + + switch (VerticalAlign) + { + case VerticalAlign.Middle: + rect.Y = theRect.Y + (theRect.Height - titleSize.Height) / 2.0F; + break; + case VerticalAlign.Top: + // do nothing! + break; + case VerticalAlign.Bottom: + rect.Y = theRect.Y + (theRect.Height - titleSize.Height); + break; + } + return rect; + } + } + + public class EtoLabel : NSTextField, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public class MacLabel : MacView + where TControl: NSTextField + where TWidget: Control + where TCallback: Control.ICallback + { + static readonly bool supportsSingleLine; + readonly NSMutableAttributedString str; + readonly NSMutableParagraphStyle paragraphStyle; + int underlineIndex; + SizeF availableSizeCached; + const NSStringDrawingOptions DrawingOptions = NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin; + + static MacLabel() + { + supportsSingleLine = ObjCExtensions.ClassInstancesRespondToSelector(Class.GetHandle("NSTextFieldCell"), Selector.GetHandle("setUsesSingleLineMode:")); + } + + public override NSView ContainerControl { get { return Control; } } + + #if !XAMMAC2 + static readonly Selector selAlignmentRectInsets = new Selector("alignmentRectInsets"); + #endif + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + if (string.IsNullOrEmpty(Text)) + return Size.Empty; + if (NaturalSize == null || availableSizeCached != availableSize) + { + #if XAMMAC2 // TODO: Fix when Xamarin.Mac2 NSEdgeInsets is fixed to use nfloat instead of float + var insets = new Size(4, 2); + #else + var insets = Control.RespondsToSelector(selAlignmentRectInsets) ? Control.AlignmentRectInsets.ToEtoSize() : new Size(4, 2); + #endif + var size = Control.Cell.CellSizeForBounds(new CGRect(CGPoint.Empty, availableSize.ToNS())).ToEto(); + + NaturalSize = Size.Round(size + insets); + availableSizeCached = availableSize; + } + + return NaturalSize.Value; + } + + public MacLabel() + { + Enabled = true; + paragraphStyle = new NSMutableParagraphStyle(); + str = new NSMutableAttributedString(); + + underlineIndex = -1; + paragraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping; + } + + protected override void Initialize() + { + base.Initialize(); + Control = CreateLabel(); + if (supportsSingleLine) + Control.Cell.UsesSingleLineMode = false; + } + + protected virtual TControl CreateLabel() + { + return new EtoLabel + { + Handler = this, + Cell = new EtoLabelFieldCell(), + DrawsBackground = false, + Bordered = false, + Bezeled = false, + Editable = false, + Selectable = false, + Alignment = NSTextAlignment.Left, + } as TControl; + } + + static readonly object TextColorKey = new object(); + + public Color TextColor + { + get { return Widget.Properties.Get(TextColorKey) ?? NSColor.Text.ToEto(); } + set + { + if (value != TextColor) + { + Widget.Properties[TextColorKey] = value; + SetAttributes(); + } + } + } + + public WrapMode Wrap + { + get + { + if (supportsSingleLine && Control.Cell.UsesSingleLineMode) + return WrapMode.None; + if (paragraphStyle.LineBreakMode == NSLineBreakMode.ByWordWrapping) + return WrapMode.Word; + return WrapMode.Character; + } + set + { + switch (value) + { + case WrapMode.None: + if (supportsSingleLine) + Control.Cell.UsesSingleLineMode = true; + paragraphStyle.LineBreakMode = NSLineBreakMode.Clipping; + break; + case WrapMode.Word: + if (supportsSingleLine) + Control.Cell.UsesSingleLineMode = false; + paragraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping; + break; + case WrapMode.Character: + if (supportsSingleLine) + Control.Cell.UsesSingleLineMode = false; + paragraphStyle.LineBreakMode = NSLineBreakMode.CharWrapping; + break; + default: + throw new NotSupportedException(); + } + SetAttributes(); + } + } + + public override bool Enabled { get; set; } + + public string Text + { + get { return str.Value; } + set + { + var oldSize = GetPreferredSize(Size.MaxValue); + if (string.IsNullOrEmpty(value)) + { + str.SetString(new NSMutableAttributedString()); + } + else + { + var match = Regex.Match(value, @"(?<=([^&](?:[&]{2})*)|^)[&](?![&])"); + if (match.Success) + { + var val = value.Remove(match.Index, match.Length).Replace("&&", "&"); + + var matches = Regex.Matches(value, @"[&][&]"); + var prefixCount = matches.Cast().Count(r => r.Index < match.Index); + + str.SetString(new NSAttributedString(val)); + underlineIndex = match.Index - prefixCount; + } + else + { + str.SetString(new NSAttributedString(value.Replace("&&", "&"))); + underlineIndex = -1; + } + } + SetAttributes(); + LayoutIfNeeded(oldSize); + } + } + + public HorizontalAlign HorizontalAlign + { + get { return paragraphStyle.Alignment.ToEto(); } + set + { + paragraphStyle.Alignment = value.ToNS(); + SetAttributes(); + } + } + + static readonly object FontKey = new object(); + + public virtual Font Font + { + get + { + return Widget.Properties.Create(FontKey, () => new Font(new FontHandler(Control.Font))); + } + set + { + if (Widget.Properties.Get(FontKey) != value) + { + var oldSize = GetPreferredSize(Size.MaxValue); + Widget.Properties[FontKey] = value; + SetAttributes(); + LayoutIfNeeded(oldSize); + } + } + } + + public VerticalAlign VerticalAlign + { + get { return ((EtoLabelFieldCell)Control.Cell).VerticalAlign; } + set { ((EtoLabelFieldCell)Control.Cell).VerticalAlign = value; } + } + + protected virtual void SetAttributes() + { + SetAttributes(false); + } + + void SetAttributes(bool force) + { + if (Widget.Loaded || force) + { + if (str.Length > 0) + { + var range = new NSRange(0, (int)str.Length); + var attr = new NSMutableDictionary(); + Widget.Properties.Get(FontKey).Apply(attr); + attr.Add(NSAttributedString.ParagraphStyleAttributeName, paragraphStyle); + attr.Add(NSAttributedString.ForegroundColorAttributeName, CurrentColor); + str.SetAttributes(attr, range); + if (underlineIndex >= 0) + { + var num = (NSNumber)str.GetAttribute(NSAttributedString.UnderlineStyleAttributeName, (nnint)underlineIndex, out range); + var newStyle = (num != null && (NSUnderlineStyle)num.Int64Value == NSUnderlineStyle.Single) ? NSUnderlineStyle.Double : NSUnderlineStyle.Single; + str.AddAttribute(NSAttributedString.UnderlineStyleAttributeName, new NSNumber((int)newStyle), new NSRange(underlineIndex, 1)); + } + } + Control.AttributedStringValue = str; + } + } + + protected virtual NSColor CurrentColor + { + get { return TextColor.ToNSUI(); } + } + + public override void OnLoad(EventArgs e) + { + base.OnLoad(e); + SetAttributes(true); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + break; + default: + base.AttachEvent(id); + break; + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/MacText.cs b/Source/Eto.Mac/Forms/Controls/MacText.cs new file mode 100644 index 0000000000..c5ef1bf9fe --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/MacText.cs @@ -0,0 +1,44 @@ +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public abstract class MacText : MacControl, TextControl.IHandler + where TControl: NSTextField + where TWidget: TextControl + where TCallback: TextControl.ICallback + { + public override Color BackgroundColor + { + get { return Control.BackgroundColor.ToEto(); } + set { Control.BackgroundColor = value.ToNSUI(); } + } + + public virtual string Text + { + get { return Control.AttributedStringValue.Value; } + set { Control.AttributedStringValue = Font.AttributedString(value ?? string.Empty, Control.AttributedStringValue); } + } + + public virtual Color TextColor + { + get { return Control.TextColor.ToEto(); } + set { Control.TextColor = value.ToNSUI(); } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/NativeControlHandler.cs b/Source/Eto.Mac/Forms/Controls/NativeControlHandler.cs new file mode 100644 index 0000000000..12e74407a5 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/NativeControlHandler.cs @@ -0,0 +1,75 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using nnint = System.nint; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +using nnint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +using nnint = System.Int32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class NativeControlHandler : MacView + { + NSViewController controller; + + public NativeControlHandler(NSView nativeControl) + { + Control = nativeControl; + AutoSize = false; + } + + public override SizeF GetPreferredSize(SizeF availableSize) + { + return Control.Frame.Size.ToEto(); + } + + public NativeControlHandler(NSViewController nativeControl) + { + controller = nativeControl; + Control = controller.View; + } + + public override NSView ContainerControl { get { return Control; } } + + public override bool Enabled + { + get + { + throw new NotSupportedException("You cannot get the enabled state of a native control"); + } + set + { + throw new NotSupportedException("You cannot set the enabled state of a native control"); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/NumericUpDownHandler.cs b/Source/Eto.Mac/Forms/Controls/NumericUpDownHandler.cs new file mode 100644 index 0000000000..955e451158 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/NumericUpDownHandler.cs @@ -0,0 +1,299 @@ +using System; +using Eto.Forms; +using SD = System.Drawing; +using Eto.Drawing; +using Eto.Mac.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using nnint = System.nint; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +using nnint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +using nnint = System.Int32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class NumericUpDownHandler : MacView, NumericUpDown.IHandler + { + readonly NSTextField text; + readonly NSStepper stepper; + Font font; + Size? naturalSize; + + public override NSView ContainerControl { get { return Control; } } + + public class EtoTextField : NSTextField, IMacControl + { + public WeakReference WeakHandler { get; set; } + } + + class EtoNumericUpDownView : MacEventView + { + public override void SetFrameSize(CGSize newSize) + { + base.SetFrameSize(newSize); + var views = Subviews; + var text = views[0]; + var splitter = views[1]; + var offset = (newSize.Height - text.Frame.Height) / 2; + text.SetFrameOrigin(new CGPoint(0, offset)); + text.SetFrameSize(new CGSize((float)(newSize.Width - splitter.Frame.Width), (float)text.Frame.Height)); + offset = (newSize.Height - splitter.Frame.Height) / 2; + splitter.SetFrameOrigin(new CGPoint(newSize.Width - splitter.Frame.Width, offset)); + } + } + + class EtoStepper : NSStepper + { + public override bool AcceptsFirstResponder() + { + return false; + } + } + + public override object EventObject + { + get { return text; } + } + + public NumericUpDownHandler() + { + this.Control = new EtoNumericUpDownView + { + Handler = this, + AutoresizesSubviews = false + }; + text = new EtoTextField + { + WeakHandler = new WeakReference(this), + Bezeled = true, + Editable = true + }; + text.Changed += HandleTextChanged; + + stepper = new EtoStepper(); + stepper.Activated += HandleStepperActivated; + MinValue = 0; + MaxValue = 100; + Value = 0; + DecimalPlaces = 0; + Control.AddSubview(text); + Control.AddSubview(stepper); + } + + static void HandleStepperActivated(object sender, EventArgs e) + { + var handler = GetHandler(((NSView)sender).Superview) as NumericUpDownHandler; + if (handler != null) + { + var val = handler.stepper.DoubleValue; + if (Math.Abs(val) < 1E-10) + { + handler.text.IntValue = 0; + } + else + { + handler.text.DoubleValue = handler.stepper.DoubleValue; + } + handler.Callback.OnValueChanged(handler.Widget, EventArgs.Empty); + } + } + + static void HandleTextChanged(object sender, EventArgs e) + { + var handler = GetHandler(((NSView)((NSNotification)sender).Object).Superview) as NumericUpDownHandler; + if (handler != null) + { + handler.stepper.DoubleValue = handler.text.DoubleValue; + handler.Callback.OnValueChanged(handler.Widget, EventArgs.Empty); + } + } + + protected override void Initialize() + { + base.Initialize(); + var size = GetNaturalSize(Size.MaxValue); + Control.Frame = new CGRect(0, 0, size.Width, size.Height); + HandleEvent(Eto.Forms.Control.KeyDownEvent); + } + + public override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + if (e.Handled) + return; + if (e.KeyData == Keys.Down) + { + var val = Value; + var newval = Math.Max(val - 1, MinValue); + if (newval < val) + { + Value = newval; + Callback.OnValueChanged(Widget, EventArgs.Empty); + } + e.Handled = true; + } + else if (e.KeyData == Keys.Up) + { + var val = Value; + var newval = Math.Min(val + 1, MaxValue); + if (newval > val) + { + Value = newval; + Callback.OnValueChanged(Widget, EventArgs.Empty); + } + e.Handled = true; + } + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + if (naturalSize == null) + { + text.SizeToFit(); + stepper.SizeToFit(); + var naturalHeight = Math.Max(text.Frame.Height, stepper.Frame.Height); + naturalSize = new Size(80, (int)naturalHeight); + } + return naturalSize.Value; + } + + public bool ReadOnly + { + get { return text.Enabled; } + set + { + text.Enabled = value; + stepper.Enabled = value; + } + } + + public double Value + { + get { return text.DoubleValue; } + set + { + if (Math.Abs(value) < 1E-10) + { + stepper.IntValue = text.IntValue = 0; + } + else + { + stepper.DoubleValue = text.DoubleValue = value; + } + } + } + + public double MinValue + { + get + { + return stepper.MinValue; + } + set + { + stepper.MinValue = value; + } + } + + public double MaxValue + { + get + { + return stepper.MaxValue; + } + set + { + stepper.MaxValue = value; + } + } + + public override bool Enabled + { + get + { + return stepper.Enabled; + } + set + { + stepper.Enabled = value; + text.Enabled = value; + } + } + + public Font Font + { + get + { + return font ?? (font = new Font(new FontHandler(text.Font))); + } + set + { + font = value; + text.Font = font == null ? null : font.ControlObject as NSFont; + text.SizeToFit(); + LayoutIfNeeded(); + } + } + + public double Increment + { + get { return stepper.Increment; } + set { stepper.Increment = value; } + } + + int decimalPlaces; + public int DecimalPlaces + { + get { return decimalPlaces; } + set + { + if (value != decimalPlaces) + { + decimalPlaces = value; + var formatter = new NSNumberFormatter(); + formatter.NumberStyle = NSNumberFormatterStyle.Decimal; + formatter.MinimumFractionDigits = (nnint)decimalPlaces; + formatter.MaximumFractionDigits = (nnint)decimalPlaces; + text.Formatter = formatter; + } + } + } + + public Color TextColor + { + get { return text.TextColor.ToEto(); } + set { text.TextColor = value.ToNSUI(); } + } + + protected override void SetBackgroundColor(Color? color) + { + if (color != null) + text.BackgroundColor = color.Value.ToNSUI(); + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/PanelHandler.cs b/Source/Eto.Mac/Forms/Controls/PanelHandler.cs new file mode 100644 index 0000000000..94499e0e80 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/PanelHandler.cs @@ -0,0 +1,27 @@ +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class PanelHandler : MacPanel, Panel.IHandler + { + public PanelHandler() + { + Control = new MacEventView{ Handler = this }; + } + + public override NSView ContainerControl { get { return Control; } } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/PasswordBoxHandler.cs b/Source/Eto.Mac/Forms/Controls/PasswordBoxHandler.cs new file mode 100644 index 0000000000..1dad513c97 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/PasswordBoxHandler.cs @@ -0,0 +1,117 @@ +using System; +using Eto.Forms; +using Eto.Mac.Forms.Controls; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class PasswordBoxHandler : MacText, PasswordBox.IHandler, ITextBoxWithMaxLength + { + class EtoTextField : NSSecureTextField, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public PasswordBoxHandler Handler + { + get { return (PasswordBoxHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public override bool HasFocus + { + get + { + if (Widget.ParentWindow == null) + return false; + return ((IMacWindow)Widget.ParentWindow.Handler).FieldEditorObject == Control; + } + } + + public PasswordBoxHandler() + { + Control = new EtoTextField + { + Handler = this, + Bezeled = true, + Editable = true, + Selectable = true, + Formatter = new EtoFormatter { Handler = this } + }; + + Control.Cell.Scrollable = true; + Control.Cell.Wraps = false; + Control.Cell.UsesSingleLineMode = true; + + MaxLength = -1; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + Control.Changed += HandleChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + static void HandleChanged(object sender, EventArgs e) + { + var handler = GetHandler(sender) as PasswordBoxHandler; + if (handler != null) + handler.Callback.OnTextChanged(handler.Widget, EventArgs.Empty); + } + + public bool ReadOnly + { + get { return !Control.Editable; } + set { Control.Editable = !value; } + } + + public int MaxLength + { + get; + set; + } + + public Char PasswordChar + { // not supported on OSX + get { return '\0'; } + set { } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/ProgressBarHandler.cs b/Source/Eto.Mac/Forms/Controls/ProgressBarHandler.cs new file mode 100644 index 0000000000..a396612fd5 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/ProgressBarHandler.cs @@ -0,0 +1,103 @@ +using System; +using Eto.Forms; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class ProgressBarHandler : MacView, ProgressBar.IHandler + { + public class EtoSlider : NSProgressIndicator, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + } + + public override NSView ContainerControl { get { return Control; } } + + public ProgressBarHandler () + { + Control = new EtoSlider { Handler = this, Indeterminate = false }; + + MinValue = 0; + MaxValue = 100; + } + + protected override SizeF GetNaturalSize (SizeF availableSize) + { + return new Size (80, 30); + } + + public override bool Enabled { + get { return true; } + set { } + } + + public bool Indeterminate { + get { return Control.Indeterminate; } + set { + Control.Indeterminate = value; + if (value) + Control.StartAnimation (Control); + else + Control.StopAnimation (Control); + } + } + + public int MaxValue { + get { return (int)Control.MaxValue; } + set { + Control.MaxValue = value; + } + } + + public int MinValue { + get { return (int)Control.MinValue; } + set { + Control.MinValue = value; + } + } + + public int Value { + get { return (int)Control.DoubleValue; } + set { Control.DoubleValue = value; } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/RadioButtonHandler.cs b/Source/Eto.Mac/Forms/Controls/RadioButtonHandler.cs new file mode 100644 index 0000000000..fde5b98d07 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/RadioButtonHandler.cs @@ -0,0 +1,105 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class RadioButtonHandler : MacButton, RadioButton.IHandler + { + List group; + + public event EventHandler Activated; + + public class EtoRadioButton : NSButton, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public RadioButtonHandler() + { + Control = new EtoRadioButton { Handler = this, Title = string.Empty }; + Control.SetButtonType(NSButtonType.Radio); + Control.Activated += HandleActivated; + } + + static void HandleActivated(object sender, EventArgs e) + { + var handler = GetHandler(sender) as RadioButtonHandler; + if (handler != null) + { + if (handler.Activated != null) + handler.Activated(handler, e); + handler.Callback.OnClick(handler.Widget, EventArgs.Empty); + handler.Callback.OnCheckedChanged(handler.Widget, EventArgs.Empty); + + if (handler.Control.AcceptsFirstResponder() && handler.Control.Window != null) + handler.Control.Window.MakeFirstResponder(handler.Control); + } + } + + public void Create(RadioButton controller) + { + + if (controller != null) + { + var controllerInner = (RadioButtonHandler)controller.Handler; + if (controllerInner.group == null) + { + controllerInner.group = new List(); + controllerInner.group.Add(controller); + controllerInner.Activated += controllerInner.control_RadioSwitch; + } + controllerInner.group.Add(Widget); + Activated += controllerInner.control_RadioSwitch; + } + } + + void control_RadioSwitch(object sender, EventArgs e) + { + if (group != null) + { + foreach (RadioButton item in group) + { + var c = (NSButton)item.ControlObject; + var ischecked = (item.Handler == sender); + c.State = ischecked ? NSCellStateValue.On : NSCellStateValue.Off; + } + } + } + + public bool Checked + { + get { return Control.State == NSCellStateValue.On; } + set + { + if (value != Checked) + { + Control.State = value ? NSCellStateValue.On : NSCellStateValue.Off; + Callback.OnCheckedChanged(Widget, EventArgs.Empty); + if (Activated != null) + Activated(this, EventArgs.Empty); + + } + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/ScrollableHandler.cs b/Source/Eto.Mac/Forms/Controls/ScrollableHandler.cs new file mode 100644 index 0000000000..9e3ac2c56a --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/ScrollableHandler.cs @@ -0,0 +1,374 @@ +// can't use flipped right now - bug in monomac/xam.mac that causes crashing since FlippedView gets disposed incorrectly +// has something to do with using layers (background colors) at the same time +//#define USE_FLIPPED + +using System; +using SD = System.Drawing; +using Eto.Drawing; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class ScrollableHandler : MacPanel, Scrollable.IHandler + { + bool expandContentWidth = true; + bool expandContentHeight = true; + Point scrollPosition; + + public override NSView ContainerControl { get { return Control; } } + + class EtoScrollView : NSScrollView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public ScrollableHandler Handler + { + get { return (ScrollableHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public override void ResetCursorRects() + { + var cursor = Handler.Cursor; + if (cursor != null) + AddCursorRect(new CGRect(CGPoint.Empty, Frame.Size), cursor.ControlObject as NSCursor); + } + } + + class FlippedView : NSView + { + public WeakReference WeakHandler { get; set; } + + public ScrollableHandler Handler + { + get { return (ScrollableHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + #if USE_FLIPPED + public override bool IsFlipped + { + get { return true; } + } + #endif + #if !USE_FLIPPED + public override void SetFrameSize(CGSize newSize) + { + base.SetFrameSize(newSize); + Handler.SetPosition(Handler.scrollPosition, true); + } + #endif + } + + public ScrollableHandler() + { + Enabled = true; + Control = new EtoScrollView + { + Handler = this, + BackgroundColor = NSColor.Control, + BorderType = NSBorderType.BezelBorder, + DrawsBackground = false, + HasVerticalScroller = true, + HasHorizontalScroller = true, + AutohidesScrollers = true, + DocumentView = new FlippedView { Handler = this } + }; + + // only draw dirty regions, instead of entire scroll area + Control.ContentView.CopiesOnScroll = true; + } + + protected override void Initialize() + { + base.Initialize(); + if (!ContentControl.IsFlipped) + // need to keep the scroll position as it scrolls instead of calculating + HandleEvent(Scrollable.ScrollEvent); + } + + public override void AttachEvent(string id) + { + switch (id) + { + case Scrollable.ScrollEvent: + Control.ContentView.PostsBoundsChangedNotifications = true; + AddObserver(NSView.BoundsChangedNotification, e => + { + var handler = e.Handler as ScrollableHandler; + if (handler != null) + { + var view = handler.ContentControl; + if (!view.IsFlipped) + { + var contentBounds = handler.Control.ContentView.Bounds; + if (contentBounds.Height > 0) + handler.scrollPosition = new Point((int)contentBounds.X, (int)Math.Max(0, (view.Frame.Height - contentBounds.Height - contentBounds.Y))); + } + handler.Callback.OnScroll(handler.Widget, new ScrollEventArgs(handler.ScrollPosition)); + } + }, Control.ContentView); + break; + default: + base.AttachEvent(id); + break; + } + } + + public BorderType Border + { + get + { + switch (Control.BorderType) + { + case NSBorderType.BezelBorder: + return BorderType.Bezel; + case NSBorderType.LineBorder: + return BorderType.Line; + case NSBorderType.NoBorder: + return BorderType.None; + default: + throw new NotSupportedException(); + } + } + set + { + switch (value) + { + case BorderType.Bezel: + Control.BorderType = NSBorderType.BezelBorder; + break; + case BorderType.Line: + Control.BorderType = NSBorderType.LineBorder; + break; + case BorderType.None: + Control.BorderType = NSBorderType.NoBorder; + break; + default: + throw new NotSupportedException(); + } + } + } + + public override NSView ContentControl + { + get { return (NSView)Control.DocumentView; } + } + + public override void LayoutChildren() + { + base.LayoutChildren(); + UpdateScrollSizes(); + } + + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + UpdateScrollSizes(); + } + + Size GetBorderSize() + { + return Border == BorderType.None ? Size.Empty : new Size(2, 2); + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + return SizeF.Min(availableSize, base.GetNaturalSize(availableSize) + GetBorderSize()); + } + + protected override CGRect GetContentBounds() + { + var contentSize = Content.GetPreferredSize(SizeF.MaxValue); + + if (ExpandContentWidth) + contentSize.Width = Math.Max(ClientSize.Width, contentSize.Width); + if (ExpandContentHeight) + contentSize.Height = Math.Max(ClientSize.Height, contentSize.Height); + return new RectangleF(contentSize).ToNS(); + } + + protected override NSViewResizingMask ContentResizingMask() + { + return ContentControl.IsFlipped ? base.ContentResizingMask() : (NSViewResizingMask)0; + } + + void InternalSetFrameSize(CGSize size) + { + var view = ContentControl; + if (!view.IsFlipped) + { + var ctl = Content.GetContainerView(); + if (ctl != null) + { + var clientHeight = Control.DocumentVisibleRect.Size.Height; + ctl.Frame = new CGRect(new CGPoint(0, (nfloat)Math.Max(0, clientHeight - size.Height)), size); + size.Height = (nfloat)Math.Max(clientHeight, size.Height); + } + } + if (size != view.Frame.Size) + { + view.SetFrameSize(size); + } + } + + public void UpdateScrollSizes() + { + InternalSetFrameSize(GetContentBounds().Size); + } + + public override Color BackgroundColor + { + get + { + return Control.BackgroundColor.ToEto(); + } + set + { + Control.BackgroundColor = value.ToNSUI(); + Control.DrawsBackground = value.A > 0; + } + } + + public Point ScrollPosition + { + get + { + var view = ContentControl; + if (Widget.Loaded && view.IsFlipped) + { + return Control.ContentView.Bounds.Location.ToEtoPoint(); + } + return scrollPosition; + } + set + { + SetPosition(value, false); + } + } + + void SetPosition(Point value, bool force) + { + if (Widget.Loaded || force) + { + var view = ContentControl; + if (view.IsFlipped) + Control.ContentView.ScrollToPoint(value.ToNS()); + else if (Control.ContentView.Frame.Height > 0) + Control.ContentView.ScrollToPoint(new CGPoint(value.X, (nfloat)Math.Max(0, view.Frame.Height - Control.ContentView.Frame.Height - value.Y))); + Control.ReflectScrolledClipView(Control.ContentView); + } + scrollPosition = value; + } + + public Size ScrollSize + { + get { return ContentControl.Frame.Size.ToEtoSize(); } + set + { + InternalSetFrameSize(value.ToNS()); + } + } + + public override Size ClientSize + { + get + { + return Control.DocumentVisibleRect.Size.ToEtoSize(); + } + set + { + + } + } + + public override bool Enabled { get; set; } + + public override void SetContentSize(CGSize contentSize) + { + if (MinimumSize != Size.Empty) + { + contentSize.Width = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width); + contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height); + } + if (ExpandContentWidth) + contentSize.Width = (nfloat)Math.Max(ClientSize.Width, contentSize.Width); + if (ExpandContentHeight) + contentSize.Height = (nfloat)Math.Max(ClientSize.Height, contentSize.Height); + InternalSetFrameSize(contentSize); + } + + #if !USE_FLIPPED + public override void OnSizeChanged(EventArgs e) + { + base.OnSizeChanged(e); + UpdateScrollSizes(); + SetPosition(scrollPosition, true); + } + #endif + + public Rectangle VisibleRect + { + get { return new Rectangle(ScrollPosition, Size.Min(ScrollSize, ClientSize)); } + } + + public bool ExpandContentWidth + { + get { return expandContentWidth; } + set + { + if (expandContentWidth != value) + { + expandContentWidth = value; + UpdateScrollSizes(); + } + } + } + + public bool ExpandContentHeight + { + get { return expandContentHeight; } + set + { + if (expandContentHeight != value) + { + expandContentHeight = value; + UpdateScrollSizes(); + } + } + } + + public float MinimumZoom { get { return 1f; } set { } } + + public float MaximumZoom { get { return 1f; } set { } } + + public float Zoom { get { return 1f; } set { } } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/SearchBoxHandler.cs b/Source/Eto.Mac/Forms/Controls/SearchBoxHandler.cs new file mode 100644 index 0000000000..31ea751364 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/SearchBoxHandler.cs @@ -0,0 +1,135 @@ +using System; +using Eto.Drawing; +using Eto.Forms; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + /// + /// TODO: Try to eliminate code duplication between this class + /// and TextBoxHandler. + /// + public class SearchBoxHandler : MacText, SearchBox.IHandler, ITextBoxWithMaxLength + { + class EtoTextField : NSSearchField, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public SearchBoxHandler Handler + { + get { return (SearchBoxHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public override bool HasFocus + { + get + { + if (Widget.ParentWindow == null) + return false; + return ((IMacWindow)Widget.ParentWindow.Handler).FieldEditorObject == Control; + } + } + + public SearchBoxHandler() + { + Control = new EtoTextField + { + Handler = this, + Bezeled = true, + Editable = true, + Selectable = true, + Formatter = new EtoFormatter { Handler = this } + }; + + Control.Cell.Scrollable = true; + Control.Cell.Wraps = false; + Control.Cell.UsesSingleLineMode = true; + + MaxLength = -1; + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + var size = base.GetNaturalSize(availableSize); + size.Width = Math.Max(100, size.Height); + return size; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + Control.Changed += HandleTextChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + static void HandleTextChanged(object sender, EventArgs e) + { + var handler = GetHandler(sender) as SearchBoxHandler; + if (handler != null) + { + handler.Callback.OnTextChanged(handler.Widget, EventArgs.Empty); + } + } + + public bool ReadOnly + { + get { return !Control.Editable; } + set { Control.Editable = !value; } + } + + public int MaxLength + { + get; + set; + } + + public string PlaceholderText + { + get { return Control.Cell.PlaceholderString; } + set { Control.Cell.PlaceholderString = value ?? string.Empty; } + } + + public void SelectAll() + { + Control.SelectText(Control); + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/SliderHandler.cs b/Source/Eto.Mac/Forms/Controls/SliderHandler.cs new file mode 100644 index 0000000000..1b1298d13e --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/SliderHandler.cs @@ -0,0 +1,132 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class SliderHandler : MacControl, Slider.IHandler + { + SliderOrientation orientation; + + public class EtoSlider : NSSlider, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public SliderHandler() + { + Control = new EtoSlider { Handler = this }; + Control.Activated += HandleActivated; + MinValue = 0; + MaxValue = 100; + } + + static void HandleActivated(object sender, EventArgs e) + { + var handler = GetHandler(sender) as SliderHandler; + if (handler != null) + { + var newval = (int)Math.Round(handler.Control.DoubleValue); + if (newval != handler.Control.IntValue) + handler.Control.IntValue = newval; + + handler.Callback.OnValueChanged(handler.Widget, EventArgs.Empty); + } + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + return Orientation == SliderOrientation.Horizontal ? new Size(80, 30) : new Size(30, 80); + } + + public int MaxValue + { + get { return (int)Control.MaxValue; } + set + { + var old = TickFrequency; + Control.MaxValue = value; + TickFrequency = old; + } + } + + public int MinValue + { + get { return (int)Control.MinValue; } + set + { + var old = TickFrequency; + Control.MinValue = value; + TickFrequency = old; + } + } + + public int Value + { + get { return Control.IntValue; } + set { Control.IntValue = value; } + } + + public bool SnapToTick + { + get { return Control.AllowsTickMarkValuesOnly; } + set { Control.AllowsTickMarkValuesOnly = value; } + } + + public int TickFrequency + { + get + { + if (Control.TickMarksCount > 1) + return (int)((MaxValue - MinValue) / (Control.TickMarksCount - 1)); + return MaxValue - MinValue; + } + set + { + Control.TickMarksCount = ((MaxValue - MinValue) / value) + 1; + } + } + + public SliderOrientation Orientation + { + get + { + return orientation; + } + set + { + orientation = value; + // wha?!?! no way to do this other than change size or sumthun? + var size = Control.Frame.Size; + if (value == SliderOrientation.Vertical) + { + size.Height = size.Width + 1; + } + else + size.Width = size.Height + 1; + Control.SetFrameSize(size); + LayoutIfNeeded(); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/SpinnerHandler.cs b/Source/Eto.Mac/Forms/Controls/SpinnerHandler.cs new file mode 100644 index 0000000000..6b299f5386 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/SpinnerHandler.cs @@ -0,0 +1,97 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class SpinnerHandler : MacView, Spinner.IHandler + { + bool enabled; + readonly NSView view; + + public override NSView ContainerControl { get { return view; } } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + return new SizeF(16, 16); + } + + public SpinnerHandler() + { + Control = new NSProgressIndicator + { + Style = NSProgressIndicatorStyle.Spinning, + ControlSize = NSControlSize.Regular + }; + view = new MacEventView { Handler = this }; + view.AddSubview(Control); + } + + protected override void Initialize() + { + base.Initialize(); + HandleEvent(Eto.Forms.Control.SizeChangedEvent); + } + + public override void OnSizeChanged(EventArgs e) + { + base.OnSizeChanged(e); + var size = Math.Max(Size.Width, Size.Height); + if (size <= 8) + Control.ControlSize = NSControlSize.Mini; + else if (size <= 20) + Control.ControlSize = NSControlSize.Small; + else if (size <= 30) + Control.ControlSize = NSControlSize.Regular; + Control.SizeToFit(); + Control.CenterInParent(); + } + + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + if (enabled) + Control.StartAnimation(Control); + } + + public override void OnUnLoad(EventArgs e) + { + base.OnUnLoad(e); + if (enabled) + Control.StopAnimation(Control); + } + + public override bool Enabled + { + get { return enabled; } + set + { + if (enabled != value) + { + enabled = value; + if (Widget.Loaded) + { + if (enabled) + Control.StartAnimation(Control); + else + Control.StopAnimation(Control); + } + } + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/SplitterHandler.cs b/Source/Eto.Mac/Forms/Controls/SplitterHandler.cs new file mode 100644 index 0000000000..5fc399151b --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/SplitterHandler.cs @@ -0,0 +1,367 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using sd = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class SplitterHandler : MacView, Splitter.IHandler + { + Control panel1; + Control panel2; + int? position; + SplitterFixedPanel fixedPanel; + bool initialPositionSet; + + public bool RecurseToChildren { get { return true; } } + + public override NSView ContainerControl { get { return Control; } } + + public virtual Size ClientSize { get { return Size; } set { Size = value; } } + + public override void AttachEvent(string id) + { + switch (id) + { + case Splitter.PositionChangedEvent: + // handled by delegate + break; + default: + base.AttachEvent(id); + break; + } + } + + static void ResizeSubviews(SplitterHandler handler, CGSize oldSize) + { + var splitView = handler.Control; + var dividerThickness = splitView.DividerThickness; + var panel1Rect = splitView.Subviews[0].Frame; + var panel2Rect = splitView.Subviews[1].Frame; + var newFrame = splitView.Frame; + + if (oldSize.Height == 0 && oldSize.Width == 0) + oldSize = newFrame.Size; + + if (splitView.IsVertical) + { + panel2Rect.Y = 0; + panel2Rect.Height = panel1Rect.Height = newFrame.Height; + panel1Rect = new CGRect(CGPoint.Empty, panel1Rect.Size); + if (handler.position == null) + { + panel1Rect.Width = (nfloat)Math.Max(0, newFrame.Width / 2); + panel2Rect.Width = (nfloat)Math.Max(0, newFrame.Width - panel1Rect.Width - dividerThickness); + } + else + { + var pos = handler.position.Value; + switch (handler.fixedPanel) + { + case SplitterFixedPanel.Panel1: + panel1Rect.Width = (nfloat)Math.Max(0, Math.Min(newFrame.Width - dividerThickness, pos)); + panel2Rect.Width = (nfloat)Math.Max(0, newFrame.Width - panel1Rect.Width - dividerThickness); + break; + case SplitterFixedPanel.Panel2: + panel2Rect.Width = (nfloat)Math.Max(0, Math.Min(newFrame.Width - dividerThickness, oldSize.Width - pos - dividerThickness)); + panel1Rect.Width = (nfloat)Math.Max(0, newFrame.Width - panel2Rect.Width - dividerThickness); + break; + case SplitterFixedPanel.None: + var oldscale = newFrame.Width / oldSize.Width; + panel1Rect.Width = (nfloat)Math.Max(0, Math.Min(newFrame.Width - dividerThickness, pos * oldscale)); + panel2Rect.Width = (nfloat)Math.Max(0, newFrame.Width - panel1Rect.Width - dividerThickness); + break; + } + } + panel2Rect.X = (nfloat)Math.Min(panel1Rect.Width + dividerThickness, newFrame.Width); + } + else + { + panel2Rect.X = 0; + panel2Rect.Width = panel1Rect.Width = newFrame.Width; + panel1Rect = new CGRect(CGPoint.Empty, panel1Rect.Size); + if (handler.position == null) + { + panel1Rect.Height = (nfloat)Math.Max(0, newFrame.Height / 2); + panel2Rect.Height = (nfloat)Math.Max(0, newFrame.Height - panel1Rect.Height - dividerThickness); + } + else + { + var pos = handler.position.Value; + switch (handler.fixedPanel) + { + case SplitterFixedPanel.Panel1: + panel1Rect.Height = (nfloat)Math.Max(0, Math.Min(newFrame.Height - dividerThickness, pos)); + panel2Rect.Height = (nfloat)Math.Max(0, newFrame.Height - panel1Rect.Height - dividerThickness); + break; + case SplitterFixedPanel.Panel2: + panel2Rect.Height = (nfloat)Math.Max(0, Math.Min(newFrame.Height - dividerThickness, oldSize.Height - pos - dividerThickness)); + panel1Rect.Height = (nfloat)Math.Max(0, newFrame.Height - panel2Rect.Height - dividerThickness); + break; + case SplitterFixedPanel.None: + var oldscale = newFrame.Height / oldSize.Height; + panel1Rect.Height = (nfloat)Math.Max(0, Math.Min(newFrame.Height - dividerThickness, pos * oldscale)); + panel2Rect.Height = (nfloat)Math.Max(0, newFrame.Height - panel1Rect.Height - dividerThickness); + break; + } + } + panel2Rect.Y = (nfloat)Math.Min(panel1Rect.Height + dividerThickness, newFrame.Height); + } + + splitView.Subviews[0].Frame = panel1Rect; + splitView.Subviews[1].Frame = panel2Rect; + } + + class SVDelegate : NSSplitViewDelegate + { + WeakReference handler; + + public SplitterHandler Handler { get { return (SplitterHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override void Resize(NSSplitView splitView, CGSize oldSize) + { + SplitterHandler.ResizeSubviews(Handler, oldSize); + } + + public override nfloat ConstrainSplitPosition(NSSplitView splitView, nfloat proposedPosition, nint subviewDividerIndex) + { + return Handler.Enabled ? proposedPosition : Handler.Position; + } + + public override void DidResizeSubviews(NSNotification notification) + { + var subview = Handler.Control.Subviews[0]; + if (subview != null && Handler.position != null && Handler.initialPositionSet && Handler.Widget.Loaded && Handler.Widget.ParentWindow != null && Handler.Widget.ParentWindow.Loaded) + { + Handler.position = Handler.Control.IsVertical ? (int)subview.Frame.Width : (int)subview.Frame.Height; + Handler.Callback.OnPositionChanged(Handler.Widget, EventArgs.Empty); + } + } + } + // stupid hack for OSX 10.5 so that mouse down/drag/up events fire in children properly.. + class EtoSplitView : NSSplitView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public SplitterHandler Handler + { + get { return (SplitterHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + public override void MouseDown(NSEvent theEvent) + { + var cursor = NSCursor.CurrentCursor; + if (cursor == NSCursor.ResizeLeftCursor || cursor == NSCursor.ResizeRightCursor || cursor == NSCursor.ResizeLeftRightCursor + || cursor == NSCursor.ResizeUpCursor || cursor == NSCursor.ResizeDownCursor || cursor == NSCursor.ResizeUpDownCursor) + base.MouseDown(theEvent); + } + + public override void MouseDragged(NSEvent theEvent) + { + var cursor = NSCursor.CurrentCursor; + if (cursor == NSCursor.ResizeLeftCursor || cursor == NSCursor.ResizeRightCursor || cursor == NSCursor.ResizeLeftRightCursor + || cursor == NSCursor.ResizeUpCursor || cursor == NSCursor.ResizeDownCursor || cursor == NSCursor.ResizeUpDownCursor) + base.MouseDragged(theEvent); + } + + public override void MouseUp(NSEvent theEvent) + { + var cursor = NSCursor.CurrentCursor; + if (cursor == NSCursor.ResizeLeftCursor || cursor == NSCursor.ResizeRightCursor || cursor == NSCursor.ResizeLeftRightCursor + || cursor == NSCursor.ResizeUpCursor || cursor == NSCursor.ResizeDownCursor || cursor == NSCursor.ResizeUpDownCursor) + base.MouseUp(theEvent); + } + } + + public SplitterHandler() + { + Enabled = true; + Control = new EtoSplitView { Handler = this }; + Control.DividerStyle = NSSplitViewDividerStyle.Thin; + Control.AddSubview(new NSView { AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable }); + Control.AddSubview(new NSView { AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable }); + Control.IsVertical = true; + Control.Delegate = new SVDelegate { Handler = this }; + } + + public int Position + { + get { return position ?? 0; } + set + { + position = value; + if (Widget.Loaded) + Control.ResizeSubviewsWithOldSize(CGSize.Empty); + } + } + + public SplitterOrientation Orientation + { + get + { + return Control.IsVertical ? SplitterOrientation.Horizontal : SplitterOrientation.Vertical; + } + set + { + Control.IsVertical = value == SplitterOrientation.Horizontal; + if (Widget.Loaded) + Control.ResizeSubviewsWithOldSize(CGSize.Empty); + } + } + + public override bool Enabled { get; set; } + + public SplitterFixedPanel FixedPanel + { + get { return fixedPanel; } + set + { + fixedPanel = value; + if (Widget.Loaded) + Control.ResizeSubviewsWithOldSize(CGSize.Empty); + } + } + + public Control Panel1 + { + get { return panel1; } + set + { + if (panel1 != value) + { + var view = value.GetContainerView(); + Control.ReplaceSubviewWith(Control.Subviews[0], view ?? new NSView()); + panel1 = value; + } + } + } + + public Control Panel2 + { + get { return panel2; } + set + { + if (panel2 != value) + { + var view = value.GetContainerView(); + Control.ReplaceSubviewWith(Control.Subviews[1], view ?? new NSView()); + panel2 = value; + } + } + } + + void SetInitialSplitPosition() + { + if (position == null) + { + switch (fixedPanel) + { + case SplitterFixedPanel.Panel1: + var size1 = panel1.GetPreferredSize(SizeF.MaxValue); + position = (int)(Orientation == SplitterOrientation.Horizontal ? size1.Width : size1.Height); + break; + case SplitterFixedPanel.Panel2: + var size2 = panel2.GetPreferredSize(SizeF.MaxValue); + if (Orientation == SplitterOrientation.Horizontal) + position = (int)(Control.Frame.Width - size2.Width - Control.DividerThickness); + else + position = (int)(Control.Frame.Height - size2.Height - Control.DividerThickness); + break; + } + } + } + + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + SetInitialSplitPosition(); + Control.ResizeSubviewsWithOldSize(CGSize.Empty); + initialPositionSet = true; + } + + public override void OnUnLoad(EventArgs e) + { + base.OnUnLoad(e); + initialPositionSet = false; + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + var size = new SizeF(); + + var p1size = panel1.GetPreferredSize(availableSize); + var p2size = panel2.GetPreferredSize(availableSize); + if (Control.IsVertical) + { + if (position != null) + { + switch (FixedPanel) + { + case SplitterFixedPanel.None: + case SplitterFixedPanel.Panel1: + p1size.Width = Math.Max(p1size.Width, position.Value); + break; + case SplitterFixedPanel.Panel2: + p2size.Width = Math.Max(p2size.Width, Size.Width - position.Value); + break; + } + } + if (position != null) + p1size.Width = position.Value; + size.Width = (float)(p1size.Width + p2size.Width + Control.DividerThickness); + size.Height = Math.Max(p1size.Height, p2size.Height); + } + else + { + if (position != null) + { + switch (FixedPanel) + { + case SplitterFixedPanel.None: + case SplitterFixedPanel.Panel1: + p1size.Height = Math.Max(p1size.Height, position.Value); + break; + case SplitterFixedPanel.Panel2: + p2size.Height = Math.Max(p2size.Height, Size.Height - position.Value); + break; + } + } + if (position != null) + p1size.Height = position.Value; + size.Height = (float)(p1size.Height + p2size.Height + Control.DividerThickness); + size.Width = Math.Max(p1size.Width, p2size.Width); + } + return size; + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/TabControlHandler.cs b/Source/Eto.Mac/Forms/Controls/TabControlHandler.cs new file mode 100644 index 0000000000..56c795c0d3 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/TabControlHandler.cs @@ -0,0 +1,126 @@ +using System; +using System.Linq; +using Eto.Forms; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class TabControlHandler : MacView, TabControl.IHandler + { + bool disableSelectedIndexChanged; + + public bool RecurseToChildren { get { return true; } } + + public override NSView ContainerControl { get { return Control; } } + + public class EtoTabView : NSTabView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + // CWEN: should have some form of implementation here + public virtual Size ClientSize { get { return Size; } set { Size = value; } } + + public TabControlHandler () + { + Enabled = true; + Control = new EtoTabView { Handler = this }; + } + + public override void OnLoadComplete (EventArgs e) + { + base.OnLoadComplete (e); + Control.ShouldSelectTabViewItem += HandleShouldSelectTabViewItem; + Control.DidSelect += HandleDidSelect; + } + + public override void OnUnLoad(EventArgs e) + { + base.OnUnLoad(e); + Control.ShouldSelectTabViewItem -= HandleShouldSelectTabViewItem; + Control.DidSelect -= HandleDidSelect; + } + + static bool HandleShouldSelectTabViewItem(NSTabView tabView, NSTabViewItem item) + { + var handler = ((EtoTabView)tabView).WeakHandler.Target as TabControlHandler; + var tab = handler.Widget.Pages.FirstOrDefault (r => ((TabPageHandler)r.Handler).TabViewItem == item); + return tab == null || tab.Enabled; + } + + static void HandleDidSelect (object sender, NSTabViewItemEventArgs e) + { + var handler = GetHandler(sender) as TabControlHandler; + if (handler != null) + { + if (!handler.disableSelectedIndexChanged) + handler.Callback.OnSelectedIndexChanged(handler.Widget, EventArgs.Empty); + } + } + + public int SelectedIndex + { + get { return (int)(Control.Selected == null ? -1 : Control.IndexOf(Control.Selected)); } + set { Control.SelectAt (value); } + } + + public override bool Enabled { get; set; } + + public void InsertTab (int index, TabPage page) + { + if (index == -1) + Control.Add (((TabPageHandler)page.Handler).TabViewItem); + else + Control.Insert (((TabPageHandler)page.Handler).TabViewItem, index); + } + + public void ClearTabs () + { + foreach (var tab in Control.Items) + Control.Remove (tab); + } + + public void RemoveTab (int index, TabPage page) + { + disableSelectedIndexChanged = true; + try { + var isSelected = SelectedIndex == index; + Control.Remove (((TabPageHandler)page.Handler).TabViewItem); + if (isSelected && Control.Items.Length > 0) + SelectedIndex = Math.Min (index, Control.Items.Length - 1); + if (Widget.Loaded) + Callback.OnSelectedIndexChanged(Widget, EventArgs.Empty); + } finally { + disableSelectedIndexChanged = false; + } + } + + protected override SizeF GetNaturalSize (SizeF availableSize) + { + var size = base.GetNaturalSize(availableSize); + foreach (var tab in Widget.Pages.Where(r => r.Visible)) { + size = SizeF.Max (size, tab.GetPreferredSize(availableSize)); + } + return size; + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/TabPageHandler.cs b/Source/Eto.Mac/Forms/Controls/TabPageHandler.cs new file mode 100644 index 0000000000..743759905f --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/TabPageHandler.cs @@ -0,0 +1,126 @@ +using System; +using Eto.Forms; +using SD = System.Drawing; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#elif !XAMMAC2 +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class TabPageHandler : MacPanel, TabPage.IHandler + { + const int ICON_PADDING = 2; + Image image; + static readonly IntPtr selDrawInRectFromRectOperationFractionRespectFlippedHints = Selector.GetHandle("drawInRect:fromRect:operation:fraction:respectFlipped:hints:"); + + public override NSView ContainerControl { get { return Control; } } + + public NSTabViewItem TabViewItem { get; private set; } + + class MyTabViewItem : NSTabViewItem + { + WeakReference handler; + + public TabPageHandler Handler { get { return (TabPageHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override void DrawLabel(bool shouldTruncateLabel, CGRect labelRect) + { + if (Handler.image != null) + { + var nsimage = (NSImage)Handler.image.ControlObject; + + if (nsimage.RespondsToSelector(new Selector(selDrawInRectFromRectOperationFractionRespectFlippedHints))) + nsimage.Draw(new CGRect(labelRect.X, labelRect.Y, labelRect.Height, labelRect.Height), new CGRect(CGPoint.Empty, nsimage.Size), NSCompositingOperation.SourceOver, 1, true, null); + else + { + #pragma warning disable 618 + nsimage.Flipped = View.IsFlipped; + #pragma warning restore 618 + nsimage.Draw(new CGRect(labelRect.X, labelRect.Y, labelRect.Height, labelRect.Height), new CGRect(CGPoint.Empty, nsimage.Size), NSCompositingOperation.SourceOver, 1); + } + + labelRect.X += labelRect.Height + ICON_PADDING; + labelRect.Width -= labelRect.Height + ICON_PADDING; + base.DrawLabel(shouldTruncateLabel, labelRect); + } + base.DrawLabel(shouldTruncateLabel, labelRect); + } + + // TODO: Mac64 + #if !Mac64 && !XAMMAC2 + public override CGSize SizeOfLabel (bool computeMin) + { + var size = base.SizeOfLabel (computeMin); + if (Handler.image != null) { + size.Width += size.Height + ICON_PADDING; + } + return size; + } + #endif + } + + public TabPageHandler() + { + TabViewItem = new MyTabViewItem + { + Handler = this, + Identifier = new NSString(Guid.NewGuid().ToString()), + View = new MacEventView { Handler = this } + }; + Control = TabViewItem.View; + Enabled = true; + } + + public string Text + { + get { return TabViewItem.Label; } + set { TabViewItem.Label = value; } + } + + public Image Image + { + get { return image; } + set + { + image = value; + if (image != null) + { + } + } + } + + public override NSView ContentControl + { + get { return TabViewItem.View; } + } + + public override bool Enabled { get; set; } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/TextAreaHandler.cs b/Source/Eto.Mac/Forms/Controls/TextAreaHandler.cs new file mode 100644 index 0000000000..023e364bb2 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/TextAreaHandler.cs @@ -0,0 +1,378 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using sd = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using nnint = System.Int32; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +using nnint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +using nnint = System.Int32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class TextAreaHandler : MacView, TextArea.IHandler + { + int? lastCaretIndex; + Range lastSelection; + + public class EtoTextView : NSTextView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public override void OnKeyDown(KeyEventArgs e) + { + if (!AcceptsTab) + { + if (e.KeyData == Keys.Tab) + { + if (Control.Window != null) + Control.Window.SelectNextKeyView(Control); + return; + } + if (e.KeyData == (Keys.Tab | Keys.Shift)) + { + if (Control.Window != null) + Control.Window.SelectPreviousKeyView(Control); + return; + } + } + if (!AcceptsReturn && e.KeyData == Keys.Enter) + { + return; + } + base.OnKeyDown(e); + } + + public NSScrollView Scroll { get; private set; } + + public override NSView ContainerControl + { + get { return Scroll; } + } + // Remove use of delegate when events work correctly in MonoMac + public class EtoDelegate : NSTextViewDelegate + { + WeakReference handler; + + public TextAreaHandler Handler { get { return (TextAreaHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override void TextDidChange(NSNotification notification) + { + Handler.Callback.OnTextChanged(Handler.Widget, EventArgs.Empty); + } + + public override void DidChangeSelection(NSNotification notification) + { + var selection = Handler.Selection; + if (selection != Handler.lastSelection) + { + Handler.Callback.OnSelectionChanged(Handler.Widget, EventArgs.Empty); + Handler.lastSelection = selection; + } + var caretIndex = Handler.CaretIndex; + if (caretIndex != Handler.lastCaretIndex) + { + Handler.Callback.OnCaretIndexChanged(Handler.Widget, EventArgs.Empty); + Handler.lastCaretIndex = caretIndex; + } + } + } + + public TextAreaHandler() + { + Control = new EtoTextView + { + Handler = this, + Delegate = new EtoDelegate { Handler = this }, + AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable, + HorizontallyResizable = true, + VerticallyResizable = true, + Editable = true, + RichText = false, + AllowsDocumentBackgroundColorChange = false, + Selectable = true, + AllowsUndo = true, + MinSize = CGSize.Empty, + MaxSize = new CGSize(float.MaxValue, float.MaxValue) + }; + Control.TextContainer.WidthTracksTextView = true; + + Scroll = new EtoScrollView + { + Handler = this, + AutoresizesSubviews = true, + HasVerticalScroller = true, + HasHorizontalScroller = true, + AutohidesScrollers = true, + BorderType = NSBorderType.BezelBorder, + DocumentView = Control + }; + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + #pragma warning disable 612,618 + return TextArea.DefaultSize; + #pragma warning restore 612,618 + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + /*Control.TextDidChange += (sender, e) => { + Widget.OnTextChanged (EventArgs.Empty); + };*/ + break; + case TextArea.SelectionChangedEvent: + /*Control.DidChangeSelection += (sender, e) => { + var selection = this.Selection; + if (selection != lastSelection) { + Widget.OnSelectionChanged (EventArgs.Empty); + lastSelection = selection; + } + };*/ + break; + case TextArea.CaretIndexChangedEvent: + /*Control.DidChangeSelection += (sender, e) => { + var caretIndex = Handler.CaretIndex; + if (caretIndex != lastCaretIndex) { + Handler.Widget.OnCaretIndexChanged (EventArgs.Empty); + lastCaretIndex = caretIndex; + } + };*/ + break; + default: + base.AttachEvent(id); + break; + } + } + + public bool ReadOnly + { + get { return !Control.Editable; } + set { Control.Editable = !value; } + } + + public override bool Enabled + { + get { return Control.Selectable; } + set + { + Control.Selectable = value; + if (!value) + { + Control.TextColor = NSColor.DisabledControlText; + Control.BackgroundColor = NSColor.ControlBackground; + } + else + { + Control.TextColor = TextColor.ToNSUI(); + Control.BackgroundColor = BackgroundColor.ToNSUI(); + } + } + } + + public string Text + { + get + { + return Control.Value; + } + set + { + Control.Value = value; + Control.DisplayIfNeeded(); + } + } + + Color? textColor; + + public Color TextColor + { + get { return textColor ?? NSColor.ControlText.ToEto(); } + set + { + if (value != textColor) + { + textColor = value; + Control.TextColor = textColor.Value.ToNSUI(); + Control.InsertionPointColor = textColor.Value.ToNSUI(); + } + } + } + + Color? backgroundColor; + + public override Color BackgroundColor + { + get { return backgroundColor ?? NSColor.ControlBackground.ToEto(); } + set + { + if (value != backgroundColor) + { + backgroundColor = value; + Control.BackgroundColor = backgroundColor.Value.ToNSUI(); + } + } + } + + Font font; + + public Font Font + { + get + { + if (font == null) + font = new Font(new FontHandler(Control.Font)); + return font; + } + set + { + if (value != font) + { + font = value; + Control.Font = font.ToNSFont(); + } + LayoutIfNeeded(); + } + } + + public bool Wrap + { + get + { + return Control.TextContainer.WidthTracksTextView; + } + set + { + if (value) + { + Control.TextContainer.WidthTracksTextView = true; + Control.TextContainer.ContainerSize = new CGSize(Scroll.DocumentVisibleRect.Size.Width, float.MaxValue); + } + else + { + Control.TextContainer.WidthTracksTextView = false; + Control.TextContainer.ContainerSize = new CGSize(float.MaxValue, float.MaxValue); + } + } + } + + public string SelectedText + { + get + { + var range = Control.SelectedRange; + if (range.Location >= 0 && range.Length > 0) + return Control.Value.Substring((int)range.Location, (int)range.Length); + return null; + } + set + { + if (value != null) + { + var range = Control.SelectedRange; + Control.Replace(range, value); + range.Length = (nnint)value.Length; + Control.SelectedRange = range; + } + } + } + + public Range Selection + { + get { return Control.SelectedRange.ToEto(); } + set { Control.SelectedRange = value.ToNS(); } + } + + public void SelectAll() + { + Control.SelectAll(Control); + } + + public int CaretIndex + { + get { return (int)Control.SelectedRange.Location; } + set { Control.SelectedRange = new NSRange(value, 0); } + } + + static readonly object AcceptsTabKey = new object(); + + public bool AcceptsTab + { + get { return Widget.Properties.Get(AcceptsTabKey) ?? true; } + set + { + Widget.Properties[AcceptsTabKey] = value; + if (!value) + HandleEvent(Eto.Forms.Control.KeyDownEvent); + } + } + + static readonly object AcceptsReturnKey = new object(); + + public bool AcceptsReturn + { + get { return Widget.Properties.Get(AcceptsReturnKey) ?? true; } + set + { + Widget.Properties[AcceptsReturnKey] = value; + if (!value) + HandleEvent(Eto.Forms.Control.KeyDownEvent); + } + } + + public void Append(string text, bool scrollToCursor) + { + var range = new NSRange(Control.Value.Length, 0); + Control.Replace(range, text); + range = new NSRange(Control.Value.Length, 0); + Control.SelectedRange = range; + if (scrollToCursor) + Control.ScrollRangeToVisible(range); + } + + public HorizontalAlign HorizontalAlign + { + get { return Control.Alignment.ToEto(); } + set { Control.Alignment = value.ToNS(); } + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/TextBoxHandler.cs b/Source/Eto.Mac/Forms/Controls/TextBoxHandler.cs new file mode 100644 index 0000000000..df1d2542b5 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/TextBoxHandler.cs @@ -0,0 +1,158 @@ +using System; +using Eto.Forms; +using Eto.Mac.Forms.Controls; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public interface ITextBoxWithMaxLength + { + int MaxLength { get; set; } + } + + public class EtoFormatter : NSFormatter + { + WeakReference handler; + + public ITextBoxWithMaxLength Handler { get { return (ITextBoxWithMaxLength)handler.Target; } set { handler = new WeakReference(value); } } + + public override string StringFor(NSObject value) + { + if (value == null) + return string.Empty; + var str = (NSString)value; + //if (str != null && value.Handle != IntPtr.Zero) + return str.ToString(); + } + + [Export("getObjectValue:forString:errorDescription:")] + public bool GetObjectValue(ref IntPtr obj, IntPtr value, ref IntPtr error) + { + obj = value; + return true; + } + + [Export("isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:")] + public bool IsPartialStringValid(ref NSString value, IntPtr proposedSelRange, NSString origString, NSRange origSelRange, ref IntPtr error) + { + if (Handler.MaxLength >= 0) + { + int size = (int)value.Length; + if (size > Handler.MaxLength) + { + return false; + } + } + return true; + } + + [Export("attributedStringForObjectValue:withDefaultAttributes:")] + public NSAttributedString AttributedStringForObjectValue(IntPtr anObject, NSDictionary attributes) + { + return null; + } + } + + public class EtoTextField : NSTextField, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public TextBoxHandler Handler + { + get { return (TextBoxHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public class TextBoxHandler : MacText, TextBox.IHandler, ITextBoxWithMaxLength + { + public override bool HasFocus + { + get + { + if (Widget.ParentWindow == null) + return false; + return ((IMacWindow)Widget.ParentWindow.Handler).FieldEditorObject == Control; + } + } + + public TextBoxHandler() + { + Control = new EtoTextField + { + Handler = this, + Bezeled = true, + Editable = true, + Selectable = true, + Formatter = new EtoFormatter { Handler = this } + }; + Control.Cell.Scrollable = true; + Control.Cell.Wraps = false; + Control.Cell.UsesSingleLineMode = true; + + MaxLength = -1; + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + var size = base.GetNaturalSize(availableSize); + size.Width = Math.Max(100, size.Height); + return size; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TextControl.TextChangedEvent: + Control.Changed += HandleTextChanged; + break; + default: + base.AttachEvent(id); + break; + } + } + + static void HandleTextChanged (object sender, EventArgs e) + { + var h = GetHandler(sender) as TextBoxHandler; + h.Callback.OnTextChanged(h.Widget, EventArgs.Empty); + } + + public bool ReadOnly + { + get { return !Control.Editable; } + set { Control.Editable = !value; } + } + + public int MaxLength + { + get; + set; + } + + public string PlaceholderText + { + get { return ((NSTextFieldCell)Control.Cell).PlaceholderString; } + set { ((NSTextFieldCell)Control.Cell).PlaceholderString = value ?? string.Empty; } + } + + public void SelectAll() + { + Control.SelectText(Control); + } + } +} diff --git a/Source/Eto.Mac/Forms/Controls/TreeGridViewHandler.cs b/Source/Eto.Mac/Forms/Controls/TreeGridViewHandler.cs new file mode 100644 index 0000000000..0885a768ed --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/TreeGridViewHandler.cs @@ -0,0 +1,446 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using System.Linq; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using nnint = System.Int32; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +using nnint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +using nnint = System.Int32; +#endif +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class TreeGridViewHandler : GridHandler, TreeGridView.IHandler, IDataViewHandler + { + ITreeGridStore store; + readonly Dictionary cachedItems = new Dictionary (); + readonly Dictionary topitems = new Dictionary (); + + class EtoTreeItem : NSObject + { + Dictionary items; + + public EtoTreeItem () + { + } + + public EtoTreeItem (IntPtr ptr) + : base(ptr) + { + } + + public EtoTreeItem (EtoTreeItem value) + { + this.Item = value.Item; + this.items = value.items; + } + + public ITreeGridItem Item { get; set; } + + public Dictionary Items { + get { + if (items == null) + items = new Dictionary (); + return items; + } + } + } + + bool ChildIsSelected (ITreeGridItem item) + { + var node = SelectedItem; + + while (node != null) { + if (node == item) + return true; + node = node.Parent; + } + return false; + } + + class EtoOutlineDelegate : NSOutlineViewDelegate + { + WeakReference handler; + public TreeGridViewHandler Handler { get { return (TreeGridViewHandler)handler.Target; } set { handler = new WeakReference(value); } } + + bool? collapsedItemIsSelected; + ITreeGridItem lastSelected; + bool skipSelectionChanged; + + public override void SelectionDidChange (NSNotification notification) + { + if (!skipSelectionChanged) { + Handler.Callback.OnSelectionChanged(Handler.Widget, EventArgs.Empty); + var item = Handler.SelectedItem; + if (!object.ReferenceEquals (item, lastSelected)) { + Handler.Callback.OnSelectedItemChanged(Handler.Widget, EventArgs.Empty); + lastSelected = item; + } + } + } + + public override void ItemDidCollapse (NSNotification notification) + { + var myitem = notification.UserInfo [(NSString)"NSObject"] as EtoTreeItem; + if (myitem != null) { + myitem.Item.Expanded = false; + Handler.Callback.OnCollapsed(Handler.Widget, new TreeGridViewItemEventArgs (myitem.Item)); + if (collapsedItemIsSelected == true) { + Handler.SelectedItem = myitem.Item; + collapsedItemIsSelected = null; + skipSelectionChanged = false; + } + } + } + + public override bool ShouldExpandItem (NSOutlineView outlineView, NSObject item) + { + var myitem = item as EtoTreeItem; + if (myitem != null) { + var args = new TreeGridViewItemCancelEventArgs (myitem.Item); + Handler.Callback.OnExpanding(Handler.Widget, args); + return !args.Cancel; + } + return true; + } + + public override bool ShouldCollapseItem (NSOutlineView outlineView, NSObject item) + { + var myitem = item as EtoTreeItem; + if (myitem != null) { + var args = new TreeGridViewItemCancelEventArgs (myitem.Item); + Handler.Callback.OnCollapsing(Handler.Widget, args); + if (!args.Cancel && !Handler.AllowMultipleSelection) { + collapsedItemIsSelected = Handler.ChildIsSelected (myitem.Item); + skipSelectionChanged = collapsedItemIsSelected ?? false; + } + else + collapsedItemIsSelected = null; + return !args.Cancel; + } + collapsedItemIsSelected = null; + return true; + } + + public override void ItemDidExpand (NSNotification notification) + { + var myitem = notification.UserInfo [(NSString)"NSObject"] as EtoTreeItem; + if (myitem != null) { + myitem.Item.Expanded = true; + Handler.Callback.OnExpanded(Handler.Widget, new TreeGridViewItemEventArgs (myitem.Item)); + Handler.AutoSizeColumns(); + } + } + + public override void DidClickTableColumn (NSOutlineView outlineView, NSTableColumn tableColumn) + { + var column = Handler.GetColumn (tableColumn); + Handler.Callback.OnColumnHeaderClick(Handler.Widget, new GridColumnEventArgs (column.Widget)); + } + + public override void WillDisplayCell (NSOutlineView outlineView, NSObject cell, NSTableColumn tableColumn, NSObject item) + { + var colHandler = Handler.GetColumn (tableColumn); + var myitem = item as EtoTreeItem; + if (myitem != null) { + Handler.OnCellFormatting(colHandler.Widget, myitem.Item, -1, cell as NSCell); + } + } + } + + class EtoDataSource : NSOutlineViewDataSource + { + WeakReference handler; + public TreeGridViewHandler Handler { get { return (TreeGridViewHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override NSObject GetObjectValue (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) + { + var colHandler = Handler.GetColumn (tableColumn); + if (colHandler != null) { + var myitem = (EtoTreeItem)item; + return colHandler.GetObjectValue (myitem.Item); + } + return null; + } + + public override void SetObjectValue (NSOutlineView outlineView, NSObject theObject, NSTableColumn tableColumn, NSObject item) + { + var colHandler = Handler.GetColumn (tableColumn); + if (colHandler != null) { + var myitem = (EtoTreeItem)item; + colHandler.SetObjectValue (myitem.Item, theObject); + } + } + + public override bool ItemExpandable (NSOutlineView outlineView, NSObject item) + { + var myitem = item as EtoTreeItem; + return myitem != null && myitem.Item.Expandable; + } + + public override NSObject GetChild (NSOutlineView outlineView, nint childIndex, NSObject item) + { + Dictionary items; + var myitem = item as EtoTreeItem; + items = myitem == null ? Handler.topitems : myitem.Items; + + EtoTreeItem etoItem; + if (!items.TryGetValue((int)childIndex, out etoItem)) { + var parentItem = myitem != null ? (ITreeGridStore)myitem.Item : Handler.store; + etoItem = new EtoTreeItem{ Item = parentItem [(int)childIndex] }; + Handler.cachedItems.Add (etoItem.Item, etoItem); + items.Add((int)childIndex, etoItem); + } + return etoItem; + } + + public override nint GetChildrenCount (NSOutlineView outlineView, NSObject item) + { + if (Handler.store == null) + return 0; + + if (item == null) + return Handler.store.Count; + + var myitem = item as EtoTreeItem; + return ((ITreeGridStore)myitem.Item).Count; + } + } + + public class EtoOutlineView : NSOutlineView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public object Handler + { + get { return WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + } + + public override object EventObject { + get { return Control; } + } + + public override void AttachEvent (string id) + { + switch (id) { + case TreeGridView.ExpandedEvent: + case TreeGridView.ExpandingEvent: + case TreeGridView.CollapsedEvent: + case TreeGridView.CollapsingEvent: + case TreeGridView.SelectedItemChangedEvent: + case Grid.SelectionChangedEvent: + case Grid.ColumnHeaderClickEvent: + // handled in delegate + break; + default: + base.AttachEvent (id); + break; + } + } + + public TreeGridViewHandler() + { + Control = new EtoOutlineView + { + Handler = this, + Delegate = new EtoOutlineDelegate { Handler = this }, + DataSource = new EtoDataSource { Handler = this }, + //HeaderView = null, + //AutoresizesOutlineColumn = true, + //AllowsColumnResizing = false, + AllowsColumnReordering = false, + FocusRingType = NSFocusRingType.None, + ColumnAutoresizingStyle = NSTableViewColumnAutoresizingStyle.None + }; + + } + + public ITreeGridStore DataStore { + get { return store; } + set { + store = value; + topitems.Clear (); + cachedItems.Clear (); + Control.ReloadData (); + ExpandItems (null); + if (Widget.Loaded) + AutoSizeColumns (); + } + } + + static IEnumerable GetParents (ITreeGridItem item) + { + var parent = item.Parent; + while (parent != null) { + yield return parent; + parent = parent.Parent; + } + } + + EtoTreeItem GetCachedItem (ITreeGridItem item) + { + EtoTreeItem myitem; + return cachedItems.TryGetValue(item, out myitem) ? myitem : null; + } + + int CountRows (ITreeGridItem item) + { + if (!item.Expanded) + return 0; + + var rows = 0; + var container = item as IDataStore; + if (container != null) { + rows += container.Count; + for (int i = 0; i < container.Count; i++) + { + rows += CountRows (container[i]); + } + } + return rows; + } + + int FindRow (IDataStore container, ITreeGridItem item) + { + int row = 0; + for (int i = 0; i < container.Count; i++) { + var current = container [i]; + if (object.ReferenceEquals (current, item)) { + return row; + } + row ++; + row += CountRows (current); + } + return -1; + } + + int? ExpandToItem (ITreeGridItem item) + { + var parents = GetParents (item).Reverse (); + IDataStore lastParent = null; + var row = 0; + foreach (var parent in parents) { + if (lastParent != null) { + var foundRow = FindRow (lastParent, parent); + if (foundRow == -1) + return null; + row += foundRow; + var foundItem = Control.ItemAtRow (row) as EtoTreeItem; + if (foundItem == null) + return null; + Control.ExpandItem (foundItem); + foundItem.Item.Expanded = true; + row ++; + } + lastParent = parent as IDataStore; + } + if (lastParent != null) { + var foundRow = FindRow (lastParent, item); + if (foundRow == -1) + return null; + + return foundRow + row; + } + return null; + } + + public ITreeGridItem SelectedItem { + get { + var row = Control.SelectedRow; + if (row == -1) + return null; + var myitem = (EtoTreeItem)Control.ItemAtRow(row); + return myitem.Item; + } + set { + if (value == null) + Control.DeselectAll(Control); + else { + + EtoTreeItem myitem; + if (cachedItems.TryGetValue (value, out myitem)) { + var cachedRow = Control.RowForItem (myitem); + if (cachedRow >= 0) { + Control.ScrollRowToVisible (cachedRow); + Control.SelectRow ((nnint)cachedRow, false); + return; + } + } + + var row = ExpandToItem (value); + if (row != null) { + Control.ScrollRowToVisible (row.Value); + Control.SelectRow ((nnint)row.Value, false); + } + } + } + } + + void ExpandItems (NSObject parent) + { + var ds = Control.DataSource; + var count = ds.GetChildrenCount (Control, parent); + for (int i=0; i 0) + Control.OutlineTableColumn = ((GridColumnHandler)Widget.Columns[0].Handler).Control; + } + else if (Widget.Columns.Count == 0) + Control.OutlineTableColumn = null; + } + + public override object GetItem (int row) + { + var item = Control.ItemAtRow(row) as EtoTreeItem; + return item != null ? item.Item : null; + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/TreeViewHandler.cs b/Source/Eto.Mac/Forms/Controls/TreeViewHandler.cs new file mode 100644 index 0000000000..61e4d44993 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/TreeViewHandler.cs @@ -0,0 +1,633 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +using Eto.Mac.Forms.Menu; +using System.Linq; +using sd = System.Drawing; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if Mac64 +using nnint = System.UInt64; +#else +using nnint = System.Int32; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class TreeViewHandler : MacControl, TreeView.IHandler + { + ITreeStore top; + ContextMenu contextMenu; + readonly Dictionary cachedItems = new Dictionary(); + readonly Dictionary topitems = new Dictionary(); + bool selectionChanging; + bool raiseExpandEvents = true; + readonly NSTableColumn column; + + public NSScrollView Scroll { get; private set; } + + public class EtoTreeItem : MacImageData + { + Dictionary items; + ITreeItem item; + + public EtoTreeItem() + { + } + + public EtoTreeItem(IntPtr ptr) + : base(ptr) + { + } + + public EtoTreeItem(EtoTreeItem value) + : base (value) + { + this.Item = value.Item; + this.items = value.items; + } + + public ITreeItem Item + { + get { return item; } + set + { + item = value; + if (item.Image != null) + Image = Item.Image.ControlObject as NSImage; + Text = (NSString)item.Text; + } + } + + public Dictionary Items + { + get + { + if (items == null) + items = new Dictionary(); + return items; + } + } + + public override object Clone() + { + return new EtoTreeItem(this); + } + } + + public class EtoOutlineDelegate : NSOutlineViewDelegate + { + WeakReference handler; + public TreeViewHandler Handler { get { return (TreeViewHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override bool ShouldEditTableColumn(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) + { + var myitem = item as EtoTreeItem; + if (myitem != null) + { + var args = new TreeViewItemCancelEventArgs(myitem.Item); + Handler.Callback.OnLabelEditing(Handler.Widget, args); + return !args.Cancel; + } + return true; + } + + public override void WillDisplayCell(NSOutlineView outlineView, NSObject cell, NSTableColumn tableColumn, NSObject item) + { + var c = cell as NSTextFieldCell; + if (c != null && + Handler.textColor != null) + c.TextColor = Handler.textColor.Value.ToNSUI(); + } + + public override void SelectionDidChange(NSNotification notification) + { + if (!Handler.selectionChanging) + Handler.Callback.OnSelectionChanged(Handler.Widget, EventArgs.Empty); + } + + public override void ItemDidCollapse(NSNotification notification) + { + if (Handler.raiseExpandEvents) + { + var myitem = notification.UserInfo[(NSString)"NSObject"] as EtoTreeItem; + if (myitem != null && myitem.Item.Expanded) + { + myitem.Item.Expanded = false; + Handler.Callback.OnCollapsed(Handler.Widget, new TreeViewItemEventArgs(myitem.Item)); + } + } + } + + public override bool ShouldExpandItem(NSOutlineView outlineView, NSObject item) + { + if (Handler.raiseExpandEvents) + { + var myitem = item as EtoTreeItem; + if (myitem != null && !myitem.Item.Expanded) + { + var args = new TreeViewItemCancelEventArgs(myitem.Item); + Handler.Callback.OnExpanding(Handler.Widget, args); + return !args.Cancel; + } + } + return true; + } + + public override bool ShouldCollapseItem(NSOutlineView outlineView, NSObject item) + { + if (Handler.raiseExpandEvents) + { + var myitem = item as EtoTreeItem; + if (myitem != null && myitem.Item.Expanded) + { + var args = new TreeViewItemCancelEventArgs(myitem.Item); + Handler.Callback.OnCollapsing(Handler.Widget, args); + return !args.Cancel; + } + } + return true; + } + + public override void ItemDidExpand(NSNotification notification) + { + if (Handler.raiseExpandEvents) + { + var myitem = notification.UserInfo[(NSString)"NSObject"] as EtoTreeItem; + if (myitem != null && !myitem.Item.Expanded) + { + myitem.Item.Expanded = true; + Handler.Callback.OnExpanded(Handler.Widget, new TreeViewItemEventArgs(myitem.Item)); + Handler.ExpandItems(myitem); + } + } + } + } + + public class EtoDataSource : NSOutlineViewDataSource + { + WeakReference handler; + public TreeViewHandler Handler { get { return (TreeViewHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override NSObject GetObjectValue(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) + { + var myitem = item as EtoTreeItem; + return myitem; + } + + public override bool ItemExpandable(NSOutlineView outlineView, NSObject item) + { + var myitem = item as EtoTreeItem; + return myitem != null && myitem.Item.Expandable; + } + + public override NSObject GetChild(NSOutlineView outlineView, nint childIndex, NSObject item) + { + Dictionary items; + var myitem = item as EtoTreeItem; + items = myitem == null ? Handler.topitems : myitem.Items; + + EtoTreeItem etoItem; + if (!items.TryGetValue((int)childIndex, out etoItem)) + { + var parentItem = myitem != null ? myitem.Item : Handler.top; + etoItem = new EtoTreeItem { Item = parentItem [(int)childIndex] }; + Handler.cachedItems[etoItem.Item] = etoItem; + items[(int)childIndex] = etoItem; + } + return etoItem; + } + + public override nint GetChildrenCount(NSOutlineView outlineView, NSObject item) + { + if (Handler.top == null) + return 0; + + if (item == null) + return Handler.top.Count; + + var myitem = item as EtoTreeItem; + return myitem.Item.Count; + } + + public override void SetObjectValue(NSOutlineView outlineView, NSObject theObject, NSTableColumn tableColumn, NSObject item) + { + var myitem = item as EtoTreeItem; + if (myitem != null) + { + var args = new TreeViewItemEditEventArgs(myitem.Item, (string)(NSString)theObject); + Handler.Callback.OnLabelEdited(Handler.Widget, args); + if (!args.Cancel) + myitem.Item.Text = args.Label; + } + } + } + + public class EtoOutlineView : NSOutlineView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public TreeViewHandler Handler + { + get { return (TreeViewHandler)WeakHandler.Target; } + set { WeakHandler = new WeakReference(value); } + } + + /// + /// The area to the right and below the rows is not filled with the background + /// color. This fixes that. See http://orangejuiceliberationfront.com/themeing-nstableview/ + /// + public override void DrawBackground(CGRect clipRect) + { + var backgroundColor = Handler.BackgroundColor; + if (backgroundColor != Colors.Transparent) { + backgroundColor.ToNSUI ().Set (); + NSGraphics.RectFill (clipRect); + } else + base.DrawBackground (clipRect); + } + } + + public override NSView ContainerControl + { + get { return Scroll; } + } + + public TreeViewHandler() + { + Control = new EtoOutlineView + { + Handler = this, + Delegate = new EtoOutlineDelegate{ Handler = this }, + DataSource = new EtoDataSource{ Handler = this }, + HeaderView = null, + AutoresizesOutlineColumn = true, + AllowsColumnResizing = false, + FocusRingType = NSFocusRingType.None, + ColumnAutoresizingStyle = NSTableViewColumnAutoresizingStyle.FirstColumnOnly + }; + column = new NSTableColumn + { + DataCell = new MacImageListItemCell { + UsesSingleLineMode = true, + Editable = true + }, + Editable = false + }; + + + Control.AddColumn(column); + Control.OutlineTableColumn = column; + + Scroll = new EtoScrollView + { + Handler = this, + HasVerticalScroller = true, + HasHorizontalScroller = true, + AutohidesScrollers = true, + BorderType = NSBorderType.BezelBorder, + DocumentView = Control + }; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case TreeView.ExpandedEvent: + case TreeView.ExpandingEvent: + case TreeView.CollapsedEvent: + case TreeView.CollapsingEvent: + case TreeView.SelectionChangedEvent: + // handled in delegate + break; + case TreeView.ActivatedEvent: + Widget.KeyDown += (sender, e) => { + if (!column.Editable && e.KeyData == Keys.Enter) + { + Callback.OnActivated(Widget, new TreeViewItemEventArgs(SelectedItem)); + e.Handled = true; + } + }; + Control.DoubleClick += HandleDoubleClick; + break; + case TreeView.LabelEditedEvent: + case TreeView.LabelEditingEvent: + // handled in delegate + break; + case TreeView.NodeMouseClickEvent: + /* TODO */ + // Control.NodeMouseClick += (s, e) => + // { + // this.Widget.OnNodeMouseClick( + // Generator.Convert(e)); + // }; + break; + + default: + base.AttachEvent(id); + break; + } + } + + static void HandleDoubleClick (object sender, EventArgs e) + { + var handler = GetHandler(sender) as TreeViewHandler; + if (handler != null) + { + if (handler.column.Editable) + handler.Control.EditColumn(handler.Control.ClickedColumn, handler.Control.ClickedRow, new NSEvent(), true); + else + handler.Callback.OnActivated(handler.Widget, new TreeViewItemEventArgs(handler.SelectedItem)); + } + } + + public ITreeStore DataStore + { + get { return top; } + set + { + top = value; + topitems.Clear(); + cachedItems.Clear(); + Control.ReloadData(); + ExpandItems(null); + } + } + + public ITreeItem SelectedItem + { + get + { + var row = Control.SelectedRow; + if (row == -1) + return null; + var myitem = Control.ItemAtRow(row) as EtoTreeItem; + return myitem == null ? null : myitem.Item; + } + set + { + PerformSelect(value, true); + } + } + + void PerformSelect(ITreeItem item, bool scrollToRow) + { + if (item == null) + Control.DeselectAll(Control); + else + { + + EtoTreeItem myitem; + if (cachedItems.TryGetValue(item, out myitem)) + { + var cachedRow = Control.RowForItem(myitem); + if (cachedRow >= 0) + { + if (scrollToRow) + Control.ScrollRowToVisible(cachedRow); + Control.SelectRow((nnint)cachedRow, false); + return; + } + } + + var row = ExpandToItem(item); + if (row != null) + { + if (scrollToRow) + Control.ScrollRowToVisible(row.Value); + Control.SelectRow((nnint)row.Value, false); + } + } + } + + public ContextMenu ContextMenu + { + get { return contextMenu; } + set + { + contextMenu = value; + Control.Menu = contextMenu == null ? null : ((ContextMenuHandler)contextMenu.Handler).Control; + } + } + + static IEnumerable GetParents(ITreeItem item) + { + var parent = item.Parent; + while (parent != null) + { + yield return parent; + parent = parent.Parent; + } + } + + int CountRows(ITreeItem item) + { + if (!item.Expanded) + return 0; + + var rows = 0; + var container = item; + if (container != null) + { + rows += container.Count; + for (int i = 0; i < container.Count; i++) + { + rows += CountRows(container[i]); + } + } + return rows; + } + + int FindRow(IDataStore container, ITreeItem item) + { + int row = 0; + for (int i = 0; i < container.Count; i++) + { + var current = container[i]; + if (object.ReferenceEquals(current, item)) + { + return row; + } + row ++; + row += CountRows(current); + } + return -1; + } + + int? ExpandToItem(ITreeItem item) + { + var parents = GetParents(item).Reverse(); + IDataStore lastParent = null; + var row = 0; + foreach (var parent in parents) + { + if (lastParent != null) + { + var foundRow = FindRow(lastParent, parent); + if (foundRow == -1) + return null; + row += foundRow; + var foundItem = Control.ItemAtRow(row) as EtoTreeItem; + if (foundItem == null) + return null; + Control.ExpandItem(foundItem); + foundItem.Item.Expanded = true; + row ++; + } + lastParent = parent; + } + if (lastParent != null) + { + var foundRow = FindRow(lastParent, item); + if (foundRow == -1) + return null; + + return foundRow + row; + } + return null; + } + + void SetItemExpansion(NSObject parent) + { + raiseExpandEvents = false; + var item = parent as EtoTreeItem; + if (item != null && item.Item.Expandable && item.Item.Expanded != Control.IsItemExpanded(item)) + { + if (item.Item.Expanded) + Control.ExpandItem(item); + else + Control.CollapseItem(item, false); + } + raiseExpandEvents = true; + } + + void ExpandItems(NSObject parent) + { + raiseExpandEvents = false; + var item = parent as EtoTreeItem; + PerformExpandItems(item); + raiseExpandEvents = true; + } + + void PerformExpandItems(NSObject parent) + { + var ds = Control.DataSource; + var count = ds.GetChildrenCount(Control, parent); + for (int i=0; i= 0) + topitems.Remove((int)row); + myitem.Items.Clear(); + SetItemExpansion(myitem); + Control.ReloadItem(myitem, true); + ExpandItems(myitem); + } + else + RefreshData(); + } + + public ITreeItem GetNodeAt(PointF point) + { + point += Scroll.ContentView.Bounds.Location.ToEto(); + var row = Control.GetRow(point.ToNS()); + if (row >= 0) + { + var item = Control.ItemAtRow(row) as EtoTreeItem; + if (item != null) + return item.Item; + } + return null; + } + + Color? textColor; + public Color TextColor + { + get { return textColor ?? Colors.Transparent; } + set { textColor = value; } + } + + public bool LabelEdit + { + get { return column.Editable; } + set { column.Editable = value; } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Controls/WebViewHandler.cs b/Source/Eto.Mac/Forms/Controls/WebViewHandler.cs new file mode 100644 index 0000000000..c711bd4b73 --- /dev/null +++ b/Source/Eto.Mac/Forms/Controls/WebViewHandler.cs @@ -0,0 +1,343 @@ +using System; +using Eto.Forms; +using System.Linq; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using wk = WebKit; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using wk = MonoMac.WebKit; +#endif + +namespace Eto.Mac.Forms.Controls +{ + public class WebViewHandler : MacView, WebView.IHandler + { + static readonly Selector selIgnore = new Selector("ignore"); + static readonly Selector selUse = new Selector("use"); + + public override NSView ContainerControl { get { return Control; } } + + NewWindowHandler newWindowHandler; + + public WebViewHandler() + { + Enabled = true; + Control = new EtoWebView + { + Handler = this, + UIDelegate = new UIDelegate { Handler = this } + }; + } + + protected override void Initialize() + { + base.Initialize(); + HandleEvent(WebView.OpenNewWindowEvent); // needed to provide default implementation + HandleEvent(WebView.DocumentLoadingEvent); + } + + public class EtoWebView : wk.WebView, IMacControl + { + public WeakReference WeakHandler { get; set; } + + public WebViewHandler Handler { get { return (WebViewHandler)WeakHandler.Target; } set { WeakHandler = new WeakReference(value); } } + } + + public class NewWindowHandler : NSObject + { + public WebViewHandler Handler { get { return WebView.Handler; } set { WebView.Handler = value; } } + + public EtoWebView WebView { get; set; } + + public NewWindowHandler() + { + WebView = new EtoWebView(); + WebView.WeakUIDelegate = this; + WebView.WeakPolicyDelegate = this; + WebView.WeakResourceLoadDelegate = this; + } + + [Export("webView:decidePolicyForNavigationAction:request:frame:decisionListener:")] + public void DecidePolicyForNavigation(wk.WebView webView, NSDictionary action, NSUrlRequest request, wk.WebFrame frame, NSObject listener) + { + var url = (NSUrl)action.ObjectForKey(new NSString("WebActionOriginalURLKey")); + var args = new WebViewNewWindowEventArgs(new Uri(url.AbsoluteString), frame.Name); + Handler.Callback.OnOpenNewWindow(Handler.Widget, args); + if (!args.Cancel) + NSWorkspace.SharedWorkspace.OpenUrl(url); + listener.PerformSelector(selIgnore, null, 0); + } + } + + class PromptDialog : Dialog + { + readonly TextBox textBox; + readonly Label prompt; + + public string Prompt + { + get { return prompt.Text; } + set { prompt.Text = value; } + } + + public string Value + { + get { return textBox.Text; } + set { textBox.Text = value; } + } + + public PromptDialog() + { + this.MinimumSize = new Size(400, 0); + var layout = new DynamicLayout { Padding = new Padding(20, 10) }; + layout.BeginVertical(padding: Padding.Empty, spacing: new Size(10, 10)); + layout.Add(prompt = new Label()); + layout.Add(textBox = new TextBox(), yscale: true); + layout.BeginVertical(padding: Padding.Empty); + layout.AddRow(null, CancelButton(), OkButton()); + layout.EndVertical(); + + Content = layout; + } + + Control CancelButton() + { + var button = new Button { Text = "Cancel" }; + AbortButton = button; + button.Click += (sender, e) => Close(false); + return button; + } + + Control OkButton() + { + var button = new Button { Text = "OK" }; + DefaultButton = button; + button.Click += (sender, e) => Close(true); + return button; + } + } + + public class UIDelegate : wk.WebUIDelegate + { + WeakReference handler; + + public WebViewHandler Handler { get { return (WebViewHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override void UIRunJavaScriptAlertPanelMessage(wk.WebView sender, string withMessage, wk.WebFrame initiatedByFrame) + { + MessageBox.Show(Handler.Widget, withMessage); + } + + public override bool UIRunJavaScriptConfirmationPanel(wk.WebView sender, string withMessage, wk.WebFrame initiatedByFrame) + { + return MessageBox.Show(Handler.Widget, withMessage, MessageBoxButtons.YesNo) == DialogResult.Yes; + } + + public override string UIRunJavaScriptTextInputPanelWithFrame(wk.WebView sender, string prompt, string defaultText, wk.WebFrame initiatedByFrame) + { + var dialog = new PromptDialog + { + Prompt = prompt, + Value = defaultText, + Title = Handler.DocumentTitle + }; + return dialog.ShowModal(Handler.Widget) ? dialog.Value : string.Empty; + } + + public override NSMenuItem[] UIGetContextMenuItems(wk.WebView sender, NSDictionary forElement, NSMenuItem[] defaultMenuItems) + { + return Handler.BrowserContextMenuEnabled ? defaultMenuItems : null; + } + + public override void UIRunOpenPanelForFileButton(wk.WebView sender, wk.WebOpenPanelResultListener resultListener) + { + var openDlg = new OpenFileDialog(); + if (openDlg.ShowDialog(Handler.Widget.ParentWindow) == DialogResult.Ok) + { + resultListener.ChooseFilenames(openDlg.Filenames.ToArray()); + } + } + + public override void UIPrintFrameView(wk.WebView sender, wk.WebFrameView frameView) + { + const float margin = 24f; + var printOperation = frameView.GetPrintOperation(new NSPrintInfo + { + VerticallyCentered = false, + LeftMargin = margin, + RightMargin = margin, + TopMargin = margin, + BottomMargin = margin + }); + printOperation.PrintPanel.Options = + NSPrintPanelOptions.ShowsCopies | + NSPrintPanelOptions.ShowsOrientation | + NSPrintPanelOptions.ShowsPageSetupAccessory | + NSPrintPanelOptions.ShowsPageRange | + NSPrintPanelOptions.ShowsPaperSize | + NSPrintPanelOptions.ShowsPreview | + NSPrintPanelOptions.ShowsPrintSelection | + NSPrintPanelOptions.ShowsScaling; + printOperation.RunOperation(); + } + + public override wk.WebView UICreateWebView(wk.WebView sender, NSUrlRequest request) + { + Handler.newWindowHandler = new NewWindowHandler { Handler = Handler }; + return Handler.newWindowHandler.WebView; + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case WebView.NavigatedEvent: + HandleEvent(WebView.DocumentLoadedEvent); + break; + case WebView.DocumentLoadedEvent: + Control.FinishedLoad += HandleFinishedLoad; + break; + case WebView.DocumentLoadingEvent: + Control.DecidePolicyForNavigation += HandleDecidePolicyForNavigation; + break; + case WebView.OpenNewWindowEvent: + Control.DecidePolicyForNewWindow += HandleDecidePolicyForNewWindow; + break; + case WebView.DocumentTitleChangedEvent: + Control.ReceivedTitle += HandleReceivedTitle; + break; + default: + base.AttachEvent(id); + break; + } + } + + static void HandleReceivedTitle(object sender, wk.WebFrameTitleEventArgs e) + { + var handler = GetHandler(e.ForFrame.WebView) as WebViewHandler; + if (handler != null) + { + handler.Callback.OnDocumentTitleChanged(handler.Widget, new WebViewTitleEventArgs(e.Title)); + } + } + + static void HandleDecidePolicyForNewWindow(object sender, wk.WebNewWindowPolicyEventArgs e) + { + var handler = GetHandler(sender) as WebViewHandler; + if (handler != null) + { + var args = new WebViewNewWindowEventArgs(new Uri(e.Request.Url.AbsoluteString), e.NewFrameName); + handler.Callback.OnOpenNewWindow(handler.Widget, args); + if (!args.Cancel) + NSWorkspace.SharedWorkspace.OpenUrl(e.Request.Url); + e.DecisionToken.PerformSelector(selIgnore, null, 0); + } + } + + static void HandleDecidePolicyForNavigation(object sender, wk.WebNavigationPolicyEventArgs e) + { + var handler = GetHandler(e.Frame.WebView) as WebViewHandler; + if (handler != null) + { + var args = new WebViewLoadingEventArgs(new Uri(e.Request.Url.AbsoluteString), e.Frame == handler.Control.MainFrame); + handler.Callback.OnDocumentLoading(handler.Widget, args); + if (args.Cancel) + e.DecisionToken.PerformSelector(selIgnore, null, 0); + else + e.DecisionToken.PerformSelector(selUse, null, 0); + } + } + + static void HandleFinishedLoad(object sender, wk.WebFrameEventArgs e) + { + var handler = GetHandler(e.ForFrame.WebView) as WebViewHandler; + if (handler != null) + { + var args = new WebViewLoadedEventArgs(handler.Url); + if (e.ForFrame == handler.Control.MainFrame) + handler.Callback.OnNavigated(handler.Widget, args); + handler.Callback.OnDocumentLoaded(handler.Widget, args); + } + } + + public Uri Url + { + get { return new Uri(Control.MainFrameUrl); } + set + { + Control.MainFrameUrl = value == null ? null : value.AbsoluteUri; + } + } + + public string DocumentTitle + { + get { return Control.MainFrameTitle; } + } + + public string ExecuteScript(string script) + { + var fullScript = string.Format("var fn = function () {{ {0} }}; fn();", script); + return Control.StringByEvaluatingJavaScriptFromString(fullScript); + } + + public void LoadHtml(string html, Uri baseUri) + { + Control.MainFrame.LoadHtmlString(html, baseUri.ToNS()); + } + + public void Stop() + { + Control.MainFrame.StopLoading(); + } + + public void Reload() + { + Control.Reload(Control); + } + + public void GoBack() + { + Control.GoBack(); + } + + public void GoForward() + { + Control.GoForward(); + } + + public override bool Enabled { get; set; } + + public bool CanGoBack + { + get { return Control.CanGoBack(); } + } + + public bool CanGoForward + { + get { return Control.CanGoForward(); } + } + + public void ShowPrintDialog() + { + Control.Print(Control); + } + + public bool BrowserContextMenuEnabled + { + get; + set; + } + } +} + diff --git a/Source/Eto.Mac/Forms/CursorHandler.cs b/Source/Eto.Mac/Forms/CursorHandler.cs new file mode 100644 index 0000000000..7cbfb18072 --- /dev/null +++ b/Source/Eto.Mac/Forms/CursorHandler.cs @@ -0,0 +1,54 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + public class CursorHandler : WidgetHandler, Cursor.IHandler + { + public void Create (CursorType cursor) + { + switch (cursor) { + case CursorType.Arrow: + Control = NSCursor.ArrowCursor; + break; + case CursorType.Crosshair: + Control = NSCursor.CrosshairCursor; + break; + case CursorType.Default: + Control = NSCursor.CurrentSystemCursor; + break; + case CursorType.HorizontalSplit: + Control = NSCursor.ResizeLeftRightCursor; + break; + case CursorType.IBeam: + Control = NSCursor.IBeamCursor; + break; + case CursorType.Move: + Control = NSCursor.OpenHandCursor; + break; + case CursorType.Pointer: + Control = NSCursor.PointingHandCursor; + break; + case CursorType.VerticalSplit: + Control = NSCursor.ResizeUpDownCursor; + break; + default: + throw new NotSupportedException(); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/DialogHandler.cs b/Source/Eto.Mac/Forms/DialogHandler.cs new file mode 100644 index 0000000000..61b03dc1a1 --- /dev/null +++ b/Source/Eto.Mac/Forms/DialogHandler.cs @@ -0,0 +1,171 @@ +using System; +using SD = System.Drawing; +using Eto.Forms; +using System.Threading.Tasks; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms +{ + public class DialogHandler : MacWindow, Dialog.IHandler + { + Button button; + MacModal.ModalHelper session; + + protected override bool DisposeControl { get { return false; } } + + class DialogWindow : MyWindow + { + public new DialogHandler Handler + { + get { return base.Handler as DialogHandler; } + set { base.Handler = value; } + } + + public DialogWindow() + : base(new CGRect(0, 0, 200, 200), NSWindowStyle.Closable | NSWindowStyle.Titled, NSBackingStore.Buffered, false) + { + } + + [Export("cancelOperation:")] + public void CancelOperation(IntPtr sender) + { + if (Handler.AbortButton != null) + { + var handler = Handler.AbortButton.Handler as IMacViewHandler; + if (handler != null) + { + var callback = handler.Callback as Button.ICallback; + if (callback != null) + callback.OnClick(Handler.AbortButton, EventArgs.Empty); + } + } + } + } + + public DialogDisplayMode DisplayMode { get; set; } + + public Button AbortButton { get; set; } + + public Button DefaultButton + { + get { return button; } + set + { + button = value; + + if (button != null) + { + var b = button.ControlObject as NSButton; + Control.DefaultButtonCell = b == null ? null : b.Cell; + } + else + Control.DefaultButtonCell = null; + } + } + + public DialogHandler() + { + var dlg = new DialogWindow(); + dlg.Handler = this; + Control = dlg; + ConfigureWindow(); + } + + public void ShowModal(Control parent) + { + session = null; + if (parent != null && parent.ParentWindow != null) + { + var nswindow = parent.ParentWindow.ControlObject as NSWindow; + if (nswindow != null) + Control.ParentWindow = nswindow; + } + Callback.OnShown(Widget, EventArgs.Empty); + + Widget.Closed += HandleClosed; + if (DisplayMode.HasFlag(DialogDisplayMode.Attached)) + MacModal.RunSheet(Control, out session); + else + { + Control.MakeKeyWindow(); + MacModal.Run(Control, out session); + } + } + + public Task ShowModalAsync(Control parent) + { + var tcs = new TaskCompletionSource(); + session = null; + if (parent != null && parent.ParentWindow != null) + { + var nswindow = parent.ParentWindow.ControlObject as NSWindow; + if (nswindow != null) + Control.ParentWindow = nswindow; + } + Callback.OnShown(Widget, EventArgs.Empty); + + Widget.Closed += HandleClosed; + if (DisplayMode.HasFlag(DialogDisplayMode.Attached)) + { + MacModal.BeginSheet(Control, out session, () => tcs.SetResult(true)); + } + else + { + Control.MakeKeyWindow(); + Application.Instance.AsyncInvoke(() => + { + MacModal.Run(Control, out session); + tcs.SetResult(true); + }); + + } + return tcs.Task; + } + + void HandleClosed(object sender, EventArgs e) + { + if (session != null) + session.Stop(); + Widget.Closed -= HandleClosed; + } + + public override void Close() + { + if (session != null && session.IsSheet) + session.Stop(); + else + base.Close(); + } + + } +} diff --git a/Source/Eto.Mac/Forms/FontDialogHandler.cs b/Source/Eto.Mac/Forms/FontDialogHandler.cs new file mode 100644 index 0000000000..6c7d75a17c --- /dev/null +++ b/Source/Eto.Mac/Forms/FontDialogHandler.cs @@ -0,0 +1,141 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + class FontDialogHelper : NSWindowDelegate + { + public static FontDialogHelper Instance { get; set; } + + public FontDialogHandler Handler { get; set; } + + [Export("changeFont:")] + public void ChangeFont(NSFontManager sender) + { + var font = sender.ConvertFont(NSFont.SystemFontOfSize(NSFont.SystemFontSize)); + Handler.Font = font != null ? new Font(new FontHandler(font)) : null; + Handler.Callback.OnFontChanged(Handler.Widget, EventArgs.Empty); + } + + public override void WillClose(NSNotification notification) + { + Handler.Manager.Target = null; + Handler.Manager.Action = null; + FontDialogHelper.Instance = null; + } + + public override void DidResignKey(NSNotification notification) + { + Handler.Control.PerformClose(this); + } + + [Export("changeAttributes:")] + void ChangeAttributes(NSObject sender) + { + } + + [Export("validModesForFontPanel:")] + NSFontPanelMode ValidModesForFontPanel(NSFontPanel fontPanel) + { + return NSFontPanelMode.SizeMask | NSFontPanelMode.FaceMask | NSFontPanelMode.CollectionMask; + } + + [Export("modalClosed:")] + public void ModalClosed(NSNotification notification) + { + Handler.Control.PerformClose(this); + NSNotificationCenter.DefaultCenter.RemoveObserver(this); + } + } + + public class FontDialogHandler : MacObject, FontDialog.IHandler + { + public NSFontManager Manager + { + get { return NSFontManager.SharedFontManager; } + } + + public FontDialogHandler() + { + Control = NSFontPanel.SharedFontPanel; + } + + public override void AttachEvent(string id) + { + switch (id) + { + case FontDialog.FontChangedEvent: + // handled by helper + break; + default: + base.AttachEvent(id); + break; + } + } + + public DialogResult ShowDialog(Window parent) + { + NSWindow parentWindow; + if (parent != null) + { + parentWindow = parent.ParentWindow.ControlObject as NSWindow ?? NSApplication.SharedApplication.KeyWindow; + if (parentWindow != null) + Control.ParentWindow = parentWindow; + } + else + parentWindow = NSApplication.SharedApplication.KeyWindow; + + FontDialogHelper.Instance = new FontDialogHelper { Handler = this }; + + Manager.Target = null; + Manager.Action = null; + if (Font != null) + { + var fontHandler = (FontHandler)Font.Handler; + Manager.SetSelectedFont(fontHandler.Control, false); + } + else + Manager.SetSelectedFont(NSFont.SystemFontOfSize(NSFont.SystemFontSize), false); + + Control.Delegate = FontDialogHelper.Instance; + Manager.Target = FontDialogHelper.Instance; + Manager.Action = new Selector("changeFont:"); + + if (parentWindow != null) + { + if (parentWindow == NSApplication.SharedApplication.ModalWindow) + { + NSNotificationCenter.DefaultCenter.AddObserver(FontDialogHelper.Instance, new Selector("modalClosed:"), new NSString("NSWindowWillCloseNotification"), parentWindow); + } + } + + Manager.OrderFrontFontPanel(parentWindow); + //if (isModal) Control.MakeKeyWindow(); + Control.MakeKeyAndOrderFront(parentWindow); + + return DialogResult.None; // signal that we are returning right away! + } + + public Font Font + { + get; + set; + } + } +} + diff --git a/Source/Eto.Mac/Forms/FormHandler.cs b/Source/Eto.Mac/Forms/FormHandler.cs new file mode 100644 index 0000000000..f6c6c5848f --- /dev/null +++ b/Source/Eto.Mac/Forms/FormHandler.cs @@ -0,0 +1,72 @@ +using System; +using Eto.Forms; +using SD = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms +{ + public class FormHandler : MacWindow, Form.IHandler + { + NSWindowController controller; + protected override bool DisposeControl { get { return false; } } + + public FormHandler(NSWindow window) + { + Control = window; + } + + public FormHandler(NSWindowController controller) + { + this.controller = controller; + Control = controller.Window; + } + + public FormHandler() + { + Control = new MyWindow(new CGRect(0, 0, 200, 200), + NSWindowStyle.Resizable | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled, + NSBackingStore.Buffered, false); + ConfigureWindow(); + } + + public void Show() + { + if (WindowState == WindowState.Minimized) + Control.MakeKeyWindow(); + else + Control.MakeKeyAndOrderFront(ApplicationHandler.Instance.AppDelegate); + if (!Control.IsVisible) + Callback.OnShown(Widget, EventArgs.Empty); + } + } +} diff --git a/Source/Eto.Platform.Mac/Forms/MacBase.cs b/Source/Eto.Mac/Forms/MacBase.cs similarity index 92% rename from Source/Eto.Platform.Mac/Forms/MacBase.cs rename to Source/Eto.Mac/Forms/MacBase.cs index 3bbcf7e6e1..c994f6883a 100644 --- a/Source/Eto.Platform.Mac/Forms/MacBase.cs +++ b/Source/Eto.Mac/Forms/MacBase.cs @@ -1,17 +1,27 @@ using System; using System.Collections.Generic; using Eto.Drawing; -using MonoMac.ObjCRuntime; -using MonoMac.Foundation; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; using MonoTouch.ObjCRuntime; using MonoTouch.Foundation; +#endif using Eto.Forms; #if IOS using NSView = MonoTouch.UIKit.UIView; #endif -namespace Eto.Platform.Mac.Forms +namespace Eto.Mac.Forms { public interface IMacControlHandler { @@ -73,7 +83,7 @@ public void AddToNotificationCenter() if (!isNotification && c != null) { NSNotificationCenter.DefaultCenter.AddObserver(this, selPerformAction, KeyPath, c); - c.Retain(); + c.DangerousRetain(); isNotification = true; } } @@ -85,7 +95,7 @@ public void AddToControl() { //Console.WriteLine ("{0}: 3. Adding observer! {1}, {2}", ((IRef)this.Handler).WidgetID, this.GetType (), Control.GetHashCode ()); c.AddObserver(this, KeyPath, NSKeyValueObservingOptions.New, IntPtr.Zero); - c.Retain(); + c.DangerousRetain(); isControl = true; } } @@ -97,14 +107,14 @@ public void Remove() { NSNotificationCenter.DefaultCenter.RemoveObserver(this); if (c != null) - c.Release(); + c.DangerousRelease(); isNotification = false; } - if (isControl && c != null) + if (isControl && c != null && KeyPath != null) { //Console.WriteLine ("{0}: 4. Removing observer! {1}, {2}", ((IRef)this.Handler).WidgetID, Handler.GetType (), Control.GetHashCode ()); c.RemoveObserver(this, KeyPath); - c.Release(); + c.DangerousRelease(); isControl = false; } } @@ -142,9 +152,9 @@ public interface IMacControl WeakReference WeakHandler { get; } } - public class MacBase : WidgetHandler + public class MacBase : WidgetHandler where TControl: class - where TWidget: InstanceWidget + where TWidget: Widget { List observers; diff --git a/Source/Eto.Mac/Forms/MacCommon.cs b/Source/Eto.Mac/Forms/MacCommon.cs new file mode 100644 index 0000000000..874ab84e25 --- /dev/null +++ b/Source/Eto.Mac/Forms/MacCommon.cs @@ -0,0 +1,39 @@ +using System; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + public static class MacCommon + { + public static IntPtr CopyWithZoneHandle = Selector.GetHandle("copyWithZone:"); + + public static IntPtr ReleaseHandle = Selector.GetHandle("release"); + + public static void SafeDispose(this NSObject obj) + { + if (obj != null) + { + var count = obj.RetainCount; + var handle = obj.Handle; + + obj.Dispose(); + // HACK: release handle since Dispose() won't do it properly yet + if (handle != IntPtr.Zero && ApplicationHandler.Instance != null && count > 2) + Messaging.void_objc_msgSend(handle, ReleaseHandle); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/MacContainer.cs b/Source/Eto.Mac/Forms/MacContainer.cs new file mode 100644 index 0000000000..f6d1584e30 --- /dev/null +++ b/Source/Eto.Mac/Forms/MacContainer.cs @@ -0,0 +1,149 @@ +using System; +using Eto.Forms; +using SD = System.Drawing; +using System.Linq; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if IOS +using MonoTouch.Foundation; + +using NSResponder = MonoTouch.UIKit.UIResponder; +using NSView = MonoTouch.UIKit.UIView; +using Eto.iOS.Forms; +#endif + +namespace Eto.Mac.Forms +{ + public interface IMacContainer : IMacControlHandler + { + void SetContentSize(CGSize contentSize); + + void LayoutParent(bool updateSize = true); + + void LayoutChildren(); + + void LayoutAllChildren(); + + bool InitialLayout { get; } + } + + public abstract class MacContainer : + MacView, + Container.IHandler, IMacContainer + where TControl: NSObject + where TWidget: Container + where TCallback: Container.ICallback + { + public bool RecurseToChildren { get { return true; } } + + public virtual Size ClientSize { get { return Size; } set { Size = value; } } + + public override bool Enabled { get; set; } + + public bool InitialLayout { get; private set; } + + protected override void Initialize() + { + base.Initialize(); + Enabled = true; + } + + public virtual void Update() + { + LayoutChildren(); + } + + public bool NeedsQueue(Action update = null) + { + #if OSX + if (ApplicationHandler.QueueResizing) + { + ApplicationHandler.Instance.AsyncInvoke(update ?? Update); + return true; + } + #endif + return false; + } + + public virtual void SetContentSize(CGSize contentSize) + { + } + + public virtual void LayoutChildren() + { + } + + public void LayoutAllChildren() + { + //Console.WriteLine("Layout all children: {0}\n {1}", this.GetType().Name, new StackTrace()); + LayoutChildren(); + foreach (var child in Widget.Controls.Select (r => r.GetMacContainer()).Where(r => r != null)) + { + child.LayoutAllChildren(); + } + } + + public override void OnLoad(EventArgs e) + { + base.OnLoad(e); + var parent = Widget.Parent.GetMacContainer(); + if (parent == null || parent.InitialLayout) + { + InitialLayout = true; + LayoutAllChildren(); + } + } + + public void LayoutParent(bool updateSize = true) + { + if (NeedsQueue(() => LayoutParent(updateSize))) + return; + var container = Widget.Parent.GetMacContainer(); + if (container != null) + { + // traverse up the tree to update everything we own + container.LayoutParent(updateSize); + return; + } + if (updateSize && !Widget.Loaded && AutoSize) + { + var size = GetPreferredSize(Size.MaxValue); + SetContentSize(size.ToNS()); + } + + // layout everything! + LayoutAllChildren(); + } + } +} diff --git a/Source/Eto.Mac/Forms/MacControlExtensions.cs b/Source/Eto.Mac/Forms/MacControlExtensions.cs new file mode 100644 index 0000000000..db6d7fbc89 --- /dev/null +++ b/Source/Eto.Mac/Forms/MacControlExtensions.cs @@ -0,0 +1,139 @@ +using Eto.Drawing; +using Eto.Forms; +using System; +using sd = System.Drawing; +using System.Text.RegularExpressions; + + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreText; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreText; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if IOS +using NSView = MonoTouch.UIKit.UIView; +using NSControl = MonoTouch.UIKit.UIControl; +using MonoTouch.Foundation; +using MonoTouch.CoreText; +#endif +namespace Eto.Mac.Forms +{ + public static class MacControlExtensions + { + public static SizeF GetPreferredSize(this Control control, SizeF availableSize) + { + if (control == null) + return Size.Empty; + var mh = control.GetMacControl(); + if (mh != null) + { + return mh.GetPreferredSize(availableSize); + } + + var c = control.ControlObject as NSControl; + if (c != null) + { + c.SizeToFit(); + return c.Frame.Size.ToEto(); + } + var child = control.ControlObject as Control; + return child == null ? SizeF.Empty : child.GetPreferredSize(availableSize); + + } + + public static IMacContainer GetMacContainer(this Control control) + { + if (control == null) + return null; + var container = control.Handler as IMacContainer; + if (container != null) + return container; + var child = control.ControlObject as Control; + return child == null ? null : child.GetMacContainer(); + } + + public static IMacControlHandler GetMacControl(this Control control) + { + if (control == null) + return null; + var container = control.Handler as IMacControlHandler; + if (container != null) + return container; + var child = control.ControlObject as Control; + return child == null ? null : child.GetMacControl(); + } + + public static NSView GetContainerView(this Widget control) + { + if (control == null) + return null; + var containerHandler = control.Handler as IMacControlHandler; + if (containerHandler != null) + return containerHandler.ContainerControl; + var childControl = control.ControlObject as Control; + if (childControl != null) + return childControl.GetContainerView(); + return control.ControlObject as NSView; + } + + public static NSAttributedString ToAttributedStringWithMnemonic(this string value, NSDictionary attributes = null) + { + if (value == null) + return null; + var match = Regex.Match(value, @"(?<=([^&](?:[&]{2})*)|^)[&](?![&])"); + if (match.Success) + { + value = value.Remove(match.Index, 1); + value = value.Replace("&&", "&"); + var str = attributes != null ? new NSMutableAttributedString(value, attributes) : new NSMutableAttributedString(value); + var attr = new CTStringAttributes(); + attr.UnderlineStyle = CTUnderlineStyle.Single; + str.AddAttributes(attr, new NSRange(match.Index, 1)); + return str; + } + else + { + value = value.Replace("&&", "&"); + return attributes != null ? new NSAttributedString(value, attributes) : new NSAttributedString(value); + } + } + + public static void CenterInParent(this NSView view) + { + var super = view.Superview; + if (super != null) + { + var superFrame = super.Frame; + var size = view.Frame.Size; + view.SetFrameOrigin(new CGPoint((nfloat)(superFrame.Width - size.Width) / 2, (nfloat)(superFrame.Height - size.Height) / 2)); + } + } + } +} + diff --git a/Source/Eto.Platform.Mac/Forms/MacFileDialog.cs b/Source/Eto.Mac/Forms/MacFileDialog.cs similarity index 80% rename from Source/Eto.Platform.Mac/Forms/MacFileDialog.cs rename to Source/Eto.Mac/Forms/MacFileDialog.cs index 4080c328c8..fe072a2a41 100644 --- a/Source/Eto.Platform.Mac/Forms/MacFileDialog.cs +++ b/Source/Eto.Mac/Forms/MacFileDialog.cs @@ -1,12 +1,41 @@ using System; using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; using System.Collections.Generic; using System.IO; using System.Linq; -namespace Eto.Platform.Mac.Forms +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms { interface IMacFileDialog { @@ -34,7 +63,7 @@ public override bool ShouldEnableUrl (NSSavePanel panel, NSUrl url) } - public abstract class MacFileDialog : WidgetHandler, IFileDialog, IMacFileDialog + public abstract class MacFileDialog : WidgetHandler, FileDialog.IHandler, IMacFileDialog where TControl: NSSavePanel where TWidget: FileDialog { @@ -75,11 +104,11 @@ void Create() Control.Update (); }; fileTypeView.AddSubview(fileTypes); - fileTypes.SetFrameOrigin(new System.Drawing.PointF(label.Frame.Width + 10, padding)); + fileTypes.SetFrameOrigin(new CGPoint((nfloat)label.Frame.Width + 10, padding)); - label.SetFrameOrigin(new System.Drawing.PointF(0, padding + (fileTypes.Frame.Height - label.Frame.Height) / 2)); + label.SetFrameOrigin(new CGPoint(0, (nfloat)(padding + (fileTypes.Frame.Height - label.Frame.Height) / 2))); - fileTypeView.Frame = new System.Drawing.RectangleF(0, 0, fileTypes.Frame.Width + label.Frame.Width + 10, fileTypes.Frame.Height + padding*2); + fileTypeView.Frame = new CGRect(0, 0, (nfloat)(fileTypes.Frame.Width + label.Frame.Width + 10), (nfloat)(fileTypes.Frame.Height + padding * 2)); Control.AccessoryView = fileTypeView; } diff --git a/Source/Eto.Platform.Mac/Forms/MacModal.cs b/Source/Eto.Mac/Forms/MacModal.cs similarity index 78% rename from Source/Eto.Platform.Mac/Forms/MacModal.cs rename to Source/Eto.Mac/Forms/MacModal.cs index a5e78d4752..199da0c517 100644 --- a/Source/Eto.Platform.Mac/Forms/MacModal.cs +++ b/Source/Eto.Mac/Forms/MacModal.cs @@ -1,10 +1,20 @@ using System; -using MonoMac.AppKit; using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; using MonoMac.Foundation; +using MonoMac.CoreGraphics; using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif -namespace Eto.Platform.Mac.Forms +namespace Eto.Mac.Forms { class MacModal : NSObject { @@ -22,16 +32,16 @@ public static int Run (NSAlert view, Control parent) if (window == null && parent.ControlObject is NSView) window = ((NSView)parent.ControlObject).Window; if (window == null || !view.RespondsToSelector (new Selector ("beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:"))) - ret = view.RunModal (); + ret = (int)view.RunModal (); else { ret = 0; NSApplication.SharedApplication.InvokeOnMainThread (delegate { view.BeginSheet (window, new MacModal (), new Selector ("alertDidEnd:returnCode:contextInfo:"), IntPtr.Zero); - ret = NSApplication.SharedApplication.RunModalForWindow (window); + ret = (int)NSApplication.SharedApplication.RunModalForWindow (window); }); } } else - ret = view.RunModal (); + ret = (int)view.RunModal (); return ret; } @@ -43,15 +53,15 @@ public static int Run (NSSavePanel panel, Control parent) if (window == null && parent.ControlObject is NSView) window = ((NSView)parent.ControlObject).Window; if (window == null || !panel.RespondsToSelector (new Selector ("beginSheetModalForWindow:completionHandler:"))) - ret = panel.RunModal (); + ret = (int)panel.RunModal (); else { panel.BeginSheet (window, delegate(int result) { NSApplication.SharedApplication.StopModalWithCode (result); }); - ret = NSApplication.SharedApplication.RunModalForWindow (window); + ret = (int)NSApplication.SharedApplication.RunModalForWindow (window); } } else - ret = panel.RunModal (); + ret = (int)panel.RunModal (); return ret; } @@ -96,7 +106,7 @@ public static void Run (NSWindow theWindow, out ModalHelper helper) // Loop until some result other than continues: do { // Run the window modally until there are no events to process: - result = app.RunModalSession (session); + result = (int)app.RunModalSession (session); // Give the main loop some time: NSRunLoop.Current.RunUntil (NSRunLoop.NSDefaultRunLoopMode, NSDate.DistantFuture); @@ -121,7 +131,7 @@ public static void RunSheet (NSWindow theWindow, out ModalHelper helper) // Loop until some result other than continues: do { // Run the window modally until there are no events to process: - result = app.RunModalSession (session); + result = (int)app.RunModalSession (session); // Give the main loop some time: NSRunLoop.Current.RunUntil (NSRunLoop.NSDefaultRunLoopMode, NSDate.DistantFuture); @@ -135,7 +145,18 @@ public static void RunSheet (NSWindow theWindow, out ModalHelper helper) app.EndSheet (theWindow); /**/ } - + public static void BeginSheet(NSWindow theWindow, out ModalHelper helper, Action completed) + { + var app = NSApplication.SharedApplication; + var parent = theWindow.ParentWindow; + app.BeginSheet(theWindow, parent, delegate { + NSApplication.SharedApplication.StopModal(); + if (completed != null) + completed(); + }); + helper = new ModalHelper { IsModal = true, IsSheet = true, Window = theWindow }; + } + } } diff --git a/Source/Eto.Mac/Forms/MacObject.cs b/Source/Eto.Mac/Forms/MacObject.cs new file mode 100644 index 0000000000..38a540d77a --- /dev/null +++ b/Source/Eto.Mac/Forms/MacObject.cs @@ -0,0 +1,66 @@ +using System; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if IOS +using MonoTouch.Foundation; +#endif + +namespace Eto.Mac.Forms +{ + public class MacObject : MacBase + where TControl: NSObject + where TWidget: Widget + { + public virtual object EventObject + { + get { return Control; } + } + + public new void AddMethod (IntPtr selector, Delegate action, string arguments, object control = null) + { + base.AddMethod (selector, action, arguments, control ?? EventObject); + } + + public new NSObject AddObserver (NSString key, Action action, NSObject control = null) + { + return base.AddObserver (key, action, control ?? Control); + } + + public new void AddControlObserver (NSString key, Action action, NSObject control = null) + { + base.AddControlObserver (key, action, control ?? Control); + } + + } +} + diff --git a/Source/Eto.Mac/Forms/MacPanel.cs b/Source/Eto.Mac/Forms/MacPanel.cs new file mode 100644 index 0000000000..e7fed00020 --- /dev/null +++ b/Source/Eto.Mac/Forms/MacPanel.cs @@ -0,0 +1,224 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using SD = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if IOS +using NSResponder = MonoTouch.UIKit.UIResponder; +using NSView = MonoTouch.UIKit.UIView; +using Eto.iOS.Forms; +using MonoTouch.UIKit; +using MonoTouch.Foundation; +#elif OSX +using Eto.Mac.Forms.Menu; +#endif + +namespace Eto.Mac.Forms +{ + + public abstract class MacPanel : MacContainer, Panel.IHandler + where TControl: NSObject + where TWidget: Panel + where TCallback: Panel.ICallback + { + Control content; + Padding padding; + + public Padding Padding + { + get { return padding; } + set + { + padding = value; + LayoutParent(); + } + } + + #if OSX + protected virtual NSViewResizingMask ContentResizingMask() + { + return NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; + } + #endif + + public Control Content + { + get { return content; } + set + { + if (content != null) + { + var oldContent = content.GetContainerView(); + oldContent.RemoveFromSuperview(); + } + + content = value; + var control = value.GetContainerView(); + if (control != null) + { + var container = ContentControl; +#if OSX + control.AutoresizingMask = ContentResizingMask(); + control.Frame = new CGRect(ContentControl.Bounds.X, ContentControl.Bounds.Y, ContentControl.Bounds.Width, ContentControl.Bounds.Height); + container.AddSubview(control); // default +#elif IOS + control.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; + control.Frame = new SD.RectangleF(0, 0, ContentControl.Bounds.Width, ContentControl.Bounds.Height); + this.AddChild(value); +#endif + } + + if (Widget.Loaded) + { + LayoutParent(); + } + } + } + +#if OSX + ContextMenu contextMenu; + public ContextMenu ContextMenu + { + get { return contextMenu; } + set + { + contextMenu = value; + EventControl.Menu = contextMenu != null ? ((ContextMenuHandler)contextMenu.Handler).Control : null; + } + } +#else + public ContextMenu ContextMenu + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } +#endif + protected override SizeF GetNaturalSize(SizeF availableSize) + { + if (content == null || !content.Visible) + return Padding.Size; + + var contentControl = content.GetMacControl(); + if (contentControl != null) + return contentControl.GetPreferredSize(availableSize) + Padding.Size; + return Padding.Size; + } + + protected virtual CGRect GetContentBounds() + { + return ContentControl.Bounds; + } + + protected virtual CGRect AdjustContent(CGRect rect) + { + return rect; + } + + public override void LayoutChildren() + { + base.LayoutChildren(); + + if (content == null) + return; + + NSView childControl = content.GetContainerView(); + var frame = GetContentBounds(); + + if (frame.Width > padding.Horizontal && frame.Height > padding.Vertical) + { + frame.X += padding.Left; + frame.Width -= padding.Horizontal; + frame.Y += padding.Bottom; + frame.Height -= padding.Vertical; + } + else + { + frame.X = 0; + frame.Y = 0; + } + frame = AdjustContent(frame); + + if (childControl.Frame != frame) + childControl.Frame = frame; + } + + public override void SetContentSize(CGSize contentSize) + { + base.SetContentSize(contentSize); + if (MinimumSize != Size.Empty) + { + contentSize.Width = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width); + contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height); + } + if (Widget.Content != null) + { + var child = Widget.Content.Handler as IMacContainer; + if (child != null) + { + child.SetContentSize(contentSize); + } + } + } + + bool isResizing; + + void HandleSizeChanged(object sender, EventArgs e) + { + if (!isResizing) + { + isResizing = true; + LayoutChildren(); + isResizing = false; + } + } + + public override void OnLoad(EventArgs e) + { + base.OnLoad(e); + LayoutChildren(); + Widget.SizeChanged += HandleSizeChanged; + } + + public override void OnUnLoad(EventArgs e) + { + base.OnUnLoad(e); + Widget.SizeChanged -= HandleSizeChanged; + } + } +} + diff --git a/Source/Eto.Platform.Mac/Forms/MacView.cs b/Source/Eto.Mac/Forms/MacView.cs similarity index 81% rename from Source/Eto.Platform.Mac/Forms/MacView.cs rename to Source/Eto.Mac/Forms/MacView.cs index fa7aa8c4e9..c7116173e8 100644 --- a/Source/Eto.Platform.Mac/Forms/MacView.cs +++ b/Source/Eto.Mac/Forms/MacView.cs @@ -1,37 +1,60 @@ using System; -using MonoMac.AppKit; using Eto.Drawing; using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; using SD = System.Drawing; -using Eto.Platform.Mac.Forms.Controls; +using Eto.Mac.Forms.Controls; using System.Collections.Generic; -using Eto.Platform.Mac.Forms.Printing; +using Eto.Mac.Forms.Printing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; using MonoMac.CoreAnimation; - -namespace Eto.Platform.Mac.Forms +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms { class MouseDelegate : NSObject { - WeakReference view; - - public NSView View { get { return (NSView)view.Target; } set { view = new WeakReference(value); } } - WeakReference widget; - public Control Widget { get { return (Control)widget.Target; } set { widget = new WeakReference(value); } } + public IMacViewHandler Handler { get { return (IMacViewHandler)widget.Target; } set { widget = new WeakReference(value); } } [Export("mouseMoved:")] public void MouseMoved(NSEvent theEvent) { - Widget.OnMouseMove(Conversions.GetMouseEvent(View, theEvent, false)); + Handler.Callback.OnMouseMove(Handler.Widget, Conversions.GetMouseEvent(Handler.EventControl, theEvent, false)); } [Export("mouseEntered:")] public void MouseEntered(NSEvent theEvent) { - Widget.OnMouseEnter(Conversions.GetMouseEvent(View, theEvent, false)); + Handler.Callback.OnMouseEnter(Handler.Widget, Conversions.GetMouseEvent(Handler.EventControl, theEvent, false)); } [Export("cursorUpdate:")] @@ -42,13 +65,13 @@ public void CursorUpdate(NSEvent theEvent) [Export("mouseExited:")] public void MouseExited(NSEvent theEvent) { - Widget.OnMouseLeave(Conversions.GetMouseEvent(View, theEvent, false)); + Handler.Callback.OnMouseLeave(Handler.Widget, Conversions.GetMouseEvent(Handler.EventControl, theEvent, false)); } [Export("scrollWheel:")] public void ScrollWheel(NSEvent theEvent) { - Widget.OnMouseWheel(Conversions.GetMouseEvent(View, theEvent, true)); + Handler.Callback.OnMouseWheel(Handler.Widget, Conversions.GetMouseEvent(Handler.EventControl, theEvent, true)); } } @@ -58,16 +81,19 @@ public interface IMacViewHandler : IMacControlHandler Control Widget { get; } - Cursor Cursor { get; set; } + Control.ICallback Callback { get; } + + Cursor CurrentCursor { get; } - void PostKeyDown(KeyEventArgs e); + void OnKeyDown(KeyEventArgs e); void OnSizeChanged(EventArgs e); } - public abstract class MacView : MacObject, IControl, IMacViewHandler - where TControl: NSResponder + public abstract class MacView : MacObject, Control.IHandler, IMacViewHandler + where TControl: NSObject where TWidget: Control + where TCallback: Control.ICallback { bool focus; bool mouseMove; @@ -77,6 +103,8 @@ public abstract class MacView : MacObject, Cursor cursor; SizeF? naturalSize; + Control.ICallback IMacViewHandler.Callback { get { return Callback; } } + public abstract NSView ContainerControl { get; } public virtual NSView ContentControl { get { return ContainerControl; } } @@ -149,7 +177,7 @@ protected virtual SizeF GetNaturalSize(SizeF availableSize) var control = Control as NSControl; if (control != null) { - SD.SizeF? size = (Widget.Loaded) ? (SD.SizeF?)control.Frame.Size : null; + var size = (Widget.Loaded) ? (CGSize?)control.Frame.Size : null; control.SizeToFit(); naturalSize = control.Frame.Size.ToEto(); if (size != null) @@ -183,9 +211,9 @@ void CreateTracking() EventControl.RemoveTrackingArea(tracking); //Console.WriteLine ("Adding mouse tracking {0} for area {1}", this.Widget.GetType ().FullName, Control.Frame.Size); if (mouseDelegate == null) - mouseDelegate = new MouseDelegate { Widget = Widget, View = EventControl }; + mouseDelegate = new MouseDelegate { Handler = this }; var options = mouseOptions | NSTrackingAreaOptions.ActiveAlways | NSTrackingAreaOptions.EnabledDuringMouseDrag | NSTrackingAreaOptions.InVisibleRect; - tracking = new NSTrackingArea(new SD.RectangleF(SD.PointF.Empty, EventControl.Frame.Size), options, mouseDelegate, new NSDictionary()); + tracking = new NSTrackingArea(new CGRect(CGPoint.Empty, EventControl.Frame.Size), options, mouseDelegate, new NSDictionary()); EventControl.AddTrackingArea(tracking); } @@ -228,7 +256,7 @@ public override void AttachEvent(string id) AddMethod(selRightMouseDragged, new Action(TriggerMouseDragged), "v@:@"); break; case Eto.Forms.Control.SizeChangedEvent: - AddMethod(selSetFrameSize, new Action(SetFrameSizeAction), "v@:{CGSize=ff}", ContainerControl); + AddMethod(selSetFrameSize, new Action(SetFrameSizeAction), "v@:{CGSize=ff}", ContainerControl); break; case Eto.Forms.Control.MouseDownEvent: AddMethod(selMouseDown, new Action(TriggerMouseDown), "v@:@"); @@ -266,7 +294,7 @@ public override void AttachEvent(string id) } } - static void SetFrameSizeAction(IntPtr sender, IntPtr sel, SD.SizeF size) + static void SetFrameSizeAction(IntPtr sender, IntPtr sel, CGSize size) { var obj = Runtime.GetNSObject(sender); Messaging.void_objc_msgSendSuper_SizeF(obj.SuperHandle, sel, size); @@ -275,7 +303,7 @@ static void SetFrameSizeAction(IntPtr sender, IntPtr sel, SD.SizeF size) if (handler != null) { handler.OnSizeChanged(EventArgs.Empty); - handler.Widget.OnSizeChanged(EventArgs.Empty); + handler.Callback.OnSizeChanged(handler.Widget, EventArgs.Empty); } } @@ -285,7 +313,7 @@ static bool TriggerGotFocus(IntPtr sender, IntPtr sel) var handler = GetHandler(obj) as IMacViewHandler; if (handler != null) { - handler.Widget.OnGotFocus(EventArgs.Empty); + handler.Callback.OnGotFocus(handler.Widget, EventArgs.Empty); return Messaging.bool_objc_msgSendSuper(obj.SuperHandle, sel); } return false; @@ -297,7 +325,7 @@ static bool TriggerLostFocus(IntPtr sender, IntPtr sel) var handler = GetHandler(obj) as IMacViewHandler; if (handler != null) { - handler.Widget.OnLostFocus(EventArgs.Empty); + handler.Callback.OnLostFocus(handler.Widget, EventArgs.Empty); return Messaging.bool_objc_msgSendSuper(obj.SuperHandle, sel); } return false; @@ -340,11 +368,11 @@ static void TriggerMouseDown(IntPtr sender, IntPtr sel, IntPtr e) var theEvent = new NSEvent(e); var args = Conversions.GetMouseEvent(handler.ContainerControl, theEvent, false); if (theEvent.ClickCount >= 2) - handler.Widget.OnMouseDoubleClick(args); + handler.Callback.OnMouseDoubleClick(handler.Widget, args); if (!args.Handled) { - handler.Widget.OnMouseDown(args); + handler.Callback.OnMouseDown(handler.Widget, args); } if (!args.Handled) { @@ -362,7 +390,7 @@ static void TriggerMouseUp(IntPtr sender, IntPtr sel, IntPtr e) { var theEvent = new NSEvent(e); var args = Conversions.GetMouseEvent(handler.ContainerControl, theEvent, false); - handler.Widget.OnMouseUp(args); + handler.Callback.OnMouseUp(handler.Widget, args); if (!args.Handled) { Messaging.void_objc_msgSendSuper_IntPtr(obj.SuperHandle, sel, e); @@ -378,7 +406,7 @@ static void TriggerMouseDragged(IntPtr sender, IntPtr sel, IntPtr e) { var theEvent = new NSEvent(e); var args = Conversions.GetMouseEvent(handler.ContainerControl, theEvent, false); - handler.Widget.OnMouseMove(args); + handler.Callback.OnMouseMove(handler.Widget, args); if (!args.Handled) { Messaging.void_objc_msgSendSuper_IntPtr(obj.SuperHandle, sel, e); @@ -396,7 +424,7 @@ static void TriggerMouseWheel(IntPtr sender, IntPtr sel, IntPtr e) var args = Conversions.GetMouseEvent(handler.ContainerControl, theEvent, true); if (!args.Delta.IsZero) { - handler.Widget.OnMouseWheel(args); + handler.Callback.OnMouseWheel(handler.Widget, args); if (!args.Handled) { Messaging.void_objc_msgSendSuper_IntPtr(obj.SuperHandle, sel, e); @@ -417,7 +445,7 @@ public virtual void Invalidate() public virtual void Invalidate(Rectangle rect) { - var region = rect.ToSDRectangleF(); + var region = rect.ToSDRectangleF().ToNS(); region.Y = EventControl.Frame.Height - region.Y - region.Height; EventControl.SetNeedsDisplayInRect(region); } @@ -445,18 +473,19 @@ public virtual Color BackgroundColor set { backgroundColor = value; - SetBackgroundColor(); + if (Widget.Loaded) + SetBackgroundColor(backgroundColor); } } - private void SetBackgroundColor() + protected virtual void SetBackgroundColor(Color? color) { - if (backgroundColor != null && Widget.Loaded) { - if (backgroundColor.Value.A > 0) { + if (color != null) { + if (color.Value.A > 0) { ContainerControl.WantsLayer = true; var layer = ContainerControl.Layer; if (layer != null) - layer.BackgroundColor = backgroundColor.Value.ToCGColor(); + layer.BackgroundColor = color.Value.ToCGColor(); } else { ContainerControl.WantsLayer = false; @@ -491,10 +520,37 @@ public virtual bool Visible } } + static readonly IntPtr selResetCursorRects = Selector.GetHandle("resetCursorRects"); + + static void TriggerResetCursorRects(IntPtr sender, IntPtr sel) + { + var obj = Runtime.GetNSObject(sender); + var handler = GetHandler(obj) as IMacViewHandler; + if (handler != null) + { + var cursor = handler.CurrentCursor; + if (cursor != null) + { + handler.EventControl.AddCursorRect(new CGRect(CGPoint.Empty, handler.EventControl.Frame.Size), cursor.ControlObject as NSCursor); + } + } + } + + public virtual Cursor CurrentCursor + { + get { return Cursor; } + } + public virtual Cursor Cursor { get { return cursor; } - set { cursor = value; } + set { + if (cursor != value) + { + cursor = value; + AddMethod(selResetCursorRects, new Action(TriggerResetCursorRects), "v@:"); + } + } } public string ToolTip @@ -523,23 +579,24 @@ public virtual void OnLoad(EventArgs e) public virtual void OnLoadComplete(EventArgs e) { if (focus && EventControl.Window != null) - EventControl.Window.MakeFirstResponder(Control); - SetBackgroundColor(); + EventControl.Window.MakeFirstResponder(EventControl); + SetBackgroundColor(backgroundColor); } public virtual void OnUnLoad(EventArgs e) { } - public virtual void PostKeyDown(KeyEventArgs e) + public virtual void OnKeyDown(KeyEventArgs e) { + Callback.OnKeyDown(Widget, e); } Control IMacViewHandler.Widget { get { return Widget; } } public virtual PointF PointFromScreen(PointF point) { - var sdpoint = point.ToSD(); + var sdpoint = point.ToNS(); if (EventControl.Window != null) { sdpoint.Y = ContentControl.Window.Screen.Frame.Height - sdpoint.Y; @@ -552,7 +609,7 @@ public virtual PointF PointFromScreen(PointF point) public virtual PointF PointToScreen(PointF point) { - var sdpoint = point.ToSD(); + var sdpoint = point.ToNS(); sdpoint.Y = ContentControl.Frame.Height - sdpoint.Y; sdpoint = ContentControl.ConvertPointToView(sdpoint, null); if (ContentControl.Window != null) @@ -563,7 +620,7 @@ public virtual PointF PointToScreen(PointF point) return sdpoint.ToEto(); } - Point IControl.Location + Point Control.IHandler.Location { get { return ContentControl.Frame.Location.ToEtoPoint(); } } @@ -571,7 +628,7 @@ Point IControl.Location static void TriggerSystemAction(IntPtr sender, IntPtr sel, IntPtr e) { var control = Runtime.GetNSObject(sender); - var handler = GetHandler(control) as MacView; + var handler = GetHandler(control) as MacView; if (handler != null) { Command command; @@ -587,7 +644,7 @@ static bool ValidateSystemMenuAction(IntPtr sender, IntPtr sel, IntPtr item) var menuItem = new NSMenuItem(item); var control = Runtime.GetNSObject(sender); - var handler = GetHandler(control) as MacView; + var handler = GetHandler(control) as MacView; if (handler != null) { Command command; @@ -605,7 +662,7 @@ static bool ValidateSystemToolbarAction(IntPtr sender, IntPtr sel, IntPtr item) var toolbarItem = new NSToolbarItem(item); var control = Runtime.GetNSObject(sender); - var handler = GetHandler(control) as MacView; + var handler = GetHandler(control) as MacView; if (handler != null) { Command command; diff --git a/Source/Eto.Mac/Forms/MacWindow.cs b/Source/Eto.Mac/Forms/MacWindow.cs new file mode 100644 index 0000000000..1ef4caea52 --- /dev/null +++ b/Source/Eto.Mac/Forms/MacWindow.cs @@ -0,0 +1,867 @@ +using System; +using System.ComponentModel; +using System.Linq; +using SD = System.Drawing; +using Eto.Drawing; +using Eto.Forms; +using Eto.Mac.Forms.Controls; +using System.Threading; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms +{ + public class MyWindow : NSWindow, IMacControl + { + CGRect oldFrame; + bool zoom; + + public WeakReference WeakHandler { get; set; } + + public IMacWindow Handler { get { return (IMacWindow)WeakHandler.Target; } set { WeakHandler = new WeakReference(value); } } + + public MyWindow(CGRect rect, NSWindowStyle style, NSBackingStore store, bool flag) + : base(rect, style, store, flag) + { + } + + public override void Center() + { + // implement centering to parent if there is a parent window for this one.. + if (ParentWindow != null) + { + var parentFrame = ParentWindow.Frame; + var frame = Frame; + var location = new CGPoint((parentFrame.Width - frame.Width) / 2 + parentFrame.X, (parentFrame.Height - frame.Height) / 2 + parentFrame.Y); + SetFrameOrigin(location); + } + else + base.Center(); + } + + public override void Zoom(NSObject sender) + { + if (zoom) + { + SetFrame(oldFrame, true, true); + zoom = false; + } + else + { + oldFrame = Frame; + base.Zoom(sender); + zoom = true; + } + Handler.Callback.OnWindowStateChanged(Handler.Widget, EventArgs.Empty); + } + } + + public interface IMacWindow + { + Rectangle? RestoreBounds { get; set; } + + Window Widget { get; } + + NSMenu MenuBar { get; } + + NSObject FieldEditorObject { get; set; } + + Size MinimumSize { get; } + + bool CloseWindow(Action closing = null); + + NSWindow Control { get; } + + Window.ICallback Callback { get; } + } + + public class CustomFieldEditor : NSTextView + { + WeakReference widget; + + public Control Widget { get { return (Control)widget.Target; } set { widget = new WeakReference(value); } } + + public CustomFieldEditor() + { + FieldEditor = true; + } + + public CustomFieldEditor(IntPtr handle) + : base(handle) + { + } + + public override void KeyDown(NSEvent theEvent) + { + if (!MacEventView.KeyDown(Widget, theEvent)) + { + base.KeyDown(theEvent); + } + } + } + + public abstract class MacWindow : MacPanel, Window.IHandler, IMacContainer, IMacWindow + where TControl: NSWindow + where TWidget: Window + where TCallback: Window.ICallback + { + + CustomFieldEditor fieldEditor; + MenuBar menuBar; + Icon icon; + Eto.Forms.ToolBar toolBar; + Rectangle? restoreBounds; + bool setInitialSize; + WindowState? initialState; + bool maximizable = true; + bool topmost; + bool setInitialPosition = true; + Point? oldLocation; + + Window.ICallback IMacWindow.Callback { get { return Callback; } } + + public override NSView ContainerControl { get { return Control.ContentView; } } + + public override object EventObject { get { return Control; } } + + static readonly Selector selSetStyleMask = new Selector("setStyleMask:"); + + public NSObject FieldEditorObject { get; set; } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + if (Content != null && Content.Visible) + { + var contentControl = Content.GetMacControl(); + if (contentControl != null) + { + return contentControl.GetPreferredSize(availableSize); + } + } + return new Size(200, 200); + } + + public override Size MinimumSize + { + get { return base.MinimumSize; } + set + { + base.MinimumSize = value; + // TODO: Mac64 + #if !Mac64 + if (value != Size.Empty) + { + Control.WillResize = (sender, frameSize) => + { + if (value != Size.Empty) + { + return new CGSize((float)Math.Max(frameSize.Width, value.Width), (float)Math.Max(frameSize.Height, value.Height)); + } + return frameSize; + }; + } + else + Control.WillResize = null; + #endif + } + } + + public NSMenu MenuBar + { + get { return menuBar == null ? null : menuBar.ControlObject as NSMenu; } + } + + protected MacWindow() + { + AutoSize = true; + } + + protected override void Initialize() + { + base.Initialize(); + Control.DidBecomeKey += HandleDidBecomeKey; + Control.ShouldZoom = HandleShouldZoom; + Control.WillMiniaturize += HandleWillMiniaturize; + } + + static void HandleDidBecomeKey(object sender, EventArgs e) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return; + if (handler.MenuBar != null) + { + NSApplication.SharedApplication.MainMenu = handler.MenuBar; + } + + } + + static bool HandleShouldZoom(NSWindow window, CGRect newFrame) + { + var handler = GetHandler(window) as MacWindow; + if (handler == null) + return true; + if (!handler.Maximizable) + return false; + if (!window.IsZoomed && window.Screen != null) + { + handler.RestoreBounds = handler.Widget.Bounds; + } + return true; + + } + + static void HandleWillMiniaturize(object sender, EventArgs e) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return; + handler.RestoreBounds = handler.Widget.Bounds; + } + + static void HandleWillClose(object sender, EventArgs e) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return; + if (ApplicationHandler.Instance.ShouldCloseForm(handler.Widget, true)) + handler.Callback.OnClosed(handler.Widget, EventArgs.Empty); + } + + static bool HandleWindowShouldClose(NSObject sender) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return true; + var args = new CancelEventArgs(); + if (ApplicationHandler.Instance.ShouldCloseForm(handler.Widget, false)) + handler.Callback.OnClosing(handler.Widget, args); + return !args.Cancel; + } + + static void HandleWindowStateChanged(object sender, EventArgs e) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return; + handler.Callback.OnWindowStateChanged(handler.Widget, EventArgs.Empty); + } + + static void HandleGotFocus(object sender, EventArgs e) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return; + handler.Callback.OnGotFocus(handler.Widget, EventArgs.Empty); + } + + static void HandleLostFocus(object sender, EventArgs e) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return; + handler.Callback.OnLostFocus(handler.Widget, EventArgs.Empty); + } + + + public override void AttachEvent(string id) + { + switch (id) + { + case Window.ClosedEvent: + Control.WillClose += HandleWillClose; + break; + case Window.ClosingEvent: + Control.WindowShouldClose = HandleWindowShouldClose; + break; + case Window.WindowStateChangedEvent: + Control.DidMiniaturize += HandleWindowStateChanged; + Control.DidDeminiaturize += HandleWindowStateChanged; + break; + case Eto.Forms.Control.ShownEvent: + // handled when shown + break; + case Eto.Forms.Control.GotFocusEvent: + Control.DidBecomeKey += HandleGotFocus; + break; + case Eto.Forms.Control.LostFocusEvent: + Control.DidResignKey += HandleLostFocus; + break; + case Eto.Forms.Control.SizeChangedEvent: + { + Size? oldSize = null; + AddObserver(NSWindow.DidResizeNotification, e => + { + var handler = (MacWindow)e.Handler; + var newSize = handler.Size; + if (oldSize != newSize) + { + handler.Callback.OnSizeChanged(handler.Widget, EventArgs.Empty); + oldSize = newSize; + } + }); + } + break; + case Window.LocationChangedEvent: + { + AddObserver(NSWindow.DidMoveNotification, e => + { + var handler = e.Handler as MacWindow; + if (handler != null) + { + var old = handler.oldLocation; + handler.oldLocation = null; + var newLocation = handler.Location; + if (old != newLocation) + { + handler.oldLocation = newLocation; + handler.Callback.OnLocationChanged(handler.Widget, EventArgs.Empty); + } + } + }); + // WillMove is only called when the user moves the window via the mouse + Control.WillMove += HandleWillMove; + } + break; + default: + base.AttachEvent(id); + break; + } + } + + void CreateCursorRect() + { + if (Cursor != null) + { + Control.ContentView.DiscardCursorRects(); + Control.ContentView.AddCursorRect(new CGRect(CGPoint.Empty, Control.Frame.Size), Cursor.ControlObject as NSCursor); + } + else + Control.ContentView.DiscardCursorRects(); + } + + /// + /// Tracks movement of the window until the mouse up button is found + /// + static void HandleWillMove(object sender, EventArgs e) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return; + handler.oldLocation = null; + // find offset of mouse cursor to location of window + var moveOffset = Size.Round((SizeF)(Mouse.Position - handler.Location)); + + ThreadPool.QueueUserWorkItem(a => + { + bool tracking = true; + while (tracking) + { + NSApplication.SharedApplication.InvokeOnMainThread(() => + { + var newLocation = Point.Round(Mouse.Position - moveOffset); + if (handler.oldLocation != newLocation) + { + handler.Callback.OnLocationChanged(handler.Widget, EventArgs.Empty); + handler.oldLocation = newLocation; + } + // check for mouse up event + tracking = NSApplication.SharedApplication.NextEventEx(NSEventMask.LeftMouseUp, null, NSRunLoop.NSRunLoopEventTracking, false) == null; + }); + } + handler.oldLocation = null; + NSApplication.SharedApplication.InvokeOnMainThread(() => handler.Callback.OnLocationChanged(handler.Widget, EventArgs.Empty)); + }); + } + + protected void ConfigureWindow() + { + var myWindow = Control as MyWindow; + if (myWindow != null) + myWindow.Handler = this; + Control.ContentView = new NSView(); + //Control.ContentMinSize = new System.Drawing.SizeF(0, 0); + Control.ContentView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; + Control.ReleasedWhenClosed = false; + Control.HasShadow = true; + Control.ShowsResizeIndicator = true; + Control.AutorecalculatesKeyViewLoop = true; + //Control.Delegate = new MacWindowDelegate{ Handler = this }; + Control.WillReturnFieldEditor = HandleWillReturnFieldEditor; + } + + static NSObject HandleWillReturnFieldEditor(NSWindow sender, NSObject client) + { + var handler = GetHandler(sender) as MacWindow; + if (handler == null) + return null; + handler.FieldEditorObject = client; + var control = client as IMacControl; + if (control != null) + { + var childHandler = control.WeakHandler.Target as IMacViewHandler; + if (childHandler != null && childHandler.IsEventHandled(Eto.Forms.Control.KeyDownEvent)) + { + if (handler.fieldEditor == null) + handler.fieldEditor = new CustomFieldEditor(); + handler.fieldEditor.Widget = childHandler.Widget; + return handler.fieldEditor; + } + } + return null; + } + + public override NSView ContentControl { get { return Control.ContentView; } } + + public virtual string Title { get { return Control.Title; } set { Control.Title = value ?? ""; } } + // Control.Title throws an exception if value is null + void SetButtonStates() + { + var button = Control.StandardWindowButton(NSWindowButton.ZoomButton); + if (button != null) + button.Enabled = Maximizable && Resizable; + } + + public bool Resizable + { + get { return Control.StyleMask.HasFlag(NSWindowStyle.Resizable); } + set + { + if (Control.RespondsToSelector(selSetStyleMask)) + { + if (value) + Control.StyleMask |= NSWindowStyle.Resizable; + else + Control.StyleMask &= ~NSWindowStyle.Resizable; + SetButtonStates(); + } + } + } + + public bool Minimizable + { + get { return Control.StyleMask.HasFlag(NSWindowStyle.Miniaturizable); } + set + { + if (Control.RespondsToSelector(selSetStyleMask)) + { + if (value) + Control.StyleMask |= NSWindowStyle.Miniaturizable; + else + Control.StyleMask &= ~NSWindowStyle.Miniaturizable; + SetButtonStates(); + } + } + } + + public bool Maximizable + { + get { return maximizable; } + set + { + if (maximizable != value) + { + maximizable = value; + SetButtonStates(); + } + } + } + + public bool ShowInTaskbar + { + get; + set; + } + + public bool Topmost + { + get { return topmost; } + set + { + if (topmost != value) + { + topmost = value; + Control.Level = value ? NSWindowLevel.PopUpMenu : NSWindowLevel.Normal; + } + } + } + + public override Size Size + { + get + { + return Control.Frame.Size.ToEtoSize(); + } + set + { + var oldFrame = Control.Frame; + var newFrame = oldFrame.SetSize(value); + newFrame.Y = (nfloat)Math.Max(0, oldFrame.Y - (value.Height - oldFrame.Height)); + Control.SetFrame(newFrame, true); + AutoSize = false; + } + } + + public MenuBar Menu + { + get + { + return menuBar; + } + set + { + menuBar = value; + if (Control.IsKeyWindow) + { + NSApplication.SharedApplication.MainMenu = (NSMenu)value.ControlObject; + } + } + } + + public bool CloseWindow(Action closing = null) + { + var args = new CancelEventArgs(); + Callback.OnClosing(Widget, args); + if (!args.Cancel && closing != null) + closing(args); + if (!args.Cancel) + { + Callback.OnClosed(Widget, EventArgs.Empty); + } + return !args.Cancel; + } + + public virtual void Close() + { + Control.Close(); + } + + public Eto.Forms.ToolBar ToolBar + { + get + { + return toolBar; + } + set + { + toolBar = value; + Control.Toolbar = (NSToolbar)toolBar.ControlObject; + } + } + + public Icon Icon + { + get { return icon; } + set + { + icon = value; + // don't really do anything here.. no where to put it + } + } + + public override void Focus() + { + Control.BecomeFirstResponder(); + } + + public string Id { get; set; } + + public override Size ClientSize + { + get { return Control.ContentView.Frame.Size.ToEtoSize(); } + set + { + var oldFrame = Control.Frame; + var oldSize = Control.ContentView.Frame; + Control.SetFrameOrigin(new CGPoint(oldFrame.X, (nfloat)Math.Max(0, oldFrame.Y - (value.Height - oldSize.Height)))); + Control.SetContentSize(value.ToNS()); + AutoSize = false; + } + } + + public override bool HasFocus + { + get { return Control.IsKeyWindow; } + } + + public override bool Visible + { + get { return Control.IsVisible; } + set + { + if (value && !Control.IsVisible) + Control.MakeKeyAndOrderFront(NSApplication.SharedApplication); + if (!value && Control.IsVisible) + Control.PerformClose(NSApplication.SharedApplication); + // huh? + } + } + + public override Cursor Cursor + { + get { return base.Cursor; } + set + { + base.Cursor = value; + CreateCursorRect(); + } + } + + public virtual Point Location + { + get + { + if (oldLocation != null) + return oldLocation.Value; + // translate location relative to the top left corner of main screen + var mainFrame = NSScreen.Screens[0].Frame; + var frame = Control.Frame; + return new Point((int)frame.X, (int)(mainFrame.Height - frame.Y - frame.Height)); + } + set + { + // location is relative to the main screen, translate to bottom left, inversed + var mainFrame = NSScreen.Screens[0].Frame; + var frame = Control.Frame; + var point = new CGPoint((nfloat)value.X, (nfloat)(mainFrame.Height - value.Y - frame.Height)); + Control.SetFrameOrigin(point); + if (Control.Screen == null) + { + // ensure that the control lands on a screen + point.X = (nfloat)Math.Min(Math.Max(mainFrame.X, point.X), mainFrame.Right - frame.Width); + point.Y = (nfloat)Math.Min(Math.Max(mainFrame.Y, point.Y), mainFrame.Bottom - frame.Height); + + Control.SetFrameOrigin(point); + } + setInitialPosition = false; + } + } + + public WindowState WindowState + { + get + { + if (initialState != null) + return initialState.Value; + if (Control.IsMiniaturized) + return WindowState.Minimized; + if (Control.IsZoomed) + return WindowState.Maximized; + return WindowState.Normal; + } + set + { + if (!Widget.Loaded) + { + initialState = value; + return; + } + switch (value) + { + case WindowState.Maximized: + if (Control.IsMiniaturized) + Control.Deminiaturize(Control); + if (!Control.IsZoomed) + Control.PerformZoom(Control); + break; + case WindowState.Minimized: + if (!Control.IsMiniaturized) + Control.Miniaturize(Control); + break; + case WindowState.Normal: + if (Control.IsZoomed) + Control.Zoom(Control); + if (Control.IsMiniaturized) + Control.Deminiaturize(Control); + break; + } + } + } + + public Rectangle? RestoreBounds + { + get { return WindowState == WindowState.Normal ? null : restoreBounds; } + set { restoreBounds = value; } + } + + public double Opacity + { + get { return Control.IsOpaque ? 1.0 : Control.AlphaValue; } + set + { + Control.IsOpaque = Math.Abs(value - 1.0) < 0.01f; + Control.AlphaValue = (float)value; + } + } + + public override void OnLoad(EventArgs e) + { + base.OnLoad(e); + if (AutoSize) + { + var size = GetPreferredSize(Size.MaxValue); + SetContentSize(size.ToNS()); + setInitialSize = true; + + PositionWindow(); + } + else + { + PositionWindow(); + } + } + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + if (initialState != null) + { + WindowState = initialState.Value; + initialState = null; + } + } + + protected virtual void PositionWindow() + { + if (setInitialPosition) + { + Control.Center(); + setInitialPosition = false; + } + } + + #region IMacContainer implementation + + public override void SetContentSize(CGSize contentSize) + { + if (MinimumSize != Size.Empty) + { + contentSize.Width = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width); + contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height); + } + + if (Widget.Loaded) + { + var diffy = ClientSize.Height - (int)contentSize.Height; + var diffx = ClientSize.Width - (int)contentSize.Width; + var frame = Control.Frame; + if (diffx < 0 || !setInitialSize) + { + frame.Width -= diffx; + } + if (diffy < 0 || !setInitialSize) + { + frame.Y += diffy; + frame.Height -= diffy; + } + Control.SetFrame(frame, false, false); + } + else + Control.SetContentSize(contentSize); + } + + #endregion + + #region IMacWindow implementation + + Rectangle? IMacWindow.RestoreBounds + { + get + { + return restoreBounds; + } + set + { + restoreBounds = value; + } + } + + Window IMacWindow.Widget + { + get { return Widget; } + } + + NSWindow IMacWindow.Control + { + get { return Control; } + } + + #endregion + + public Screen Screen + { + get { return new Screen(new ScreenHandler(Control.Screen)); } + } + + public override PointF PointFromScreen(PointF point) + { + var sdpoint = point.ToNS(); + sdpoint = Control.ConvertBaseToScreen(sdpoint); + sdpoint.Y = Control.Screen.Frame.Height - sdpoint.Y; + return sdpoint.ToEto(); + } + + public override PointF PointToScreen(PointF point) + { + var sdpoint = point.ToNS(); + sdpoint = Control.ConvertBaseToScreen(sdpoint); + sdpoint.Y = Control.Screen.Frame.Height - sdpoint.Y; + return sdpoint.ToEto(); + } + + public WindowStyle WindowStyle + { + get { return Control.StyleMask.ToEtoWindowStyle(); } + set + { + if (Control.RespondsToSelector(selSetStyleMask)) + { + Control.StyleMask = value.ToNS(Control.StyleMask); + } + } + } + + public void BringToFront() + { + Control.OrderFront(Control); + Control.MakeKeyWindow(); + } + + public void SendToBack() + { + Control.OrderBack(Control); + var window = NSApplication.SharedApplication.Windows.FirstOrDefault(r => r != Control); + if (window != null) + window.MakeKeyWindow(); + Control.ResignKeyWindow(); + } + } +} diff --git a/Source/Eto.Mac/Forms/Menu/CheckMenuItemHandler.cs b/Source/Eto.Mac/Forms/Menu/CheckMenuItemHandler.cs new file mode 100644 index 0000000000..7195215634 --- /dev/null +++ b/Source/Eto.Mac/Forms/Menu/CheckMenuItemHandler.cs @@ -0,0 +1,83 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Menu +{ + public class CheckMenuItemHandler : MenuHandler, CheckMenuItem.IHandler, IMenuActionHandler + { + public CheckMenuItemHandler () + { + Control = new NSMenuItem (); + Enabled = true; + Control.Target = new MenuActionHandler{ Handler = this }; + Control.Action = MenuActionHandler.selActivate; + } + + public void HandleClick () + { + Callback.OnClick (Widget, EventArgs.Empty); + } + + #region IMenuItem Members + + public bool Enabled { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + + public string Text { + get { return Control.Title; } + set { Control.SetTitleWithMnemonic (value); } + } + + public string ToolTip { + get { return Control.ToolTip; } + set { Control.ToolTip = value ?? string.Empty; } + } + + public Keys Shortcut { + get { return KeyMap.Convert (Control.KeyEquivalent, Control.KeyEquivalentModifierMask); } + set { + Control.KeyEquivalent = KeyMap.KeyEquivalent (value); + Control.KeyEquivalentModifierMask = KeyMap.KeyEquivalentModifierMask (value); + } + } + + public bool Checked { + get { return Control.State == NSCellStateValue.On; } + set { Control.State = value ? NSCellStateValue.On : NSCellStateValue.Off; } + } + + #endregion + + MenuItem IMenuActionHandler.Widget { + get { return Widget; } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case MenuItem.ValidateEvent: + // handled in MenuActionHandler + break; + default: + base.AttachEvent(id); + break; + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Menu/ContextMenuHandler.cs b/Source/Eto.Mac/Forms/Menu/ContextMenuHandler.cs new file mode 100644 index 0000000000..d129ea897f --- /dev/null +++ b/Source/Eto.Mac/Forms/Menu/ContextMenuHandler.cs @@ -0,0 +1,61 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Menu +{ + public class ContextMenuHandler : WidgetHandler, ContextMenu.IHandler + { + public ContextMenuHandler () + { + Control = new NSMenu (); + Control.AutoEnablesItems = false; + Control.ShowsStateColumn = true; + } + + public void AddMenu (int index, MenuItem item) + { + Control.InsertItem ((NSMenuItem)item.ControlObject, index); + } + + public void RemoveMenu (MenuItem item) + { + Control.RemoveItem ((NSMenuItem)item.ControlObject); + } + + public void Clear () + { + Control.RemoveAllItems (); + } + + public void Show (Control relativeTo) + { + NSEvent nsevent = NSApplication.SharedApplication.CurrentEvent; + if (nsevent == null) { + var location = NSEvent.CurrentMouseLocation; + location = NSApplication.SharedApplication.KeyWindow.ConvertScreenToBase (location); + + var time = DateTime.Now.ToOADate(); + var windowNumber = NSApplication.SharedApplication.KeyWindow.WindowNumber; + + nsevent = NSEvent.MouseEvent(NSEventType.RightMouseDown, location, 0, time, windowNumber, null, 0, 0, 0.1f); + } + var view = relativeTo != null ? relativeTo.ControlObject as NSView : null; + NSMenu.PopUpContextMenu(Control, nsevent, view); + } + + } +} + diff --git a/Source/Eto.Platform.Mac/Forms/Menu/ImageMenuItemHandler.cs b/Source/Eto.Mac/Forms/Menu/ImageMenuItemHandler.cs similarity index 81% rename from Source/Eto.Platform.Mac/Forms/Menu/ImageMenuItemHandler.cs rename to Source/Eto.Mac/Forms/Menu/ImageMenuItemHandler.cs index bfec982cab..47bb71debb 100644 --- a/Source/Eto.Platform.Mac/Forms/Menu/ImageMenuItemHandler.cs +++ b/Source/Eto.Mac/Forms/Menu/ImageMenuItemHandler.cs @@ -1,13 +1,25 @@ using System; using Eto.Drawing; using Eto.Forms; -using Eto.Platform.Mac.Forms.Actions; -using MonoMac.AppKit; +using Eto.Mac.Forms.Actions; using sd = System.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif -namespace Eto.Platform.Mac +namespace Eto.Mac.Forms.Menu { - public class ImageMenuItemHandler : MenuHandler, IButtonMenuItem, IMenuActionHandler + public class ImageMenuItemHandler : MenuHandler, ButtonMenuItem.IHandler, IMenuActionHandler { Image image; string text; @@ -34,7 +46,7 @@ public ImageMenuItemHandler() public void HandleClick() { - Widget.OnClick(EventArgs.Empty); + Callback.OnClick(Widget, EventArgs.Empty); } public override void AttachEvent(string id) diff --git a/Source/Eto.Mac/Forms/Menu/MenuActionHandler.cs b/Source/Eto.Mac/Forms/Menu/MenuActionHandler.cs new file mode 100644 index 0000000000..8884c964a7 --- /dev/null +++ b/Source/Eto.Mac/Forms/Menu/MenuActionHandler.cs @@ -0,0 +1,59 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Menu +{ + public interface IMenuActionHandler + { + void HandleClick(); + + bool Enabled { get; } + + MenuItem Widget { get; } + + MenuItem.ICallback Callback { get; } + } + + [Register("EtoMenuActionHandler")] + public class MenuActionHandler : NSObject + { + internal static Selector selActivate = new Selector("activate:"); + WeakReference handler; + + public IMenuActionHandler Handler { get { return (IMenuActionHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [Export("activate:")] + public void Activate(NSObject sender) + { + var h = Handler; + if (h != null) + h.HandleClick(); + } + + [Export("validateMenuItem:")] + public bool ValidateMenuItem(NSMenuItem item) + { + var h = Handler; + if (h != null) + { + h.Callback.OnValidate(h.Widget, EventArgs.Empty); + return h.Enabled; + } + return false; + } + } +} + diff --git a/Source/Eto.Mac/Forms/Menu/MenuBarHandler.cs b/Source/Eto.Mac/Forms/Menu/MenuBarHandler.cs new file mode 100644 index 0000000000..78f9b9f4f3 --- /dev/null +++ b/Source/Eto.Mac/Forms/Menu/MenuBarHandler.cs @@ -0,0 +1,215 @@ +using Eto.Forms; +using System.Collections.Generic; +using Eto.Mac.Forms.Actions; +using System.Linq; +using Eto.Mac.Forms; +using System.Collections.ObjectModel; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Menu +{ + public class MenuBarHandler : WidgetHandler, MenuBar.IHandler + { + public bool AddPrintingMenuItems { get; set; } + + string applicationMenuName = "Application"; + + public MenuBarHandler() + { + Control = new NSMenu(); + Control.AutoEnablesItems = false; + Control.ShowsStateColumn = true; + } + + public void AddMenu(int index, MenuItem item) + { + var itemHandler = item.Handler as IMenuHandler; + if (itemHandler != null) + itemHandler.EnsureSubMenu(); + Control.InsertItem((NSMenuItem)item.ControlObject, index); + } + + public void RemoveMenu(MenuItem item) + { + Control.RemoveItem((NSMenuItem)item.ControlObject); + } + + public void Clear() + { + Control.RemoveAllItems(); + } + + public ButtonMenuItem ApplicationMenu + { + get { return Widget.Items.GetSubmenu(applicationMenuName, -100); } + } + + public ButtonMenuItem HelpMenu + { + get { return Widget.Items.GetSubmenu("&Help", 1000); } + } + + MenuItem quitItem; + public void SetQuitItem(MenuItem item) + { + item.Order = 1000; + var appMenu = ApplicationMenu; + if (quitItem != null) + appMenu.Items.Remove(quitItem); + appMenu.Items.Add(item); + quitItem = item; + } + + MenuItem aboutItem; + public void SetAboutItem(MenuItem item) + { + item.Order = -100; + var appMenu = ApplicationMenu; + if (aboutItem != null) + appMenu.Items.Remove(aboutItem); + appMenu.Items.Add(item); + if (aboutItem == null) + appMenu.Items.AddSeparator(item.Order); + aboutItem = item; + } + + public IEnumerable GetSystemCommands() + { + var appName = Application.Instance.Name ?? NSRunningApplication.CurrentApplication.LocalizedName; + yield return new Command((sender, e) => NSApplication.SharedApplication.Hide(NSApplication.SharedApplication)) + { + ID = "mac_hide", + MenuText = string.Format("Hide {0}", appName), + ToolBarText = "Hide", + ToolTip = string.Format("Hides the main {0} window", appName), + Shortcut = Keys.H | Keys.Application + }; + + yield return new Command((sender, e) => NSApplication.SharedApplication.HideOtherApplications(NSApplication.SharedApplication)) + { + ID = "mac_hideothers", + MenuText = "Hide Others", + ToolBarText = "Hide Others", + ToolTip = "Hides all other application windows", + Shortcut = Keys.H | Keys.Application | Keys.Alt + }; + + yield return new Command((sender, e) => NSApplication.SharedApplication.UnhideAllApplications(NSApplication.SharedApplication)) + { + ID = "mac_showall", + MenuText = "Show All", + ToolBarText = "Show All", + ToolTip = "Show All Windows" + }; + + yield return new MacCommand("mac_performMiniaturize", "Minimize", "performMiniaturize:") { Shortcut = Keys.Application | Keys.M }; + yield return new MacCommand("mac_performZoom", "Zoom", "performZoom:"); + yield return new MacCommand("mac_performClose", "Close", "performClose:") { Shortcut = Keys.Application | Keys.W }; + yield return new MacCommand("mac_arrangeInFront", "Bring All To Front", "arrangeInFront:"); + yield return new MacCommand("mac_cut", "Cut", "cut:") { Shortcut = Keys.Application | Keys.X }; + yield return new MacCommand("mac_copy", "Copy", "copy:") { Shortcut = Keys.Application | Keys.C }; + yield return new MacCommand("mac_paste", "Paste", "paste:") { Shortcut = Keys.Application | Keys.V }; + yield return new MacCommand("mac_pasteAsPlainText", "Paste and Match Style", "pasteAsPlainText:") { Shortcut = Keys.Application | Keys.Alt | Keys.Shift | Keys.V }; + yield return new MacCommand("mac_delete", "Delete", "delete:"); + yield return new MacCommand("mac_selectAll", "Select All", "selectAll:") { Shortcut = Keys.Application | Keys.A }; + yield return new MacCommand("mac_undo", "Undo", "undo:") { Shortcut = Keys.Application | Keys.Z }; + yield return new MacCommand("mac_redo", "Redo", "redo:") { Shortcut = Keys.Application | Keys.Shift | Keys.Z }; + yield return new MacCommand("mac_toggleFullScreen", "Enter Full Screen", "toggleFullScreen:") { Shortcut = Keys.Application | Keys.Control | Keys.F }; + yield return new MacCommand("mac_runPageLayout", "Page Setup...", "runPageLayout:") { Shortcut = Keys.Application | Keys.Shift | Keys.P }; + yield return new MacCommand("mac_print", "Print...", "print:") { Shortcut = Keys.Application | Keys.P }; + } + + public void CreateLegacySystemMenu() + { + applicationMenuName = Application.Instance.Name ?? applicationMenuName; + CreateSystemMenu(); + } + + public void CreateSystemMenu() + { + var items = Widget.Items; + var lookup = Widget.SystemCommands.ToLookup(r => r.ID); + if (Widget.IncludeSystemItems.HasFlag(MenuBarSystemItems.Quit) && quitItem == null) + { + var application = ApplicationMenu; + var quitCommand = new Command { MenuText = "Quit", Shortcut = Keys.Application | Keys.Q }; + quitCommand.Executed += (sender, e) => Application.Instance.Quit(); + application.Items.AddSeparator(999); + application.Items.Add(quitCommand, 1000); + } + if (Widget.IncludeSystemItems.HasFlag(MenuBarSystemItems.Common)) + { + var application = ApplicationMenu; + application.Items.AddSeparator(800); + application.Items.AddRange(lookup["mac_hide"], 800); + application.Items.AddRange(lookup["mac_hideothers"], 800); + application.Items.AddRange(lookup["mac_showall"], 800); + application.Items.AddSeparator(801); + + var file = items.GetSubmenu("&File", 100); + file.Trim = true; + file.Items.AddSeparator(900); + file.Items.AddRange(lookup["mac_performClose"], 900); + + if (AddPrintingMenuItems) + { + file.Items.AddSeparator(1000); + file.Items.AddRange(lookup["mac_runPageLayout"], 1000); + file.Items.AddRange(lookup["mac_print"], 1000); + } + + var edit = items.GetSubmenu("&Edit", 200); + edit.Trim = true; + edit.Items.AddSeparator(100); + edit.Items.AddRange(lookup["mac_undo"], 100); + edit.Items.AddRange(lookup["mac_redo"], 100); + edit.Items.AddSeparator(101); + + edit.Items.AddSeparator(200); + edit.Items.AddRange(lookup["mac_cut"], 200); + edit.Items.AddRange(lookup["mac_copy"], 200); + edit.Items.AddRange(lookup["mac_paste"], 200); + edit.Items.AddRange(lookup["mac_delete"], 200); + edit.Items.AddRange(lookup["mac_selectAll"], 200); + edit.Items.AddSeparator(201); + + var window = items.GetSubmenu("&Window", 900); + window.Trim = true; + window.Items.AddSeparator(100); + window.Items.AddRange(lookup["mac_performMiniaturize"], 100); + window.Items.AddRange(lookup["mac_performZoom"], 100); + window.Items.AddSeparator(101); + + window.Items.AddSeparator(200); + window.Items.AddRange(lookup["mac_arrangeInFront"], 200); + window.Items.AddSeparator(201); + + if (ApplicationHandler.Instance.AddFullScreenMenuItem) + { + var view = items.GetSubmenu("&View", 300); + view.Trim = true; + view.Items.AddSeparator(900); + view.Items.AddRange(lookup["mac_toggleFullScreen"], 900); + view.Items.AddSeparator(901); + } + + var help = items.GetSubmenu("&Help", 900); + // always show help menu + help.Trim = false; + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Menu/MenuHandler.cs b/Source/Eto.Mac/Forms/Menu/MenuHandler.cs new file mode 100644 index 0000000000..d327a945a2 --- /dev/null +++ b/Source/Eto.Mac/Forms/Menu/MenuHandler.cs @@ -0,0 +1,63 @@ +using Eto.Forms; +using Eto.Mac.Forms.Actions; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Menu +{ + public interface IMenuHandler + { + void EnsureSubMenu(); + } + + public abstract class MenuHandler : WidgetHandler, Eto.Forms.Menu.IHandler, IMenuHandler + where TControl: NSMenuItem + where TWidget: Eto.Forms.Menu + where TCallback: Eto.Forms.Menu.ICallback + { + public void EnsureSubMenu() + { + if (!Control.HasSubmenu) + Control.Submenu = new NSMenu { AutoEnablesItems = true, ShowsStateColumn = true, Title = Control.Title }; + } + + public virtual void AddMenu(int index, MenuItem item) + { + EnsureSubMenu(); + Control.Submenu.InsertItem((NSMenuItem)item.ControlObject, index); + } + + public virtual void RemoveMenu(MenuItem item) + { + if (Control.Submenu == null) + return; + Control.Submenu.RemoveItem((NSMenuItem)item.ControlObject); + } + + public virtual void Clear() + { + Control.Submenu = null; + } + + public void CreateFromCommand(Command command) + { + var m = command as MacCommand; + if (m != null) + { + Control.Target = null; + Control.Action = m.Selector; + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Menu/RadioMenuItemHandler.cs b/Source/Eto.Mac/Forms/Menu/RadioMenuItemHandler.cs new file mode 100644 index 0000000000..c3ed41f4db --- /dev/null +++ b/Source/Eto.Mac/Forms/Menu/RadioMenuItemHandler.cs @@ -0,0 +1,113 @@ +using System; +using Eto.Forms; +using System.Collections.Generic; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Menu +{ + public class RadioMenuItemHandler : MenuHandler, RadioMenuItem.IHandler, IMenuActionHandler + { + List radioGroup; + + public RadioMenuItemHandler() + { + Control = new NSMenuItem(); + Enabled = true; + //control.SetButtonType(NSButtonType.Radio); + Control.Target = new MenuActionHandler { Handler = this }; + Control.Action = MenuActionHandler.selActivate; + } + + public void HandleClick() + { + Callback.OnClick(Widget, EventArgs.Empty); + + if (radioGroup != null) + { + foreach (RadioMenuItem item in radioGroup) + { + item.Checked = (item.ControlObject == Control); + } + } + } + + public void Create(RadioMenuItem controller) + { + if (controller != null) + { + var controllerInner = (RadioMenuItemHandler)controller.Handler; + if (controllerInner.radioGroup == null) + { + controllerInner.radioGroup = new List(); + controllerInner.radioGroup.Add(controller); + } + controllerInner.radioGroup.Add(Widget); + radioGroup = controllerInner.radioGroup; + } + } + + public bool Enabled + { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + + public string Text + { + get { return Control.Title; } + set { Control.SetTitleWithMnemonic(value); } + } + + public string ToolTip + { + get { return Control.ToolTip; } + set { Control.ToolTip = value ?? string.Empty; } + } + + public Keys Shortcut + { + get { return KeyMap.Convert(Control.KeyEquivalent, Control.KeyEquivalentModifierMask); } + set + { + Control.KeyEquivalent = KeyMap.KeyEquivalent(value); + Control.KeyEquivalentModifierMask = KeyMap.KeyEquivalentModifierMask(value); + } + } + + public bool Checked + { + get { return Control.State == NSCellStateValue.On; } + set { Control.State = value ? NSCellStateValue.On : NSCellStateValue.Off; } + } + + MenuItem IMenuActionHandler.Widget + { + get { return Widget; } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case MenuItem.ValidateEvent: + // handled in MenuActionHandler + break; + default: + base.AttachEvent(id); + break; + } + } + } +} diff --git a/Source/Eto.Mac/Forms/Menu/SeparatorMenuItem.cs b/Source/Eto.Mac/Forms/Menu/SeparatorMenuItem.cs new file mode 100644 index 0000000000..480df2782a --- /dev/null +++ b/Source/Eto.Mac/Forms/Menu/SeparatorMenuItem.cs @@ -0,0 +1,47 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Menu +{ + public class SeparatorMenuItemHandler : MenuHandler, SeparatorMenuItem.IHandler + { + public SeparatorMenuItemHandler () + { + Control = NSMenuItem.SeparatorItem; + } + + public bool Enabled { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + + public string Text { + get { return string.Empty; } + set { throw new NotSupportedException (); } + } + + public Keys Shortcut { + get { return Keys.None; } + set { throw new NotSupportedException (); } + } + + public string ToolTip { + get { return string.Empty; } + set { throw new NotSupportedException (); } + } + + } +} diff --git a/Source/Eto.Mac/Forms/MessageBoxHandler.cs b/Source/Eto.Mac/Forms/MessageBoxHandler.cs new file mode 100644 index 0000000000..9f286a1799 --- /dev/null +++ b/Source/Eto.Mac/Forms/MessageBoxHandler.cs @@ -0,0 +1,155 @@ +using System; +using Eto.Forms; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms +{ + public class MessageBoxHandler : WidgetHandler, MessageBox.IHandler + { + public string Text { get; set; } + + public string Caption { get; set; } + + public MessageBoxType Type { get; set; } + + public MessageBoxButtons Buttons { get; set; } + + public MessageBoxDefaultButton DefaultButton { get; set; } + + public DialogResult ShowDialog(Control parent) + { + var alert = new NSAlert(); + + AddButtons(alert); + + alert.AlertStyle = Convert(Type); + alert.MessageText = Caption ?? string.Empty; + alert.InformativeText = Text ?? string.Empty; + var ret = MacModal.Run(alert, parent); + switch (Buttons) + { + default: + return DialogResult.Ok; + case MessageBoxButtons.OKCancel: + return (ret == 1000) ? DialogResult.Ok : DialogResult.Cancel; + case MessageBoxButtons.YesNo: + return (ret == 1000) ? DialogResult.Yes : DialogResult.No; + case MessageBoxButtons.YesNoCancel: + return (ret == 1000) ? DialogResult.Yes : (ret == 1001) ? DialogResult.Cancel : DialogResult.No; + } + } + + void AddButtons(NSAlert alert) + { + var OkButton = "OK"; + var CancelButton = "Cancel"; + var YesButton = "Yes"; + var NoButton = "No"; + + switch (Buttons) + { + case MessageBoxButtons.OK: + alert.AddButton(OkButton); + break; + case MessageBoxButtons.OKCancel: + { + var ok = alert.AddButton(OkButton); + var cancel = alert.AddButton(CancelButton); + switch (DefaultButton) + { + case MessageBoxDefaultButton.OK: + ok.BecomeFirstResponder(); + break; + case MessageBoxDefaultButton.Cancel: + case MessageBoxDefaultButton.Default: + cancel.BecomeFirstResponder(); + break; + } + } + break; + case MessageBoxButtons.YesNo: + { + var yes = alert.AddButton(YesButton); + var no = alert.AddButton(NoButton); + switch (DefaultButton) + { + case MessageBoxDefaultButton.Yes: + yes.BecomeFirstResponder(); + break; + case MessageBoxDefaultButton.No: + case MessageBoxDefaultButton.Default: + no.BecomeFirstResponder(); + break; + } + } + break; + case MessageBoxButtons.YesNoCancel: + { + var yes = alert.AddButton(YesButton); + var cancel = alert.AddButton(CancelButton); + var no = alert.AddButton(NoButton); + switch (DefaultButton) + { + case MessageBoxDefaultButton.Yes: + yes.BecomeFirstResponder(); + break; + case MessageBoxDefaultButton.No: + no.BecomeFirstResponder(); + break; + case MessageBoxDefaultButton.Cancel: + case MessageBoxDefaultButton.Default: + cancel.BecomeFirstResponder(); + break; + } + } + break; + } + } + + static NSAlertStyle Convert(MessageBoxType type) + { + switch (type) + { + case MessageBoxType.Information: + case MessageBoxType.Question: + return NSAlertStyle.Informational; + case MessageBoxType.Warning: + return NSAlertStyle.Warning; + case MessageBoxType.Error: + return NSAlertStyle.Critical; + default: + throw new NotSupportedException(); + } + } + } +} diff --git a/Source/Eto.Mac/Forms/MouseHandler.cs b/Source/Eto.Mac/Forms/MouseHandler.cs new file mode 100644 index 0000000000..b618194273 --- /dev/null +++ b/Source/Eto.Mac/Forms/MouseHandler.cs @@ -0,0 +1,56 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + public class MouseHandler : Mouse.IHandler + { + public void Initialize () + { + } + public Widget Widget { get; set; } + + public Eto.Platform Platform { get; set; } + + public Eto.Drawing.PointF Position + { + get + { + var mouseLocation = NSEvent.CurrentMouseLocation; + var origin = NSScreen.Screens[0].Frame.Bottom; + mouseLocation.Y = origin - mouseLocation.Y; + return mouseLocation.ToEto(); + } + } + + public MouseButtons Buttons + { + get + { + var current = NSEvent.CurrentPressedMouseButtons; + var buttons = MouseButtons.None; + if ((current & 1) != 0) + buttons |= MouseButtons.Primary; + if ((current & 2) != 0) + buttons |= MouseButtons.Alternate; + if ((current & 4) != 0) + buttons |= MouseButtons.Middle; + return buttons; + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/OpenFileDialog.cs b/Source/Eto.Mac/Forms/OpenFileDialog.cs new file mode 100644 index 0000000000..7898dc083f --- /dev/null +++ b/Source/Eto.Mac/Forms/OpenFileDialog.cs @@ -0,0 +1,57 @@ +using System.Linq; +using Eto.Forms; +using System.Collections.Generic; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms +{ + public class OpenFileDialogHandler : MacFileDialog, OpenFileDialog.IHandler + { + + public OpenFileDialogHandler() + { + Control = NSOpenPanel.OpenPanel; + } + + public bool MultiSelect + { + get { return Control.AllowsMultipleSelection; } + set { Control.AllowsMultipleSelection = value; } + } + + public IEnumerable Filenames + { + get { return Control.Urls.Select(a => a.Path); } + } + } +} diff --git a/Source/Eto.Mac/Forms/PixelLayoutHandler.cs b/Source/Eto.Mac/Forms/PixelLayoutHandler.cs new file mode 100644 index 0000000000..f88c120fb8 --- /dev/null +++ b/Source/Eto.Mac/Forms/PixelLayoutHandler.cs @@ -0,0 +1,171 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using SD = System.Drawing; +using System.Collections.Generic; +using System.Linq; +using Eto.Mac.Forms.Controls; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms +{ + public class PixelLayoutHandler : MacContainer, PixelLayout.IHandler + { + readonly Dictionary points = new Dictionary(); + + public override NSView ContainerControl { get { return Control; } } + + public PixelLayoutHandler() + { + Control = new MacEventView { Handler = this }; + } + + public CGRect GetPosition(Control control) + { + PointF point; + if (points.TryGetValue(control, out point)) + { + var frameSize = ((NSView)control.ControlObject).Frame.Size; + return new CGRect(point.ToNS(), frameSize); + } + return control.GetContainerView().Frame; + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + SizeF size = SizeF.Empty; + foreach (var item in points.Where(r => r.Key.Visible)) + { + var frameSize = item.Key.GetPreferredSize(availableSize); + size = SizeF.Max(size, frameSize + new SizeF(item.Value)); + } + return size; + } + + public override void OnLoadComplete(EventArgs e) + { + base.OnLoadComplete(e); + LayoutChildren(); + Widget.SizeChanged += HandleSizeChanged; + } + + public override void OnUnLoad(EventArgs e) + { + base.OnUnLoad(e); + Widget.SizeChanged -= HandleSizeChanged; + } + + void HandleSizeChanged (object sender, EventArgs e) + { + LayoutChildren(); + } + + void SetPosition(Control control, PointF point, float frameHeight, bool flipped) + { + var offset = ((IMacViewHandler)control.Handler).PositionOffset; + var childView = control.GetContainerView(); + + var preferredSize = control.GetPreferredSize(Control.Frame.Size.ToEtoSize()); + + CGPoint origin; + if (flipped) + origin = new CGPoint( + point.X + offset.Width, + point.Y + offset.Height + ); + else + origin = new CGPoint( + point.X + offset.Width, + frameHeight - (preferredSize.Height + point.Y + offset.Height) + ); + + var frame = new CGRect(origin, preferredSize.ToNS()); + if (frame != childView.Frame) + { + childView.Frame = frame; + } + } + + public override void LayoutChildren() + { + if (NeedsQueue()) + return; + var controlPoints = points.ToArray(); + var frameHeight = Control.Frame.Height; + var flipped = Control.IsFlipped; + foreach (var item in controlPoints) + { + SetPosition(item.Key, item.Value, (float)frameHeight, flipped); + } + } + + public void Add(Control child, int x, int y) + { + var location = new Point(x, y); + points[child] = location; + var childView = child.GetContainerView(); + if (Widget.Loaded) + { + var frameHeight = Control.Frame.Height; + SetPosition(child, location, (float)frameHeight, Control.IsFlipped); + } + Control.AddSubview(childView); + if (Widget.Loaded) + LayoutParent(); + } + + public void Move(Control child, int x, int y) + { + var location = new Point(x, y); + if (points[child] != location) + { + points[child] = location; + if (Widget.Loaded) + { + var frameHeight = Control.Frame.Height; + SetPosition(child, location, (float)frameHeight, Control.IsFlipped); + LayoutParent(); + } + } + } + + public void Remove(Control child) + { + var childView = child.GetContainerView(); + points.Remove(child); + childView.RemoveFromSuperview(); + if (Widget.Loaded) + LayoutParent(); + } + } +} diff --git a/Source/Eto.Mac/Forms/Printing/PrintDialogHandler.cs b/Source/Eto.Mac/Forms/Printing/PrintDialogHandler.cs new file mode 100644 index 0000000000..45eb954757 --- /dev/null +++ b/Source/Eto.Mac/Forms/Printing/PrintDialogHandler.cs @@ -0,0 +1,117 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Printing +{ + public class PrintDialogHandler : WidgetHandler, PrintDialog.IHandler + { + PrintSettings settings; + + public PrintDialogHandler() + { + Control = new NSPrintPanel(); + } + + class SheetHelper : NSObject + { + [Export("printPanelDidEnd:returnCode:contextInfo:")] + public void PrintPanelDidEnd(NSPrintPanel printPanel, int returnCode, IntPtr contextInfo) + { + NSApplication.SharedApplication.StopModalWithCode(returnCode); + } + } + + public PrintDocument Document { get; set; } + + public DialogResult ShowDialog(Window parent) + { + int ret; + var docHandler = Document != null ? Document.Handler as PrintDocumentHandler : null; + + if (docHandler != null) + { + Control.Options |= NSPrintPanelOptions.ShowsPreview; + ret = docHandler.Print(true, parent, Control) ? 1 : 0; + } + else + { + var printInfo = settings.ToNS(); + if (parent != null) + { + var parentHandler = (IMacWindow)parent.Handler; + var closeSheet = new SheetHelper(); + Control.BeginSheet(printInfo, parentHandler.Control, closeSheet, new Selector("printPanelDidEnd:returnCode:contextInfo:"), IntPtr.Zero); + ret = (int)NSApplication.SharedApplication.RunModalForWindow(parentHandler.Control); + } + else + ret = (int)Control.RunModalWithPrintInfo(printInfo); + } + + return ret == 1 ? DialogResult.Ok : DialogResult.Cancel; + } + + public PrintSettings PrintSettings + { + get + { + if (settings == null) + settings = Control.PrintInfo.ToEto(); + return settings; + } + set + { + settings = value; + } + } + + public bool AllowCopies + { + get { return Control.Options.HasFlag(NSPrintPanelOptions.ShowsCopies); } + set + { + if (value) + Control.Options |= NSPrintPanelOptions.ShowsCopies; + else + Control.Options &= ~NSPrintPanelOptions.ShowsCopies; + } + } + + public bool AllowPageRange + { + get { return Control.Options.HasFlag(NSPrintPanelOptions.ShowsPageRange); } + set + { + if (value) + Control.Options |= NSPrintPanelOptions.ShowsPageRange; + else + Control.Options &= ~NSPrintPanelOptions.ShowsPageRange; + } + } + + public bool AllowSelection + { + get { return Control.Options.HasFlag(NSPrintPanelOptions.ShowsPrintSelection); } + set + { + if (value) + Control.Options |= NSPrintPanelOptions.ShowsPrintSelection; + else + Control.Options &= ~NSPrintPanelOptions.ShowsPrintSelection; + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Printing/PrintDocumentHandler.cs b/Source/Eto.Mac/Forms/Printing/PrintDocumentHandler.cs new file mode 100644 index 0000000000..276ebd148d --- /dev/null +++ b/Source/Eto.Mac/Forms/Printing/PrintDocumentHandler.cs @@ -0,0 +1,171 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using Eto.Mac.Drawing; +using sd = System.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.Printing +{ + public class PrintDocumentHandler : WidgetHandler, PrintDocument.IHandler + { + PrintSettings printSettings; + + [Register("PrintView")] + public class PrintView : NSView + { + public PrintView() + { + } + + public PrintView(IntPtr handle) + : base(handle) + { + } + + public PrintView(NSCoder coder) + : base(coder) + { + } + + public PrintDocumentHandler Handler { get; set; } + + public override string PrintJobTitle + { + get { return Handler.Name ?? string.Empty; } + } + + public override CGRect RectForPage(nint pageNumber) + { + var operation = NSPrintOperation.CurrentOperation; + if (Frame.Size != operation.PrintInfo.PaperSize) + SetFrameSize(operation.PrintInfo.PaperSize); + return new CGRect(new CGPoint(0, 0), operation.PrintInfo.PaperSize); + //return this.Frame; + } + + static readonly IntPtr selCurrentContext = Selector.GetHandle("currentContext"); + static readonly IntPtr classNSGraphicsContext = Class.GetHandle("NSGraphicsContext"); + + public override void DrawRect(CGRect dirtyRect) + { + var operation = NSPrintOperation.CurrentOperation; + + var context = new NSGraphicsContext(Messaging.IntPtr_objc_msgSend(classNSGraphicsContext, selCurrentContext)); + // this causes monomac to hang for some reason: + //var context = NSGraphicsContext.CurrentContext; + + using (var graphics = new Graphics(new GraphicsHandler(this, context, (float)Frame.Height, IsFlipped))) + { + Handler.Callback.OnPrintPage(Handler.Widget, new PrintPageEventArgs(graphics, operation.PrintInfo.PaperSize.ToEto(), (int)operation.CurrentPage - 1)); + } + } + + public override bool KnowsPageRange(ref NSRange aRange) + { + aRange = new NSRange(1, Handler.PageCount); + return true; + } + } + + public PrintDocumentHandler() + { + Control = new PrintView { Handler = this }; + } + + public void Print() + { + Print(false, null, null); + } + + class SheetHelper : NSObject + { + public bool Success { get; set; } + + [Export("printOperationDidRun:success:contextInfo:")] + public void PrintOperationDidRun(IntPtr printOperation, bool success, IntPtr contextInfo) + { + Success = success; + NSApplication.SharedApplication.StopModalWithCode(success ? 1 : 0); + } + } + + public bool Print(bool showPanel, Window parent, NSPrintPanel panel) + { + var op = NSPrintOperation.FromView(Control); + if (printSettings != null) + op.PrintInfo = printSettings.ToNS(); + if (panel != null) + op.PrintPanel = panel; + op.ShowsPrintPanel = showPanel; + if (parent != null) + { + var parentHandler = (IMacWindow)parent.Handler; + var closeSheet = new SheetHelper(); + op.RunOperationModal(parentHandler.Control, closeSheet, new Selector("printOperationDidRun:success:contextInfo:"), IntPtr.Zero); + NSApplication.SharedApplication.RunModalForWindow(parentHandler.Control); + return closeSheet.Success; + } + return op.RunOperation(); + } + + public string Name { get; set; } + + public int PageCount { get; set; } + + public PrintSettings PrintSettings + { + get + { + if (printSettings == null) + printSettings = new PrintSettings(); + return printSettings; + } + set + { + printSettings = value; + //Control.PrintInfo = printSettings == null ? null : ((PrintSettingsHandler)printSettings.Handler).Control; + } + } + + public override void AttachEvent(string id) + { + switch (id) + { + case PrintDocument.PrintPageEvent: + break; + default: + base.AttachEvent(id); + break; + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/Printing/PrintSettingsHandler.cs b/Source/Eto.Mac/Forms/Printing/PrintSettingsHandler.cs new file mode 100644 index 0000000000..4d4269d113 --- /dev/null +++ b/Source/Eto.Mac/Forms/Printing/PrintSettingsHandler.cs @@ -0,0 +1,157 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.Printing +{ + public class PrintSettingsHandler : WidgetHandler, PrintSettings.IHandler + { + int lastSelectedPage; + int firstSelectedPage; + + public PrintSettingsHandler(NSPrintInfo info) + { + Control = info; + } + + public PrintSettingsHandler() + { + Control = new NSPrintInfo(); + MaximumPageRange = new Range(1, 1); + SelectedPageRange = new Range(1, 1); + } + + public int Copies + { + get { return (int)(NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMCopies"]; } + set { Control.PrintSettings["com_apple_print_PrintSettings_PMCopies"] = new NSNumber(value); } + } + + public Range MaximumPageRange + { + get + { + var range = ((NSArray)Control.PrintSettings["com_apple_print_PrintSettings_PMPageRange"]); + var firstPage = new NSNumber(range.ValueAt(0)).Int32Value; + var lastPage = new NSNumber(range.ValueAt(1)).Int32Value; + return new Range(firstPage, lastPage - firstPage + 1); + } + set + { + var array = NSArray.FromNSObjects(new NSNumber(value.Start), new NSNumber(value.End)); + Control.PrintSettings["com_apple_print_PrintSettings_PMPageRange"] = array; + } + } + + public Range SelectedPageRange + { + get + { + if (IsAllPages) + { + return new Range(firstSelectedPage, lastSelectedPage); + } + else + { + var firstPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"]).Int32Value; + var lastPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"]).Int32Value; + return new Range(firstPage, lastPage); + } + } + set + { + lastSelectedPage = value.End; + firstSelectedPage = value.Start; + + if (!IsAllPages) + { + var firstPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"]).Int32Value; + if (value.Start < firstPage) + { + Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"] = new NSNumber(value.Start); + Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"] = new NSNumber(value.End); + } + else + { + Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"] = new NSNumber(value.End); + Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"] = new NSNumber(value.Start); + } + } + } + } + + public PageOrientation Orientation + { + get { return Control.Orientation.ToEto(); } + set { Control.Orientation = value.ToNS(); } + } + + public bool Collate + { + get { return ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMCopyCollate"]).BoolValue; } + set { Control.PrintSettings["com_apple_print_PrintSettings_PMCopyCollate"] = new NSNumber(value); } + } + + bool IsAllPages + { + get + { + var lastPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"]).Int32Value; + var firstPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"]).Int32Value; + return firstPage == 1 && lastPage == Int32.MaxValue; + } + } + + public PrintSelection PrintSelection + { + get + { + if (Control.SelectionOnly) + return PrintSelection.Selection; + return IsAllPages ? PrintSelection.AllPages : PrintSelection.SelectedPages; + } + set + { + switch (value) + { + case Eto.Forms.PrintSelection.AllPages: + Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"] = new NSNumber(Int32.MaxValue); + Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"] = new NSNumber(1); + Control.SelectionOnly = false; + break; + case Eto.Forms.PrintSelection.SelectedPages: + Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"] = new NSNumber(lastSelectedPage); + Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"] = new NSNumber(firstSelectedPage); + Control.SelectionOnly = false; + break; + case Eto.Forms.PrintSelection.Selection: + Control.SelectionOnly = true; + break; + } + } + } + + public bool Reverse + { + get + { + var order = (NSString)Control.PrintSettings["OutputOrder"]; + return order != null && order == "Reverse"; + } + set { Control.PrintSettings["OutputOrder"] = new NSString(value ? "Reverse" : "Normal"); } + } + } +} + diff --git a/Source/Eto.Mac/Forms/SaveFileDialogHandler.cs b/Source/Eto.Mac/Forms/SaveFileDialogHandler.cs new file mode 100644 index 0000000000..9a1bc2b846 --- /dev/null +++ b/Source/Eto.Mac/Forms/SaveFileDialogHandler.cs @@ -0,0 +1,81 @@ +using System; +using SD = System.Drawing; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + [Register("MySavePanel")] + class MySavePanel : NSSavePanel + { + public IMacFileDialog Handler { get; set; } + + public MySavePanel () + { + } + + public MySavePanel (IntPtr handle) + : base(handle) + { + + } + + [Export ("initWithCoder:")] + public MySavePanel (NSCoder coder) + : base(coder) + { + } + + [Obsolete] + public override string RequiredFileType { + get { + var ext = Handler.GetDefaultExtension (); + return !string.IsNullOrEmpty(ext) ? ext : base.RequiredFileType; + } + set { + base.RequiredFileType = value; + } + } + + /* + protected override void Dispose (bool disposing) + { + base.Dispose (disposing); + }*/ + + } + + public class SaveFileDialogHandler : MacFileDialog, SaveFileDialog.IHandler + { + public override string FileName { + get { + return base.FileName; + } + set { + Control.NameFieldStringValue = value; + } + } + + public SaveFileDialogHandler () + { + //MySavePanel.Sa + Control = NSSavePanel.SavePanel; //new MySavePanel{ Handler = this }; + Control.AllowsOtherFileTypes = true; + Control.CanSelectHiddenExtension = true; + } + + + } +} diff --git a/Source/Eto.Mac/Forms/ScreenHandler.cs b/Source/Eto.Mac/Forms/ScreenHandler.cs new file mode 100644 index 0000000000..4f8c7faa48 --- /dev/null +++ b/Source/Eto.Mac/Forms/ScreenHandler.cs @@ -0,0 +1,80 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + public class ScreenHandler : WidgetHandler, Screen.IHandler + { + public ScreenHandler (NSScreen screen) + { + this.Control = screen; + } + + static readonly Selector selBackingScaleFactor = new Selector ("backingScaleFactor"); + +#pragma warning disable 612, 618 + public float RealScale + { + get + { + if (Control.RespondsToSelector(selBackingScaleFactor)) + return (float)Control.BackingScaleFactor; + return (float)Control.UserSpaceScaleFactor; + } + } +#pragma warning restore 612, 618 + + public float Scale + { + get { return 1f; } + } + + public RectangleF Bounds + { + get + { + var bounds = Control.Frame; + var origin = NSScreen.Screens[0].Frame.Bottom; + bounds.Y = origin - bounds.Height - bounds.Y; + return bounds.ToEto(); + + } + } + + public RectangleF WorkingArea + { + get + { + var workingArea = Control.VisibleFrame; + var origin = NSScreen.Screens[0].Frame.Bottom; + workingArea.Y = origin - workingArea.Height - workingArea.Y; + return workingArea.ToEto(); + } + } + + public int BitsPerPixel + { + get { return (int)NSGraphics.BitsPerPixelFromDepth (Control.Depth); } + } + + public bool IsPrimary + { + get { return Control == NSScreen.Screens[0]; } + } + } +} + diff --git a/Source/Eto.Mac/Forms/ScreensHandler.cs b/Source/Eto.Mac/Forms/ScreensHandler.cs new file mode 100644 index 0000000000..98fc9906f1 --- /dev/null +++ b/Source/Eto.Mac/Forms/ScreensHandler.cs @@ -0,0 +1,42 @@ +using Eto.Forms; +using System.Collections.Generic; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + public class ScreensHandler : Screen.IScreensHandler + { + public IEnumerable Screens + { + get + { + foreach (var screen in NSScreen.Screens) + { + yield return new Screen(new ScreenHandler(screen)); + } + } + } + + public Screen PrimaryScreen + { + get + { + var screen = NSScreen.Screens[0]; + return new Screen(new ScreenHandler(screen)); + } + } + } +} + diff --git a/Source/Eto.Mac/Forms/SelectFolderDialogHandler.cs b/Source/Eto.Mac/Forms/SelectFolderDialogHandler.cs new file mode 100644 index 0000000000..e5cb2e191d --- /dev/null +++ b/Source/Eto.Mac/Forms/SelectFolderDialogHandler.cs @@ -0,0 +1,55 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + public class SelectFolderDialogHandler : WidgetHandler, SelectFolderDialog.IHandler + { + public SelectFolderDialogHandler () + { + Control = new NSOpenPanel(); + Control.CanChooseDirectories = true; + Control.CanChooseFiles = false; + Control.CanCreateDirectories = true; + } + + public DialogResult ShowDialog (Window parent) + { + var ret = Control.RunModal(); + return ret == 1 ? DialogResult.Ok : DialogResult.Cancel; + } + + public string Title { + get { + return Control.Title; + } + set { + Control.Title = value; + } + } + + public string Directory { + get { + return Control.DirectoryUrl.Path; + } + set { + Control.DirectoryUrl = new NSUrl(value); + } + } + + } +} + diff --git a/Source/Eto.Mac/Forms/TableLayoutHandler.cs b/Source/Eto.Mac/Forms/TableLayoutHandler.cs new file mode 100644 index 0000000000..268b135602 --- /dev/null +++ b/Source/Eto.Mac/Forms/TableLayoutHandler.cs @@ -0,0 +1,383 @@ +using System; +using Eto.Forms; +using System.Linq; +using Eto.Drawing; +using sd = System.Drawing; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +#if IOS +using MonoTouch.UIKit; +using NSView = MonoTouch.UIKit.UIView; +using IMacView = Eto.iOS.Forms.IIosView; +using MacContainer = Eto.iOS.Forms.IosLayout; + +#elif OSX +using Eto.Mac.Forms.Controls; + +#if XAMMAC2 +using MacContainer = Eto.Mac.Forms.MacContainer; +#else +using MacContainer = Eto.Mac.Forms.MacContainer; +#endif + +#endif +namespace Eto.Mac.Forms +{ + public class TableLayoutHandler : MacContainer, TableLayout.IHandler + { + Control[,] views; + bool[] xscaling; + bool[] yscaling; + int lastxscale; + int lastyscale; + Size spacing; + Padding padding; + sd.SizeF oldFrameSize; + + public override NSView ContainerControl { get { return Control; } } + + public Size Spacing + { + get { return spacing; } + set + { + spacing = value; + if (Widget.Loaded) + LayoutParent(); + } + } + + public Padding Padding + { + get { return padding; } + set + { + padding = value; + if (Widget.Loaded) + LayoutParent(); + } + } + + public TableLayoutHandler() + { +#if OSX + Control = new MacEventView { Handler = this }; +#elif IOS + Control = new NSView(); +#endif + + #pragma warning disable 612,618 + spacing = TableLayout.DefaultSpacing; + padding = TableLayout.DefaultPadding; + #pragma warning restore 612,618 + } + + protected override void Initialize() + { + base.Initialize(); + + Widget.SizeChanged += HandleSizeChanged; + } + + bool isResizing; + + void HandleSizeChanged(object sender, EventArgs e) + { + if (!isResizing) + { + isResizing = true; + LayoutChildren(); + isResizing = false; + } + } + + public override void OnLoad(EventArgs e) + { + base.OnLoad(e); + LayoutChildren(); + } + + protected override SizeF GetNaturalSize(SizeF availableSize) + { + if (views == null) + return SizeF.Empty; + var heights = new float[views.GetLength(0)]; + var widths = new float[views.GetLength(1)]; + float totalxpadding = Padding.Horizontal + Spacing.Width * (widths.Length - 1); + float totalypadding = Padding.Vertical + Spacing.Height * (heights.Length - 1); + var requiredx = totalxpadding; + var requiredy = totalypadding; + + for (int y = 0; y < heights.Length; y++) + { + heights[y] = 0; + } + for (int x = 0; x < widths.Length; x++) + { + widths[x] = 0; + } + + for (int y = 0; y < heights.Length; y++) + for (int x = 0; x < widths.Length; x++) + { + var view = views[y, x]; + if (view != null && view.Visible) + { + var size = view.GetPreferredSize(Size.MaxValue); + if (size.Width > widths[x]) + { + requiredx += size.Width - widths[x]; + widths[x] = size.Width; + } + if (size.Height > heights[y]) + { + requiredy += size.Height - heights[y]; + heights[y] = size.Height; + } + } + } + return new SizeF(requiredx, requiredy); + } + + public override void LayoutChildren() + { + if (!Widget.Loaded || views == null || NeedsQueue()) + return; + var heights = new float[views.GetLength(0)]; + var widths = new float[views.GetLength(1)]; + var controlFrame = ContentControl.Frame; + float totalxpadding = Padding.Horizontal + Spacing.Width * (widths.Length - 1); + float totalypadding = Padding.Vertical + Spacing.Height * (heights.Length - 1); + var totalx = (float)controlFrame.Width - totalxpadding; + var totaly = (float)controlFrame.Height - totalypadding; + var requiredx = totalxpadding; + var requiredy = totalypadding; + var numx = 0; + var numy = 0; + + for (int y = 0; y < heights.Length; y++) + { + heights[y] = 0; + if (yscaling[y] || lastyscale == y) + numy++; + } + for (int x = 0; x < widths.Length; x++) + { + widths[x] = 0; + if (xscaling[x] || lastxscale == x) + numx++; + } + + var availableSize = Size.Max(Size.Empty, Control.Frame.Size.ToEtoSize() - new Size((int)requiredx, (int)requiredy)); + for (int y = 0; y < heights.Length; y++) + for (int x = 0; x < widths.Length; x++) + { + var view = views[y, x]; + if (view != null && view.Visible) + { + var size = view.GetPreferredSize(availableSize); + if (!xscaling[x] && lastxscale != x && widths[x] < size.Width) + { + requiredx += size.Width - widths[x]; + widths[x] = size.Width; + } + if (!yscaling[y] && lastyscale != y && heights[y] < size.Height) + { + requiredy += size.Height - heights[y]; + heights[y] = size.Height; + } + } + } + if (controlFrame.Width < requiredx) + { + totalx = requiredx - totalxpadding; + } + if (controlFrame.Height < requiredy) + { + totaly = requiredy - totalypadding; + } + + for (int y = 0; y < heights.Length; y++) + if (!yscaling[y] && lastyscale != y) + totaly -= heights[y]; + for (int x = 0; x < widths.Length; x++) + if (!xscaling[x] && lastxscale != x) + totalx -= widths[x]; + + var chunkx = (numx > 0) ? (float)Math.Truncate(Math.Max(totalx, 0) / numx) : totalx; + var chunky = (numy > 0) ? (float)Math.Truncate(Math.Max(totaly, 0) / numy) : totaly; + +#if OSX + bool flipped = Control.IsFlipped; +#elif IOS + bool flipped = !Control.Layer.GeometryFlipped; +#endif + float starty = Padding.Top; + for (int x = 0; x < widths.Length; x++) + { + if (xscaling[x] || lastxscale == x) + { + widths[x] = Math.Min(chunkx, totalx); + totalx -= chunkx; + } + } + + for (int y = 0; y < heights.Length; y++) + { + if (yscaling[y] || lastyscale == y) + { + heights[y] = Math.Min(chunky, totaly); + totaly -= chunky; + } + float startx = Padding.Left; + for (int x = 0; x < widths.Length; x++) + { + var view = views[y, x]; + if (view != null && view.Visible) + { + var nsview = view.GetContainerView(); + var frame = nsview.Frame; + var oldframe = frame; + frame.Width = widths[x]; + frame.Height = heights[y]; + frame.X = Math.Max(0, startx); + frame.Y = flipped ? starty : controlFrame.Height - starty - frame.Height; + if (frame != oldframe) + nsview.Frame = frame; + else if (oldframe.Right > oldFrameSize.Width || oldframe.Bottom > oldFrameSize.Height + || frame.Right > oldFrameSize.Width || frame.Bottom > oldFrameSize.Height) + nsview.SetNeedsDisplay(); + //Console.WriteLine("*** x:{2} y:{3} view: {0} size: {1} totalx:{4} totaly:{5}", view, view.Size, x, y, totalx, totaly); + } + startx += widths[x] + Spacing.Width; + } + starty += heights[y] + Spacing.Height; + } + oldFrameSize = controlFrame.Size.ToSD(); + } + + public void Add(Control child, int x, int y) + { + var current = views[y, x]; + if (current != null) + { + var currentView = current.GetContainerView(); + if (currentView != null) + currentView.RemoveFromSuperview(); + } + views[y, x] = child; + if (child != null) + { + var view = child.GetContainerView(); + if (Widget.Loaded) + LayoutParent(); + Control.AddSubview(view); + } + else if (Widget.Loaded) + LayoutParent(); + } + + public void Move(Control child, int x, int y) + { + var current = views[y, x]; + if (current != null) + { + var currentView = current.GetContainerView(); + if (currentView != null) + currentView.RemoveFromSuperview(); + } + for (int yy = 0; yy < views.GetLength(0); yy++) + for (int xx = 0; xx < views.GetLength(1); xx++) + { + if (object.ReferenceEquals(views[yy, xx], child)) + views[yy, xx] = null; + } + + views[y, x] = child; + if (Widget.Loaded) + LayoutParent(); + } + + public void Remove(Control child) + { + for (int y = 0; y < views.GetLength(0); y++) + for (int x = 0; x < views.GetLength(1); x++) + { + if (object.ReferenceEquals(views[y, x], child)) + { + var view = child.GetContainerView(); + view.RemoveFromSuperview(); + views[y, x] = null; + if (Widget.Loaded) + LayoutParent(); + return; + } + } + } + + public void CreateControl(int cols, int rows) + { + views = new Control[rows, cols]; + xscaling = new bool[cols]; + lastxscale = cols - 1; + yscaling = new bool[rows]; + lastyscale = rows - 1; + } + + public void SetColumnScale(int column, bool scale) + { + xscaling[column] = scale; + lastxscale = xscaling.Any(r => r) ? -1 : xscaling.Length - 1; + if (Widget.Loaded) + LayoutParent(); + } + + public bool GetColumnScale(int column) + { + return xscaling[column]; + } + + public void SetRowScale(int row, bool scale) + { + yscaling[row] = scale; + lastyscale = yscaling.Any(r => r) ? -1 : yscaling.Length - 1; + if (Widget.Loaded) + LayoutParent(); + } + + public bool GetRowScale(int row) + { + return yscaling[row]; + } + } +} diff --git a/Source/Eto.Mac/Forms/ToolBar/ButtonToolItemHandler.cs b/Source/Eto.Mac/Forms/ToolBar/ButtonToolItemHandler.cs new file mode 100644 index 0000000000..930906b15b --- /dev/null +++ b/Source/Eto.Mac/Forms/ToolBar/ButtonToolItemHandler.cs @@ -0,0 +1,27 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.ToolBar +{ + + public class ButtonToolItemHandler : ToolItemHandler, ButtonToolItem.IHandler + { + public override void InvokeButton() + { + Widget.OnClick(EventArgs.Empty); + } + } +} diff --git a/Source/Eto.Mac/Forms/ToolBar/CheckToolItemHandler.cs b/Source/Eto.Mac/Forms/ToolBar/CheckToolItemHandler.cs new file mode 100644 index 0000000000..53b73eaa29 --- /dev/null +++ b/Source/Eto.Mac/Forms/ToolBar/CheckToolItemHandler.cs @@ -0,0 +1,40 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.ToolBar +{ + public class CheckToolItemHandler : ToolItemHandler, CheckToolItem.IHandler + { + public bool Checked + { + get { return Button.State == NSCellStateValue.On; } + set { + Button.State = value ? NSCellStateValue.On : NSCellStateValue.Off; + } + } + + protected override void Initialize() + { + base.Initialize(); + Button.SetButtonType(NSButtonType.PushOnPushOff); + } + + public override void InvokeButton() + { + Widget.OnClick(EventArgs.Empty); + } + } +} diff --git a/Source/Eto.Mac/Forms/ToolBar/RadioToolItemHandler.cs b/Source/Eto.Mac/Forms/ToolBar/RadioToolItemHandler.cs new file mode 100644 index 0000000000..cb86202831 --- /dev/null +++ b/Source/Eto.Mac/Forms/ToolBar/RadioToolItemHandler.cs @@ -0,0 +1,62 @@ +using System; +using Eto.Forms; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms.ToolBar +{ + public class RadioToolItemHandler : ToolItemHandler, RadioToolItem.IHandler + { + bool isChecked; + ToolBarHandler toolbarHandler; + + protected override MacToolBarItemStyle DefaultStyle + { + get { return MacToolBarItemStyle.Default; } + } + + public bool Checked + { + get { return isChecked; } + set { + isChecked = value; + if (isChecked && Control != null && toolbarHandler != null && toolbarHandler.Control != null) + toolbarHandler.Control.SelectedItemIdentifier = Identifier; + } + } + + protected override void Initialize() + { + base.Initialize(); + Selectable = true; + } + + public override void ControlAdded (ToolBarHandler toolbar) + { + base.ControlAdded (toolbar); + toolbarHandler = toolbar; + if (isChecked) + toolbar.Control.SelectedItemIdentifier = Identifier; + } + + public override void InvokeButton() + { + if (toolbarHandler != null && toolbarHandler.Control != null) + { + isChecked = toolbarHandler.Control.SelectedItemIdentifier == Identifier; + } + Widget.OnClick(EventArgs.Empty); + } + } +} diff --git a/Source/Eto.Mac/Forms/ToolBar/SeparatorToolItemHandler.cs b/Source/Eto.Mac/Forms/ToolBar/SeparatorToolItemHandler.cs new file mode 100644 index 0000000000..985828f42e --- /dev/null +++ b/Source/Eto.Mac/Forms/ToolBar/SeparatorToolItemHandler.cs @@ -0,0 +1,119 @@ +using Eto.Forms; +using System; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.ToolBar +{ + public class SeparatorToolItemHandler : WidgetHandler, SeparatorToolItem.IHandler, IToolBarBaseItemHandler + { + public static string DividerIdentifier = "divider"; + + public SeparatorToolItemHandler() + { + Type = SeparatorToolItemType.Divider; + } + + public virtual string Identifier + { + get + { + switch (Type) + { + case SeparatorToolItemType.Divider: + return DividerIdentifier; + case SeparatorToolItemType.Space: + return NSToolbar.NSToolbarSpaceItemIdentifier; + case SeparatorToolItemType.FlexibleSpace: + return NSToolbar.NSToolbarFlexibleSpaceItemIdentifier; + default: + throw new NotSupportedException(); + } + + } + } + + public bool Selectable + { + get { return false; } + } + + SeparatorToolItemType type; + public SeparatorToolItemType Type + { + get { return type; } + set + { + type = value; + if (type == SeparatorToolItemType.Divider) + { + Control = new NSToolbarItem(SeparatorToolItemHandler.DividerIdentifier) + { + View = new NSView(), + PaletteLabel = "Small Space" + }; + } + else + Control = null; + } + } + + public void ControlAdded(ToolBarHandler toolbar) + { + } + + public void CreateFromCommand(Command command) + { + } + + public string Text + { + get { return null; } + set { throw new NotSupportedException(); } + } + + public string ToolTip + { + get { return null; } + set { throw new NotSupportedException(); } + } + + public Eto.Drawing.Image Image + { + get { return null; } + set { throw new NotSupportedException(); } + } + + public bool Enabled + { + get { return false; } + set { throw new NotSupportedException(); } + } + } +} diff --git a/Source/Eto.Mac/Forms/ToolBar/ToolBarHandler.cs b/Source/Eto.Mac/Forms/ToolBar/ToolBarHandler.cs new file mode 100644 index 0000000000..08982749d0 --- /dev/null +++ b/Source/Eto.Mac/Forms/ToolBar/ToolBarHandler.cs @@ -0,0 +1,164 @@ +using System; +using Eto.Forms; +using System.Linq; +using System.Collections.Generic; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.ToolBar +{ + public class ToolBarHandler : WidgetHandler, Eto.Forms.ToolBar.IHandler + { + ToolBarDock dock = ToolBarDock.Top; + readonly List items = new List(); + + class TBDelegate : NSToolbarDelegate + { + WeakReference handler; + + public ToolBarHandler Handler { get { return (ToolBarHandler)handler.Target; } set { handler = new WeakReference(value); } } + + public override string[] SelectableItemIdentifiers(NSToolbar toolbar) + { + return Handler.items.Where(r => r.Selectable).Select(r => r.Identifier).ToArray(); + } + + public override void WillAddItem(NSNotification notification) + { + + } + + public override void DidRemoveItem(NSNotification notification) + { + } + + public override NSToolbarItem WillInsertItem(NSToolbar toolbar, string itemIdentifier, bool willBeInserted) + { + var item = Handler.items.FirstOrDefault(r => r.Identifier == itemIdentifier); + return item == null ? null : item.Control; + } + + public override string[] DefaultItemIdentifiers(NSToolbar toolbar) + { + return Handler.items.Select(r => r.Identifier).ToArray(); + } + + public override string[] AllowedItemIdentifiers(NSToolbar toolbar) + { + return Handler.items.Select(r => r.Identifier) + .Union( + new string[] + { + SeparatorToolItemHandler.DividerIdentifier, + NSToolbar.NSToolbarSeparatorItemIdentifier, + NSToolbar.NSToolbarSpaceItemIdentifier, + NSToolbar.NSToolbarFlexibleSpaceItemIdentifier, + NSToolbar.NSToolbarCustomizeToolbarItemIdentifier + }).ToArray(); + } + } + + public ToolBarHandler() + { + Control = new NSToolbar("main"); + Control.SizeMode = NSToolbarSizeMode.Default; + Control.Visible = true; + Control.ShowsBaselineSeparator = true; + //Control.AllowsUserCustomization = true; + Control.DisplayMode = NSToolbarDisplayMode.IconAndLabel; + Control.Delegate = new TBDelegate { Handler = this }; + } + + public ToolBarDock Dock + { + get { return dock; } + set { dock = value; } + } + + public void AddButton(ToolItem item, int index) + { + var handler = (IToolBarBaseItemHandler)item.Handler; + items.Insert(index, handler); + Control.InsertItem(handler.Identifier, index); + if (handler != null) + handler.ControlAdded(this); + //Control.ValidateVisibleItems(); + } + + public void RemoveButton(ToolItem item) + { + var handler = item.Handler as IToolBarBaseItemHandler; + var index = items.IndexOf(handler); + items.Remove(handler); + //var handler = item.Handler as IToolBarItemHandler; + Control.RemoveItem(index); + //Control.ValidateVisibleItems(); + } + + public ToolBarTextAlign TextAlign + { + get + { + /*switch (control.TextAlign) + { + case SWF.ToolBarTextAlign.Right: + return ToolBarTextAlign.Right; + default: + case SWF.ToolBarTextAlign.Underneath: + return ToolBarTextAlign.Underneath; + } + */ + return ToolBarTextAlign.Underneath; + } + set + { + switch (value) + { + case ToolBarTextAlign.Right: + //control.TextAlign = SWF.ToolBarTextAlign.Right; + break; + } + } + } + + public void Clear() + { + for (int i = Control.Items.Length - 1; i >= 0; i--) + { + Control.RemoveItem(i); + } + items.Clear(); + // allow menu items to be GC'd + var newitems = Control.Items; + + //Control.ValidateVisibleItems(); + } + } +} diff --git a/Source/Eto.Mac/Forms/ToolBar/ToolItemHandler.cs b/Source/Eto.Mac/Forms/ToolBar/ToolItemHandler.cs new file mode 100644 index 0000000000..f752009906 --- /dev/null +++ b/Source/Eto.Mac/Forms/ToolBar/ToolItemHandler.cs @@ -0,0 +1,271 @@ +using System; +using Eto.Forms; +using Eto.Drawing; +using sd = System.Drawing; +using Eto.Mac.Forms.Actions; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.Forms.ToolBar +{ + public interface IToolBarBaseItemHandler + { + string Identifier { get; } + + NSToolbarItem Control { get; } + + bool Selectable { get; } + + void ControlAdded(ToolBarHandler toolbar); + } + + public interface IToolBarItemHandler : IToolBarBaseItemHandler + { + void OnClick(); + + bool Enabled { get; } + + NSButton Button { get; } + + MacToolBarItemStyle ToolBarItemStyle {get; set;} + } + + class ToolBarItemHandlerTarget : NSObject + { + WeakReference handler; + + public IToolBarItemHandler Handler { get { return (IToolBarItemHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [Export("validateToolbarItem:")] + public bool ValidateToolbarItem(NSToolbarItem item) + { + return Handler.Enabled; + } + + [Export("action")] + public bool Action() + { + Handler.OnClick(); + return true; + } + } + + /// + /// A toolbar item can be displayed in three ways. + /// To set a non-default style, create a custom style handler + /// for the Mac platform that sets the style to one of these types. + /// + public enum MacToolBarItemStyle + { + /// + /// The default appearance, with 32x32 icons. + /// Does not have a View. + /// + Default, + /// + /// A small button with a rounded bezel. + /// + StandardButton, + /// + /// A large button. Similar in appearance to Default, + /// but uses a Button as the View. + /// + LargeButton + } + + public abstract class ToolItemHandler : WidgetHandler, ToolItem.IHandler, IToolBarItemHandler + where TControl: NSToolbarItem + where TWidget: ToolItem + { + Image image; + NSButton button; + NSMenuItem menuItem; + Color? tint; + + CGSize ButtonSize + { + get { + if (toolBarItemStyle == MacToolBarItemStyle.Default) + return new CGSize (40, 32); + else if (toolBarItemStyle == MacToolBarItemStyle.StandardButton) + return new CGSize (40, 24); + else // large button + return new CGSize (40, 32); + } + } + + public int ImageSize { get { return (toolBarItemStyle == MacToolBarItemStyle.StandardButton) ? 20 : 32; } } + + MacToolBarItemStyle toolBarItemStyle; + public MacToolBarItemStyle ToolBarItemStyle + { + get { return toolBarItemStyle; } + set { + toolBarItemStyle = value; // set the value first because ButtonSize and ImageSize depend on it. + button = null; + if (value == MacToolBarItemStyle.StandardButton || value == MacToolBarItemStyle.LargeButton) { + button = new NSButton { + Title = string.Empty, + BezelStyle = NSBezelStyle.TexturedRounded, + Bordered = toolBarItemStyle == MacToolBarItemStyle.StandardButton, // no border or bezel in the large button style + Frame = new CGRect(CGPoint.Empty, ButtonSize), + Target = Control.Target, + Action = Control.Action, + }; + if (value == MacToolBarItemStyle.LargeButton) + button.SetButtonType (NSButtonType.MomentaryChange); // prevents a flash in the large button view. See the comment at the bottom of http://yellowfieldtechnologies.wordpress.com/2011/11/18/nspopover-from-nstoolbaritem/#comments + Control.View = button; + } + SetImage (); + } + } + + public NSButton Button + { + get { return button; } + } + + public Color? Tint + { + get { return tint; } + set + { + tint = value; + } + } + + public string Identifier { get; set; } + + protected ToolItemHandler() + { + this.Identifier = Guid.NewGuid().ToString(); + Control = (TControl)new NSToolbarItem(Identifier); + Control.Target = new ToolBarItemHandlerTarget { Handler = this }; + Control.Action = selAction; + Control.Autovalidates = false; + Control.Label = string.Empty; + + menuItem = new NSMenuItem(string.Empty); + menuItem.Action = Control.Action; + menuItem.Target = Control.Target; + Control.MenuFormRepresentation = menuItem; + Control.Enabled = true; + } + + protected virtual MacToolBarItemStyle DefaultStyle { get { return MacToolBarItemStyle.StandardButton; } } + + protected override void Initialize() + { + base.Initialize(); + this.ToolBarItemStyle = DefaultStyle; + + } + + [Obsolete("Use ToolBarItemStyle and Tint properties instead")] + public void UseStandardButton(bool grayscale) + { + this.ToolBarItemStyle = MacToolBarItemStyle.StandardButton; + if (grayscale) + Tint = Colors.Gray; + } + + static readonly Selector selAction = new Selector("action"); + + public virtual void ControlAdded(ToolBarHandler toolbar) + { + } + + public virtual void InvokeButton() + { + } + + public string Text + { + get { return Control.Label; } + set { Control.Label = menuItem.Title = value ?? string.Empty; } + } + + public string ToolTip + { + get { return Control.ToolTip; } + set { + if (menuItem != null) + menuItem.ToolTip = value ?? string.Empty; + if (button != null) + button.ToolTip = value ?? string.Empty; + } + } + + public Image Image + { + get { return image; } + set + { + image = value; + SetImage(); + } + } + + void SetImage() + { + var nsimage = image.ToNS(ImageSize); + if (tint != null && nsimage != null) + nsimage = nsimage.Tint(tint.Value.ToNSUI()); + Control.Image = nsimage; + } + + public virtual bool Enabled + { + get { return Control.Enabled; } + set { Control.Enabled = value; } + } + + public virtual bool Selectable { get; set; } + + public void OnClick() + { + InvokeButton(); + } + + NSToolbarItem IToolBarBaseItemHandler.Control + { + get { return Control; } + } + + public void CreateFromCommand(Command command) + { + var m = command as MacCommand; + if (m != null) + { + Control.Target = null; + Control.Action = m.Selector; + } + } + } +} diff --git a/Source/Eto.Mac/Forms/UITimerHandler.cs b/Source/Eto.Mac/Forms/UITimerHandler.cs new file mode 100644 index 0000000000..bae6c3887b --- /dev/null +++ b/Source/Eto.Mac/Forms/UITimerHandler.cs @@ -0,0 +1,76 @@ +using System; +using Eto.Forms; +#if IOS +using MonoTouch.Foundation; +#else +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif +#endif + +#if IOS +namespace Eto.iOS.Forms + +#elif OSX +namespace Eto.Mac.Forms +#endif +{ + public class UITimerHandler : WidgetHandler, UITimer.IHandler + { + double interval = 1f; + + class Helper + { + WeakReference handler; + public UITimerHandler Handler { get { return (UITimerHandler)handler.Target; } set { handler = new WeakReference(value); } } + + #if XAMMAC2 + public void Elapsed(NSTimer timer) + #else + public void Elapsed() + #endif + { + var h = Handler; + if (h != null) + { + h.Callback.OnElapsed(h.Widget, EventArgs.Empty); + } + } + } + + public void Start () + { + Stop(); + var helper = new Helper { Handler = this }; + Control = NSTimer.CreateRepeatingTimer(interval, helper.Elapsed); + NSRunLoop.Current.AddTimer(Control, NSRunLoopMode.Default); + } + + public void Stop () + { + if (Control != null) + { + Control.Invalidate(); + Control.Dispose (); + Control = null; + } + } + + public double Interval + { + get { return interval; } + set { interval = value; } + } + } +} + diff --git a/Source/Eto.Mac/Forms/iosCompatibility.cs b/Source/Eto.Mac/Forms/iosCompatibility.cs new file mode 100644 index 0000000000..fa7c15f566 --- /dev/null +++ b/Source/Eto.Mac/Forms/iosCompatibility.cs @@ -0,0 +1,28 @@ +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Forms +{ + public static class IosCompatibility + { + /// + /// Compatibility with ios + /// + public static void SetNeedsDisplay(this NSView view) + { + view.NeedsDisplay = true; + } + } +} + diff --git a/Source/Eto.Mac/IO/SystemIconsHandler.cs b/Source/Eto.Mac/IO/SystemIconsHandler.cs new file mode 100644 index 0000000000..04fbe7954f --- /dev/null +++ b/Source/Eto.Mac/IO/SystemIconsHandler.cs @@ -0,0 +1,70 @@ +using Eto.IO; +using Eto.Drawing; +using System.IO; +using Eto.Mac.Drawing; +using System; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac.IO +{ + public class SystemIconsHandler : SystemIcons.IHandler + { + + public Icon GetFileIcon(string fileName, IconSize size) + { + var ws = new NSWorkspace(); + var image = ws.IconForFileType(Path.GetExtension(fileName)); + return new Icon(new IconHandler(image)); + } + + public Icon GetStaticIcon(StaticIconType type, IconSize size) + { + var ws = new NSWorkspace(); + string code; + switch (type) + { + case StaticIconType.OpenDirectory: + code = "ofld"; + break; + case StaticIconType.CloseDirectory: + code = "ofld"; + break; + default: + throw new NotSupportedException(); + } + var image = ws.IconForFileType(code); + return new Icon(new IconHandler(image)); + } + } +} + diff --git a/Source/Eto.Mac/InvokeHelper.cs b/Source/Eto.Mac/InvokeHelper.cs new file mode 100644 index 0000000000..9fb86c881d --- /dev/null +++ b/Source/Eto.Mac/InvokeHelper.cs @@ -0,0 +1,16 @@ +using System; +namespace Eto.Mac +{ + class InvokeHelper + { + public Delegate Delegate { get; set; } + public object[] Args { get; set; } + public object Return { get; private set; } + + public void Action() + { + Return = Delegate.DynamicInvoke(Args); + } + } +} + diff --git a/Source/Eto.Mac/KeyMap.cs b/Source/Eto.Mac/KeyMap.cs new file mode 100644 index 0000000000..5f850a6e6a --- /dev/null +++ b/Source/Eto.Mac/KeyMap.cs @@ -0,0 +1,254 @@ +using System.Collections.Generic; +using Eto.Forms; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac +{ + public static class KeyMap + { + static readonly Dictionary keymap = new Dictionary (); + static readonly Dictionary inverse = new Dictionary (); + + public static Keys MapKey (ushort key) + { + Keys value; + return keymap.TryGetValue(key, out value) ? value : Keys.None; + } + + enum KeyCharacters { + NSParagraphSeparatorCharacter = 0x2029, + NSLineSeparatorCharacter = 0x2028, + NSTabCharacter = 0x0009, + NSFormFeedCharacter = 0x000c, + NSNewlineCharacter = 0x000a, + NSCarriageReturnCharacter = 0x000d, + NSEnterCharacter = 0x0003, + NSBackspaceCharacter = 0x0008, + NSBackTabCharacter = 0x0019, + NSDeleteCharacter = 0x007f + }; + + public static Keys Convert (string keyEquivalent, NSEventModifierMask modifier) + { + return Keys.None; + } + + public static string KeyEquivalent (Keys key) + { + string value; + return inverse.TryGetValue(key & Keys.KeyMask, out value) ? value : string.Empty; + } + + public static NSEventModifierMask KeyEquivalentModifierMask (Keys key) + { + key &= Keys.ModifierMask; + var mask = (NSEventModifierMask)0; + if (key.HasFlag(Keys.Shift)) + mask |= NSEventModifierMask.ShiftKeyMask; + if (key.HasFlag(Keys.Alt)) + mask |= NSEventModifierMask.AlternateKeyMask; + if (key.HasFlag(Keys.Control)) + mask |= NSEventModifierMask.ControlKeyMask; + if (key.HasFlag(Keys.Application)) + mask |= NSEventModifierMask.CommandKeyMask; + return mask; + } + + public static Keys GetModifiers (NSEvent theEvent) + { + Keys key = Keys.None; + if ((theEvent.ModifierFlags & NSEventModifierMask.ControlKeyMask) != 0) + key |= Keys.Control; + if ((theEvent.ModifierFlags & NSEventModifierMask.CommandKeyMask) != 0) + key |= Keys.Application; + if ((theEvent.ModifierFlags & NSEventModifierMask.ShiftKeyMask) != 0) + key |= Keys.Shift; + if ((theEvent.ModifierFlags & NSEventModifierMask.AlternateKeyMask) != 0) + key |= Keys.Alt; + return key; + } + + static KeyMap () + { + keymap.Add(0, Keys.A); + keymap.Add(11, Keys.B); + keymap.Add(8, Keys.C); + keymap.Add(2, Keys.D); + keymap.Add(14, Keys.E); + keymap.Add(3, Keys.F); + keymap.Add(5, Keys.G); + keymap.Add(4, Keys.H); + keymap.Add(34, Keys.I); + keymap.Add(38, Keys.J); + keymap.Add(40, Keys.K); + keymap.Add(37, Keys.L); + keymap.Add(46, Keys.M); + keymap.Add(45, Keys.N); + keymap.Add(31, Keys.O); + keymap.Add(35, Keys.P); + keymap.Add(12, Keys.Q); + keymap.Add(15, Keys.R); + keymap.Add(1, Keys.S); + keymap.Add(17, Keys.T); + keymap.Add(32, Keys.U); + keymap.Add(9, Keys.V); + keymap.Add(13, Keys.W); + keymap.Add(7, Keys.X); + keymap.Add(16, Keys.Y); + keymap.Add(6, Keys.Z); + keymap.Add(18, Keys.D1); + keymap.Add(19, Keys.D2); + keymap.Add(20, Keys.D3); + keymap.Add(21, Keys.D4); + keymap.Add(23, Keys.D5); + keymap.Add(22, Keys.D6); + keymap.Add(26, Keys.D7); + keymap.Add(28, Keys.D8); + keymap.Add(25, Keys.D9); + keymap.Add(29, Keys.D0); + keymap.Add(122, Keys.F1); + keymap.Add(120, Keys.F2); + keymap.Add(99, Keys.F3); + keymap.Add(118, Keys.F4); + keymap.Add(96, Keys.F5); + keymap.Add(97, Keys.F6); + keymap.Add(98, Keys.F7); + keymap.Add(100, Keys.F8); + keymap.Add(101, Keys.F9); + keymap.Add(109, Keys.F10); + keymap.Add(103, Keys.F11); + keymap.Add(111, Keys.F12); + keymap.Add(50, Keys.Grave); + keymap.Add(27, Keys.Minus); + keymap.Add(24, Keys.Equal); + keymap.Add(42, Keys.Backslash); + keymap.Add(49, Keys.Space); + //keymap.Add(30, Keys.]); + //keymap.Add(33, Keys.[); + keymap.Add(39, Keys.Quote); + keymap.Add(41, Keys.Semicolon); + keymap.Add(44, Keys.ForwardSlash); + keymap.Add(47, Keys.Period); + keymap.Add(43, Keys.Comma); + keymap.Add(36, Keys.Enter); + keymap.Add(48, Keys.Tab); + //keymap.Add(76, Keys.Return); + keymap.Add(53, Keys.Escape); + + keymap.Add(76, Keys.Insert); + keymap.Add(51, Keys.Backspace); + keymap.Add(117, Keys.Delete); + + keymap.Add(125, Keys.Down); + keymap.Add(126, Keys.Up); + keymap.Add(123, Keys.Left); + keymap.Add(124, Keys.Right); + + keymap.Add(116, Keys.PageUp); + keymap.Add(121, Keys.PageDown); + keymap.Add(119, Keys.End); + keymap.Add(115, Keys.Home); + keymap.Add(110, Keys.ContextMenu); + + + inverse.Add (Keys.A, "a"); + inverse.Add (Keys.B, "b"); + inverse.Add (Keys.C, "c"); + inverse.Add (Keys.D, "d"); + inverse.Add (Keys.E, "e"); + inverse.Add (Keys.F, "f"); + inverse.Add (Keys.G, "g"); + inverse.Add (Keys.H, "h"); + inverse.Add (Keys.I, "i"); + inverse.Add (Keys.J, "j"); + inverse.Add (Keys.K, "k"); + inverse.Add (Keys.L, "l"); + inverse.Add (Keys.M, "m"); + inverse.Add (Keys.N, "n"); + inverse.Add (Keys.O, "o"); + inverse.Add (Keys.P, "p"); + inverse.Add (Keys.Q, "q"); + inverse.Add (Keys.R, "r"); + inverse.Add (Keys.S, "s"); + inverse.Add (Keys.T, "t"); + inverse.Add (Keys.U, "u"); + inverse.Add (Keys.V, "v"); + inverse.Add (Keys.W, "w"); + inverse.Add (Keys.X, "x"); + inverse.Add (Keys.Y, "y"); + inverse.Add (Keys.Z, "z"); + inverse.Add (Keys.Period, "."); + inverse.Add (Keys.Comma, ","); + inverse.Add (Keys.Space, " "); + inverse.Add (Keys.Backslash, "\\"); + inverse.Add (Keys.ForwardSlash, "/"); + inverse.Add (Keys.Equal, "="); + inverse.Add (Keys.Grave, "`"); + inverse.Add (Keys.Minus, "-"); + inverse.Add (Keys.Semicolon, ";"); + inverse.Add (Keys.Up, ((char)NSKey.UpArrow).ToString()); + inverse.Add (Keys.Down, ((char)NSKey.DownArrow).ToString()); + inverse.Add (Keys.Right, ((char)NSKey.RightArrow).ToString()); + inverse.Add (Keys.Left, ((char)NSKey.LeftArrow).ToString()); + inverse.Add (Keys.Home, ((char)NSKey.Home).ToString()); + inverse.Add (Keys.End, ((char)NSKey.End).ToString()); + inverse.Add (Keys.Insert, ((char)NSKey.Insert).ToString()); + inverse.Add (Keys.Delete, ((char)KeyCharacters.NSDeleteCharacter).ToString()); + inverse.Add (Keys.Backspace, ((char)KeyCharacters.NSBackspaceCharacter).ToString()); + inverse.Add (Keys.Tab, ((char)KeyCharacters.NSTabCharacter).ToString()); + inverse.Add (Keys.D0, "0"); + inverse.Add (Keys.D1, "1"); + inverse.Add (Keys.D2, "2"); + inverse.Add (Keys.D3, "3"); + inverse.Add (Keys.D4, "4"); + inverse.Add (Keys.D5, "5"); + inverse.Add (Keys.D6, "6"); + inverse.Add (Keys.D7, "7"); + inverse.Add (Keys.D8, "8"); + inverse.Add (Keys.D9, "9"); + inverse.Add (Keys.F1, ((char)NSKey.F1).ToString()); + inverse.Add (Keys.F2, ((char)NSKey.F2).ToString()); + inverse.Add (Keys.F3, ((char)NSKey.F3).ToString()); + inverse.Add (Keys.F4, ((char)NSKey.F4).ToString()); + inverse.Add (Keys.F5, ((char)NSKey.F5).ToString()); + inverse.Add (Keys.F6, ((char)NSKey.F6).ToString()); + inverse.Add (Keys.F7, ((char)NSKey.F7).ToString()); + inverse.Add (Keys.F8, ((char)NSKey.F8).ToString()); + inverse.Add (Keys.F9, ((char)NSKey.F9).ToString()); + inverse.Add (Keys.F10, ((char)NSKey.F10).ToString()); + inverse.Add (Keys.F11, ((char)NSKey.F11).ToString()); + inverse.Add (Keys.F12, ((char)NSKey.F12).ToString()); + } + } +} + diff --git a/Source/Eto.Mac/Mac64Extensions.cs b/Source/Eto.Mac/Mac64Extensions.cs new file mode 100644 index 0000000000..cda9673d66 --- /dev/null +++ b/Source/Eto.Mac/Mac64Extensions.cs @@ -0,0 +1,125 @@ +using System; +using Eto.Drawing; +using System.Runtime.InteropServices; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac +{ + public static class Mac64Extensions + { + + public static CGPoint ToNS(this Point point) + { + return new CGPoint(point.X, point.Y); + } + + public static PointF ToEto(this CGPoint point) + { + return new PointF((float)point.X, (float)point.Y); + } + + public static Point ToEtoPoint(this CGPoint point) + { + return new Point((int)point.X, (int)point.Y); + } + + public static CGPoint ToNS(this PointF point) + { + return new CGPoint(point.X, point.Y); + } + + public static CGPoint ToNS(this System.Drawing.PointF point) + { + return new CGPoint(point.X, point.Y); + } + + public static CGSize ToNS(this SizeF size) + { + return new CGSize(size.Width, size.Height); + } + + public static SizeF ToEto(this CGSize point) + { + return new SizeF((float)point.Width, (float)point.Height); + } + + public static System.Drawing.SizeF ToSD(this CGSize size) + { + return new System.Drawing.SizeF((float)size.Width, (float)size.Height); + } + + public static CGSize ToNS(this Size size) + { + return new CGSize((float)size.Width, (float)size.Height); + } + + public static CGSize ToNS(this System.Drawing.Size size) + { + return new CGSize((float)size.Width, (float)size.Height); + } + + public static CGSize ToNS(this System.Drawing.SizeF size) + { + return new CGSize((float)size.Width, (float)size.Height); + } + + public static Size ToEtoSize(this CGSize size) + { + return new Size((int)size.Width, (int)size.Height); + } + + public static CGRect ToNS(this RectangleF rect) + { + return new CGRect(rect.X, rect.Y, rect.Width, rect.Height); + } + + public static CGRect ToNS(this System.Drawing.RectangleF rect) + { + return new CGRect(rect.X, rect.Y, rect.Width, rect.Height); + } + + public static RectangleF ToEto(this CGRect rect) + { + return new RectangleF((float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height); + } + + public static System.Drawing.RectangleF ToSD(this CGRect rect) + { + return new System.Drawing.RectangleF((float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height); + } + + public static CGRect SetSize(this CGRect frame, SizeF size) + { + frame.Size = size.ToNS(); + return frame; + } + } +} + diff --git a/Source/Eto.Mac/MacExtensions.cs b/Source/Eto.Mac/MacExtensions.cs new file mode 100644 index 0000000000..0e44472480 --- /dev/null +++ b/Source/Eto.Mac/MacExtensions.cs @@ -0,0 +1,94 @@ +using System; +using System.Runtime.InteropServices; +using System.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac +{ + /// + /// These are extensions for missing methods in monomac/xamarin.mac, or incorrectly bound. + /// + /// + /// Once monomac/xam.mac supports these methods or are implemented properly, then remove from here. + /// + public static class MacExtensions + { + static readonly IntPtr selBoundingRectWithSize = Selector.GetHandle("boundingRectWithSize:options:"); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend_stret")] + static extern void RectangleF_objc_msgSend_stret_SizeF_int(out CGRect retval, IntPtr receiver, IntPtr selector, CGSize arg1, nint arg2); + + // not bound + public static CGRect BoundingRect(this NSAttributedString str, CGSize size, NSStringDrawingOptions options) + { + CGRect rect; + RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options); + return rect; + } + + static readonly IntPtr selNextEventMatchingMask = Selector.GetHandle("nextEventMatchingMask:untilDate:inMode:dequeue:"); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] + static extern IntPtr IntPtr_objc_msgSend_nuint_IntPtr_IntPtr_bool(IntPtr receiver, IntPtr selector, nuint mask, IntPtr untilDate, IntPtr mode, bool dequeue); + + // untilDate isn't allowed null + public static NSEvent NextEventEx(this NSApplication app, NSEventMask mask, NSDate untilDate, NSString mode, bool dequeue) + { + return (NSEvent)Runtime.GetNSObject(IntPtr_objc_msgSend_nuint_IntPtr_IntPtr_bool(app.Handle, selNextEventMatchingMask, (nuint)(uint)mask, untilDate != null ? untilDate.Handle : IntPtr.Zero, mode.Handle, dequeue)); + } + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] + static extern void void_objc_msgSend_NSRange_CGPoint(IntPtr receiver, IntPtr selector, NSRange arg1, CGPoint arg2); + + static readonly IntPtr selDrawGlyphs = Selector.GetHandle("drawGlyphsForGlyphRange:atPoint:"); + + // not bound + public static void DrawGlyphs(this NSLayoutManager layout, NSRange range, CGPoint point) + { + void_objc_msgSend_NSRange_CGPoint(layout.Handle, selDrawGlyphs, range, point); + } + + #if !XAMMAC + public static void DangerousRetain(this NSObject obj) + { + obj.Retain(); + } + + public static void DangerousRelease(this NSObject obj) + { + obj.Release(); + } + #endif + + } +} + diff --git a/Source/Eto.Mac/MacHelpers.cs b/Source/Eto.Mac/MacHelpers.cs new file mode 100644 index 0000000000..bd831eb55e --- /dev/null +++ b/Source/Eto.Mac/MacHelpers.cs @@ -0,0 +1,93 @@ +using System; +using Eto.Forms; +using Eto.Mac.Forms; +using Eto.Mac.Forms.Controls; +using Eto.Drawing; + +#if XAMMAC2 +using AppKit; +#else +using MonoMac.AppKit; +#endif + +namespace Eto.Forms +{ + public static class + #if XAMMAC2 + XamMac2Helpers + #elif XAMMAC + XamMacHelpers + #elif Mac64 + MonoMac64Helpers + #elif MONOMAC + MonoMacHelpers + #endif + { + /// + /// Gets the native Mac NSView that contains the Eto.Forms control. + /// + /// + /// Note for some controls, this will not be the 'main' native control. + /// For example, a GridView on OS X will return a NSScrollView instead of a NSTableView, since the table view + /// itself does not scroll. + /// + /// When you intend on using the control inside an existing native application, set to + /// true so that it can prepare for attaching to the native application by sending OnPreLoad/Load/LoadComplete events. + /// + /// The native control that can be used to add this control to an existing application. + /// Control to get the native control for. + /// If set to true the control is to be attached to an existing application, or false to get the native control directly. + public static NSView ToNative(this Control control, bool attach = false) + { + if (attach && !control.Loaded) + { + control.AttachNative(); + var macControl = control.GetMacControl(); + if (macControl != null && macControl.AutoSize) + macControl.ContainerControl.SetFrameSize(macControl.GetPreferredSize(SizeF.MaxValue).ToSD()); + } + return control.GetContainerView(); + } + + /// + /// Wraps the specified to an Eto control that can be used directly in Eto.Forms code. + /// + /// The eto control wrapper around the native control. + /// Native control to wrap. + public static Control ToEto(this NSView view) + { + return new Control(new NativeControlHandler(view)); + } + + /// + /// Wraps the specified to an Eto control that can be used directly in Eto.Forms code. + /// + /// The eto control wrapper around the native control. + /// Native control to wrap. + public static Control ToEto(this NSViewController viewController) + { + return new Control(new NativeControlHandler(viewController)); + } + + /// + /// Wraps the specified Cocoa in an Eto control so it can be used as a parent when showing dialogs, etc. + /// + /// The eto window wrapper around the native Cocoa window. + /// Cocoa Window to wrap. + public static Window ToEtoWindow(this NSWindow window) + { + return new Form(new FormHandler(window)); + } + + /// + /// Wraps the specified Cocoa in an Eto control so it can be used as a parent when showing dialogs, etc. + /// + /// The eto window wrapper around the native Cocoa window. + /// Cocoa Window to wrap. + public static Window ToEtoWindow(this NSWindowController windowController) + { + return new Form(new FormHandler(windowController)); + } + } +} + diff --git a/Source/Eto.Mac/Messaging.cs b/Source/Eto.Mac/Messaging.cs new file mode 100644 index 0000000000..876e16e083 --- /dev/null +++ b/Source/Eto.Mac/Messaging.cs @@ -0,0 +1,61 @@ +using System; +using System.Runtime.InteropServices; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac +{ + public static class Messaging + { + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSendSuper")] + public static extern IntPtr IntPtr_objc_msgSendSuper_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSendSuper")] + public static extern void void_objc_msgSendSuper_SizeF(IntPtr receiver, IntPtr selector, CGSize arg1); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSendSuper")] + public static extern bool bool_objc_msgSendSuper(IntPtr receiver, IntPtr selector); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSendSuper")] + public static extern void void_objc_msgSendSuper_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] + public static extern bool bool_objc_msgSend_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] + public static extern bool bool_objc_msgSend_IntPtr_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] + public static extern void void_objc_msgSend(IntPtr receiver, IntPtr selector); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] + public static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector); + } +} + diff --git a/Source/Eto.Mac/NSImageExtensions.cs b/Source/Eto.Mac/NSImageExtensions.cs new file mode 100644 index 0000000000..321a1a1889 --- /dev/null +++ b/Source/Eto.Mac/NSImageExtensions.cs @@ -0,0 +1,108 @@ +using System; +using sd = System.Drawing; +using Eto.Drawing; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +using CoreImage; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +using MonoMac.CoreImage; +#if Mac64 +using CGSize = MonoMac.Foundation.NSSize; +using CGRect = MonoMac.Foundation.NSRect; +using CGPoint = MonoMac.Foundation.NSPoint; +using nfloat = System.Double; +using nint = System.Int64; +using nuint = System.UInt64; +#else +using CGSize = System.Drawing.SizeF; +using CGRect = System.Drawing.RectangleF; +using CGPoint = System.Drawing.PointF; +using nfloat = System.Single; +using nint = System.Int32; +using nuint = System.UInt32; +#endif +#endif + +namespace Eto.Mac +{ + public static class NSImageExtensions + { + public static NSImage Resize(this NSImage image, CGSize newsize, ImageInterpolation interpolation = ImageInterpolation.Default) + { + var newimage = new NSImage(newsize); + var newrep = new NSBitmapImageRep(IntPtr.Zero, (nint)newsize.Width, (nint)newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * (nint)newsize.Width, 32); + newimage.AddRepresentation(newrep); + + var graphics = NSGraphicsContext.FromBitmap(newrep); + NSGraphicsContext.GlobalSaveGraphicsState(); + NSGraphicsContext.CurrentContext = graphics; + graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG(); + image.DrawInRect(new CGRect(CGPoint.Empty, newimage.Size), new CGRect(CGPoint.Empty, image.Size), NSCompositingOperation.SourceOver, 1f); + NSGraphicsContext.GlobalRestoreGraphicsState(); + return newimage; + } + + public static NSImage Tint(this NSImage image, NSColor tint) + { + var colorGenerator = new CIConstantColorGenerator + { + Color = CIColor.FromCGColor(tint.CGColor) + }; + + var colorFilter = new CIColorControls + { + Image = (CIImage)colorGenerator.ValueForKey(CIFilterOutputKey.Image), + Saturation = 3f, + Brightness = 0.35f, + Contrast = 1f + }; + + var monochromeFilter = new CIColorMonochrome + { + Image = CIImage.FromCGImage(image.CGImage), + Color = CIColor.FromRgb(0.75f, 0.75f, 0.75f), + Intensity = 1f + }; + + var compositingFilter = new CIMultiplyCompositing + { + Image = (CIImage)colorFilter.ValueForKey(CIFilterOutputKey.Image), + BackgroundImage = (CIImage)monochromeFilter.ValueForKey(CIFilterOutputKey.Image) + }; + + var outputImage = (CIImage)compositingFilter.ValueForKey(CIFilterOutputKey.Image); + var extent = outputImage.Extent; + + var newsize = sd.Size.Truncate(extent.Size.ToSD()); + if (newsize.IsEmpty) + return image; + + var tintedImage = new NSImage(newsize.ToNS()); + tintedImage.LockFocus(); + try + { + var graphics = NSGraphicsContext.CurrentContext.GraphicsPort; + var ciContext = CIContext.FromContext(graphics, new CIContextOptions { UseSoftwareRenderer = true }); + ciContext.DrawImage(outputImage, extent, extent); + } + finally + { + tintedImage.UnlockFocus(); + } + + var newrep = tintedImage.Representations()[0]; + newrep.Size = image.Size; + return tintedImage; + } + } +} + diff --git a/Source/Eto.Platform.Mac/ObjCExtensions.cs b/Source/Eto.Mac/ObjCExtensions.cs similarity index 88% rename from Source/Eto.Platform.Mac/ObjCExtensions.cs rename to Source/Eto.Mac/ObjCExtensions.cs index d51f423339..582ce21035 100644 --- a/Source/Eto.Platform.Mac/ObjCExtensions.cs +++ b/Source/Eto.Mac/ObjCExtensions.cs @@ -1,9 +1,22 @@ using System; -using MonoMac.ObjCRuntime; using System.Runtime.InteropServices; +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#elif OSX +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#elif IOS using MonoTouch.ObjCRuntime; +#endif -namespace Eto.Platform.Mac +namespace Eto.Mac { public static class ObjCExtensions { diff --git a/Source/Eto.Mac/Platform.cs b/Source/Eto.Mac/Platform.cs new file mode 100644 index 0000000000..02c0406161 --- /dev/null +++ b/Source/Eto.Mac/Platform.cs @@ -0,0 +1,197 @@ +using System; +using Eto.Drawing; +using Eto.Forms; +using Eto.IO; +using Eto.Mac.Drawing; +using Eto.Mac.IO; +using Eto.Mac.Forms.Controls; +using Eto.Mac.Forms.Printing; +using Eto.Mac.Forms; +using Eto.Mac.Forms.Menu; +using Eto.Mac.Threading; +using Eto.Threading; +using System.Reflection; +using Eto.Mac.Forms.Cells; +using Eto.Mac.Forms.ToolBar; + +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac +{ + + [Preserve(AllMembers = true)] + public class Platform : Eto.Platform + { + public override bool IsDesktop { get { return true; } } + + public override bool IsMac { get { return true; } } + + #if XAMMAC + public override string ID { get { return "xammac"; } } + +#else + public override string ID { get { return "mac"; } } + #endif + static bool initialized; + + public Platform() + { + #if Mac64 + unsafe + { + if (sizeof(IntPtr) != 8) + throw new EtoException("You can only run this platform in 64-bit mode. Use the 32-bit Eto.Mac platform instead."); + } + #endif + if (!initialized) + { + var appType = typeof(NSApplication); + var initField = appType.GetField("initialized", BindingFlags.Static | BindingFlags.NonPublic); + if (initField == null || Equals(initField.GetValue(null), false)) + NSApplication.Init(); + // until everything is marked as thread safe correctly in monomac + // e.g. overriding NSButtonCell.DrawBezelWithFrame will throw an exception + NSApplication.CheckForIllegalCrossThreadCalls = false; + + initialized = true; + } + AddTo(this); + } + + public static void AddTo(Eto.Platform p) + { + // Drawing + p.Add(() => new BitmapHandler()); + p.Add(() => new FontFamilyHandler()); + p.Add(() => new FontHandler()); + p.Add(() => new FontsHandler()); + p.Add(() => new GraphicsHandler()); + p.Add(() => new GraphicsPathHandler()); + p.Add(() => new IconHandler()); + p.Add(() => new IndexedBitmapHandler()); + p.Add(() => new MatrixHandler()); + p.Add(() => new PenHandler()); + p.Add(() => new SolidBrushHandler()); + p.Add(() => new TextureBrushHandler()); + p.Add(() => new LinearGradientBrushHandler()); + + // Forms.Cells + p.Add(() => new CheckBoxCellHandler()); + p.Add(() => new ComboBoxCellHandler()); + p.Add(() => new ImageTextCellHandler()); + p.Add(() => new ImageViewCellHandler()); + p.Add(() => new TextBoxCellHandler()); + p.Add(() => new DrawableCellHandler()); + + // Forms.Controls + p.Add(() => new ButtonHandler()); + p.Add(() => new CalendarHandler()); + p.Add(() => new CheckBoxHandler()); + p.Add(() => new DropDownHandler()); + p.Add(() => new ComboBoxHandler()); + p.Add(() => new ColorPickerHandler()); + p.Add(() => new DateTimePickerHandler()); + p.Add(() => new DrawableHandler()); + p.Add(() => new GridColumnHandler()); + p.Add(() => new GridViewHandler()); + p.Add(() => new GroupBoxHandler()); + p.Add(() => new ImageViewHandler()); + p.Add(() => new LabelHandler()); + p.Add(() => new LinkButtonHandler()); + p.Add(() => new ListBoxHandler()); + p.Add(() => new NumericUpDownHandler()); + p.Add(() => new PanelHandler()); + p.Add(() => new PasswordBoxHandler()); + p.Add(() => new ProgressBarHandler()); + p.Add(() => new RadioButtonHandler()); + p.Add(() => new ScrollableHandler()); + p.Add(() => new SearchBoxHandler()); + p.Add(() => new SliderHandler()); + p.Add(() => new SpinnerHandler()); + p.Add(() => new SplitterHandler()); + p.Add(() => new TabControlHandler()); + p.Add(() => new TabPageHandler()); + p.Add(() => new TextAreaHandler()); + p.Add(() => new TextBoxHandler()); + p.Add(() => new TreeGridViewHandler()); + p.Add(() => new TreeViewHandler()); + p.Add(() => new WebViewHandler()); + p.Add(() => new ScreensHandler()); + + // Forms.Menu + p.Add(() => new CheckMenuItemHandler()); + p.Add(() => new ContextMenuHandler()); + p.Add(() => new ImageMenuItemHandler()); + p.Add(() => new MenuBarHandler()); + p.Add(() => new RadioMenuItemHandler()); + p.Add(() => new SeparatorMenuItemHandler()); + + // Forms.Printing + p.Add(() => new PrintDialogHandler()); + p.Add(() => new PrintDocumentHandler()); + p.Add(() => new PrintSettingsHandler()); + + // Forms.ToolBar + p.Add(() => new CheckToolItemHandler()); + p.Add(() => new RadioToolItemHandler()); + p.Add(() => new SeparatorToolItemHandler()); + p.Add(() => new ButtonToolItemHandler()); + p.Add(() => new ToolBarHandler()); + + // Forms + p.Add(() => new ApplicationHandler()); + p.Add(() => new ClipboardHandler()); + p.Add(() => new ColorDialogHandler()); + p.Add(() => new CursorHandler()); + p.Add(() => new DialogHandler()); + p.Add(() => new FontDialogHandler()); + p.Add(() => new FormHandler()); + p.Add(() => new MessageBoxHandler()); + p.Add(() => new OpenFileDialogHandler()); + p.Add(() => new PixelLayoutHandler()); + p.Add(() => new SaveFileDialogHandler()); + p.Add(() => new SelectFolderDialogHandler()); + p.Add(() => new TableLayoutHandler()); + p.Add(() => new UITimerHandler()); + p.Add(() => new MouseHandler()); + + // IO + p.Add(() => new SystemIconsHandler()); + + // General + p.Add(() => new EtoEnvironmentHandler()); + p.Add(() => new ThreadHandler()); + } + + public override IDisposable ThreadStart() + { + return new NSAutoreleasePool(); + } + + public override bool IsValid + { + get + { + return Assembly.GetEntryAssembly().Location.StartsWith(NSBundle.MainBundle.BundlePath, StringComparison.Ordinal); + } + } + + static void LinkingOverrides() + { + // Prevent linking system code used via reflection in Eto.dll due to pcl restrictions + Assembly.GetCallingAssembly(); + } + } +} diff --git a/Source/Eto.Mac/Properties/AssemblyInfo.cs b/Source/Eto.Mac/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..0795b816ee --- /dev/null +++ b/Source/Eto.Mac/Properties/AssemblyInfo.cs @@ -0,0 +1,16 @@ +using System.Reflection; + +#if XAMMAC2 +[assembly: AssemblyTitle("Eto.Forms - Xamarin.Mac (unified) Platform")] +[assembly: AssemblyDescription("OS X Platform for the Eto.Forms UI Framework using 64-bit Xamarin.Mac v2.0 (unified)")] +#elif XAMMAC +[assembly: AssemblyTitle("Eto.Forms - Xamarin.Mac (classic) Platform")] +[assembly: AssemblyDescription("OS X Platform for the Eto.Forms UI Framework using Xamarin.Mac v1.0 (classic)")] +#elif Mac64 +[assembly: AssemblyTitle("Eto.Forms - MonoMac 64-bit Platform")] +[assembly: AssemblyDescription("OS X Platform for the Eto.Forms UI Framework using the open-source MonoMac with 64-bit mono")] +#else +[assembly: AssemblyTitle("Eto.Forms - MonoMac Platform")] +[assembly: AssemblyDescription("OS X Platform for the Eto.Forms UI Framework using the open-source MonoMac")] +#endif + diff --git a/Source/Eto.Mac/Threading/ThreadHandler.cs b/Source/Eto.Mac/Threading/ThreadHandler.cs new file mode 100644 index 0000000000..6e19fa90c1 --- /dev/null +++ b/Source/Eto.Mac/Threading/ThreadHandler.cs @@ -0,0 +1,77 @@ +using System; +using Eto.Threading; + +#if OSX +#if XAMMAC2 +using AppKit; +using Foundation; +using CoreGraphics; +using ObjCRuntime; +using CoreAnimation; +#else +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.CoreGraphics; +using MonoMac.ObjCRuntime; +using MonoMac.CoreAnimation; +#endif + +namespace Eto.Mac.Threading +#elif IOS + +using MonoTouch.Foundation; +using MonoTouch.ObjCRuntime; + +namespace Eto.iOS.Threading +#endif +{ + public class ThreadHandler : WidgetHandler, Thread.IHandler + { + class Delegate : NSObject + { + WeakReference handler; + public ThreadHandler Handler { get { return (ThreadHandler)handler.Target; } set { handler = new WeakReference(value); } } + + [Export("execute")] + public void Execute() + { + using (var pool = new NSAutoreleasePool()) + { + Handler.Callback.OnExecuted(Handler.Widget); + } + } + } + + static readonly Selector selExecute = new Selector("execute"); + + public void Create() + { + Control = new NSThread(new Delegate { Handler = this }, selExecute, null); + } + + public void CreateCurrent() + { + Control = NSThread.Current; + } + + public void CreateMain() + { + Control = NSThread.MainThread; + } + + public void Start() + { + Control.Start(); + } + + public void Abort() + { + Control.Cancel(); + } + + public bool IsAlive { get { return Control.IsExecuting; } } + + public bool IsMain { get { return Control.IsMainThread; } } + } +} + diff --git a/Source/Eto.Platform.Android/Conversions.cs b/Source/Eto.Platform.Android/Conversions.cs deleted file mode 100644 index 4c8ec66832..0000000000 --- a/Source/Eto.Platform.Android/Conversions.cs +++ /dev/null @@ -1,300 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using a = Android; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; -using Eto.Platform.Android.Drawing; - -namespace Eto.Platform.Android -{ - public static class Conversions - { - public static Padding GetPadding(this av.View view) - { - return new Padding(view.PaddingLeft, view.PaddingTop, view.PaddingRight, view.PaddingBottom); - } - - public static void SetPadding(this av.View view, Padding padding) - { - view.SetPadding(padding.Left, padding.Top, padding.Right, padding.Bottom); - } - - public static Color ToEto(this ag.Color color) - { - return Color.FromArgb(color.R, color.G, color.B, color.A); - } - - public static ag.Color ToAndroid(this Color color) - { - return new ag.Color((int)color.ToArgb()); - } - - public static ag.Paint ToAndroid(this Pen pen) - { - return (ag.Paint)pen.ControlObject; - } - - public static ag.Paint ToAndroid(this Brush brush) - { - return ((BrushHandler)brush.Handler).GetPaint(brush); - } - - public static MouseEventArgs ToEto(av.MotionEvent e) - { - if (e.Action == av.MotionEventActions.Down) - { - return new MouseEventArgs(MouseButtons.Primary, Key.None, new PointF(e.GetX(), e.GetY())); - } - // Is this correct? It generates a mouse event for pointer-up and cancel actions - // See the iOS handler as well, which does something similar - return new MouseEventArgs(MouseButtons.Primary, Key.None, Point.Empty); - } - - public static ag.Paint.Join ToAndroid(this PenLineJoin value) - { - switch (value) - { - case PenLineJoin.Miter: - return ag.Paint.Join.Miter; - case PenLineJoin.Bevel: - return ag.Paint.Join.Bevel; - case PenLineJoin.Round: - return ag.Paint.Join.Round; - default: - throw new NotSupportedException(); - } - } - - public static PenLineJoin ToEto(this ag.Paint.Join value) - { - if (object.ReferenceEquals(value, ag.Paint.Join.Bevel)) - return PenLineJoin.Bevel; - if (object.ReferenceEquals(value, ag.Paint.Join.Miter)) - return PenLineJoin.Miter; - if (object.ReferenceEquals(value, ag.Paint.Join.Round)) - return PenLineJoin.Round; - throw new NotSupportedException(); - } - - public static ag.Paint.Cap ToSD(this PenLineCap value) - { - switch (value) - { - case PenLineCap.Butt: - return ag.Paint.Cap.Butt; - case PenLineCap.Round: - return ag.Paint.Cap.Round; - case PenLineCap.Square: - return ag.Paint.Cap.Square; - default: - throw new NotSupportedException(); - } - } - - public static PenLineCap ToEto(this ag.Paint.Cap value) - { - if (object.ReferenceEquals(value, ag.Paint.Cap.Butt)) - return PenLineCap.Butt; - if (object.ReferenceEquals(value, ag.Paint.Cap.Round)) - return PenLineCap.Round; - if (object.ReferenceEquals(value, ag.Paint.Cap.Square)) - return PenLineCap.Square; - throw new NotSupportedException(); - } - - public static ag.Matrix ToAndroid(this IMatrix m) - { - return (ag.Matrix)m.ControlObject; - } - - public static Point ToEto(this ag.Point point) - { - return new Point(point.X, point.Y); - } - - public static PointF ToEto(this ag.PointF point) - { - return new PointF(point.X, point.Y); - } - - public static ag.PointF ToAndroid(this PointF point) - { - return new ag.PointF(point.X, point.Y); - } - - public static ag.Point ToAndroidPoint(this PointF point) - { - return new ag.Point((int)point.X, (int)point.Y); - } - - public static Rectangle ToEto(this ag.Rect rect) - { - return new Rectangle(rect.Left, rect.Top, rect.Width(), rect.Height()); - } - - public static RectangleF ToEto(this ag.RectF rect) - { - return new RectangleF(rect.Left, rect.Top, rect.Width(), rect.Height()); - } - - public static ag.Rect ToAndroid(this Rectangle rect) - { - return new ag.Rect(rect.X, rect.Y, rect.Width, rect.Height); - } - - public static ag.RectF ToAndroid(this RectangleF rect) - { - return new ag.RectF(rect.X, rect.Y, rect.Width, rect.Height); - } - - public static ag.Rect ToAndroidRectangle(this RectangleF rect) - { - return new ag.Rect((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height); - } - - internal static ag.Point[] ToAndroid(this Point[] points) - { - var result = - new ag.Point[points.Length]; - - for (var i = 0; - i < points.Length; - ++i) - { - var p = points[i]; - result[i] = - new ag.Point(p.X, p.Y); - } - - return result; - } - - internal static ag.PointF[] ToAndroid(this PointF[] points) - { - var result = - new ag.PointF[points.Length]; - - for (var i = 0; - i < points.Length; - ++i) - { - var p = points[i]; - result[i] = - new ag.PointF(p.X, p.Y); - } - - return result; - } - - internal static PointF[] ToEto(this ag.PointF[] points) - { - var result = - new PointF[points.Length]; - - for (var i = 0; - i < points.Length; - ++i) - { - var p = points[i]; - result[i] = - new PointF(p.X, p.Y); - } - - return result; - } - - public static GraphicsPathHandler ToHandler(this IGraphicsPath path) - { - return ((GraphicsPathHandler)path.ControlObject); - } - - public static ag.Path ToAndroid(this IGraphicsPath path) - { - return ((GraphicsPathHandler)path.ControlObject).Control; - } - - public static ag.TypefaceStyle ToAndroid(this FontStyle style) - { - var ret = ag.TypefaceStyle.Normal; - if ((style & FontStyle.Bold) != 0) - ret = ag.TypefaceStyle.Bold; - if ((style & FontStyle.Italic) != 0) - ret = ag.TypefaceStyle.Italic; - return ret; - } - - public static FontStyle ToEto(this ag.TypefaceStyle style) - { - var ret = FontStyle.None; - if (style == ag.TypefaceStyle.Normal) - ret = FontStyle.None; - else if (style == ag.TypefaceStyle.Bold) - ret = FontStyle.Bold; - else if (style == ag.TypefaceStyle.Italic) - ret = FontStyle.Italic; - return ret; - } - - public static HorizontalAlign ToEtoHorizontal(this av.GravityFlags gravity) - { - switch (gravity & av.GravityFlags.HorizontalGravityMask) - { - case av.GravityFlags.CenterHorizontal: - return HorizontalAlign.Center; - case av.GravityFlags.Left: - return HorizontalAlign.Left; - case av.GravityFlags.Right: - return HorizontalAlign.Right; - default: - throw new NotSupportedException(); - } - } - - public static av.GravityFlags ToAndroid(this HorizontalAlign value) - { - switch (value) - { - case HorizontalAlign.Center: - return av.GravityFlags.CenterHorizontal; - case HorizontalAlign.Right: - return av.GravityFlags.Right; - case HorizontalAlign.Left: - return av.GravityFlags.Left; - default: - throw new NotSupportedException(); - } - } - - public static VerticalAlign ToEtoVertical(this av.GravityFlags gravity) - { - switch (gravity & av.GravityFlags.VerticalGravityMask) - { - case av.GravityFlags.CenterVertical: - return VerticalAlign.Middle; - case av.GravityFlags.Top: - return VerticalAlign.Top; - case av.GravityFlags.Bottom: - return VerticalAlign.Bottom; - default: - throw new NotSupportedException(); - } - } - - public static av.GravityFlags ToAndroid(this VerticalAlign value) - { - switch (value) - { - case VerticalAlign.Middle: - return av.GravityFlags.CenterVertical; - case VerticalAlign.Top: - return av.GravityFlags.Top; - case VerticalAlign.Bottom: - return av.GravityFlags.Bottom; - default: - throw new NotSupportedException(); - } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/BitmapHandler.cs b/Source/Eto.Platform.Android/Drawing/BitmapHandler.cs deleted file mode 100644 index 17d73371b8..0000000000 --- a/Source/Eto.Platform.Android/Drawing/BitmapHandler.cs +++ /dev/null @@ -1,160 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - /// - /// Interface for all Android images - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public interface IAndroidImage - { - ag.Bitmap GetImageWithSize(int? size); - - void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination); - - void DrawImage(GraphicsHandler graphics, float x, float y); - - void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height); - } - - - /// - /// Bitmap handler. - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - class BitmapHandler : WidgetHandler, IBitmap, IAndroidImage - { - public BitmapHandler() - { - } - - public BitmapHandler(ag.Bitmap image) - { - Control = image; - } - - public void Create(string fileName) - { - Control = ag.BitmapFactory.DecodeFile(fileName); - } - - public void Create(System.IO.Stream stream) - { - Control = ag.BitmapFactory.DecodeStream(stream); - } - - public void Create(int width, int height, PixelFormat pixelFormat) - { - ag.Bitmap.Config config = ag.Bitmap.Config.Argb8888; - switch(pixelFormat) - { - case PixelFormat.Format32bppRgb: - throw new NotImplementedException(); // TODO - //config = ag.Bitmap.Config.Argb8888; - break; - case PixelFormat.Format24bppRgb: - throw new NotImplementedException(); // TODO - //config = ag.Bitmap.Config.Argb8888; - break; - /*case PixelFormat.Format16bppRgb555: - config = ag.Bitmap.Config.Argb8888; - break;*/ - case PixelFormat.Format32bppRgba: - config = ag.Bitmap.Config.Argb8888; - break; - default: - throw new ArgumentOutOfRangeException("pixelFormat", pixelFormat, "Not supported"); - } - - Control = ag.Bitmap.CreateBitmap(width, height, config); - } - - public void Create(int width, int height, Graphics graphics) - { - throw new NotImplementedException(); - } - - public void Create(Image image, int width, int height, ImageInterpolation interpolation) - { - throw new NotImplementedException(); - } - - public void Save(System.IO.Stream stream, ImageFormat format) - { - ag.Bitmap.CompressFormat compressFormat; - if(format == ImageFormat.Jpeg) - compressFormat =ag.Bitmap.CompressFormat.Jpeg; - else if(format == ImageFormat.Png) - compressFormat = ag.Bitmap.CompressFormat.Png; - else - throw new ArgumentException("ImageFormat must be Jpeg or Png"); - Control.Compress(compressFormat, 100, stream); // 100 means maximum quality. Png ignores this since it is lossless. - } - - public Bitmap Clone(Rectangle? rectangle = null) - { - if (rectangle != null) - { - var r = rectangle.Value; - return new Bitmap(this.Generator, new BitmapHandler( - ag.Bitmap.CreateBitmap(this.Control, r.X, r.Y, r.Width, r.Height))); - } - else - return new Bitmap(this.Generator, new BitmapHandler(ag.Bitmap.CreateBitmap(this.Control))); - } - - public Color GetPixel(int x, int y) - { - return new ag.Color(Control.GetPixel(x, y)).ToEto(); - } - - public Size Size - { - get { return new Size(Control.Width, Control.Height); } - } - - public BitmapData Lock() - { - throw new NotImplementedException(); - } - - public void Unlock(BitmapData bitmapData) - { - throw new NotImplementedException(); - } - - public ag.Bitmap GetImageWithSize(int? size) - { - throw new NotImplementedException(); - } - - public void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) - { - graphics.Control.DrawBitmap(Control, new Rectangle(source).ToAndroid(), destination.ToAndroid(), paint: null); - } - - public void DrawImage(GraphicsHandler graphics, float x, float y) - { - graphics.Control.DrawBitmap(Control, x, y, paint: null); - } - - public void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height) - { - graphics.Control.DrawBitmap(Control, null, new RectangleF(x, y, width, height).ToAndroid(), paint: null); - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/BrushHandler.cs b/Source/Eto.Platform.Android/Drawing/BrushHandler.cs deleted file mode 100644 index 33b9662820..0000000000 --- a/Source/Eto.Platform.Android/Drawing/BrushHandler.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - public abstract class BrushHandler - { - public abstract ag.Paint GetPaint(Brush brush); - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/FontFamilyHandler.cs b/Source/Eto.Platform.Android/Drawing/FontFamilyHandler.cs deleted file mode 100644 index b220554a45..0000000000 --- a/Source/Eto.Platform.Android/Drawing/FontFamilyHandler.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - public class FontFamilyHandler : WidgetHandler, IFontFamily - { - public string Name - { - get { throw new NotImplementedException(); } - } - - public IEnumerable Typefaces - { - get { throw new NotImplementedException(); } - } - - public void Create(string familyName) - { - Control = ag.Typeface.Create(familyName, ag.TypefaceStyle.Normal); // the style doesn't matter - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/FontHandler.cs b/Source/Eto.Platform.Android/Drawing/FontHandler.cs deleted file mode 100644 index f5079887b6..0000000000 --- a/Source/Eto.Platform.Android/Drawing/FontHandler.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class FontHandler : WidgetHandler, IFont - { - float size; - /// - /// Used by GraphicsHandler.MeasureText - /// - ag.Paint paint; - public ag.Paint Paint - { - get - { - if (paint == null) - { - paint = new ag.Paint(); - paint.SetTypeface(this.Control); - } - return paint; - } - } - - ag.Paint.FontMetrics fontMetrics; - ag.Paint.FontMetrics FontMetrics { get { return fontMetrics = fontMetrics ?? Paint.GetFontMetrics(); } } - - public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) - { - this.size = size; - this.Control = ag.Typeface.Create(family.ControlObject as ag.Typeface, style.ToAndroid()); - } - - public void Create(SystemFont systemFont, float? size, FontDecoration decoration) - { - throw new NotImplementedException(); - } - - public void Create(FontTypeface typeface, float size, FontDecoration decoration) - { - this.size = size; - this.Control = ag.Typeface.Create(typeface.Family.Name, typeface.FontStyle.ToAndroid()); - } - - public float XHeight - { - get { throw new NotImplementedException(); } - } - - public float Ascent - { - get { return Math.Abs(FontMetrics.Ascent); } // TODO: does this need to be scaled? - } - - public float Descent - { - get { return Math.Abs(FontMetrics.Descent); } // TODO: does this need to be scaled? - } - - public float LineHeight - { - get { throw new NotImplementedException(); } - } - - public float Leading - { - get { return Math.Abs(FontMetrics.Leading); } // TODO: does this need to be scaled? - } - - public float Baseline - { - get { throw new NotImplementedException(); } - } - - public float Size - { - get { throw new NotImplementedException(); } - } - - public string FamilyName - { - get { throw new NotImplementedException(); } - } - - public FontStyle FontStyle - { - get { throw new NotImplementedException(); } - } - - public FontDecoration FontDecoration - { - get { throw new NotImplementedException(); } - } - - public FontFamily Family - { - get { throw new NotImplementedException(); } - } - - public FontTypeface Typeface - { - get { throw new NotImplementedException(); } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/FontTypefaceHandler.cs b/Source/Eto.Platform.Android/Drawing/FontTypefaceHandler.cs deleted file mode 100644 index 3c5fdc3875..0000000000 --- a/Source/Eto.Platform.Android/Drawing/FontTypefaceHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - class FontTypefaceHandler : WidgetHandler, IFontTypeface - { - public FontTypefaceHandler(ag.TypefaceStyle style) - { - this.Control = style; - Name = this.FontStyle.ToString().Replace(',', ' '); - } - - public string Name { get; set; } - - public FontStyle FontStyle - { - get { return Control.ToEto(); } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/FontsHandler.cs b/Source/Eto.Platform.Android/Drawing/FontsHandler.cs deleted file mode 100644 index 3e15b89aa7..0000000000 --- a/Source/Eto.Platform.Android/Drawing/FontsHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - class FontsHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/GraphicsHandler.cs b/Source/Eto.Platform.Android/Drawing/GraphicsHandler.cs deleted file mode 100644 index 6a6bdc91e8..0000000000 --- a/Source/Eto.Platform.Android/Drawing/GraphicsHandler.cs +++ /dev/null @@ -1,209 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class GraphicsHandler : WidgetHandler, IGraphics - { - public GraphicsHandler() - { - } - - public float PointsPerPixel { get { return 1f; } } // TODO - - public PixelOffsetMode PixelOffsetMode { get; set; } // TODO - - public void CreateFromImage(Bitmap image) - { - Control = new ag.Canvas((ag.Bitmap)image.ControlObject); - } - - public void DrawLine(Pen pen, float startx, float starty, float endx, float endy) - { - Control.DrawLine(startx, starty, endx, endy, pen.ToAndroid()); - } - - public void DrawRectangle(Pen pen, float x, float y, float width, float height) - { - Control.DrawRect(new RectangleF(x, y, width, height).ToAndroid(), pen.ToAndroid()); - } - - public void FillRectangle(Brush brush, float x, float y, float width, float height) - { - Control.DrawRect(new RectangleF(x, y, width, height).ToAndroid(), brush.ToAndroid()); - } - - public void FillEllipse(Brush brush, float x, float y, float width, float height) - { - Control.DrawOval(new RectangleF(x, y, width, height).ToAndroid(), brush.ToAndroid()); - } - - public void DrawEllipse(Pen pen, float x, float y, float width, float height) - { - Control.DrawOval(new RectangleF(x, y, width, height).ToAndroid(), pen.ToAndroid()); - } - - public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - Control.DrawArc(new RectangleF(x, y, width, height).ToAndroid(), startAngle, sweepAngle, false, pen.ToAndroid()); - } - - public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - Control.DrawArc(new RectangleF(x, y, width, height).ToAndroid(), startAngle, sweepAngle, true, brush.ToAndroid()); - } - - public void FillPath(Brush brush, IGraphicsPath path) - { - Control.DrawPath(path.ToAndroid(), brush.ToAndroid()); - } - - public void DrawPath(Pen pen, IGraphicsPath path) - { - Control.DrawPath(path.ToAndroid(), pen.ToAndroid()); - } - - public void DrawImage(Image image, float x, float y) - { - var handler = image.Handler as IAndroidImage; - handler.DrawImage(this, x, y); - } - - public void DrawImage(Image image, float x, float y, float width, float height) - { - var handler = image.Handler as IAndroidImage; - handler.DrawImage(this, x, y, width, height); - } - - public void DrawImage(Image image, RectangleF source, RectangleF destination) - { - var handler = image.Handler as IAndroidImage; - handler.DrawImage(this, source, destination); - } - - - public void DrawText(Font font, SolidBrush brush, float x, float y, string text) - { - var paint = GetTextPaint(font); - paint.Color = brush.ToAndroid().Color; // this overwrites the color on the cached paint, but that's ok since it is only used here. - Control.DrawText(text, x, y, paint); - } - - public SizeF MeasureString(Font font, string text) - { - if(string.IsNullOrEmpty(text)) // needed to avoid exception - return SizeF.Empty; - var paint = GetTextPaint(font); - - // See http://stackoverflow.com/questions/7549182/android-paint-measuretext-vs-gettextbounds - var bounds = new ag.Rect(); - paint.GetTextBounds(text, 0, text.Length, bounds); - - // TODO: see the above article; the width may be truncated to the nearest integer. - return new SizeF(bounds.Width(), bounds.Height()); - } - - /// - /// Returns a Paint that is cached on the font. - /// This is used by all font operations (across all Canvases) that use the same font. - /// - private ag.Paint GetTextPaint(Font font) - { - var paint = (font.Handler as FontHandler).Paint; - paint.AntiAlias = AntiAlias; - return paint; - } - - public void Flush() - { - } - - // The ANTI_ALIAS flag on Paint (not Canvas) causes it to render antialiased. - // SUBPIXEL_TEXT_FLAG is currently unsupported on Android. - // See http://stackoverflow.com/questions/4740565/meaning-of-some-paint-constants-in-android - public bool AntiAlias { get; set; } - - // TODO: setting the FILTER_BITMAP_FLAG on Paint (not Canvas) - // causes it to do a bilinear interpolation. - public ImageInterpolation ImageInterpolation { get; set; } - - public bool IsRetained - { - get { return false; } - } - - public void TranslateTransform(float offsetX, float offsetY) - { - Control.Translate(offsetX, offsetY); - } - - public void RotateTransform(float angle) - { - Control.Rotate(angle); - } - - public void ScaleTransform(float scaleX, float scaleY) - { - Control.Scale(scaleX, scaleY); - } - - public void MultiplyTransform(IMatrix matrix) - { - Control.Concat(matrix.ToAndroid()); - } - - public void SaveTransform() - { - Control.Save(ag.SaveFlags.Matrix); - } - - public void RestoreTransform() - { - Control.Restore(); - } - - public RectangleF ClipBounds - { - get { return Control.ClipBounds.ToEto(); } - } - - public void SetClip(RectangleF rectangle) - { - Control.ClipRect(rectangle.ToAndroid(), ag.Region.Op.Replace); - } - - public void SetClip(IGraphicsPath path) - { - // NOTE: This may not work with hardware acceleration. - // See http://developer.android.com/guide/topics/graphics/hardware-accel.html#drawing-support - // See http://stackoverflow.com/questions/16889815/canvas-clippath-only-works-on-android-emulator - Control.ClipPath(path.ToAndroid(), ag.Region.Op.Replace); - } - - public void ResetClip() - { - Control.ClipRect(new ag.Rect(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue)); - } - - public void Clear(SolidBrush brush) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/GraphicsPathHandler.cs b/Source/Eto.Platform.Android/Drawing/GraphicsPathHandler.cs deleted file mode 100644 index 420c2aba1d..0000000000 --- a/Source/Eto.Platform.Android/Drawing/GraphicsPathHandler.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class GraphicsPathHandler : IGraphicsPathHandler - { - public ag.Path Control { get; private set; } - ag.PointF position; - - public GraphicsPathHandler() - { - Control = new ag.Path(); - } - - public GraphicsPathHandler(ag.Path control) - { - Control = control; - } - - public RectangleF Bounds - { - get { throw new NotImplementedException(); } - } - - public FillMode FillMode - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public bool IsEmpty - { - get { return Control.IsEmpty; } - } - - public PointF CurrentPoint - { - get { throw new NotImplementedException(); } - } - - public void AddLine(float startX, float startY, float endX, float endY) - { - this.Control.MoveTo(startX, startY); - this.Control.LineTo(endX, endY); - position = new ag.PointF(endX, endY); - } - - public void AddLines(IEnumerable points) - { - throw new NotImplementedException(); - } - - public void LineTo(float x, float y) - { - throw new NotImplementedException(); - } - - public void MoveTo(float x, float y) - { - throw new NotImplementedException(); - } - - public void AddArc(float x, float y, float width, float height, float startAngle, float sweepAngle) - { - throw new NotImplementedException(); - } - - public void AddBezier(PointF start, PointF control1, PointF control2, PointF end) - { - throw new NotImplementedException(); - } - - public void AddCurve(IEnumerable points, float tension = 0.5f) - { - throw new NotImplementedException(); - } - - public void AddEllipse(float x, float y, float width, float height) - { - throw new NotImplementedException(); - } - - public void AddRectangle(float x, float y, float width, float height) - { - throw new NotImplementedException(); - } - - public void AddPath(IGraphicsPath path, bool connect = false) - { - throw new NotImplementedException(); - } - - public void Transform(IMatrix matrix) - { - throw new NotImplementedException(); - } - - public void StartFigure() - { - throw new NotImplementedException(); - } - - public void CloseFigure() - { - throw new NotImplementedException(); - } - - public IGraphicsPath Clone() - { - return new GraphicsPathHandler(new ag.Path(this.Control)); - } - - public void Dispose() - { - Control.Dispose(); - } - - public object ControlObject - { - get { return this; } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/IconHandler.cs b/Source/Eto.Platform.Android/Drawing/IconHandler.cs deleted file mode 100644 index d3eed7a9c1..0000000000 --- a/Source/Eto.Platform.Android/Drawing/IconHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - class IconHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Platform.Android/Drawing/IndexedBitmapHandler.cs deleted file mode 100644 index f5479baa26..0000000000 --- a/Source/Eto.Platform.Android/Drawing/IndexedBitmapHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - class IndexedBitmapHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/LinearGradientBrushHandler.cs b/Source/Eto.Platform.Android/Drawing/LinearGradientBrushHandler.cs deleted file mode 100644 index 7a6b4a149d..0000000000 --- a/Source/Eto.Platform.Android/Drawing/LinearGradientBrushHandler.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - public class LinearGradientBrushHandler : BrushHandler, ILinearGradientBrush - { - // TODO: Android does not have the concept of a linear - class BrushObject - { - public ag.Paint Paint { get; set; } - public ag.Matrix InitialMatrix { get; set; } - public IMatrix Matrix { get; set; } - } - - public override ag.Paint GetPaint(Brush brush) - { - return ((BrushObject)brush.ControlObject).Paint; - } - - public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint) - { - var shader = new ag.LinearGradient(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, startColor.ToAndroid(), endColor.ToAndroid(), - // is this correct? - ag.Shader.TileMode.Clamp); - var paint = new ag.Paint(); - paint.SetShader(shader); - return new BrushObject { Paint = paint }; // TODO: initial matrix - } - - public object Create(RectangleF rectangle, Color startColor, Color endColor, float angle) - { - throw new NotImplementedException(); - } - - public IMatrix GetTransform(LinearGradientBrush widget) - { - throw new NotImplementedException(); - } - - public void SetTransform(LinearGradientBrush widget, IMatrix transform) - { - throw new NotImplementedException(); - } - - public GradientWrapMode GetGradientWrap(LinearGradientBrush widget) - { - throw new NotImplementedException(); - } - - public void SetGradientWrap(LinearGradientBrush widget, GradientWrapMode gradientWrap) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/MatrixHandler.cs b/Source/Eto.Platform.Android/Drawing/MatrixHandler.cs deleted file mode 100644 index 5adf650062..0000000000 --- a/Source/Eto.Platform.Android/Drawing/MatrixHandler.cs +++ /dev/null @@ -1,232 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class MatrixHandler : IMatrixHandler, IDisposable - { - ag.Matrix control; - - public ag.Matrix Control { get { return control; } } - - object IControlObjectSource.ControlObject { get { return control; } } - - public MatrixHandler() - { - } - - public MatrixHandler(ag.Matrix matrix) - { - control = matrix; - } - - public float[] Elements - { - get - { - var nineValues = NineValues; - var result = new float[6] - { - nineValues[0], nineValues[1], // array[2] not copied as it is always 1 - nineValues[3], nineValues[4], // array[5] not copied as it is always 1 - nineValues[6], nineValues[7] // array[8] not copied as it is always 1 - }; - - return result; - } - } - - private float[] NineValues - { - get - { - var nineValues = new float[9]; - control.GetValues(nineValues); - return nineValues; - } - } - - private void SetValue(int indexInNineValues, float value) - { - var nineValues = new float[9]; - control.GetValues(nineValues); - nineValues[indexInNineValues] = value; - control.SetValues(nineValues); - } - - public float Xx - { - get { return NineValues[0]; } - set { SetValue(0, value); } - } - - public float Xy - { - get { return NineValues[1]; } - set { SetValue(1, value); } - } - - public float Yx - { - get { return NineValues[3]; } - set { SetValue(3, value); } - } - - public float Yy - { - get { return NineValues[4]; } - set { SetValue(4, value); } - } - - public float X0 - { - get { return NineValues[6]; } - set { SetValue(6, value); } - } - - public float Y0 - { - get { return NineValues[7]; } - set { SetValue(7, value); } - } - - public void Rotate(float angle) - { - this.Control.PreRotate(angle); - } - - public void RotateAt(float angle, float centerX, float centerY) - { -#if TODO - this.Control.RotateAt(angle, new ag.PointF(centerX, centerY), ag.MatrixOrder.Prepend); -#else - throw new NotImplementedException(); -#endif - } - - public void Translate(float x, float y) - { - this.Control.PreTranslate(x, y); - } - - public void Scale(float scaleX, float scaleY) - { - this.Control.PreScale(scaleX, scaleY); - } - - public void ScaleAt(float scaleX, float scaleY, float centerX, float centerY) - { -#if TODO - var m = new ag.Matrix(scaleX, 0, 0, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); - this.Control.Multiply(m, ag.MatrixOrder.Prepend); -#else - throw new NotImplementedException(); -#endif - } - - public void Skew(float skewX, float skewY) - { -#if TODO - var m = new ag.Matrix(1, (float)Math.Tan(Conversions.DegreesToRadians(skewX)), (float)Math.Tan(Conversions.DegreesToRadians(skewY)), 1, 0, 0); - this.Control.Multiply(m, ag.MatrixOrder.Prepend); -#else - throw new NotImplementedException(); -#endif - } - - public void Append(IMatrix matrix) - { - this.Control.PostConcat(matrix.ToAndroid()); - } - - public void Prepend(IMatrix matrix) - { - this.Control.PreConcat(matrix.ToAndroid()); - } - - public void Create() - { - control = new ag.Matrix(); - } - - public void Create(float xx, float yx, float xy, float yy, float dx, float dy) - { - control = new ag.Matrix(); - var values = new float[] - { - xx, yx, 1, - xy, yy, 1, - dx, dy, 1 - }; - control.SetValues(values); - } - - public void Invert() - { - var inverse = new ag.Matrix(); - this.Control.Invert(inverse); - this.control = inverse; - } - - public PointF TransformPoint(Point p) - { - var px = new ag.Point[] { Conversions.ToAndroidPoint(p) }; - -#if TODO - this.Control.TransformPoints(px); - - return Platform.Conversions.ToEto(px[0]); -#else - throw new NotImplementedException(); -#endif - } - - public PointF TransformPoint(PointF p) - { - var px = new ag.PointF[] { p.ToAndroid() }; - -#if TODO - this.Control.TransformPoints(px); -#else - throw new NotImplementedException(); -#endif - - - return px[0].ToEto(); - } - - public void Dispose() - { - if (control != null) - { - control.Dispose(); - control = null; - } - } - - public IMatrix Clone() - { -#if TODO - return new MatrixHandler(control.Clone()); -#else - throw new NotImplementedException(); -#endif - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/PenHandler.cs b/Source/Eto.Platform.Android/Drawing/PenHandler.cs deleted file mode 100644 index 456bdd0a4d..0000000000 --- a/Source/Eto.Platform.Android/Drawing/PenHandler.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class PenHandler : IPen - { - public object Create(Color color, float thickness) - { - var paint = new ag.Paint - { - Color = color.ToAndroid(), - StrokeWidth = thickness, - StrokeCap = ag.Paint.Cap.Square, - StrokeMiter = 10f - }; - return paint; - } - - public Color GetColor(Pen widget) - { - return widget.ToAndroid().Color.ToEto(); - } - - public void SetColor(Pen widget, Color color) - { - widget.ToAndroid().Color = color.ToAndroid(); - } - - public float GetThickness(Pen widget) - { - return widget.ToAndroid().StrokeWidth; - } - - public void SetThickness(Pen widget, float thickness) - { - widget.ToAndroid().StrokeWidth = thickness; - } - - public PenLineJoin GetLineJoin(Pen widget) - { - return widget.ToAndroid().StrokeJoin.ToEto(); - } - - public void SetLineJoin(Pen widget, PenLineJoin lineJoin) - { - widget.ToAndroid().StrokeJoin = lineJoin.ToAndroid(); - } - - public PenLineCap GetLineCap(Pen widget) - { - return widget.ToAndroid().StrokeCap.ToEto(); - } - - public void SetLineCap(Pen widget, PenLineCap lineCap) - { - var pen = widget.ToAndroid(); - pen.StrokeCap = lineCap.ToSD(); - SetDashStyle(widget, widget.DashStyle); - } - - public float GetMiterLimit(Pen widget) - { - return widget.ToAndroid().StrokeMiter; - } - - public void SetMiterLimit(Pen widget, float miterLimit) - { - widget.ToAndroid().StrokeMiter = miterLimit; - } - - public void SetDashStyle(Pen widget, DashStyle dashStyle) - { - var pen = widget.ToAndroid(); - - if (dashStyle == null || dashStyle.IsSolid) - pen.SetPathEffect(null); - else - { - // TODO: create a new ag.DashPathEffect with the appropriate intervals - throw new NotImplementedException(); - } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/SolidBrushHandler.cs b/Source/Eto.Platform.Android/Drawing/SolidBrushHandler.cs deleted file mode 100644 index 16bb802768..0000000000 --- a/Source/Eto.Platform.Android/Drawing/SolidBrushHandler.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class SolidBrushHandler : BrushHandler, ISolidBrush - { - public object Create(Color color) - { - var result = new ag.Paint - { - Color = color.ToAndroid(), - }; - result.SetStyle(ag.Paint.Style.Fill); - return result; - } - - public Color GetColor(SolidBrush widget) - { - return ((ag.Paint)widget.ControlObject).Color.ToEto(); - } - - public void SetColor(SolidBrush widget, Color color) - { - throw new NotImplementedException(); - } - - public override ag.Paint GetPaint(Brush brush) - { - return (ag.Paint)brush.ControlObject; - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Drawing/TextureBrushHandler.cs b/Source/Eto.Platform.Android/Drawing/TextureBrushHandler.cs deleted file mode 100644 index 8e0e36cb80..0000000000 --- a/Source/Eto.Platform.Android/Drawing/TextureBrushHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Drawing -{ - class TextureBrushHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Eto.Platform.Android.csproj b/Source/Eto.Platform.Android/Eto.Platform.Android.csproj deleted file mode 100644 index 72a4754cf3..0000000000 --- a/Source/Eto.Platform.Android/Eto.Platform.Android.csproj +++ /dev/null @@ -1,116 +0,0 @@ - - - - Debug - AnyCPU - {7A02E771-D30B-41A1-8A35-C78D3940FC33} - {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Eto.Platform.Android - Assets - Resources - Eto.Platform.Android - Resources\Resource.designer.cs - Resource - True - v4.3 - - - true - full - false - ..\..\BuildOutput\Android\Debug - DEBUG; - 4 - false - None - - - full - true - ..\..\BuildOutput\Android\Release - 4 - false - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {73A5AD74-68BC-448C-A38C-CFBAF014A311} - Eto - Android - - - - \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/AndroidContainer.cs b/Source/Eto.Platform.Android/Forms/AndroidContainer.cs deleted file mode 100644 index f22e60bafa..0000000000 --- a/Source/Eto.Platform.Android/Forms/AndroidContainer.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using a = Android; -using av = Android.Views; -using aw = Android.Widget; - -namespace Eto.Platform.Android.Forms -{ - /// - /// Base handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public abstract class AndroidContainer : AndroidControl, IContainer - where TWidget: Container - { - protected AndroidContainer() - { - } - - public virtual bool RecurseToChildren { get { return true; } } - - public virtual Size ClientSize { get { return Size; } set { Size = value; } } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/AndroidControl.cs b/Source/Eto.Platform.Android/Forms/AndroidControl.cs deleted file mode 100644 index fed32b9ad5..0000000000 --- a/Source/Eto.Platform.Android/Forms/AndroidControl.cs +++ /dev/null @@ -1,156 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using a = Android; -using av = Android.Views; -using aw = Android.Widget; -using System.Collections.Generic; -using System.Linq; - -namespace Eto.Platform.Android.Forms -{ - public interface IAndroidControl - { - av.View ContainerControl { get; } - } - - /// - /// Base handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public abstract class AndroidControl : WidgetHandler, IControl, IAndroidControl - where TWidget: Control - { - public abstract av.View ContainerControl { get; } - - public void Invalidate() - { - throw new NotImplementedException(); - } - - public void Invalidate(Rectangle rect) - { - throw new NotImplementedException(); - } - - public void SuspendLayout() - { - throw new NotImplementedException(); - } - - public void ResumeLayout() - { - throw new NotImplementedException(); - } - - public void Focus() - { - throw new NotImplementedException(); - } - - public virtual void OnPreLoad(EventArgs e) - { - } - - public virtual void OnLoad(EventArgs e) - { - } - - public virtual void OnLoadComplete(EventArgs e) - { - } - - public virtual void OnUnLoad(EventArgs e) - { - } - - public virtual void SetParent(Container parent) - { - } - - public PointF PointFromScreen(PointF point) - { - throw new NotImplementedException(); - } - - public PointF PointToScreen(PointF point) - { - throw new NotImplementedException(); - } - - Color? backgroundColor; - public Color BackgroundColor - { - get { return backgroundColor ?? Colors.Transparent; } - set - { - backgroundColor = value; - ContainerControl.SetBackgroundColor(value.ToAndroid()); - } - } - - public Size Size - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public virtual bool Enabled - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public bool HasFocus - { - get - { - throw new NotImplementedException(); - } - } - - public bool Visible - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public virtual Point Location - { - get - { - throw new NotImplementedException(); - } - set { } - } - - public IEnumerable SupportedPlatformCommands - { - get { return Enumerable.Empty(); } - } - - public void MapPlatformCommand(string systemAction, Command action) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/AndroidPanel.cs b/Source/Eto.Platform.Android/Forms/AndroidPanel.cs deleted file mode 100644 index c7d2ce2865..0000000000 --- a/Source/Eto.Platform.Android/Forms/AndroidPanel.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using a = Android; -using av = Android.Views; -using aw = Android.Widget; - -namespace Eto.Platform.Android.Forms -{ - /// - /// Base handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public abstract class AndroidPanel : AndroidContainer, IPanel - where TWidget: Panel - { - readonly aw.FrameLayout frame; - Control content; - Size minimumSize; - - protected aw.FrameLayout InnerFrame { get { return frame; } } - - protected AndroidPanel() - { - frame = new aw.FrameLayout(a.App.Application.Context); - } - - protected override void Initialize() - { - base.Initialize(); - SetContent(frame); - } - - public Control Content - { - get { return content; } - set - { - if (content != null) - { - var view = content.GetContainerView(); - frame.RemoveView(view); - } - content = value; - if (content != null) - { - var view = content.GetContainerView(); - view.LayoutParameters = new av.ViewGroup.LayoutParams(av.ViewGroup.LayoutParams.FillParent, av.ViewGroup.LayoutParams.FillParent); - frame.AddView(view); - } - } - } - - protected abstract void SetContent(av.View content); - - public Padding Padding - { - get { return frame.GetPadding(); } - set { frame.SetPadding(value); } - } - - public Size MinimumSize - { - get { return minimumSize; } - set - { - minimumSize = value; - ContainerControl.SetMinimumWidth(value.Width); - ContainerControl.SetMinimumHeight(value.Height); - } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/AndroidWindow.cs b/Source/Eto.Platform.Android/Forms/AndroidWindow.cs deleted file mode 100644 index b08bb58744..0000000000 --- a/Source/Eto.Platform.Android/Forms/AndroidWindow.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Threading.Tasks; -using Eto.Forms; -using Eto.Drawing; -using a = Android; -using av = Android.Views; -using aw = Android.Widget; - -namespace Eto.Platform.Android.Forms -{ - public interface IAndroidWindow - { - a.App.Activity Activity { get; set; } - } - - /// - /// Base handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public abstract class AndroidWindow : AndroidPanel, IWindow, IAndroidWindow - where TWidget: Window - { - a.App.Activity activity; - public a.App.Activity Activity - { - get { return activity ?? (activity = CreateActivity()); } - set { activity = value; } - } - - protected virtual a.App.Activity CreateActivity() - { - return null; // todo - } - - protected AndroidWindow() - { - } - - public override av.View ContainerControl - { - get { return InnerFrame; } - } - - public void Close() - { - //a.App.Application.Context.Start - } - - protected override void SetContent(av.View content) - { - } - - public ToolBar ToolBar { get; set; } - - public double Opacity { get; set; } - - public string Title { get; set; } - - public Screen Screen - { - get - { - throw new NotImplementedException(); - } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/ApplicationHandler.cs b/Source/Eto.Platform.Android/Forms/ApplicationHandler.cs deleted file mode 100644 index 71c52efabf..0000000000 --- a/Source/Eto.Platform.Android/Forms/ApplicationHandler.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using a = Android; -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.Android.Forms -{ - /// - /// Handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public class ApplicationHandler : WidgetHandler, IApplication - { - public static ApplicationHandler Instance { get { return Application.Instance.Handler as ApplicationHandler; } } - - public a.App.Activity MainActivity { get; private set; } - - public ApplicationHandler() - { - Control = a.App.Application.Context as a.App.Application; - } - - public void OnMainFormChanged() - { - if (Widget.MainForm != null) - { - var window = Widget.MainForm.Handler as IAndroidWindow; - if (window != null) - window.Activity = MainActivity; - } - } - - public void Attach(object context) - { - var activity = context as a.App.Activity; - if (activity != null) - { - MainActivity = activity; - } - } - - public void Run(string[] args) - { - Widget.OnInitialized(EventArgs.Empty); - } - - public void Quit() - { - throw new NotImplementedException(); - } - - public void GetSystemActions(List actions, ISubMenuWidget menu, ToolBar toolBar, bool addStandardItems) - { - throw new NotImplementedException(); - } - - public void Open(string url) - { - throw new NotImplementedException(); - } - - public void Invoke(Action action) - { - throw new NotImplementedException(); - } - - public void AsyncInvoke(Action action) - { - throw new NotImplementedException(); - } - - public Keys CommonModifier - { - get { return Key.Control; } - } - - public Keys AlternateModifier - { - get { return Key.Alt; } - } - - public string BadgeLabel - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - - public IEnumerable GetSystemCommands() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Cells/TextBoxCellHandler.cs b/Source/Eto.Platform.Android/Forms/Cells/TextBoxCellHandler.cs deleted file mode 100644 index 0e2788979e..0000000000 --- a/Source/Eto.Platform.Android/Forms/Cells/TextBoxCellHandler.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using Android.App; -using Android.Content; -using Android.OS; -using Android.Runtime; -using Android.Views; -using Android.Widget; -using Eto.Forms; - -namespace Eto.Platform.Android.Forms.Cells -{ - public class TextBoxCellHandler : WidgetHandler, ITextBoxCell - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/AndroidCommonControl.cs b/Source/Eto.Platform.Android/Forms/Controls/AndroidCommonControl.cs deleted file mode 100644 index 1b74c4372d..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/AndroidCommonControl.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using a = Android; -using av = Android.Views; -using aw = Android.Widget; - -namespace Eto.Platform.Android.Forms.Controls -{ - public abstract class AndroidCommonControl : AndroidControl, ICommonControl - where TWidget: CommonControl - where T: av.View - { - public override av.View ContainerControl - { - get { return Control; } - } - - public Font Font - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/ButtonHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/ButtonHandler.cs deleted file mode 100644 index 3badf6d687..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/ButtonHandler.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class ButtonHandler : AndroidCommonControl, IButton - { - public ButtonHandler() - { - Control = new aw.Button(aa.Application.Context); - } - - public Eto.Drawing.Image Image - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public ButtonImagePosition ImagePosition - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/CheckBoxHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/CheckBoxHandler.cs deleted file mode 100644 index 50e93267c7..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/CheckBoxHandler.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - public class CheckBoxHandler : AndroidCommonControl, ICheckBox - { - public CheckBoxHandler() - { - Control = new aw.CheckBox(aa.Application.Context); - } - - public bool? Checked - { - get { return Control.Checked; } - set { Control.Checked = value ?? false; } - } - - public bool ThreeState - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/ComboBoxHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/ComboBoxHandler.cs deleted file mode 100644 index 7a8f592994..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/ComboBoxHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class ComboBoxHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/DateTimePickerHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/DateTimePickerHandler.cs deleted file mode 100644 index d83fb10b3a..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/DateTimePickerHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class DateTimePickerHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/DrawableHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/DrawableHandler.cs deleted file mode 100644 index 6cb8980394..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/DrawableHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class DrawableHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/GridColumnHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/GridColumnHandler.cs deleted file mode 100644 index 46376f6833..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/GridColumnHandler.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - public class GridColumnHandler : WidgetHandler, IGridColumn - { - public string HeaderText { get; set; } - public bool Resizable { get; set; } - public bool Sortable { get; set; } - public bool AutoSize { get; set; } - public int Width { get; set; } - public Cell DataCell { get; set; } - public bool Editable { get; set; } - public bool Visible { get; set; } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/GridHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/GridHandler.cs deleted file mode 100644 index 60b80869e4..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/GridHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class GridHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/GridViewHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/GridViewHandler.cs deleted file mode 100644 index 22dd0cf693..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/GridViewHandler.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - public class GridViewHandler : AndroidControl, IGridView - { - public IDataStore DataStore { get; set; } - - public bool ShowCellBorders { get; set; } - - public bool ShowHeader { get; set; } - - public int RowHeight { get; set; } - - public bool AllowColumnReordering { get; set; } - - public bool AllowMultipleSelection { get; set; } - - public IEnumerable SelectedRows - { - get { if (false) yield return 1; } - } - - public void SelectRow(int row) - { - } - - public void UnselectRow(int row) - { - } - - public void SelectAll() - { - } - - public void UnselectAll() - { - } - - public override av.View ContainerControl - { - get { return null; } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/GroupBoxHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/GroupBoxHandler.cs deleted file mode 100644 index f05958d0bc..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/GroupBoxHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class GroupBoxHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/ImageViewHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/ImageViewHandler.cs deleted file mode 100644 index ee19694f57..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/ImageViewHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class ImageViewHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/LabelHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/LabelHandler.cs deleted file mode 100644 index 7c3726b9b1..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/LabelHandler.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using a = Android; -using av = Android.Views; -using aw = Android.Widget; - -namespace Eto.Platform.Android.Forms.Controls -{ - /// - /// Handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public class LabelHandler : AndroidCommonControl, ILabel - { - const av.GravityFlags AlignmentMask = av.GravityFlags.HorizontalGravityMask | av.GravityFlags.VerticalGravityMask; - - public LabelHandler() - { - Control = new aw.TextView(a.App.Application.Context); - } - - public HorizontalAlign HorizontalAlign - { - get { return Control.Gravity.ToEtoHorizontal(); } - set - { - var gravity = value.ToAndroid(); - Control.Gravity = (Control.Gravity & ~av.GravityFlags.HorizontalGravityMask & AlignmentMask) | gravity; - } - } - - public VerticalAlign VerticalAlign - { - get { return Control.Gravity.ToEtoVertical(); } - set - { - var gravity = value.ToAndroid(); - Control.Gravity = (Control.Gravity & ~av.GravityFlags.VerticalGravityMask & AlignmentMask) | gravity; - } - } - - public WrapMode Wrap - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public Color TextColor - { - get { return Color.FromArgb((uint)Control.CurrentTextColor); } - set { Control.SetTextColor(value.ToAndroid()); } - } - - public string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/ListBoxHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/ListBoxHandler.cs deleted file mode 100644 index b5135f865a..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/ListBoxHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class ListBoxHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/NumericUpDownHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/NumericUpDownHandler.cs deleted file mode 100644 index efda7818da..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/NumericUpDownHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class NumericUpDownHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/PanelHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/PanelHandler.cs deleted file mode 100644 index ab0163d374..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/PanelHandler.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - /// - /// Handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public class PanelHandler : AndroidPanel, IPanel - { - public override av.View ContainerControl { get { return InnerFrame; } } - - protected override void SetContent(av.View content) - { - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/PasswordBoxHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/PasswordBoxHandler.cs deleted file mode 100644 index a5170c8d96..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/PasswordBoxHandler.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; -using Eto.Drawing; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class PasswordBoxHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/ProgressBarHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/ProgressBarHandler.cs deleted file mode 100644 index a7bdc1ecd9..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/ProgressBarHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class ProgressBarHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/RadioButtonHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/RadioButtonHandler.cs deleted file mode 100644 index 0da6880d6e..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/RadioButtonHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class RadioButtonHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/ScrollableHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/ScrollableHandler.cs deleted file mode 100644 index a6c1945af5..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/ScrollableHandler.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; -using Eto.Drawing; -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - /// - /// Handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public class ScrollableHandler : AndroidPanel, IScrollable - { - public void UpdateScrollSizes() - { - Control = new aw.ScrollView(aa.Application.Context); - } - - public override av.View ContainerControl - { - get { return Control; } - } - - protected override void SetContent(av.View content) - { - Control.AddView(content); - } - - public Point ScrollPosition - { - get { return new Point(Control.ScrollX, Control.ScrollY); } - set { Control.ScrollTo(value.X, value.Y); } - } - - public float MinimumZoom { get; set; } - - public float MaximumZoom { get; set; } - - public float Zoom { get; set; } - - public Size ScrollSize - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public BorderType Border - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public Rectangle VisibleRect - { - get - { - throw new NotImplementedException(); - } - } - - public bool ExpandContentWidth - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public bool ExpandContentHeight - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public bool RecurseToChildren { get { return true; } } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/SearchBoxHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/SearchBoxHandler.cs deleted file mode 100644 index 8b95f33451..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/SearchBoxHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class SearchBoxHandler : TextBoxHandler, ISearchBox - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/SliderHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/SliderHandler.cs deleted file mode 100644 index c40b34251b..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/SliderHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class SliderHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/SpinnerHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/SpinnerHandler.cs deleted file mode 100644 index b090eeb097..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/SpinnerHandler.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - public class SpinnerHandler : AndroidControl, ISpinner - { - bool enabled; - - public override av.View ContainerControl { get { return Control; } } - - public SpinnerHandler() - { - Control = new aw.ProgressBar(aa.Application.Context); - Control.Indeterminate = true; - } - - public override bool Enabled - { - get { return enabled; } - set - { - if (enabled != value) - { - enabled = value; - if (enabled) - Control.Visibility = av.ViewStates.Visible; - else - Control.Visibility = av.ViewStates.Invisible; - } - } - } - } -} - diff --git a/Source/Eto.Platform.Android/Forms/Controls/SplitterHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/SplitterHandler.cs deleted file mode 100644 index aaac76f919..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/SplitterHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class SplitterHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/TabControlHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/TabControlHandler.cs deleted file mode 100644 index 9cbefa4f30..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/TabControlHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class TabControlHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/TabPageHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/TabPageHandler.cs deleted file mode 100644 index e17237b01b..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/TabPageHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class TabPageHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/TextAreaHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/TextAreaHandler.cs deleted file mode 100644 index 40724040e6..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/TextAreaHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class TextAreaHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/TextBoxHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/TextBoxHandler.cs deleted file mode 100644 index d184aad024..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/TextBoxHandler.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - class TextBoxHandler : AndroidControl, ITextBox - { - public bool ReadOnly - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public int MaxLength - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public void SelectAll() - { - throw new NotImplementedException(); - } - - public string PlaceholderText { get; set; } - - public string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - - public Eto.Drawing.Font Font - { - get - { - throw new NotImplementedException(); - } - set - { - throw new NotImplementedException(); - } - } - - public override av.View ContainerControl - { - get { throw new NotImplementedException(); } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/TreeGridViewHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/TreeGridViewHandler.cs deleted file mode 100644 index f6d16dfab1..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/TreeGridViewHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class TreeGridViewHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/TreeViewHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/TreeViewHandler.cs deleted file mode 100644 index f9609fa013..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/TreeViewHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class TreeViewHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/Controls/WebViewHandler.cs b/Source/Eto.Platform.Android/Forms/Controls/WebViewHandler.cs deleted file mode 100644 index d085dc362a..0000000000 --- a/Source/Eto.Platform.Android/Forms/Controls/WebViewHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms.Controls -{ - class WebViewHandler - { - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Forms/FormHandler.cs b/Source/Eto.Platform.Android/Forms/FormHandler.cs deleted file mode 100644 index 7447e489ed..0000000000 --- a/Source/Eto.Platform.Android/Forms/FormHandler.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using a = Android; -using av = Android.Views; -using aw = Android.Widget; - -namespace Eto.Platform.Android.Forms -{ - /// - /// Handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public class FormHandler : AndroidWindow
, IForm - { - public void Show() - { - // TODO: create activity if it doesn't exist - Activity.SetContentView(ContainerControl); - } - } -} - diff --git a/Source/Eto.Platform.Android/Forms/TableLayoutHandler.cs b/Source/Eto.Platform.Android/Forms/TableLayoutHandler.cs deleted file mode 100644 index 57442073de..0000000000 --- a/Source/Eto.Platform.Android/Forms/TableLayoutHandler.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; -using Eto.Drawing; -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; -using ag = Android.Graphics; - -namespace Eto.Platform.Android.Forms -{ - /// - /// Handler for - /// - /// (c) 2013 by Curtis Wensley - /// See LICENSE for full terms - public class TableLayoutHandler : AndroidContainer, ITableLayout - { - int lastColumnScale; - bool[] columnScale; - int lastRowScale; - bool[] rowScale; - - public override av.View ContainerControl { get { return Control; } } - - public TableLayoutHandler() - { - Control = new aw.TableLayout(aa.Application.Context); - } - - public void CreateControl(int cols, int rows) - { - lastColumnScale = cols - 1; - columnScale = new bool[cols]; - lastRowScale = rows - 1; - rowScale = new bool[rows]; - for (int y = 0; y < rows; y++) - { - var row = new aw.TableRow(aa.Application.Context); - for (int x = 0; x < cols; x++) - { - row.AddView(new av.View(aa.Application.Context), new aw.TableRow.LayoutParams(av.ViewGroup.LayoutParams.FillParent, av.ViewGroup.LayoutParams.FillParent) { Column = x }); - } - Control.AddView(row, new aw.TableLayout.LayoutParams(av.ViewGroup.LayoutParams.FillParent, av.ViewGroup.LayoutParams.FillParent, y == lastRowScale ? 1f : 0f)); - } - Control.SetColumnStretchable(cols - 1, true); - } - - public bool GetColumnScale(int column) - { - return columnScale[column]; - } - - public void SetColumnScale(int column, bool scale) - { - var lastScale = lastColumnScale; - columnScale[column] = scale; - Control.SetColumnStretchable(column, scale); - lastColumnScale = columnScale.Any(r => r) ? -1 : columnScale.Length - 1; - if (lastScale != lastColumnScale) - { - Control.SetColumnStretchable(columnScale.Length - 1, column == lastColumnScale || columnScale[columnScale.Length - 1]); - } - } - - public bool GetRowScale(int row) - { - return rowScale[row]; - } - - public void SetRowScale(int row, bool scale) - { - var lastScale = lastRowScale; - rowScale[row] = scale; - var layout = Control.GetChildAt(row).LayoutParameters as aw.TableLayout.LayoutParams; - layout.Weight = scale ? 1f : 0f; - lastRowScale = rowScale.Any(r => r) ? -1 : rowScale.Length - 1; - if (lastScale != lastRowScale) - { - layout = Control.GetChildAt(rowScale.Length - 1).LayoutParameters as aw.TableLayout.LayoutParams; - layout.Weight = row == lastRowScale || rowScale[rowScale.Length - 1] ? 1f : 0f; - } - } - - public Size Spacing { get; set; } - - public Padding Padding - { - get { return Control.GetPadding(); } - set { Control.SetPadding(value); } - } - - public void Add(Control child, int x, int y) - { - var control = child.GetContainerView() ?? new av.View(aa.Application.Context); - var row = (aw.TableRow)Control.GetChildAt(y); - row.RemoveViewAt(x); - row.AddView(control, x, new aw.TableRow.LayoutParams(av.ViewGroup.LayoutParams.FillParent, av.ViewGroup.LayoutParams.FillParent) { Column = x }); - } - - public void Move(Control child, int x, int y) - { - Remove(child); - Add(child, x, y); - } - - public void Remove(Control child) - { - var control = child.GetContainerView(); - var row = control.Parent as aw.TableRow; - if (row != null && object.ReferenceEquals(row.Parent, Control)) - { - var x = row.IndexOfChild(control); - row.RemoveView(control); - row.AddView(new av.View(aa.Application.Context), new aw.TableRow.LayoutParams(av.ViewGroup.LayoutParams.FillParent, av.ViewGroup.LayoutParams.FillParent) { Column = x }); - } - } - - public void Update() - { - Control.ForceLayout(); - } - } -} - diff --git a/Source/Eto.Platform.Android/Generator.cs b/Source/Eto.Platform.Android/Generator.cs deleted file mode 100644 index f57909ccb3..0000000000 --- a/Source/Eto.Platform.Android/Generator.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using Eto.Drawing; -using Eto.Forms; -using Eto.Platform.Android.Drawing; -using Eto.Platform.Android.Forms.Controls; -using Eto.Platform.Android.Forms; -using Eto.Platform.Android.Forms.Cells; - -namespace Eto.Platform.Android -{ - public class Generator : Eto.Generator - { - public override string ID { get { return Generators.Android; } } - - public Generator() - { - AddTo(this); - } - - public static void AddTo(Generator g) - { - // Drawing - g.Add(() => new BitmapHandler()); - g.Add(() => new FontFamilyHandler()); - g.Add(() => new FontHandler()); - //g.Add(() => new FontsHandler()); - g.Add(() => new GraphicsHandler()); - g.Add(() => new GraphicsPathHandler()); - //g.Add(() => new IconHandler()); - //g.Add(() => new IndexedBitmapHandler()); - g.Add(() => new MatrixHandler()); - g.Add(() => new PenHandler()); - g.Add(() => new SolidBrushHandler()); - //g.Add(() => new TextureBrushHandler()); - g.Add(() => new LinearGradientBrushHandler()); - - // Forms.Cells - //g.Add (() => new CheckBoxCellHandler ()); - //g.Add (() => new ComboBoxCellHandler ()); - //g.Add(() => new ImageTextCellHandler()); - //g.Add (() => new ImageViewCellHandler ()); - g.Add(() => new TextBoxCellHandler()); - - // Forms.Controls - g.Add(() => new ButtonHandler()); - //g.Add(() => new CheckBoxHandler()); - //g.Add(() => new ComboBoxHandler()); - //g.Add (() => new DateTimePickerHandler ()); - //g.Add(() => new DrawableHandler()); - g.Add(() => new GridColumnHandler()); - g.Add(() => new GridViewHandler()); - //g.Add (() => new GroupBoxHandler ()); - //g.Add(() => new ImageViewHandler()); - g.Add(() => new LabelHandler()); - //g.Add(() => new ListBoxHandler()); - //g.Add(() => new NumericUpDownHandler()); - g.Add(() => new PanelHandler()); - //g.Add(() => new PasswordBoxHandler()); - //g.Add(() => new ProgressBarHandler()); - //g.Add(() => new RadioButtonHandler()); - g.Add(() => new ScrollableHandler()); - g.Add(() => new SearchBoxHandler()); - //g.Add(() => new SliderHandler()); - g.Add(() => new SpinnerHandler()); - //g.Add(() => new SplitterHandler()); - //g.Add (() => new TabControlHandler ()); - //g.Add (() => new TabPageHandler ()); - //g.Add(() => new TextAreaHandler()); - g.Add(() => new TextBoxHandler()); - //g.Add(() => new TreeGridViewHandler()); - //g.Add (() => new TreeViewHandler ()); - //g.Add(() => new WebViewHandler()); - //g.Add(() => new NavigationHandler()); - - // Forms.Menu - //g.Add (() => new CheckMenuItemHandler ()); - //g.Add (() => new ContextMenuHandler ()); - //g.Add (() => new ImageMenuItemHandler ()); - //g.Add (() => new MenuBarHandler ()); - //g.Add (() => new RadioMenuItemHandler ()); - //g.Add (() => new SeparatorMenuItemHandler ()); - - // Forms.Printing - //g.Add (() => new PrintDialogHandler ()); - //g.Add (() => new PrintDocumentHandler ()); - //g.Add (() => new PrintSettingsHandler ()); - - // Forms.ToolBar - //g.Add (() => new CheckToolBarButtonHandler ()); - //g.Add (() => new SeparatorToolBarItemHandler ()); - //g.Add (() => new ToolBarButtonHandler ()); - //g.Add (() => new ToolBarHandler ()); - - // Forms - g.Add(() => new ApplicationHandler()); - //g.Add (() => new ClipboardHandler ()); - //g.Add (() => new ColorDialogHandler ()); - //g.Add (() => new CursorHandler ()); - //g.Add(() => new DialogHandler()); - //g.Add (() => new FontDialogHandler ()); - g.Add(() => new FormHandler()); - //g.Add(() => new MessageBoxHandler()); - //g.Add (() => new OpenFileDialogHandler ()); - //g.Add(() => new PixelLayoutHandler()); - //g.Add (() => new SaveFileDialogHandler ()); - //g.Add (() => new SelectFolderDialogHandler ()); - g.Add(() => new TableLayoutHandler()); - //g.Add(() => new UITimerHandler()); - - // IO - //g.Add (() => new SystemIconsHandler ()); - - // General - //g.Add(() => new EtoEnvironmentHandler()); - } - } -} diff --git a/Source/Eto.Platform.Android/KeyMap.cs b/Source/Eto.Platform.Android/KeyMap.cs deleted file mode 100644 index b41b51d2ce..0000000000 --- a/Source/Eto.Platform.Android/KeyMap.cs +++ /dev/null @@ -1,164 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Forms; - -using aa = Android.App; -using ac = Android.Content; -using ao = Android.OS; -using ar = Android.Runtime; -using av = Android.Views; -using aw = Android.Widget; - -namespace Eto.Platform.Android -{ - public static class KeyMap - { - static Dictionary keymap = new Dictionary(); - static Dictionary inverse = new Dictionary(); - - public static Key ToEto (this av.Keycode keyData) - { - // convert the modifiers - Key modifiers = Key.None; - -#if TODO - // Shift - if ((keyData & av.Keycode.Shift) == av.Keycode.Shift) - modifiers |= Key.Shift; - - // Control - if ((keyData & av.Keycode.Control) == av.Keycode.Control) - modifiers |= Key.Control; - - // Alt - if ((keyData & av.Keycode.Alt) == av.Keycode.Alt) - modifiers |= Key.Alt; - - var keyCode = - Find(keyData & ~(av.Keycode.Shift | av.Keycode.Control | av.Keycode.Alt)); -#else - var keyCode = Find(keyData); // This is incomplete; modifiers are not currently handled -#endif - - return keyCode | modifiers; - } - - private static Key Find(av.Keycode key) - { - Key mapped; - if (keymap.TryGetValue(key, out mapped)) return mapped; - else return Key.None; - } - - public static av.Keycode Find(Key key) - { - av.Keycode mapped; - if (inverse.TryGetValue(key, out mapped)) return mapped; - else return av.Keycode.Unknown; - } - - public static av.Keycode ToSWF (this Key key) - { - var code = key & Key.KeyMask; - av.Keycode modifiers = av.Keycode.Unknown; - -#if TODO - // convert the modifiers - // Shift - if ((key & Key.Shift) == Key.Shift) - modifiers |= av.Keycode.Shift; - - // Control - if ((key & Key.Control) == Key.Control) - modifiers |= av.Keycode.Control; - - // Alt - if ((key & Key.Alt) == Key.Alt) - modifiers |= av.Keycode.Alt; -#endif - - return Find (code) | modifiers; - } - - static KeyMap() - { - keymap.Add(av.Keycode.A, Key.A); - keymap.Add(av.Keycode.B, Key.B); - keymap.Add(av.Keycode.C, Key.C); - keymap.Add(av.Keycode.D, Key.D); - keymap.Add(av.Keycode.E, Key.E); - keymap.Add(av.Keycode.F, Key.F); - keymap.Add(av.Keycode.G, Key.G); - keymap.Add(av.Keycode.H, Key.H); - keymap.Add(av.Keycode.I, Key.I); - keymap.Add(av.Keycode.J, Key.J); - keymap.Add(av.Keycode.K, Key.K); - keymap.Add(av.Keycode.L, Key.L); - keymap.Add(av.Keycode.M, Key.M); - keymap.Add(av.Keycode.N, Key.N); - keymap.Add(av.Keycode.O, Key.O); - keymap.Add(av.Keycode.P, Key.P); - keymap.Add(av.Keycode.Q, Key.Q); - keymap.Add(av.Keycode.R, Key.R); - keymap.Add(av.Keycode.S, Key.S); - keymap.Add(av.Keycode.T, Key.T); - keymap.Add(av.Keycode.U, Key.U); - keymap.Add(av.Keycode.V, Key.V); - keymap.Add(av.Keycode.W, Key.W); - keymap.Add(av.Keycode.X, Key.X); - keymap.Add(av.Keycode.Y, Key.Y); - keymap.Add(av.Keycode.Z, Key.Z); - //keymap.Add(av.Keycode.F1, Key.F1); - //keymap.Add(av.Keycode.F2, Key.F2); - //keymap.Add(av.Keycode.F3, Key.F3); - //keymap.Add(av.Keycode.F4, Key.F4); - //keymap.Add(av.Keycode.F5, Key.F5); - //keymap.Add(av.Keycode.F6, Key.F6); - //keymap.Add(av.Keycode.F7, Key.F7); - //keymap.Add(av.Keycode.F8, Key.F8); - //keymap.Add(av.Keycode.F9, Key.F9); - //keymap.Add(av.Keycode.F10, Key.F10); - //keymap.Add(av.Keycode.F11, Key.F11); - //keymap.Add(av.Keycode.F12, Key.F12); - keymap.Add(av.Keycode.Num0, Key.D0); - keymap.Add(av.Keycode.Num1, Key.D1); - keymap.Add(av.Keycode.Num2, Key.D2); - keymap.Add(av.Keycode.Num3, Key.D3); - keymap.Add(av.Keycode.Num4, Key.D4); - keymap.Add(av.Keycode.Num5, Key.D5); - keymap.Add(av.Keycode.Num6, Key.D6); - keymap.Add(av.Keycode.Num7, Key.D7); - keymap.Add(av.Keycode.Num8, Key.D8); - keymap.Add(av.Keycode.Num9, Key.D9); - keymap.Add(av.Keycode.Space, Key.Space); - //keymap.Add(av.Keycode.Up, Key.Up); - //keymap.Add(av.Keycode.Down, Key.Down); - //keymap.Add(av.Keycode.Left, Key.Left); - //keymap.Add(av.Keycode.Right, Key.Right); - //keymap.Add(av.Keycode.PageDown, Key.PageDown); - //keymap.Add(av.Keycode.PageUp, Key.PageUp); - keymap.Add(av.Keycode.Home, Key.Home); - //keymap.Add(av.Keycode.End, Key.End); - //keymap.Add(av.Keycode.Alt, Key.Alt); - //keymap.Add(av.Keycode.Control, Key.Control); - //keymap.Add(av.Keycode.Shift, Key.Shift); - keymap.Add(av.Keycode.Menu, Key.Menu); - //keymap.Add(av.Keycode.Escape, Key.Escape); - keymap.Add(av.Keycode.Del, Key.Delete); - keymap.Add(av.Keycode.Back, Key.Backspace); - //keymap.Add(av.Keycode.Divide, Key.Divide); - keymap.Add(av.Keycode.Enter, Key.Enter); - //keymap.Add(av.Keycode.Insert, Key.Insert); - keymap.Add(av.Keycode.Period, Key.Period); - keymap.Add(av.Keycode.Tab, Key.Tab); - //keymap.Add(av.Keycode.Apps, Key.ContextMenu); - - foreach (var entry in keymap) - { - inverse.Add(entry.Value, entry.Key); - } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Android/Resources/Resource.designer.cs b/Source/Eto.Platform.Android/Resources/Resource.designer.cs deleted file mode 100644 index c1c129ec50..0000000000 --- a/Source/Eto.Platform.Android/Resources/Resource.designer.cs +++ /dev/null @@ -1,57 +0,0 @@ -#pragma warning disable 1591 -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.18449 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -[assembly: global::Android.Runtime.ResourceDesignerAttribute("Eto.Platform.Android.Resource", IsApplication=false)] - -namespace Eto.Platform.Android -{ - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] - public partial class Resource - { - - static Resource() - { - global::Android.Runtime.ResourceIdManager.UpdateIdValues(); - } - - public partial class Attribute - { - - static Attribute() - { - global::Android.Runtime.ResourceIdManager.UpdateIdValues(); - } - - private Attribute() - { - } - } - - public partial class String - { - - // aapt resource value: 0x7f020000 - public static int library_name = 2130837504; - - static String() - { - global::Android.Runtime.ResourceIdManager.UpdateIdValues(); - } - - private String() - { - } - } - } -} -#pragma warning restore 1591 diff --git a/Source/Eto.Platform.Direct2D/Conversions.cs b/Source/Eto.Platform.Direct2D/Conversions.cs deleted file mode 100644 index 53aab35b35..0000000000 --- a/Source/Eto.Platform.Direct2D/Conversions.cs +++ /dev/null @@ -1,376 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using Eto.Platform.Direct2D.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.DirectWrite; - -namespace Eto.Platform.Direct2D -{ - public static class Conversions - { - public static s.Color4 ToDx(this Color color) - { - return new s.Color4(color.R, color.G, color.B, color.A); - } - - public static s.Color ToDxColor(this Color color) - { - return new s.Color(color.R, color.G, color.B, color.A); - } - - public static Color ToEto(this s.Color4 value) - { - return new Color { A = value.Alpha, R = value.Red, G = value.Green, B = value.Blue }; - } - - public static Rectangle ToEto(this s.RectangleF value) - { - return new Rectangle((int)value.X, (int)value.Y, (int)value.Width, (int)value.Height); - } - - public static RectangleF ToEtoF(this s.RectangleF value) - { - return new RectangleF((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height); - } - - public static s.RectangleF ToDxF(this Rectangle value) - { - return new s.RectangleF(value.X, value.Y, value.Width, value.Height); - } - - public static s.Rectangle ToDx(this Rectangle value) - { - return new s.Rectangle(value.X, value.Y, value.Width, value.Height); - } - - public static s.RectangleF ToDx(this RectangleF value) - { - return new s.RectangleF(value.X, value.Y, value.Width, value.Height); - } - - public static Size ToEto(this s.Size2 value) - { - return new Size(value.Width, value.Height); - } - - public static s.Size2 ToDx(this Size value) - { - return new s.Size2(value.Width, value.Height); - } - - public static SizeF ToEto(this s.Size2F value) - { - return new SizeF(value.Width, value.Height); - } - - public static s.Size2F ToDx(this SizeF value) - { - return new s.Size2F(value.Width, value.Height); - } - - public static Point ToEto(this s.Vector2 value) - { - return new Point((int)value.X, (int)value.Y); - } - - public static s.Vector2 ToDx(this PointF value) - { - return new s.Vector2(value.X, value.Y); - } - - public static string ToWpfMneumonic(this string value) - { - if (value == null) return null; - return value.Replace("_", "__").Replace("&", "_"); - } - - public static sd.BitmapInterpolationMode ToDx(this ImageInterpolation value) - { - switch (value) - { - case ImageInterpolation.None: - return sd.BitmapInterpolationMode.NearestNeighbor; - case ImageInterpolation.Default: - case ImageInterpolation.Low: - case ImageInterpolation.Medium: - case ImageInterpolation.High: - return sd.BitmapInterpolationMode.Linear; - default: - throw new NotSupportedException(); - } - } - - public static ImageInterpolation ToEto(this sd.BitmapInterpolationMode value) - { - switch (value) - { - case sd.BitmapInterpolationMode.Linear: - return ImageInterpolation.High; - case sd.BitmapInterpolationMode.NearestNeighbor: - return ImageInterpolation.None; - default: - throw new NotSupportedException(); - } - } - - public static sd.Bitmap ToDx(this Image image, sd.RenderTarget target) - { - var handler = (ID2DBitmapHandler)image.Handler; - return handler.GetBitmap(target); - } - - public static FontStyle ToEtoStyle(this sw.Font font) - { - var style = FontStyle.None; - if (font.Style == sw.FontStyle.Italic || font.Style == sw.FontStyle.Oblique) - style |= FontStyle.Italic; - - if (font.Weight.IsBold()) - style |= FontStyle.Bold; - return style; - } - - public static bool IsBold(this sw.FontWeight weight) - { - switch (weight) - { - case SharpDX.DirectWrite.FontWeight.Bold: - case SharpDX.DirectWrite.FontWeight.DemiBold: - case SharpDX.DirectWrite.FontWeight.ExtraBold: - case SharpDX.DirectWrite.FontWeight.Heavy: - return true; - case SharpDX.DirectWrite.FontWeight.ExtraBlack: - case SharpDX.DirectWrite.FontWeight.ExtraLight: - case SharpDX.DirectWrite.FontWeight.Light: - case SharpDX.DirectWrite.FontWeight.Medium: - case SharpDX.DirectWrite.FontWeight.Normal: - case SharpDX.DirectWrite.FontWeight.Thin: - default: - return false; - } - } - - public static void Convert(FontStyle value, out sw.FontStyle fontStyle, out sw.FontWeight fontWeight) - { - fontStyle = sw.FontStyle.Normal; - fontWeight = sw.FontWeight.Normal; - - if (value.HasFlag(FontStyle.Italic)) - fontStyle = sw.FontStyle.Italic; - - if (value.HasFlag(FontStyle.Bold)) - fontWeight = sw.FontWeight.Bold; - } - - public static sd.DashStyle ToDx(this DashStyle d) - { - if (d == DashStyles.Solid) - return sd.DashStyle.Solid; - else if (d == DashStyles.Dash) - return sd.DashStyle.Dash; - else if (d == DashStyles.DashDot) - return sd.DashStyle.DashDot; - else if (d == DashStyles.DashDotDot) - return sd.DashStyle.DashDotDot; - else if (d == DashStyles.Dot) - return sd.DashStyle.Dot; - else - { - return sd.DashStyle.Custom; - } - } - - public static sd.LineJoin ToDx(this PenLineJoin lineJoin) - { - switch (lineJoin) - { - case PenLineJoin.Miter: - return sd.LineJoin.MiterOrBevel; - case PenLineJoin.Bevel: - return sd.LineJoin.Bevel; - case PenLineJoin.Round: - return sd.LineJoin.Round; - default: - throw new NotSupportedException(); - } - } - - public static sd.CapStyle ToDx(this PenLineCap lineCap) - { - switch (lineCap) - { - case PenLineCap.Square: - return sd.CapStyle.Square; - case PenLineCap.Butt: - return sd.CapStyle.Flat; - case PenLineCap.Round: - return sd.CapStyle.Round; - default: - throw new NotSupportedException(); - } - } - - public static DashStyle ToEto(this sd.DashStyle d) - { - if (object.ReferenceEquals(d, sd.DashStyle.Dash)) - return DashStyles.Dash; - else if (object.ReferenceEquals(d, sd.DashStyle.DashDot)) - return DashStyles.DashDot; - else if (object.ReferenceEquals(d, sd.DashStyle.DashDotDot)) - return DashStyles.DashDotDot; - else if (object.ReferenceEquals(d, sd.DashStyle.Dot)) - return DashStyles.Dot; - else - return DashStyles.Solid; - } - - public static FillMode ToEto(this sd.FillMode f) - { - return - f == sd.FillMode.Alternate - ? FillMode.Alternate - : FillMode.Winding; - } - - public static sd.FillMode ToDx(this FillMode f) - { - return - f == FillMode.Alternate - ? sd.FillMode.Alternate - : sd.FillMode.Winding; - } - - public static s.Vector2[] ToDx(this PointF[] points) - { - var p = new s.Vector2[points.Length]; - for (var i = 0; i < points.Length; ++i) - p[i] = points[i].ToDx(); - return p; - } - - public static s.Matrix3x2 ToDx(this IMatrix m) - { - return m != null ? (s.Matrix3x2)m.ControlObject : s.Matrix3x2.Identity; - } - - public static float DegreesToRadians(float angle) - { - return (float)Math.PI * angle / 180.0f; - } - - public static PenData ToPenData(this Pen pen) - { - return (PenData)pen.ControlObject; - } - - public static sd.Brush ToDx(this Brush brush, sd.RenderTarget target) - { - var obj = (BrushData)brush.ControlObject; - return obj.Get(target); - } - - public static GraphicsPathHandler ToHandler(this IGraphicsPath path) - { - return path as GraphicsPathHandler ?? ((IHandlerSource)path).Handler as GraphicsPathHandler; - } - - public static sd.Geometry ToGeometry(this IGraphicsPath path) - { - var handler = path.ToHandler(); - handler.CloseSink(); - return handler.Control; - } - - public static sd.PixelFormat ToDx(this PixelFormat format) - { - switch (format) - { - case PixelFormat.Format32bppRgb: - return new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Ignore); - case PixelFormat.Format24bppRgb: - return new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Ignore); - case PixelFormat.Format32bppRgba: - return new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Premultiplied); - default: - throw new NotSupportedException(); - } - } - - public static Guid ToWic(this PixelFormat format) - { - switch (format) - { - case PixelFormat.Format32bppRgb: - return s.WIC.PixelFormat.Format32bppBGR; - case PixelFormat.Format24bppRgb: - return s.WIC.PixelFormat.Format24bppBGR; - case PixelFormat.Format32bppRgba: - return s.WIC.PixelFormat.Format32bppPBGRA; - default: - throw new NotSupportedException(); - } - } - - public static System.Drawing.Imaging.PixelFormat ToSDPixelFormat(this Guid pixelFormat) - { - if (pixelFormat == s.WIC.PixelFormat.Format32bppBGR) - return System.Drawing.Imaging.PixelFormat.Format32bppRgb; - if (pixelFormat == s.WIC.PixelFormat.Format32bppPBGRA) - return System.Drawing.Imaging.PixelFormat.Format32bppPArgb; - if (pixelFormat == s.WIC.PixelFormat.Format24bppBGR) - return System.Drawing.Imaging.PixelFormat.Format24bppRgb; - if (pixelFormat == s.WIC.PixelFormat.Format8bppIndexed) - return System.Drawing.Imaging.PixelFormat.Format8bppIndexed; - throw new NotSupportedException(); - } - - public static Guid ToWic(this ImageFormat format) - { - switch (format) - { - case ImageFormat.Jpeg: - return s.WIC.ContainerFormatGuids.Jpeg; - case ImageFormat.Bitmap: - return s.WIC.ContainerFormatGuids.Bmp; - case ImageFormat.Tiff: - return s.WIC.ContainerFormatGuids.Tiff; - case ImageFormat.Png: - return s.WIC.ContainerFormatGuids.Png; - case ImageFormat.Gif: - return s.WIC.ContainerFormatGuids.Gif; - default: - throw new NotSupportedException(); - } - } - - public static System.Drawing.Bitmap ToSD(this s.WIC.Bitmap bmp) - { - using (var bl = bmp.Lock(s.WIC.BitmapLockFlags.Read)) - { - var pixelFormat = bmp.PixelFormat.ToSDPixelFormat(); - - return new System.Drawing.Bitmap(bmp.Size.Width, bmp.Size.Height, bl.Data.Pitch, pixelFormat, bl.Data.DataPointer); - } - } - - public static s.WIC.Bitmap ToBitmap(this s.WIC.BitmapSource bmp, Guid? pixelFormat = null) - { - using (var converter = new s.WIC.FormatConverter(SDFactory.WicImagingFactory)) - { - converter.Initialize( - bmp, - pixelFormat ?? s.WIC.PixelFormat.Format32bppPBGRA, - s.WIC.BitmapDitherType.None, - null, - 0f, - s.WIC.BitmapPaletteType.Custom); - - return new s.WIC.Bitmap(SDFactory.WicImagingFactory, converter, s.WIC.BitmapCreateCacheOption.CacheOnLoad); - } - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/BitmapHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/BitmapHandler.cs deleted file mode 100644 index e4aa06bd1f..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/BitmapHandler.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.WIC; -using System.IO; - -namespace Eto.Platform.Direct2D.Drawing -{ - public class WicBitmapData : BitmapData - { - public WicBitmapData(Image image, sw.BitmapLock bitmapLock, int bitsPerPixel) - : base(image, bitmapLock.Data.DataPointer, bitmapLock.Data.Pitch, bitsPerPixel, bitmapLock) - { - } - - public override uint TranslateArgbToData(uint argb) - { - return argb; - } - - public override uint TranslateDataToArgb(uint bitmapData) - { - return bitmapData; - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - ((sw.BitmapLock)ControlObject).Dispose(); - } - base.Dispose(disposing); - } - } - - public class BitmapHandler : ImageHandler, IBitmap - { - public BitmapData Lock() - { - var data = Control.Lock(sw.BitmapLockFlags.Write); - return new WicBitmapData(Widget, data, 32); - } - - public void Unlock(BitmapData bitmapData) - { - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/FontFamilyHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/FontFamilyHandler.cs deleted file mode 100644 index 751f17db05..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/FontFamilyHandler.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.DirectWrite; - -namespace Eto.Platform.Direct2D.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class FontFamilyHandler : WidgetHandler, IFontFamily - { - public string Name { get; private set; } - - FontTypeface[] typefaces; - public IEnumerable Typefaces - { - get { - return typefaces ?? (typefaces = Enumerable.Range(0, Control.FontCount) - .Select(r => Control.GetFont(r)) - .Select(r => new FontTypeface(Widget, new FontTypefaceHandler(r))) - .ToArray()); - } - } - - public FontFamilyHandler() - { - } - - public FontFamilyHandler(sw.FontFamily family) - { - Control = family; - } - - public void Create(string familyName) - { - string translatedName = Name = familyName; - - switch (familyName.ToUpperInvariant()) - { - case FontFamilies.MonospaceFamilyName: - translatedName = "Courier New"; - break; - case FontFamilies.SansFamilyName: - translatedName = "Microsoft Sans Serif"; - break; - case FontFamilies.SerifFamilyName: - translatedName = "Times New Roman"; - break; - case FontFamilies.CursiveFamilyName: - translatedName = "Comic Sans MS"; - break; - case FontFamilies.FantasyFamilyName: - translatedName = "Gabriola"; - break; - } - - int index; - if (FontHandler.FontCollection.FindFamilyName(translatedName, out index)) - { - Control = FontHandler.FontCollection.GetFontFamily(index); - } - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/FontHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/FontHandler.cs deleted file mode 100644 index fb4defcf2c..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/FontHandler.cs +++ /dev/null @@ -1,172 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.DirectWrite; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Direct2D.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class FontHandler : WidgetHandler, IFont, IWindowsFontSource - { - sw.TextFormat textFormat; - public sw.TextFormat TextFormat - { - get - { - if (textFormat == null) - { - textFormat = new sw.TextFormat( - SDFactory.DirectWriteFactory, - Control.FontFamily.FamilyNames.GetString(0), - FontCollection, - Control.Weight, - Control.Style, - Control.Stretch, - Size * 96.0f / 72.0f // convert from points to pixels. (The documentation says device-independent pixels.) - ); - } - return textFormat; - } - } - - public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) - { - this.family = family; - Size = size; - FontStyle = style; - FontDecoration = decoration; - - sw.FontStyle fontStyle; - sw.FontWeight fontWeight; - Conversions.Convert(style, out fontStyle, out fontWeight); - - var familyHandler = (FontFamilyHandler)family.Handler; - Control = familyHandler.Control.GetFirstMatchingFont(fontWeight, sw.FontStretch.Normal, fontStyle); - } - - public void Create(SystemFont systemFont, float? size, FontDecoration decoration) - { - var sdfont = Eto.Platform.Windows.Conversions.ToSD(systemFont); - Create(sdfont.Name, size ?? sdfont.SizeInPoints, FontStyle.None, decoration); - } - - public void Create(FontTypeface typeface, float size, FontDecoration decoration) - { - family = typeface.Family; - this.typeface = typeface; - var typefaceHandler = (FontTypefaceHandler)typeface.Handler; - - Control = typefaceHandler.Font; - FontStyle = Control.ToEtoStyle(); - FontDecoration = decoration; - Size = size; - } - - void Create(string familyName, float sizeInPoints, FontStyle style, FontDecoration decoration) - { - Size = sizeInPoints; - FontStyle = style; - FontDecoration = decoration; - int index; - if (FontCollection.FindFamilyName(familyName, out index)) - { - sw.FontStyle fontStyle; - sw.FontWeight fontWeight; - Conversions.Convert(style, out fontStyle, out fontWeight); - Control = FontCollection.GetFontFamily(index).GetFirstMatchingFont(fontWeight, sw.FontStretch.Normal, fontStyle); - } - } - - static sw.FontCollection fontCollection; - public static sw.FontCollection FontCollection - { - get - { - return fontCollection = fontCollection ?? SDFactory.DirectWriteFactory.GetSystemFontCollection(checkForUpdates: false); - } - } - - protected override void Dispose(bool disposing) - { - if (textFormat != null) - { - textFormat.Dispose(); - textFormat = null; - } - - base.Dispose(disposing); - } - - FontFamily family; - public FontFamily Family - { - get { return family ?? (family = new FontFamily(Generator, new FontFamilyHandler(Control.FontFamily))); } - } - - public string FamilyName - { - get { return Family.Name; } - } - - public FontStyle FontStyle { get; private set; } - - public FontDecoration FontDecoration { get; private set; } - - /// - /// The size in points. - /// - public float Size { get; private set; } - - FontTypeface typeface; - public FontTypeface Typeface - { - get { return typeface ?? (typeface = new FontTypeface(Family, new FontTypefaceHandler(Control))); } - } - - public float XHeight - { - get { return Size * Control.Metrics.XHeight / Control.Metrics.DesignUnitsPerEm; } - } - - public float Ascent - { - get { return Size * Control.Metrics.Ascent / Control.Metrics.DesignUnitsPerEm; } - } - - public float Descent - { - get { return Size * Control.Metrics.Descent / Control.Metrics.DesignUnitsPerEm; } - } - - public float LineHeight - { - get { return Ascent + Descent + Size * Control.Metrics.LineGap / Control.Metrics.DesignUnitsPerEm; } - } - - public float Leading - { - get { return LineHeight - (Ascent + Descent);} - } - - public float Baseline - { - get { return Ascent; } - } - - public System.Drawing.Font GetFont() - { - var familyName = Control.FontFamily.FamilyNames.GetString(0); - var style = Eto.Platform.Windows.Conversions.ToSD(FontStyle) | Eto.Platform.Windows.Conversions.ToSD(FontDecoration); - return new System.Drawing.Font(familyName, Size, style); - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/FontTypefaceHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/FontTypefaceHandler.cs deleted file mode 100644 index 8a863d7390..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/FontTypefaceHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.DirectWrite; - -namespace Eto.Platform.Direct2D.Drawing -{ - public class FontTypefaceHandler : WidgetHandler, IFontTypeface - { - public sw.Font Font { get; private set; } - - public FontTypefaceHandler(sw.Font font) - { - Font = font; - Control = new sw.FontFace(font); - } - - public FontStyle FontStyle - { - get { return Font.ToEtoStyle(); } - } - - public string Name - { - get { return Font.FaceNames.GetString(0); } - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/FontsHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/FontsHandler.cs deleted file mode 100644 index 1289027a69..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/FontsHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.DirectWrite; - -namespace Eto.Platform.Direct2D.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class FontsHandler : WidgetHandler, IFonts - { - FontFamily[] availableFontFamilies; - public IEnumerable AvailableFontFamilies - { - get - { - if (availableFontFamilies == null) - { - var fonts = FontHandler.FontCollection; - availableFontFamilies = Enumerable.Range(0, fonts.FontFamilyCount) - .Select(r => fonts.GetFontFamily(r).FamilyNames.GetString(0)) - .Distinct() - .Select(r => new FontFamily(Generator, r)) - .ToArray(); - } - return availableFontFamilies; - } - } - - public bool FontFamilyAvailable(string fontFamily) - { - return AvailableFontFamilies.Any(r => string.Equals(r.Name, fontFamily, StringComparison.InvariantCultureIgnoreCase)); - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/GraphicsHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/GraphicsHandler.cs deleted file mode 100644 index a3f4f047cb..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/GraphicsHandler.cs +++ /dev/null @@ -1,537 +0,0 @@ -using System; -using System.Collections.Generic; -using Eto.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.DirectWrite; -using swf = System.Windows.Forms; -using Eto.Forms; -using Eto.Platform.Windows; -using System.Diagnostics; - -namespace Eto.Platform.Direct2D.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class GraphicsHandler : WidgetHandler, IGraphics - { - bool hasBegan; - bool disposeControl = true; - Bitmap image; - float offset = 0.5f; - float fillOffset; - sd.Layer clipLayer; - RectangleF clipBounds; - DrawableHandler drawable; - - public float PointsPerPixel { get { return 72f / Control.DotsPerInch.Width; } } - - protected override bool DisposeControl { get { return disposeControl; } } - - public GraphicsHandler() - { - } - - public GraphicsHandler(GraphicsHandler other) - { - Control = other.Control; - disposeControl = false; - } - - public GraphicsHandler(DrawableHandler drawable) - { - this.drawable = drawable; - CreateRenderTarget(); - - //set hwnd target properties (permit to attach Direct2D to window) - //target creation - drawable.Control.SizeChanged += HandleSizeChanged; - } - - void CreateRenderTarget() - { - var renderProp = new sd.RenderTargetProperties - { - DpiX = 0, - DpiY = 0, - MinLevel = sd.FeatureLevel.Level_DEFAULT, - Type = sd.RenderTargetType.Default, - Usage = sd.RenderTargetUsage.None - }; - - if (drawable != null) - { - renderProp.PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Premultiplied); - var winProp = new sd.HwndRenderTargetProperties - { - Hwnd = drawable.Control.Handle, - PixelSize = drawable.ClientSize.ToDx(), - PresentOptions = sd.PresentOptions.Immediately - }; - - Control = new sd.WindowRenderTarget(SDFactory.D2D1Factory, renderProp, winProp); - } - else if (image != null) - { - var imageHandler = image.Handler as BitmapHandler; - renderProp.PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.Unknown, sd.AlphaMode.Unknown); - Control = new sd.WicRenderTarget(SDFactory.D2D1Factory, imageHandler.Control, renderProp); - } - } - - void HandleSizeChanged(object sender, EventArgs e) - { - var target = Control as sd.WindowRenderTarget; - if (target == null) - return; - try - { - target.Resize(drawable.ClientSize.ToDx()); - drawable.Invalidate(); - } - catch (Exception ex) - { - Debug.Print(string.Format("Could not resize: {0}", ex)); - } - } - - sd.Ellipse GetEllipse(float x, float y, float width, float height) - { - var rx = width / 2f; - var ry = height / 2f; - - return new sd.Ellipse(center: new s.Vector2(x + rx, y + ry), radiusX: rx, radiusY: ry); - } - - public bool AntiAlias - { - get { return Control.AntialiasMode == sd.AntialiasMode.PerPrimitive; } - set { Control.AntialiasMode = value ? sd.AntialiasMode.PerPrimitive : sd.AntialiasMode.Aliased; } - } - - public ImageInterpolation ImageInterpolation { get; set; } - - public bool IsRetained - { - get { return false; } - } - - public double DpiX - { - get { return Control.DotsPerInch.Width; } - } - - public double DpiY - { - get { return Control.DotsPerInch.Height; } - } - - public RectangleF ClipBounds - { - get - { - // not very efficient, but works - var transform = Control.Transform; - transform.Invert(); - var start = s.Matrix3x2.TransformPoint(transform, clipBounds.Location.ToDx()).ToEto(); - var end = s.Matrix3x2.TransformPoint(transform, clipBounds.EndLocation.ToDx()).ToEto(); - return new RectangleF(start, end); - } - } - - public void SetClip(RectangleF rect) - { - ResetClip(); - clipBounds = rect; - var parameters = new sd.LayerParameters - { - ContentBounds = clipBounds.ToDx(), - GeometricMask = new sd.RectangleGeometry(SDFactory.D2D1Factory, rect.ToDx()), - MaskAntialiasMode = Control.AntialiasMode, - MaskTransform = s.Matrix3x2.Identity, - Opacity = 1f - }; - clipLayer = new sd.Layer(Control); - Control.PushLayer(ref parameters, clipLayer); - } - - public void SetClip(IGraphicsPath path) - { - ResetClip(); - clipBounds = path.Bounds; - var parameters = new sd.LayerParameters - { - ContentBounds = clipBounds.ToDx(), - GeometricMask = path.ToGeometry(), - MaskAntialiasMode = Control.AntialiasMode, - MaskTransform = s.Matrix3x2.Identity, - Opacity = 1f - }; - clipLayer = new sd.Layer(Control); - Control.PushLayer(ref parameters, clipLayer); - } - - public void ResetClip() - { - if (clipLayer != null) - { - Control.PopLayer(); - clipLayer.Dispose(); - clipLayer = null; - clipBounds = new RectangleF(Control.Size.ToEto()); - } - } - - public void TranslateTransform(float dx, float dy) - { - Control.Transform = s.Matrix3x2.Multiply(s.Matrix3x2.Translation(dx, dy), Control.Transform); - } - - public void RotateTransform(float angle) - { - Control.Transform = s.Matrix3x2.Multiply(s.Matrix3x2.Rotation((float)(Conversions.DegreesToRadians(angle))), Control.Transform); - } - - public void ScaleTransform(float sx, float sy) - { - Control.Transform = s.Matrix3x2.Multiply(s.Matrix3x2.Scaling(sx, sy), Control.Transform); - } - - public void MultiplyTransform(IMatrix matrix) - { - Control.Transform = s.Matrix3x2.Multiply((s.Matrix3x2)matrix.ControlObject, Control.Transform); - } - - Stack transformStack; - - public void SaveTransform() - { - if (transformStack == null) - transformStack = new Stack(); - transformStack.Push(Control.Transform); - } - - public void RestoreTransform() - { - Control.Transform = transformStack.Pop(); - } - - public void CreateFromImage(Bitmap image) - { - this.image = image; - CreateRenderTarget(); - BeginDrawing(); - } - - public void DrawText(Font font, SolidBrush brush, float x, float y, string text) - { - using (var textLayout = GetTextLayout(font, text)) - { - Control.DrawTextLayout(new s.Vector2(x, y), textLayout, brush.ToDx(Control)); - } - } - - public SizeF MeasureString(Font font, string text) - { - using (var textLayout = GetTextLayout(font, text)) - { - var metrics = textLayout.Metrics; - return new SizeF(metrics.WidthIncludingTrailingWhitespace, metrics.Height); - } - } - - static sw.TextLayout GetTextLayout(Font font, string text) - { - var fontHandler = (FontHandler)font.Handler; - var textLayout = new sw.TextLayout(SDFactory.DirectWriteFactory, text, fontHandler.TextFormat, float.MaxValue, float.MaxValue); - return textLayout; - } - - public void Flush() - { - Control.Flush(); - } - - public PixelOffsetMode PixelOffsetMode - { - get { return offset == 0f ? PixelOffsetMode.None : PixelOffsetMode.Half; } - set - { - if (value == PixelOffsetMode.None) - { - offset = .5f; - fillOffset = 0f; - } - else - { - offset = 0f; - fillOffset = -.5f; - } - } - } - - public void DrawRectangle(Pen pen, float x, float y, float width, float height) - { - var pd = pen.ToPenData(); - Control.DrawRectangle(new s.RectangleF(x + offset, y + offset, width, height), pd.GetBrush(Control), pd.Width, pd.StrokeStyle); - } - - public void FillRectangle(Brush brush, float x, float y, float width, float height) - { - Control.FillRectangle(new s.RectangleF(x + fillOffset, y + fillOffset, width, height), brush.ToDx(Control)); - } - - public void DrawLine(Pen pen, float startx, float starty, float endx, float endy) - { - var pd = pen.ToPenData(); - Control.DrawLine( - new s.Vector2(startx + offset, starty + offset), - new s.Vector2(endx + offset, endy + offset), - pd.GetBrush(Control), - pd.Width, - pd.StrokeStyle); - } - - public void FillEllipse(Brush brush, float x, float y, float width, float height) - { - Control.FillEllipse(GetEllipse(x + fillOffset, y + fillOffset, width, height), brush.ToDx(Control)); - } - - public void DrawEllipse(Pen pen, float x, float y, float width, float height) - { - var pd = pen.ToPenData(); - Control.DrawEllipse(GetEllipse(x + offset, y + offset, width, height), pd.GetBrush(Control), pd.Width, pd.StrokeStyle); - } - - public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - PointF start; - var arc = CreateArc(x + offset, y + offset, width, height, startAngle, sweepAngle, out start); - var path = new sd.PathGeometry(SDFactory.D2D1Factory); - var sink = path.Open(); - sink.BeginFigure(start.ToDx(), sd.FigureBegin.Hollow); - sink.AddArc(arc); - sink.EndFigure(sd.FigureEnd.Open); - sink.Close(); - sink.Dispose(); - var pd = pen.ToPenData(); - Control.DrawGeometry(path, pd.GetBrush(Control), pd.Width, pd.StrokeStyle); - } - - internal static sd.ArcSegment CreateArc(float x, float y, float width, float height, float startAngle, float sweepAngle, out PointF start) - { - // degrees to radians conversion - float startRadians = startAngle * (float)Math.PI / 180.0f; - float sweepRadians = sweepAngle * (float)Math.PI / 180.0f; - - // x and y radius - float dx = width / 2; - float dy = height / 2; - - // determine the start point - float xs = x + dx + ((float)Math.Cos(startRadians) * dx); - float ys = y + dy + ((float)Math.Sin(startRadians) * dy); - - // determine the end point - float xe = x + dx + ((float)Math.Cos(startRadians + sweepRadians) * dx); - float ye = y + dy + ((float)Math.Sin(startRadians + sweepRadians) * dy); - - bool isLargeArc = Math.Abs(sweepAngle) > 180; - bool isClockwise = sweepAngle >= 0 && Math.Abs(sweepAngle) < 360; - start = new PointF(xs, ys); - return new sd.ArcSegment - { - Point = new s.Vector2(xe, ye), - Size = new s.Size2F(dx, dy), - SweepDirection = isClockwise ? sd.SweepDirection.Clockwise : sd.SweepDirection.CounterClockwise, - ArcSize = isLargeArc ? sd.ArcSize.Large : sd.ArcSize.Small - }; - } - - - public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - PointF start; - x += fillOffset; - y += fillOffset; - var arc = CreateArc(x, y, width, height, startAngle, sweepAngle, out start); - var path = new sd.PathGeometry(SDFactory.D2D1Factory); - var sink = path.Open(); - var center = new s.Vector2(x + width / 2, y + height / 2); - sink.BeginFigure(center, sd.FigureBegin.Filled); - sink.AddLine(start.ToDx()); - sink.AddArc(arc); - sink.AddLine(center); - sink.EndFigure(sd.FigureEnd.Open); - sink.Close(); - sink.Dispose(); - Control.FillGeometry(path, brush.ToDx(Control)); - } - - public void FillPath(Brush brush, IGraphicsPath path) - { - SaveTransform(); - TranslateTransform(-fillOffset, -fillOffset); - Control.FillGeometry(path.ToGeometry(), brush.ToDx(Control)); - RestoreTransform(); - } - - public void DrawPath(Pen pen, IGraphicsPath path) - { - var pd = pen.ToPenData(); - SaveTransform(); - TranslateTransform(offset, offset); - Control.DrawGeometry(path.ToGeometry(), pd.GetBrush(Control), pd.Width, pd.StrokeStyle); - RestoreTransform(); - } - - public void DrawImage(Image image, RectangleF source, RectangleF destination) - { - var bmp = image.ToDx(Control); - Control.DrawBitmap(bmp, destination.ToDx(), 1f, sd.BitmapInterpolationMode.Linear, source.ToDx()); - } - - public void DrawImage(Image image, float x, float y) - { - var bmp = image.ToDx(Control); - Control.DrawBitmap(bmp, new s.RectangleF(x, y, bmp.Size.Width, bmp.Size.Height), 1f, ImageInterpolation.ToDx()); - } - - public void DrawImage(Image image, float x, float y, float width, float height) - { - var bmp = image.ToDx(Control); - Control.DrawBitmap(bmp, new s.RectangleF(x, y, width, height), 1f, ImageInterpolation.ToDx()); - } - - public object ControlObject - { - get { throw new NotImplementedException(); } - } - - public void Clear(SolidBrush brush) - { - // TODO: doesn't actually clear to transparent (e.g. on a bitmap) - var rect = new s.RectangleF(0, 0, Control.PixelSize.Width, Control.PixelSize.Height); - if (brush != null) - Control.Clear(brush.Color.ToDx()); - else - Control.Clear(s.Color4.Black); - } - - static sd.RenderTarget globalRenderTarget; - /// - /// This is a HACK. - /// Brushes, bitmaps and other resources are associated with a specific - /// render target in D2D. Eto does not currently support this. - /// - public static sd.RenderTarget CurrentRenderTarget - { - get - { - if (globalRenderTarget == null) - { - // hack for now, use a temporary control to get the current target - // ideally, each brush/etc will create itself when needed, not right away. - // though, this may be difficult for things like a bitmap - var ctl = new System.Windows.Forms.Control(); - var winProp = new sd.HwndRenderTargetProperties - { - Hwnd = ctl.Handle, - PixelSize = new s.Size2(2000, 2000), - PresentOptions = sd.PresentOptions.Immediately - }; - var renderProp = new sd.RenderTargetProperties - { - DpiX = 0, - DpiY = 0, - MinLevel = sd.FeatureLevel.Level_10, - PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Premultiplied), - Type = sd.RenderTargetType.Hardware, - Usage = sd.RenderTargetUsage.None - }; - globalRenderTarget = new sd.WindowRenderTarget(SDFactory.D2D1Factory, renderProp, winProp); - } - return currentRenderTarget ?? globalRenderTarget; - } - set - { - currentRenderTarget = value; - } - } - - static sd.RenderTarget currentRenderTarget; - - public void BeginDrawing(RectangleF? clipRect = null) - { - CurrentRenderTarget = Control; - Control.BeginDraw(); - Control.Transform = s.Matrix3x2.Identity; - if (transformStack != null) - transformStack.Clear(); - ResetClip(); - clipBounds = new RectangleF(Control.Size.ToEto()); - if (clipRect != null) - Control.PushAxisAlignedClip(clipRect.Value.ToDx(), SharpDX.Direct2D1.AntialiasMode.PerPrimitive); - hasBegan = true; - } - - public void EndDrawing(bool popClip = false) - { - if (hasBegan) - { - ResetClip(); - CurrentRenderTarget = null; - - if (popClip) - Control.PopAxisAlignedClip(); - - Control.EndDraw(); - hasBegan = false; - - if (image != null) - { - var imageHandler = image.Handler as BitmapHandler; - imageHandler.Reset(); - } - } - } - - public void PerformDrawing(RectangleF? clipRect, Action draw) - { - bool recreated = false; - do - { - try - { - recreated = false; - BeginDrawing(clipRect); - draw(); - EndDrawing(clipRect != null); - } - catch (s.SharpDXException ex) - { - if (ex.ResultCode == 0x8899000C) // D2DERR_RECREATE_TARGET - { - Debug.Print("Recreating targets"); - // need to recreate render target - CreateRenderTarget(); - CurrentRenderTarget = Control; - globalRenderTarget = null; - recreated = true; - } - } - } - while (recreated); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - EndDrawing(); - base.Dispose(disposing); - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/GraphicsPathHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/GraphicsPathHandler.cs deleted file mode 100644 index c6c00c18c0..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/GraphicsPathHandler.cs +++ /dev/null @@ -1,241 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.DirectWrite; -using Eto.Drawing; - -namespace Eto.Platform.Direct2D.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class GraphicsPathHandler : IGraphicsPathHandler - { - List geometries = new List(); - IMatrix transform; - sd.PathGeometry path; - bool isInFigure = false; - sd.FillMode fillMode; - sd.Geometry control; - - public PointF CurrentPoint { get; private set; } - public object ControlObject { get { return this.Control; } } - - public sd.Geometry Control - { - get - { - if (control == null) - { - if (geometries.Count > 0) - { - control = new sd.GeometryGroup(SDFactory.D2D1Factory, fillMode, geometries.ToArray()); - } - if (transform != null && control != null) - control = new sd.TransformedGeometry(SDFactory.D2D1Factory, control, transform.ToDx()); - } - return control; - } - } - public RectangleF Bounds - { - get - { - return Control.GetBounds().ToEto(); - } - } - - sd.GeometrySink sink; - public sd.GeometrySink Sink - { - get - { - if (sink == null) - { - geometries.Add(path = new sd.PathGeometry(SDFactory.D2D1Factory)); - control = null; - sink = path.Open(); - } - return sink; - } - } - - public GraphicsPathHandler() - { - } - - public void CloseSink() - { - // This must be called before rendering the path. - if (sink != null) - { - if (isInFigure) - sink.EndFigure(sd.FigureEnd.Open); - isInFigure = false; - sink.Close(); - sink.Dispose(); - sink = null; - } - } - - public void AddBezier(PointF pt1, PointF pt2, PointF pt3, PointF pt4) - { - ConnectTo(pt1); - AddBezier(pt2, pt3, pt4); - } - - void AddBezier(PointF pt2, PointF pt3, PointF pt4) - { - Sink.AddBezier(new sd.BezierSegment - { - Point1 = pt2.ToDx(), - Point2 = pt3.ToDx(), - Point3 = pt4.ToDx() - }); - - CurrentPoint = pt4; - } - - public IGraphicsPath Clone() - { - throw new NotImplementedException(); - } - - public FillMode FillMode - { - get { return fillMode.ToEto(); ; } - set { fillMode = value.ToDx(); } - } - - public bool IsEmpty - { - get { return geometries.Count == 0; } - } - - void ConnectTo(PointF p) - { - var pt = p.ToDx(); - if (isInFigure) - Sink.AddLine(pt); - else - { - isInFigure = true; - // create filled for when we fill with a brush - Sink.BeginFigure(pt, sd.FigureBegin.Filled); - } - - CurrentPoint = p; - } - - public void StartFigure() - { - if (isInFigure) - { - Sink.EndFigure(sd.FigureEnd.Open); - isInFigure = false; - } - } - - public void CloseFigure() - { - if (isInFigure) - { - Sink.EndFigure(sd.FigureEnd.Closed); - isInFigure = false; - } - } - - public void Transform(IMatrix matrix) - { - if (matrix != null) - { - if (transform != null) - transform.Prepend(matrix); - else - transform = matrix.Clone(); - } - else - transform = null; - control = null; - } - - public void AddLine(float startX, float startY, float endX, float endY) - { - ConnectTo(new PointF(startX, startY)); - ConnectTo(new PointF(endX, endY)); - } - - public void AddLines(IEnumerable points) - { - foreach (var p in points) - ConnectTo(p); - } - - public void LineTo(float x, float y) - { - ConnectTo(new PointF(x, y)); - } - - public void MoveTo(float x, float y) - { - StartFigure(); - ConnectTo(new PointF(x, y)); - } - - public void AddCurve(IEnumerable points, float tension = 0.5f) - { - var temp = SplineHelper.SplineCurve(points, tension); - SplineHelper.Draw(temp, ConnectTo, AddBezier); - } - - public void AddArc(float x, float y, float width, float height, float startAngle, float sweepAngle) - { - PointF start; - var arc = GraphicsHandler.CreateArc(x, y, width, height, startAngle, sweepAngle, out start); - ConnectTo(start); - Sink.AddArc(arc); - } - - public void AddEllipse(float x, float y, float width, float height) - { - CloseSink(); - var ellipse = new sd.Ellipse(new s.Vector2(x + width / 2, y + height / 2), width / 2, height / 2); - geometries.Add(new sd.EllipseGeometry(SDFactory.D2D1Factory, ellipse)); - control = null; - } - - public void AddPath(IGraphicsPath path, bool connect) - { - var inputGeometry = path.ToHandler(); - if (connect) - { - // TODO: how do we attach to the existing sink? throws an exception otherwise - StartFigure(); - inputGeometry.Control.Simplify(sd.GeometrySimplificationOption.CubicsAndLines, Sink); - } - else - { - CloseSink(); - geometries.Add(inputGeometry.Control); - } - control = null; - } - - public void AddRectangle(float x, float y, float width, float height) - { - CloseSink(); - geometries.Add(new sd.RectangleGeometry(SDFactory.D2D1Factory, new s.RectangleF(x, y, width, height))); - control = null; - } - - public void Dispose() - { - Control.Dispose(); - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/IconHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/IconHandler.cs deleted file mode 100644 index e8c0a2081c..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/IconHandler.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.WIC; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Direct2D.Drawing -{ - public class IconHandler : ImageHandler, IIcon, IWindowsIconSource - { - System.Drawing.Icon sdicon; - public System.Drawing.Icon GetIcon() - { - if (sdicon == null && Frames != null) - { - // TODO: Convert each bitmap in Frames to a single icon - sdicon = System.Drawing.Icon.FromHandle(Control.ToBitmap().ToSD().GetHicon()); - } - return sdicon; - } - - public override void Reset() - { - base.Reset(); - if (sdicon != null) - { - sdicon.Dispose(); - sdicon = null; - } - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/ImageHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/ImageHandler.cs deleted file mode 100644 index 0687bc5c4d..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/ImageHandler.cs +++ /dev/null @@ -1,181 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.WIC; -using System.IO; -using Eto.Platform.Windows.Drawing; -using System.Diagnostics; - -namespace Eto.Platform.Direct2D.Drawing -{ - public interface ID2DBitmapHandler - { - sd.Bitmap GetBitmap(sd.RenderTarget target); - } - - public class ImageHandler : WidgetHandler, IImage, ID2DBitmapHandler, IWindowsImageSource - where TWidget: Image - { - sd.Bitmap targetBitmap; - public sw.Bitmap[] Frames { get; private set; } - public sd.Bitmap GetBitmap(sd.RenderTarget target) - { - if (targetBitmap == null || !ReferenceEquals(targetBitmap.Tag, target)) - { - targetBitmap = CreateDrawableBitmap(target); - } - return targetBitmap; - } - - protected virtual sd.Bitmap CreateDrawableBitmap(sd.RenderTarget target) - { - return sd.Bitmap.FromWicBitmap(target, Control); - } - - void Initialize(s.WIC.BitmapDecoder decoder) - { - Frames = Enumerable.Range(0, decoder.FrameCount).Select(r => decoder.GetFrame(r).ToBitmap()).ToArray(); - // find largest frame (e.g. when loading icons) - Control = Frames.Aggregate((x,y) => x.Size.Width > y.Size.Width || x.Size.Height > y.Size.Height ? x : y); - } - - public void Create(string filename) - { - using (var decoder = new s.WIC.BitmapDecoder( - SDFactory.WicImagingFactory, - filename, - s.WIC.DecodeOptions.CacheOnDemand)) - Initialize(decoder); - } - - public void Create(System.IO.Stream stream) - { - using (var decoder = new s.WIC.BitmapDecoder( - SDFactory.WicImagingFactory, - stream, - s.WIC.DecodeOptions.CacheOnDemand)) - Initialize(decoder); - } - - public void Create(int width, int height, PixelFormat pixelFormat) - { - Control = new sw.Bitmap(SDFactory.WicImagingFactory, width, height, pixelFormat.ToWic(), sw.BitmapCreateCacheOption.CacheOnLoad); - } - - public void Create(int width, int height, Graphics graphics) - { - Create(width, height, PixelFormat.Format32bppRgba); - } - - public void Save(Stream stream, ImageFormat format) - { - using (var encoder = new s.WIC.BitmapEncoder( - SDFactory.WicImagingFactory, - format.ToWic())) - { - encoder.Initialize(stream); - using (var frameEncoder = new s.WIC.BitmapFrameEncode(encoder)) - { - frameEncoder.WriteSource(Control); - frameEncoder.Commit(); - } - encoder.Commit(); - } - } - - public Bitmap Clone(Rectangle? rectangle = null) - { - sw.Bitmap bmp = Control; - if (rectangle != null) - bmp = new sw.Bitmap(SDFactory.WicImagingFactory, bmp, rectangle.Value.ToDx()); - else - bmp = new sw.Bitmap(SDFactory.WicImagingFactory, bmp, sw.BitmapCreateCacheOption.CacheOnLoad); - - return new Bitmap(Generator, new BitmapHandler { Control = bmp }); - } - - public Color GetPixel(int x, int y) - { - try - { - var output = new uint[1]; - Control.CopyPixels(new s.Rectangle(x, y, 1, 1), output); - return new s.Color4(new s.ColorBGRA(output[0]).ToRgba()).ToEto(); - } - catch (s.SharpDXException ex) - { - Debug.Print("GetPixel: {0}", ex.ToString()); - throw; - } - } - - public Size Size - { - get { return Control.Size.ToEto(); } - } - - public void Create(Image image, int width, int height, ImageInterpolation interpolation) - { - var imageHandler = (ImageHandler)image.Handler; - - Control = new sw.Bitmap(SDFactory.WicImagingFactory, width, height, imageHandler.Control.PixelFormat, sw.BitmapCreateCacheOption.CacheOnLoad); - using (var graphics = new Graphics(Widget as Bitmap)) - { - graphics.ImageInterpolation = interpolation; - var rect = new Rectangle(0, 0, width, height); - graphics.FillRectangle(Colors.Transparent, rect); - graphics.DrawImage(image, rect); - } - } - - public virtual void Reset() - { - if (targetBitmap != null) - { - targetBitmap.Dispose(); - targetBitmap = null; - } - if (sdimage != null) - { - sdimage.Dispose(); - sdimage = null; - } - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - Reset(); - if (Frames != null) - { - foreach (var frame in Frames) - { - frame.Dispose(); - } - Control = null; - } - } - base.Dispose(disposing); - } - - System.Drawing.Image sdimage; - - public virtual System.Drawing.Image GetImageWithSize(int? size) - { - if (size != null && Frames != null && Control.Size.Width > size.Value) - { - var src = Frames.Aggregate((x, y) => Math.Abs(x.Size.Width - size.Value) < Math.Abs(y.Size.Width - size.Value) ? x : y); - if (src != null) - { - return src.ToBitmap().ToSD(); - } - } - return sdimage ?? (sdimage = Control.ToSD()); - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/IndexedBitmapHandler.cs deleted file mode 100644 index 23bcb3a289..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/IndexedBitmapHandler.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.WIC; -using System.IO; - -namespace Eto.Platform.Direct2D.Drawing -{ - public class IndexedBitmapHandler : ImageHandler, IIndexedBitmap - { - public static Guid GetFormat(int bitsPerPixel) - { - switch (bitsPerPixel) - { - case 8: - return sw.PixelFormat.Format8bppIndexed; - case 4: - return sw.PixelFormat.Format4bppIndexed; - case 2: - return sw.PixelFormat.Format2bppIndexed; - case 1: - return sw.PixelFormat.Format1bppIndexed; - default: - throw new NotSupportedException(); - } - } - - protected override sd.Bitmap CreateDrawableBitmap(sd.RenderTarget target) - { - using (var converter = new sw.FormatConverter(SDFactory.WicImagingFactory)) - { - converter.Initialize(Control, sw.PixelFormat.Format32bppPBGRA); - var bmp = new sw.Bitmap(SDFactory.WicImagingFactory, converter, sw.BitmapCreateCacheOption.CacheOnLoad); - return sd.Bitmap.FromWicBitmap(target, bmp); - } - } - - public void Create(int width, int height, int bitsPerPixel) - { - Control = new sw.Bitmap(SDFactory.WicImagingFactory, width, height, GetFormat(bitsPerPixel), sw.BitmapCreateCacheOption.CacheOnLoad); - } - - public BitmapData Lock() - { - var data = Control.Lock(sw.BitmapLockFlags.Write); - return new WicBitmapData(Widget, data, Widget.BitsPerPixel); - } - - public void Unlock(BitmapData bitmapData) - { - Reset(); - } - - public void Resize(int width, int height) - { - throw new NotImplementedException(); - } - - Palette palette; - public Palette Palette - { - get { return palette; } - set - { - palette = value; - var pal = new sw.Palette(SDFactory.WicImagingFactory); - // for some reason, Red/Blue are swapped here when displaying the bitmap - pal.Initialize(palette.Select(r => new s.Color4(r.B, r.G, r.R, r.A)).ToArray()); - Control.Palette = pal; - } - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Direct2D/Drawing/LinearGradientBrushHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/LinearGradientBrushHandler.cs deleted file mode 100644 index 9702400b4d..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/LinearGradientBrushHandler.cs +++ /dev/null @@ -1,85 +0,0 @@ -using Eto.Drawing; -using sd = SharpDX.Direct2D1; -using s = SharpDX; - -namespace Eto.Platform.Direct2D.Drawing -{ - public class LinearGradientBrushHandler : ILinearGradientBrush - { - public class LinearBrushData : TransformBrushData - { - public PointF StartPoint { get; set; } - public PointF EndPoint { get; set; } - public Color StartColor { get; set; } - public Color EndColor { get; set; } - public GradientWrapMode WrapMode { get; set; } - - protected override sd.Brush Create(sd.RenderTarget target) - { - return new sd.LinearGradientBrush( - target, - new sd.LinearGradientBrushProperties - { - StartPoint = StartPoint.ToDx(), - EndPoint = EndPoint.ToDx() - }, - new sd.GradientStopCollection(GraphicsHandler.CurrentRenderTarget, new[] { - new sd.GradientStop { Color = StartColor.ToDx(), Position = 0f }, - new sd.GradientStop { Color = EndColor.ToDx(), Position = 1f } - }, WrapMode == GradientWrapMode.Reflect ? sd.ExtendMode.Mirror : sd.ExtendMode.Wrap) - ); - } - } - - public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint) - { - return new LinearBrushData - { - StartColor = startColor, - EndColor = endColor, - StartPoint = startPoint, - EndPoint = endPoint - }; - } - - public object Create(RectangleF rectangle, Color startColor, Color endColor, float angle) - { - var matrix = new MatrixHandler(); - var startPoint = rectangle.Location; - matrix.RotateAt(angle - 45, startPoint.X, startPoint.Y); - var endPoint = matrix.TransformPoint(rectangle.EndLocation); - return new LinearBrushData - { - StartColor = startColor, - EndColor = endColor, - StartPoint = rectangle.Location, - EndPoint = rectangle.EndLocation - }; - } - - public IMatrix GetTransform(LinearGradientBrush widget) - { - var brush = (LinearBrushData)widget.ControlObject; - return brush.Transform; - } - - public void SetTransform(LinearGradientBrush widget, IMatrix transform) - { - var brush = (LinearBrushData)widget.ControlObject; - brush.Transform = transform; - } - - public GradientWrapMode GetGradientWrap(LinearGradientBrush widget) - { - var brush = (LinearBrushData)widget.ControlObject; - return brush.WrapMode; - } - - public void SetGradientWrap(LinearGradientBrush widget, GradientWrapMode gradientWrap) - { - var brush = (LinearBrushData)widget.ControlObject; - brush.WrapMode = gradientWrap; - brush.Reset(); - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/MatrixHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/MatrixHandler.cs deleted file mode 100644 index 21bfd1645f..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/MatrixHandler.cs +++ /dev/null @@ -1,174 +0,0 @@ -using System; -using Eto.Drawing; -using s = SharpDX; - -namespace Eto.Platform.Direct2D.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class MatrixHandler : IMatrixHandler - { - s.Matrix3x2 Control; - - public MatrixHandler() - { - this.Control = s.Matrix3x2.Identity; - } - - public MatrixHandler(ref s.Matrix3x2 m) - { - this.Control = m; // copied the value as Control is a struct - } - - public float[] Elements - { - get - { - return new float[] { - (float)Control.M11, - (float)Control.M12, - (float)Control.M21, - (float)Control.M22, - (float)Control.M31, - (float)Control.M32}; - } - } - - public float OffsetX - { - get { return (float)Control.M31; } - } - - public float OffsetY - { - get { return (float)Control.M32; } - } - - public void Rotate(float angle) - { - Control = s.Matrix3x2.Multiply(s.Matrix3x2.Rotation(Conversions.DegreesToRadians(angle)), Control); // premultiply - } - - public void RotateAt(float angle, float centerX, float centerY) - { - angle = Conversions.DegreesToRadians(angle); - var sina = (float)Math.Sin(angle); - var cosa = (float)Math.Cos(angle); - var matrix = new s.Matrix3x2(cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa); - Control = s.Matrix3x2.Multiply(matrix, Control); - } - - public void Translate(float x, float y) - { - Control = s.Matrix3x2.Multiply(s.Matrix3x2.Translation(x, y), Control); // premultiply - } - - public void Scale(float sx, float sy) - { - Control = s.Matrix3x2.Multiply(s.Matrix3x2.Scaling(sx, sy), Control); // premultiply - } - - public void Skew(float skewX, float skewY) - { - var matrix = new s.Matrix3x2(1, (float)Math.Tan(Conversions.DegreesToRadians(skewX)), (float)Math.Tan(Conversions.DegreesToRadians(skewY)), 1, 0, 0); - Control = s.Matrix3x2.Multiply(matrix, Control); - } - - public void ScaleAt(float scaleX, float scaleY, float centerX, float centerY) - { - var matrix = new s.Matrix3x2(scaleX, 0f, 0f, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); - Control = s.Matrix3x2.Multiply(matrix, Control); - } - - public void Prepend(IMatrix matrix) - { - Control = s.Matrix3x2.Multiply(matrix.ToDx(), this.Control); - } - - public void Append(IMatrix matrix) - { - Control = s.Matrix3x2.Multiply(this.Control, matrix.ToDx()); - } - - public void Create(float m11, float m12, float m21, float m22, float dx, float dy) - { - this.Control = new s.Matrix3x2(m11, m12, m21, m22, dx, dy); - } - - public void Create() - { - this.Control = s.Matrix3x2.Identity; - } - - public void Invert() - { - this.Control = s.Matrix3x2.Invert(this.Control); - } - - public PointF TransformPoint(Point p) - { - s.Vector2 v = s.Matrix3x2.TransformPoint(this.Control, new s.Vector2(p.X, p.Y)); // implicit conversion from Vector2 to Vector2 - return v.ToEto(); - } - - public PointF TransformPoint(PointF p) - { - s.Vector2 v = s.Matrix3x2.TransformPoint(this.Control, p.ToDx()); // implicit conversion from Vector2 to Vector2 - return v.ToEto(); - } - - public float Xx - { - get { return Control.M11; } - set { Control.M11 = value; } - } - - public float Xy - { - get { return Control.M21; } - set { Control.M21 = value; } - } - - public float Yx - { - get { return Control.M12; } - set { Control.M12 = value; } - } - - public float Yy - { - get { return Control.M22; } - set { Control.M22 = value; } - } - - public float X0 - { - get { return Control.M31; } - set { Control.M31 = value; } - } - - public float Y0 - { - get { return Control.M32; } - set { Control.M32 = value; } - } - - public object ControlObject - { - get { return Control; } - } - - public IMatrix Clone() - { - return new MatrixHandler(ref Control); - } - - public void Dispose() - { - // do nothing - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/PenHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/PenHandler.cs deleted file mode 100644 index 328953d52a..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/PenHandler.cs +++ /dev/null @@ -1,189 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using Eto.Drawing; - -namespace Eto.Platform.Direct2D.Drawing -{ - /// - /// Combines a brush and a stroke style - /// - public class PenData : IDisposable - { - sd.Brush brush; - public sd.Brush GetBrush(sd.RenderTarget target) - { - if (brush == null || !ReferenceEquals(brush.Tag, target)) - { - if (brush != null) - brush.Dispose(); - brush = new sd.SolidColorBrush(target, Color.ToDx()) { Tag = target }; - } - return brush; - } - - sd.StrokeStyle strokeStyle; - public sd.StrokeStyle StrokeStyle - { - get - { - if (strokeStyle == null) - { - var properties = new sd.StrokeStyleProperties - { - DashStyle = dashStyle.ToDx(), - LineJoin = lineJoin.ToDx(), - MiterLimit = miterLimit, - DashCap = lineCap == PenLineCap.Round ? sd.CapStyle.Round : sd.CapStyle.Square, - DashOffset = lineCap == PenLineCap.Butt ? -.5f + dashStyle.Offset : dashStyle.Offset - }; - properties.StartCap = properties.EndCap = lineCap.ToDx(); - if (properties.DashStyle == sd.DashStyle.Custom) - strokeStyle = new sd.StrokeStyle(SDFactory.D2D1Factory, properties, dashStyle.Dashes); - else - strokeStyle = new sd.StrokeStyle(SDFactory.D2D1Factory, properties); - } - - return strokeStyle; - } - } - - void Reset() - { - if (strokeStyle != null) - { - strokeStyle.Dispose(); - strokeStyle = null; - } - } - - float miterLimit = 10f; - public float MiterLimit - { - get { return miterLimit; } - set - { - miterLimit = value; - Reset(); - } - } - - public Color Color { get; set; } - - public float Width { get; set; } - - DashStyle dashStyle = DashStyles.Solid; - public DashStyle DashStyle - { - get { return dashStyle; } - set - { - dashStyle = value ?? DashStyles.Solid; - Reset(); - } - } - - PenLineCap lineCap; - public PenLineCap LineCap - { - get { return lineCap; } - set - { - lineCap = value; - Reset(); - } - } - - PenLineJoin lineJoin; - public PenLineJoin LineJoin - { - get { return lineJoin; } - set - { - lineJoin = value; - Reset(); - } - } - - public void Dispose() - { - if (brush != null) - { - brush.Dispose(); - brush = null; - } - - if (strokeStyle != null) - { - strokeStyle.Dispose(); - strokeStyle = null; - } - } - } - - public class PenHandler : IPen - { - public object Create(Color color, float thickness) - { - return new PenData { Color = color, Width = thickness }; - } - - public Color GetColor(Pen widget) - { - return widget.ToPenData().Color; - } - - public void SetColor(Pen widget, Color color) - { - widget.ToPenData().Color = color; - } - - public float GetThickness(Pen widget) - { - return widget.ToPenData().Width; - } - - public void SetThickness(Pen widget, float thickness) - { - widget.ToPenData().Width = thickness; - } - - public PenLineJoin GetLineJoin(Pen widget) - { - return widget.ToPenData().LineJoin; - } - - public void SetLineJoin(Pen widget, PenLineJoin lineJoin) - { - widget.ToPenData().LineJoin = lineJoin; - } - - public PenLineCap GetLineCap(Pen widget) - { - return widget.ToPenData().LineCap; - } - - public void SetLineCap(Pen widget, PenLineCap lineCap) - { - widget.ToPenData().LineCap = lineCap; - } - - public float GetMiterLimit(Pen widget) - { - return widget.ToPenData().MiterLimit; - } - - public void SetMiterLimit(Pen widget, float miterLimit) - { - widget.ToPenData().MiterLimit = miterLimit; - } - - public void SetDashStyle(Pen widget, DashStyle dashStyle) - { - widget.ToPenData().DashStyle = dashStyle; - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/SDFactory.cs b/Source/Eto.Platform.Direct2D/Drawing/SDFactory.cs deleted file mode 100644 index 87b9a3eb1b..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/SDFactory.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using s = SharpDX; -using sd = SharpDX.Direct2D1; -using sw = SharpDX.DirectWrite; - -namespace Eto.Platform.Direct2D.Drawing -{ - public static class SDFactory - { - static sd.Factory d2D1Factory; - public static sd.Factory D2D1Factory { get { return d2D1Factory = d2D1Factory ?? new sd.Factory(); } } - - static s.WIC.ImagingFactory wicImagingFactory; - public static s.WIC.ImagingFactory WicImagingFactory { get { return wicImagingFactory = wicImagingFactory ?? new s.WIC.ImagingFactory(); } } - - static sw.Factory directWriteFactory; - public static sw.Factory DirectWriteFactory { get { return directWriteFactory = directWriteFactory ?? new sw.Factory(); } } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/SolidBrushHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/SolidBrushHandler.cs deleted file mode 100644 index 6f2be7dcdf..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/SolidBrushHandler.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Eto.Drawing; -using sd = SharpDX.Direct2D1; - -namespace Eto.Platform.Direct2D.Drawing -{ - /// - /// Handler for - /// - /// (c) 2013 by Vivek Jhaveri - /// See LICENSE for full terms - public class SolidBrushHandler : ISolidBrush - { - public class SolidBrushData : BrushData - { - public Color Color { get; set; } - - protected override sd.Brush Create(sd.RenderTarget target) - { - return new sd.SolidColorBrush(target, Color.ToDx()); - } - } - - public object Create(Color color) - { - return new SolidBrushData { Color = color }; - } - - public Color GetColor(SolidBrush widget) - { - return ((SolidBrushData)widget.ControlObject).Color; - } - - public void SetColor(SolidBrush widget, Color color) - { - var brush = ((SolidBrushData)widget.ControlObject); - brush.Reset(); - brush.Color = color; - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Drawing/TextureBrushHandler.cs b/Source/Eto.Platform.Direct2D/Drawing/TextureBrushHandler.cs deleted file mode 100644 index e8172a1664..0000000000 --- a/Source/Eto.Platform.Direct2D/Drawing/TextureBrushHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Eto.Drawing; -using System; -using sd = SharpDX.Direct2D1; - -namespace Eto.Platform.Direct2D.Drawing -{ - public class TextureBrushHandler : ITextureBrush - { - public class TextureBrushData : TransformBrushData - { - public Image Image { get; set; } - - protected override sd.Brush Create(sd.RenderTarget target) - { - var brush = new sd.BitmapBrush(target, Image.ToDx(target)); - brush.ExtendModeX = brush.ExtendModeY = sd.ExtendMode.Wrap; - if (Transform != null) - brush.Transform = Transform.ToDx(); - return brush; - } - } - - public IMatrix GetTransform(TextureBrush widget) - { - var brush = (TextureBrushData)widget.ControlObject; - return brush.Transform; - } - - public void SetTransform(TextureBrush widget, IMatrix transform) - { - var brush = (TextureBrushData)widget.ControlObject; - brush.Transform = transform; - } - - public void SetOpacity(TextureBrush widget, float opacity) - { - var brush = (TextureBrushData)widget.ControlObject; - brush.Alpha = opacity; - } - - public object Create(Image image, float opacity) - { - return new TextureBrushData { Image = image, Alpha = opacity }; - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Eto.Platform.Direct2D.csproj b/Source/Eto.Platform.Direct2D/Eto.Platform.Direct2D.csproj deleted file mode 100644 index 1f3c89c524..0000000000 --- a/Source/Eto.Platform.Direct2D/Eto.Platform.Direct2D.csproj +++ /dev/null @@ -1,110 +0,0 @@ - - - - Debug - AnyCPU - {3C1B77D5-6C93-4366-A487-3D307FC29FFB} - Library - Properties - Eto.Platform.Direct2D - Eto.Platform.Direct2D - v4.0 - 512 - ..\..\..\ - true - - - true - full - false - ..\..\BuildOutput\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\..\BuildOutput\Release\ - TRACE - prompt - 4 - - - .. - - - - - - - - - - - - - - ..\packages\SharpDX.2.5.0\lib\net40\SharpDX.dll - - - ..\packages\SharpDX.Direct2D1.2.5.0\lib\net40\SharpDX.Direct2D1.dll - - - ..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll - - - - - Properties\GlobalAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - Drawing\SplineHelper.cs - - - - - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491} - Eto.Platform.Windows - - - {16289D2F-044C-49EF-83E9-9391AFF8FD2B} - Eto - - - - - - - - - - \ No newline at end of file diff --git a/Source/Eto.Platform.Direct2D/Forms/Controls/DrawableHandler.cs b/Source/Eto.Platform.Direct2D/Forms/Controls/DrawableHandler.cs deleted file mode 100644 index eb27ad0e5d..0000000000 --- a/Source/Eto.Platform.Direct2D/Forms/Controls/DrawableHandler.cs +++ /dev/null @@ -1,85 +0,0 @@ -using Eto.Drawing; -using Eto.Forms; -using Eto.Platform.Direct2D.Drawing; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using swf = System.Windows.Forms; - -namespace Eto.Platform.Direct2D.Forms.Controls -{ - public class DrawableHandler : Eto.Platform.Windows.DrawableHandler - { - Graphics graphics; - GraphicsHandler graphicsHandler; - SolidBrush backgroundColor; - Scrollable scrollable; - - public override Color BackgroundColor - { - get { return backgroundColor != null ? backgroundColor.Color : base.BackgroundColor; } - set - { - backgroundColor = value.A > 0 ? new SolidBrush(value, Generator) : null; - if (Widget.Loaded) - Invalidate(); - } - } - - protected override void Initialize() - { - base.Initialize(); - Control.SetStyle(swf.ControlStyles.SupportsTransparentBackColor | swf.ControlStyles.DoubleBuffer, false); - Control.SetStyle(swf.ControlStyles.AllPaintingInWmPaint | swf.ControlStyles.Opaque, true); - Control.HandleCreated += (sender, e) => - { - graphics = new Graphics(Generator, new GraphicsHandler(this)); - graphicsHandler = (GraphicsHandler)graphics.Handler; - }; - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - scrollable = Widget.FindParent(); - } - - public override Graphics CreateGraphics() - { - if (graphics == null) - return null; - var handler = new GraphicsHandler((GraphicsHandler)graphics.Handler); - handler.BeginDrawing(); - return new Graphics(Generator, handler); - } - - public override void Update(Eto.Drawing.Rectangle rect) - { - if (graphics == null) - return; - graphicsHandler.PerformDrawing(null, () => - { - Widget.OnPaint(new PaintEventArgs(graphics, rect)); - }); - } - - protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) - { - if (graphics == null) - return; - var clipRect = e.ClipRectangle.ToEto(); - graphicsHandler.PerformDrawing(clipRect, () => - { - // clear to control's background color - if (backgroundColor == null) - backgroundColor = new SolidBrush(base.BackgroundColor, Generator); - graphics.Clear(backgroundColor); - - // perform user painting - Widget.OnPaint(new PaintEventArgs(graphics, clipRect)); - }); - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Forms/Printing/PrintDocumentHandler.cs b/Source/Eto.Platform.Direct2D/Forms/Printing/PrintDocumentHandler.cs deleted file mode 100644 index acdb160bd7..0000000000 --- a/Source/Eto.Platform.Direct2D/Forms/Printing/PrintDocumentHandler.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Eto.Platform.Direct2D.Forms.Printing -{ - public class PrintDocumentHandler : Eto.Platform.Windows.Forms.Printing.PrintDocumentHandler - { - protected override void Initialize() - { - base.Initialize(); - // set to base generator to use gdi graphics - Generator = ((Eto.Platform.Direct2D.Generator)Generator).BaseGenerator; - } - } -} diff --git a/Source/Eto.Platform.Direct2D/Generator.cs b/Source/Eto.Platform.Direct2D/Generator.cs deleted file mode 100644 index 3e9cb74f1f..0000000000 --- a/Source/Eto.Platform.Direct2D/Generator.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Eto.Drawing; -using Eto.Forms; -using Eto.IO; -using Eto.Platform.Direct2D.Drawing; -using Eto.Platform.Direct2D.Forms.Controls; -using Eto.Platform.Direct2D.Forms.Printing; - -namespace Eto.Platform.Direct2D -{ - public class Generator : Eto.Platform.Windows.Generator - { - public override string ID - { - get { return Generators.Direct2D; } - } - - public Generator() - { - // generator to use for scenarios where direct 2d doesn't work (e.g. printing) - BaseGenerator = new Eto.Platform.Windows.Generator(); - - Eto.Platform.Windows.Generator.AddTo(this); - - // This is added after the base class's assembly - AddTo(this); - } - - public Eto.Generator BaseGenerator - { - get; - set; - } - - public static new void AddTo(Eto.Generator g) - { - // Drawing - g.Add(() => new BitmapHandler()); - g.Add(() => new FontFamilyHandler()); - g.Add(() => new FontHandler()); - g.Add(() => new FontsHandler()); - g.Add(() => new GraphicsHandler()); - g.Add(() => new GraphicsPathHandler()); - g.Add(() => new IconHandler()); - g.Add(() => new IndexedBitmapHandler()); - g.Add(() => new MatrixHandler()); - g.Add(() => new PenHandler()); - g.Add(() => new SolidBrushHandler()); - g.Add(() => new TextureBrushHandler()); - g.Add(() => new LinearGradientBrushHandler()); - - // Forms.Cells - g.Add(() => new DrawableHandler()); - - // Forms.Printing - g.Add(() => new PrintDocumentHandler()); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Conversions.cs b/Source/Eto.Platform.Gtk/Conversions.cs deleted file mode 100644 index 6162d9152e..0000000000 --- a/Source/Eto.Platform.Gtk/Conversions.cs +++ /dev/null @@ -1,534 +0,0 @@ -using System; -using Eto.Drawing; -using Eto.Forms; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public static class Conversions - { - public static Gdk.Color ToGdk(this Color color) - { - return new Gdk.Color((byte)(color.R * byte.MaxValue), (byte)(color.G * byte.MaxValue), (byte)(color.B * byte.MaxValue)); - } - - public static Cairo.Color ToCairo(this Color color) - { - return new Cairo.Color((double)color.R, (double)color.G, (double)color.B, (double)color.A); - } - -#if GTK3 - public static Cairo.Color ToCairo(this Gdk.RGBA color) - { - return new Cairo.Color(color.Red, color.Green, color.Blue, color.Alpha); - } - - public static Gdk.RGBA ToRGBA(this Color color) - { - return new Gdk.RGBA { Red = color.R, Green = color.G, Blue = color.B, Alpha = color.A }; - } -#endif - - public static Color ToEto(this Cairo.Color color) - { - return new Color((float)color.R, (float)color.G, (float)color.B, (float)color.A); - } - - public static Cairo.Rectangle ToCairo(this Rectangle rectangle) - { - return new Cairo.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); - } - - public static Cairo.Rectangle ToCairo(this RectangleF rectangle) - { - return new Cairo.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); - } - - public static Rectangle ToEto(this Cairo.Rectangle rectangle) - { - return new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height); - } - - public static Cairo.Filter ToCairo(this ImageInterpolation value) - { - switch (value) - { - case ImageInterpolation.Default: - return Cairo.Filter.Bilinear; - case ImageInterpolation.None: - return Cairo.Filter.Nearest; - case ImageInterpolation.High: - return Cairo.Filter.Best; - case ImageInterpolation.Low: - return Cairo.Filter.Fast; - case ImageInterpolation.Medium: - return Cairo.Filter.Good; - default: - throw new NotSupportedException(); - } - } - - public static Gdk.InterpType ToGdk(this ImageInterpolation value) - { - - switch (value) - { - case ImageInterpolation.Default: - return Gdk.InterpType.Bilinear; - case ImageInterpolation.None: - return Gdk.InterpType.Nearest; - case ImageInterpolation.High: - return Gdk.InterpType.Hyper; - case ImageInterpolation.Low: - return Gdk.InterpType.Tiles; - case ImageInterpolation.Medium: - return Gdk.InterpType.Bilinear; - default: - throw new NotSupportedException(); - } - } - - public static Color ToEto(this Gdk.Color color) - { - return new Color((float)color.Red / ushort.MaxValue, (float)color.Green / ushort.MaxValue, (float)color.Blue / ushort.MaxValue); - } - - public static Gdk.Size ToGdk(this Size size) - { - return new Gdk.Size(size.Width, size.Height); - } - - public static Size ToEto(this Gdk.Size size) - { - return new Size(size.Width, size.Height); - } - - public static Size ToEto(this Gtk.Requisition req) - { - return new Size(req.Width, req.Height); - } - - public static Gdk.Point ToGdk(this Point point) - { - return new Gdk.Point(point.X, point.Y); - } - - public static Point ToEto(this Gdk.Point point) - { - return new Point(point.X, point.Y); - } - - public static Gdk.Rectangle ToGdk(this Rectangle rect) - { - return new Gdk.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); - } - - public static Rectangle ToEto(this Gdk.Rectangle rect) - { - return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height); - } - - public static DialogResult ToEto(this Gtk.ResponseType result) - { - switch (result) - { - case Gtk.ResponseType.None: - return DialogResult.None; - case Gtk.ResponseType.Reject: - return DialogResult.Abort; - case Gtk.ResponseType.Accept: - return DialogResult.Ignore; - case Gtk.ResponseType.Ok: - return DialogResult.Ok; - case Gtk.ResponseType.Cancel: - return DialogResult.Cancel; - case Gtk.ResponseType.Yes: - return DialogResult.Yes; - case Gtk.ResponseType.No: - return DialogResult.No; - default: - return DialogResult.None; - } - } - - public static string ToGdk(this ImageFormat format) - { - switch (format) - { - case ImageFormat.Jpeg: - return "jpeg"; - case ImageFormat.Bitmap: - return "bmp"; - case ImageFormat.Gif: - return "gif"; - case ImageFormat.Tiff: - return "tiff"; - case ImageFormat.Png: - return "png"; - default: - throw new Exception("Invalid format specified"); - } - } - - public static Gdk.CursorType ToGdk(this CursorType cursor) - { - switch (cursor) - { - case CursorType.Arrow: - return Gdk.CursorType.Arrow; - case CursorType.Crosshair: - return Gdk.CursorType.Crosshair; - case CursorType.Default: - return Gdk.CursorType.Arrow; - case CursorType.HorizontalSplit: - return Gdk.CursorType.SbHDoubleArrow; - case CursorType.VerticalSplit: - return Gdk.CursorType.SbVDoubleArrow; - case CursorType.IBeam: - return Gdk.CursorType.Xterm; - case CursorType.Move: - return Gdk.CursorType.Fleur; - case CursorType.Pointer: - return Gdk.CursorType.Hand2; - default: - throw new NotSupportedException(); - } - } - - public static Gtk.ButtonsType ToGtk(this MessageBoxButtons buttons) - { - switch (buttons) - { - default: - return Gtk.ButtonsType.Ok; - case MessageBoxButtons.OKCancel: - return Gtk.ButtonsType.OkCancel; - case MessageBoxButtons.YesNo: - return Gtk.ButtonsType.YesNo; - case MessageBoxButtons.YesNoCancel: - return Gtk.ButtonsType.YesNo; - } - } - - public static Gtk.ResponseType ToGtk(this MessageBoxDefaultButton button, MessageBoxButtons buttons) - { - switch (button) - { - case MessageBoxDefaultButton.OK: - if (buttons == MessageBoxButtons.YesNo || buttons == MessageBoxButtons.YesNoCancel) - return Gtk.ResponseType.Yes; - return Gtk.ResponseType.Ok; - case MessageBoxDefaultButton.No: - return Gtk.ResponseType.No; - case MessageBoxDefaultButton.Cancel: - return Gtk.ResponseType.Cancel; - case MessageBoxDefaultButton.Default: - switch (buttons) - { - case MessageBoxButtons.OK: - return Gtk.ResponseType.Ok; - case MessageBoxButtons.OKCancel: - case MessageBoxButtons.YesNoCancel: - return Gtk.ResponseType.Cancel; - case MessageBoxButtons.YesNo: - return Gtk.ResponseType.No; - default: - throw new NotSupportedException(); - } - default: - throw new NotSupportedException(); - } - } - - public static Gtk.MessageType ToGtk(this MessageBoxType type) - { - switch (type) - { - default: - return Gtk.MessageType.Info; - case MessageBoxType.Error: - return Gtk.MessageType.Error; - case MessageBoxType.Warning: - return Gtk.MessageType.Warning; - case MessageBoxType.Question: - return Gtk.MessageType.Question; - } - } - - public static Gtk.PageOrientation ToGtk(this PageOrientation value) - { - switch (value) - { - case PageOrientation.Landscape: - return Gtk.PageOrientation.Landscape; - case PageOrientation.Portrait: - return Gtk.PageOrientation.Portrait; - default: - throw new NotSupportedException(); - } - } - - public static PageOrientation ToEto(this Gtk.PageOrientation value) - { - switch (value) - { - case Gtk.PageOrientation.Landscape: - return PageOrientation.Landscape; - case Gtk.PageOrientation.Portrait: - return PageOrientation.Portrait; - default: - throw new NotSupportedException(); - } - } - - public static Gtk.PageRange ToGtkPageRange(this Range range) - { - return new Gtk.PageRange { Start = range.Start - 1, End = range.End - 1 }; - } - - public static Range ToEto(this Gtk.PageRange range) - { - return new Range(range.Start + 1, range.End - range.Start + 1); - } - - public static Gtk.PrintPages ToGtk(this PrintSelection value) - { - switch (value) - { - case PrintSelection.AllPages: - return Gtk.PrintPages.All; - case PrintSelection.SelectedPages: - return Gtk.PrintPages.Ranges; - default: - throw new NotSupportedException(); - } - } - - public static PrintSelection ToEto(this Gtk.PrintPages value) - { - switch (value) - { - case Gtk.PrintPages.All: - return PrintSelection.AllPages; - case Gtk.PrintPages.Ranges: - return PrintSelection.SelectedPages; - default: - throw new NotSupportedException(); - } - } - - public static float DegreesToRadians(float angle) - { - return (float)Math.PI * angle / 180.0f; - } - - public static void Apply(this Pen pen, GraphicsHandler graphics) - { - ((PenHandler)pen.Handler).Apply(pen, graphics); - } - - public static void Apply(this Brush brush, GraphicsHandler graphics) - { - ((BrushHandler)brush.Handler).Apply(brush.ControlObject, graphics); - } - - public static Cairo.LineJoin ToCairo(this PenLineJoin value) - { - switch (value) - { - case PenLineJoin.Miter: - return Cairo.LineJoin.Miter; - case PenLineJoin.Bevel: - return Cairo.LineJoin.Bevel; - case PenLineJoin.Round: - return Cairo.LineJoin.Round; - default: - throw new NotSupportedException(); - } - } - - public static PenLineJoin ToEto(this Cairo.LineJoin value) - { - switch (value) - { - case Cairo.LineJoin.Bevel: - return PenLineJoin.Bevel; - case Cairo.LineJoin.Miter: - return PenLineJoin.Miter; - case Cairo.LineJoin.Round: - return PenLineJoin.Round; - default: - throw new NotSupportedException(); - } - } - - public static Cairo.LineCap ToCairo(this PenLineCap value) - { - switch (value) - { - case PenLineCap.Butt: - return Cairo.LineCap.Butt; - case PenLineCap.Round: - return Cairo.LineCap.Round; - case PenLineCap.Square: - return Cairo.LineCap.Square; - default: - throw new NotSupportedException(); - } - } - - public static PenLineCap ToEto(this Cairo.LineCap value) - { - switch (value) - { - case Cairo.LineCap.Butt: - return PenLineCap.Butt; - case Cairo.LineCap.Round: - return PenLineCap.Round; - case Cairo.LineCap.Square: - return PenLineCap.Square; - default: - throw new NotSupportedException(); - } - } - - public static Cairo.PointD ToCairo(this PointF point) - { - return new Cairo.PointD(point.X, point.Y); - } - - public static PointF ToEto(this Cairo.PointD point) - { - return new PointF((float)point.X, (float)point.Y); - } - - public static GraphicsPathHandler ToHandler(this IGraphicsPath path) - { - return ((GraphicsPathHandler)path.ControlObject); - } - - public static void Apply(this IGraphicsPath path, Cairo.Context context) - { - ((GraphicsPathHandler)path.ControlObject).Apply(context); - } - - public static Cairo.Matrix ToCairo(this IMatrix matrix) - { - return (Cairo.Matrix)matrix.ControlObject; - } - - public static IMatrix ToEto(this Cairo.Matrix matrix) - { - return new MatrixHandler(matrix); - } - - public static Gdk.Pixbuf ToGdk(this Image image) - { - var handler = image.Handler as IGtkPixbuf; - return handler != null ? handler.Pixbuf : null; - } - - public static void SetCairoSurface(this Image image, Cairo.Context context, float x, float y) - { - Gdk.CairoHelper.SetSourcePixbuf(context, image.ToGdk(), x, y); - } - - public static GradientWrapMode ToEto(this Cairo.Extend extend) - { - switch (extend) - { - case Cairo.Extend.Reflect: - return GradientWrapMode.Reflect; - case Cairo.Extend.Repeat: - return GradientWrapMode.Repeat; - default: - throw new NotSupportedException(); - } - } - - public static Cairo.Extend ToCairo(this GradientWrapMode wrap) - { - switch (wrap) - { - case GradientWrapMode.Reflect: - return Cairo.Extend.Reflect; - case GradientWrapMode.Repeat: - return Cairo.Extend.Repeat; - default: - throw new NotSupportedException(); - } - } - - public static Gtk.Image ToGtk(this Image image, Gtk.IconSize? size = null) - { - if (image == null) - return null; - var handler = (IImageHandler)image.Handler; - var gtkimage = new Gtk.Image(); - handler.SetImage(gtkimage, size); - return gtkimage; - } - - public static void SetGtkImage(this Image image, Gtk.Image gtkimage, Gtk.IconSize? size = null) - { - if (image == null) - return; - var handler = (IImageHandler)image.Handler; - handler.SetImage(gtkimage, size); - } - - public static Cairo.FillRule ToCairo(this FillMode value) - { - switch (value) - { - case FillMode.Alternate: - return Cairo.FillRule.EvenOdd; - case FillMode.Winding: - return Cairo.FillRule.Winding; - default: - throw new NotSupportedException(); - } - } - - public static KeyEventArgs ToEto(this Gdk.EventKey args) - { - Key key = args.Key.ToEto() | args.State.ToEtoKey(); - - if (key != Key.None) - { - Key modifiers = (key & Key.ModifierMask); - if (args.KeyValue <= 128 && ((modifiers & ~Key.Shift) == 0)) - return new KeyEventArgs(key, KeyEventType.KeyDown, (char)args.KeyValue); - return new KeyEventArgs(key, KeyEventType.KeyDown); - } - return args.KeyValue <= 128 ? new KeyEventArgs(key, KeyEventType.KeyDown, (char)args.KeyValue) : null; - } - - public static MouseButtons ToEtoMouseButtons(this Gdk.ModifierType modifiers) - { - MouseButtons buttons = MouseButtons.None; - if (modifiers.HasFlag(Gdk.ModifierType.Button1Mask)) - buttons |= MouseButtons.Primary; - if (modifiers.HasFlag(Gdk.ModifierType.Button2Mask)) - buttons |= MouseButtons.Middle; - if (modifiers.HasFlag(Gdk.ModifierType.Button3Mask)) - buttons |= MouseButtons.Alternate; - return buttons; - } - - public static MouseButtons ToEtoMouseButtons(this Gdk.EventButton ev) - { - switch (ev.Button) - { - case 1: - return MouseButtons.Primary; - case 2: - return MouseButtons.Middle; - case 3: - return MouseButtons.Alternate; - default: - return MouseButtons.None; - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/DllMap.cs b/Source/Eto.Platform.Gtk/DllMap.cs deleted file mode 100644 index 7441f22dfc..0000000000 --- a/Source/Eto.Platform.Gtk/DllMap.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp -{ - public class DllMap : Dictionary - { - public DllMap () - { - if (EtoEnvironment.Platform.IsUnix) { - this.Add ("libgio-2.0-0.dll", "libgio-2.0.so.0"); - this.Add ("libglib-2.0-0.dll", "libglib-2.0.so.0"); - this.Add ("libgobject-2.0-0.dll", "libgobject-2.0.so.0"); - this.Add ("libgdk-win32-3.0-0.dll", "libgdk-3.so.0"); - this.Add ("libgdk_pixbuf-2.0-0.dll", "libgdk_pixbuf-2.0.so.0"); - this.Add ("libatk-1.0-0.dll", "libatk-1.0.so.0"); - this.Add ("libgdk-win32-3.0-0.dll", "libgdk-3.so.0"); - this.Add ("libgtk-win32-3.0-0.dll", "libgtk-3.so.0"); - this.Add ("libpango-1.0-0.dll", "libpango-1.0.so.0"); - this.Add ("libpangocairo-1.0-0.dll", "libpangocairo-1.0.so.0"); - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/BitmapHandler.cs b/Source/Eto.Platform.Gtk/Drawing/BitmapHandler.cs deleted file mode 100644 index 1636b21ea2..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/BitmapHandler.cs +++ /dev/null @@ -1,257 +0,0 @@ -using System; -using System.IO; -using Eto.Drawing; -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp.Drawing -{ - /// - /// Bitmap data handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class BitmapDataHandler : BitmapData - { - public BitmapDataHandler(Image image, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) - : base(image, data, scanWidth, bitsPerPixel, controlObject) - { - } - - public override uint TranslateArgbToData(uint argb) - { - return (argb & 0xFF00FF00) | ((argb & 0xFF) << 16) | ((argb & 0xFF0000) >> 16); - } - - public override uint TranslateDataToArgb(uint bitmapData) - { - return (bitmapData & 0xFF00FF00) | ((bitmapData & 0xFF) << 16) | ((bitmapData & 0xFF0000) >> 16); - } - } - - /// - /// Bitmap handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class BitmapHandler : ImageHandler, IBitmap, IGtkPixbuf - { - readonly Dictionary sizes = new Dictionary(); - - public bool Alpha { get; set; } - - public BitmapHandler() - { - } - - public BitmapHandler(Gdk.Pixbuf pixbuf) - { - this.Control = pixbuf; - } - - public void Create(string fileName) - { - Control = new Gdk.Pixbuf(fileName); - } - - public void Create(Stream stream) - { - Control = new Gdk.Pixbuf(stream); - } - - public void Create(int width, int height, PixelFormat pixelFormat) - { - switch (pixelFormat) - { - case PixelFormat.Format32bppRgba: - Control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, width, height); - Control.Fill(0); - Alpha = true; - break; - case PixelFormat.Format32bppRgb: - Control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, width, height); - Control.Fill(0x000000FF); - break; - case PixelFormat.Format24bppRgb: - Control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, width, height); - break; - /*case PixelFormat.Format16bppRgb555: - control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 5, width, height); - break;*/ - default: - throw new NotSupportedException(); - } - } - - public void Create(int width, int height, Graphics graphics) - { - Create(width, height, PixelFormat.Format32bppRgba); - } - - public void Create(Image image, int width, int height, ImageInterpolation interpolation) - { - var pixbuf = image.ToGdk(); - Control = pixbuf.ScaleSimple(width, height, interpolation.ToGdk()); - } - - public BitmapData Lock() - { - return new BitmapDataHandler(Widget, Control.Pixels, Control.Rowstride, Control.HasAlpha ? 32 : 24, null); - } - - public void Unlock(BitmapData bitmapData) - { - sizes.Clear(); - } - - public void Save(Stream stream, ImageFormat format) - { - string fileName = Guid.NewGuid().ToString(); - Control.Save(fileName, format.ToGdk()); - Stream fileStream = File.OpenRead(fileName); - var buffer = new byte[4096]; - - int size = fileStream.Read(buffer, 0, buffer.Length); - while (size > 0) - { - stream.Write(buffer, 0, size); - size = fileStream.Read(buffer, 0, buffer.Length); - } - fileStream.Close(); - File.Delete(fileName); - } - - public override Size Size - { - get { return new Size(Control.Width, Control.Height); } - } - - public override void SetImage(Gtk.Image imageView, Gtk.IconSize? iconSize) - { - if (iconSize != null) - imageView.SetFromIconSet(new Gtk.IconSet(Control), iconSize.Value); - else - imageView.Pixbuf = Control; - } - - public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) - { - var context = graphics.Control; - context.Save(); - destination.X += (float)graphics.InverseOffset; - destination.Y += (float)graphics.InverseOffset; - context.Rectangle(destination.ToCairo()); - double scalex = 1; - double scaley = 1; - if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f) - { - scalex = (double)destination.Width / (double)source.Width; - scaley = (double)destination.Height / (double)source.Height; - context.Scale(scalex, scaley); - } - Gdk.CairoHelper.SetSourcePixbuf(context, Control, (destination.Left / scalex) - source.Left, (destination.Top / scaley) - source.Top); - var pattern = (Cairo.SurfacePattern)context.Source; - pattern.Filter = graphics.ImageInterpolation.ToCairo(); - context.Fill(); - context.Restore(); - - /* - Gdk.Pixbuf pb = Control; - - - if (source.Width != destination.Width || source.Height != destination.Height) { - Gdk.Pixbuf pbDest = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height); - double scalex = (double)(destination.Width) / (double)(source.Width); - double scaley = (double)(destination.Height) / (double)(source.Height); - pb.Scale (pbDest, 0, 0, destination.Width, destination.Height, -(source.X * scalex), -(source.Y * scaley), - scalex, scaley, Gdk.InterpType.Bilinear); - source.Location = new Point (0, 0); - pb = pbDest; - } - /* - * - pb.RenderToDrawable (graphics.Control, graphics.GC, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); - /* - * - Gdk.Pixmap pm, mask; - pb.RenderPixmapAndMask(out pm, out mask, 0); - graphics.Drawable.DrawDrawable(graphics.GC, pm, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height); - pm.Dispose(); - mask.Dispose(); - /* - * - graphics.Drawable.DrawPixbuf(null, pb, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); - /* - */ - /*if (pb != Control) - pb.Dispose ();*/ - } - - public Gdk.Pixbuf Pixbuf - { - get - { - return Control; - } - } - - public Gdk.Pixbuf GetPixbuf(Size maxSize) - { - Gdk.Pixbuf pixbuf = Control; - if (pixbuf.Width > maxSize.Width && pixbuf.Height > maxSize.Height) - { - if (!sizes.TryGetValue(maxSize, out pixbuf)) - { - pixbuf = Control.ScaleSimple(maxSize.Width, maxSize.Height, Gdk.InterpType.Bilinear); - sizes[maxSize] = pixbuf; - } - } - - return pixbuf; - } - - public Bitmap Clone(Rectangle? rectangle = null) - { - if (rectangle == null) - return new Bitmap(Generator, new BitmapHandler(Control.Copy())); - else - { - var rect = rectangle.Value; - PixelFormat format; - if (Control.BitsPerSample == 24) - format = PixelFormat.Format24bppRgb; - else if (Control.HasAlpha) - format = PixelFormat.Format32bppRgba; - else - format = PixelFormat.Format32bppRgb; - var bmp = new Bitmap(rect.Width, rect.Height, format, Generator); - Control.CopyArea(rect.X, rect.Y, rect.Width, rect.Height, bmp.ToGdk(), 0, 0); - return bmp; - } - } - - public Color GetPixel(int x, int y) - { - using (var data = Lock()) - { - unsafe - { - var srcrow = (byte*)data.Data; - srcrow += y * data.ScanWidth; - srcrow += x * data.BytesPerPixel; - if (data.BytesPerPixel == 4) - { - return Color.FromArgb(data.TranslateDataToArgb(*(uint*)srcrow)); - } - if (data.BytesPerPixel == 3) - { - var b = *(srcrow++); - var g = *(srcrow++); - var r = *(srcrow++); - return Color.FromArgb(r, g, b); - } - throw new NotSupportedException(); - } - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Drawing/BrushHandler.cs b/Source/Eto.Platform.Gtk/Drawing/BrushHandler.cs deleted file mode 100644 index 6f82013ade..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/BrushHandler.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Drawing -{ - /// - /// Handler for the - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public abstract class BrushHandler : IBrush - { - public abstract void Apply (object control, GraphicsHandler graphics); - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/FontFamilyHandler.cs b/Source/Eto.Platform.Gtk/Drawing/FontFamilyHandler.cs deleted file mode 100644 index cd6879a686..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/FontFamilyHandler.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using Eto.Drawing; -using System.Collections.Generic; -using System.Linq; - -namespace Eto.Platform.GtkSharp.Drawing -{ - public class FontFamilyHandler : WidgetHandler, IFontFamily - { - public string Name { get; set; } - - public IEnumerable Typefaces - { - get { return Control.Faces.Select (r => new FontTypeface(Widget, new FontTypefaceHandler(r))); } - } - - public FontFamilyHandler () - { - } - - public FontFamilyHandler (Pango.FontFamily pangoFamily) - { - Control = pangoFamily; - Name = Control.Name; - } - - public void Create (string familyName) - { - Name = familyName; - switch (familyName.ToUpperInvariant()) { - case FontFamilies.MonospaceFamilyName: - Control = GetFontFamily("monospace", "FreeMono", "Courier"); - break; - case FontFamilies.SansFamilyName: - Control = GetFontFamily("sans", "FreeSans"); - break; - case FontFamilies.SerifFamilyName: - Control = GetFontFamily("serif", "FreeSerif"); - break; - case FontFamilies.CursiveFamilyName: - // from http://www.codestyle.org/css/font-family/sampler-Cursive.shtml#cursive-linux - Control = GetFontFamily("URW Chancery L", "Comic Sans MS", "Purisa", "Vemana2000", "Domestic Manners", "serif"); - break; - case FontFamilies.FantasyFamilyName: - // from http://www.codestyle.org/css/font-family/sampler-Fantasy.shtml#fantasy-linux - Control = GetFontFamily("Impact", "Penguin Attack", "Balker", "Marked Fool", "Junkyard", "Linux Biolinum", "serif"); - break; - default: - Control = GetFontFamily(familyName); - if (Control == null) - throw new ArgumentOutOfRangeException("familyName", familyName, "Font Family specified is not supported by this system"); - Name = Control.Name; - break; - } - } - - static Pango.FontFamily GetFontFamily(params string [] familyNames) - { - foreach (var familyName in familyNames) - { - var family = GetFontFamily (familyName); - if (family != null) - return family; - } - return null; - } - - public static Pango.FontFamily GetFontFamily(string familyName) - { - return FontsHandler.Context.Families.FirstOrDefault(r => string.Equals(r.Name, familyName, StringComparison.InvariantCultureIgnoreCase)); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/FontHandler.cs b/Source/Eto.Platform.Gtk/Drawing/FontHandler.cs deleted file mode 100644 index c802a7f849..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/FontHandler.cs +++ /dev/null @@ -1,301 +0,0 @@ -using System; -using Eto.Drawing; -using System.Linq; - -namespace Eto.Platform.GtkSharp.Drawing -{ - public static class FontHandlerExtensions - { - public static void Apply(this Font font, Gtk.TextTag tag) - { - if (tag != null) - { - if (font != null) - { - tag.Underline = font.FontDecoration.HasFlag(FontDecoration.Underline) ? Pango.Underline.Single : Pango.Underline.None; - tag.Strikethrough = font.FontDecoration.HasFlag(FontDecoration.Strikethrough); - } - else - { - tag.Underline = Pango.Underline.None; - tag.Strikethrough = false; - } - } - } - - public static void Apply(this Font font, Pango.Layout layout) - { - if (font != null) - { - var handler = (FontHandler)font.Handler; - layout.FontDescription = handler.Control; - layout.Attributes = handler.Attributes; - } - } - } - - public class FontHandler : WidgetHandler, IFont - { - FontFamily family; - FontTypeface typeface; - FontStyle? style; - Pango.AttrList attributes; - - public FontHandler() - { - } - - public FontHandler(Gtk.Widget widget) - : this (widget.Style.FontDescription) - { - } - - public FontHandler(Pango.FontDescription fontDescription) - { - Control = fontDescription; - } - - public FontHandler(string fontName) - { - Control = Pango.FontDescription.FromString(fontName); - } - - public void Create(SystemFont systemFont, float? size, FontDecoration decoration) - { - switch (systemFont) - { - case SystemFont.Default: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - case SystemFont.Bold: - Control = new Pango.FontDescription(); - Control.Merge(Gtk.Widget.DefaultStyle.FontDescription, true); - Control.Weight = Pango.Weight.Bold; - break; - case SystemFont.TitleBar: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - case SystemFont.ToolTip: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - case SystemFont.Label: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - case SystemFont.MenuBar: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - case SystemFont.Menu: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - case SystemFont.Message: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - case SystemFont.Palette: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - case SystemFont.StatusBar: - Control = Gtk.Widget.DefaultStyle.FontDescription; - break; - default: - throw new NotSupportedException(); - } - if (size != null) - { - var old = Control; - Control = new Pango.FontDescription(); - Control.Merge(old, true); - if (size != null) - Control.Size = (int)(size * Pango.Scale.PangoScale); - } - FontDecoration = decoration; - } - - public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) - { - this.family = family; - Control = new Pango.FontDescription(); - SetStyle(style); - Size = size; - FontDecoration = decoration; - - var familyHandler = (FontFamilyHandler)family.Handler; - Control.Family = familyHandler.Control.Name; - } - - public void Create(FontTypeface face, float size, FontDecoration decoration) - { - typeface = face; - Control = ((FontTypefaceHandler)face.Handler).Control.Describe(); - Size = size; - FontDecoration = decoration; - } - - void SetStyle(FontStyle style) - { - if ((style & FontStyle.Bold) != 0) - Control.Weight = Pango.Weight.Bold; - if ((style & FontStyle.Italic) != 0) - Control.Style = Pango.Style.Italic; - } - - public Pango.AttrList Attributes - { - get - { - if (attributes == null) - { - attributes = new Pango.AttrList(); - attributes.Insert(new Pango.AttrUnderline(FontDecoration.HasFlag(FontDecoration.Underline) ? Pango.Underline.Single : Pango.Underline.None)); - attributes.Insert(new Pango.AttrStrikethrough(FontDecoration.HasFlag(FontDecoration.Strikethrough))); - } - return attributes; - } - } - - public float Size - { - get { return (float)(Control.Size / Pango.Scale.PangoScale); } - private set { Control.Size = (int)(value * Pango.Scale.PangoScale); } - } - - public FontStyle FontStyle - { - get - { - if (style == null) - { - style = FontStyle.None; - if (Control.Weight == Pango.Weight.Bold) - style |= FontStyle.Bold; - if (Control.Style == Pango.Style.Italic) - style |= FontStyle.Italic; - } - return style.Value; - } - } - - public FontDecoration FontDecoration { get; private set; } - - public string FamilyName - { - get { return Control.Family; } - } - - public FontFamily Family - { - get - { - if (family == null) - { - family = new FontFamily(Widget.Generator, Control.Family); - } - return family; - } - } - - public FontTypeface Typeface - { - get - { - if (typeface == null) - { - typeface = Family.Typefaces.FirstOrDefault(r => r.FontStyle == FontStyle); - } - return typeface; - } - } - - Pango.FontMetrics metrics; - - public Pango.FontMetrics Metrics - { - get - { - if (metrics == null) - metrics = FontsHandler.Context.GetMetrics(Control, Pango.Language.Default); - return metrics; - } - } - - public float Ascent - { - get { return (float)Metrics.Ascent / (float)Pango.Scale.PangoScale; } - } - - public float Descent - { - get { return (float)Metrics.Descent / (float)Pango.Scale.PangoScale; } - } - - float? lineHeight; - - public float LineHeight - { - get - { - if (lineHeight == null) - { - using (var layout = new Pango.Layout(FontsHandler.Context)) - { - layout.FontDescription = Control; - layout.SetText("X"); - Pango.Rectangle ink, logical; - layout.GetExtents(out ink, out logical); - lineHeight = (float)logical.Height / (float)Pango.Scale.PangoScale; - } - } - return lineHeight ?? 0f; - } - } - - public float Baseline - { - get { return Ascent; } - } - - float? leading; - - public float Leading - { - get - { - if (leading == null) - { - using (var layout = new Pango.Layout(FontsHandler.Context)) - { - layout.FontDescription = Control; - layout.SetText("X"); - Pango.Rectangle ink, logical; - layout.GetExtents(out ink, out logical); - leading = (float)(ink.Y - logical.Y) / (float)Pango.Scale.PangoScale; - } - } - return leading ?? 0f; - } - } - - float? xheight; - - public float XHeight - { - get - { - if (xheight == null) - { - using (var layout = new Pango.Layout(FontsHandler.Context)) - { - layout.FontDescription = Control; - layout.SetText("x"); - layout.Spacing = 0; - layout.Alignment = Pango.Alignment.Left; - layout.Width = int.MaxValue; - Pango.Rectangle ink, logical; - layout.GetExtents(out ink, out logical); - xheight = (float)ink.Height / (float)Pango.Scale.PangoScale; - } - } - return xheight ?? 0f; - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Drawing/FontTypefaceHandler.cs b/Source/Eto.Platform.Gtk/Drawing/FontTypefaceHandler.cs deleted file mode 100644 index 4f74ddab54..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/FontTypefaceHandler.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Drawing -{ - public class FontTypefaceHandler : WidgetHandler, IFontTypeface - { - public FontTypefaceHandler (Pango.FontFace pangoFace) - { - this.Control = pangoFace; - } - - public string Name - { - get { return Control.FaceName; } - } - - public FontStyle FontStyle - { - get { - var style = FontStyle.None; - var description = Control.Describe (); - if (description.Style.HasFlag (Pango.Style.Italic)) - style |= FontStyle.Italic; - if (description.Weight.HasFlag (Pango.Weight.Bold)) - style |= FontStyle.Bold; - return style; - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/FontsHandler.cs b/Source/Eto.Platform.Gtk/Drawing/FontsHandler.cs deleted file mode 100644 index 43de833c17..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/FontsHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Eto.Drawing; -using System.Collections.Generic; -using System.Linq; - -namespace Eto.Platform.GtkSharp.Drawing -{ - public class FontsHandler : WidgetHandler, IFonts - { - HashSet familyNames; - static Pango.Context context; - - public static Pango.Context Context - { - get - { - if (context == null) { - var window = new Gtk.Window (string.Empty); - context = window.PangoContext; - } - return context; - } - } - - public IEnumerable AvailableFontFamilies - { - get { return Context.Families.Select (r => new FontFamily (Generator, new FontFamilyHandler (r))); } - } - - public bool FontFamilyAvailable (string fontFamily) - { - if (familyNames == null) { - familyNames = new HashSet (StringComparer.InvariantCultureIgnoreCase); - foreach (var family in Context.Families) { - familyNames.Add (family.Name); - } - } - return familyNames.Contains (fontFamily); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/GraphicsHandler.cs b/Source/Eto.Platform.Gtk/Drawing/GraphicsHandler.cs deleted file mode 100644 index ed0101980d..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/GraphicsHandler.cs +++ /dev/null @@ -1,422 +0,0 @@ -using System; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Drawing -{ - public class GraphicsHandler : WidgetHandler, IGraphics - { - Pango.Context pangoContext; - readonly Gtk.Widget widget; - Image image; - Cairo.ImageSurface surface; - double offset = 0.5; - double inverseoffset; - PixelOffsetMode pixelOffsetMode = PixelOffsetMode.None; - RectangleF? clipBounds; - IGraphicsPath clipPath; - bool disposeControl = true; - #if GTK2 - readonly Gdk.Drawable drawable; - - public GraphicsHandler(Gtk.Widget widget, Gdk.Drawable drawable) - { - this.widget = widget; - this.drawable = drawable; - this.Control = Gdk.CairoHelper.Create(drawable); - } - #else - public GraphicsHandler (Gtk.Widget widget, Gdk.Window drawable) - { - this.widget = widget; - this.Control = Gdk.CairoHelper.Create (drawable); - } -#endif - public GraphicsHandler(Cairo.Context context, Pango.Context pangoContext, bool dispose = true) - { - this.Control = context; - this.pangoContext = pangoContext; - this.disposeControl = dispose; - } - - protected override bool DisposeControl { get { return disposeControl; } } - - public PixelOffsetMode PixelOffsetMode - { - get { return pixelOffsetMode; } - set - { - pixelOffsetMode = value; - offset = value == PixelOffsetMode.None ? 0.5 : 0; - inverseoffset = value == PixelOffsetMode.None ? 0 : 0.5; - } - } - - public float PointsPerPixel { get { return PangoContext != null ? 72f / (float)Pango.CairoHelper.ContextGetResolution(PangoContext) : 72f / 96f; } } - - public double Offset { get { return offset; } } - - public double InverseOffset { get { return inverseoffset; } } - - public GraphicsHandler() - { - } - - public bool IsRetained { get { return false; } } - - public bool AntiAlias - { - get { return Control.Antialias != Cairo.Antialias.None; } - set { Control.Antialias = value ? Cairo.Antialias.Default : Cairo.Antialias.None; } - } - - public ImageInterpolation ImageInterpolation - { - get; - set; - } - - public Pango.Context PangoContext - { - get - { - if (pangoContext == null && widget != null) - { - pangoContext = widget.PangoContext; - } - return pangoContext; - } - } - - public void CreateFromImage(Bitmap image) - { - this.image = image; - var handler = (BitmapHandler)image.Handler; - - var format = handler.Alpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24; - surface = new Cairo.ImageSurface(format, image.Size.Width, image.Size.Height); - Control = new Cairo.Context(surface); - Control.Save(); - Control.Rectangle(0, 0, image.Size.Width, image.Size.Height); - Gdk.CairoHelper.SetSourcePixbuf(Control, handler.Control, 0, 0); - Control.Operator = Cairo.Operator.Source; - Control.Fill(); - Control.Restore(); - } - - public void Flush() - { - if (image != null) - { - var handler = (BitmapHandler)image.Handler; - Gdk.Pixbuf pb = handler.GetPixbuf(Size.MaxValue); - if (pb != null) - { - - surface.Flush(); - var bd = handler.Lock(); - unsafe - { - var srcrow = (byte*)surface.DataPtr; - var destrow = (byte*)bd.Data; - for (int y=0; y height) - Control.Scale(1.0, height / width); - else - Control.Scale(width / height, 1.0); - Control.Arc(0, 0, radius, 0, 2 * Math.PI); - Control.Restore(); - pen.Apply(this); - } - - public void FillEllipse(Brush brush, float x, float y, float width, float height) - { - Control.Save(); - Control.Translate(x + width / 2 + inverseoffset, y + height / 2 + inverseoffset); - double radius = Math.Max(width / 2.0, height / 2.0); - if (width > height) - Control.Scale(1.0, height / width); - else - Control.Scale(width / height, 1.0); - Control.Arc(0, 0, radius, 0, 2 * Math.PI); - Control.Restore(); - Control.Save(); - brush.Apply(this); - Control.Restore(); - } - - public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - Control.Save(); - Control.Translate(x + width / 2 + offset, y + height / 2 + offset); - double radius = Math.Max(width / 2.0, height / 2.0); - if (width > height) - Control.Scale(1.0, height / width); - else - Control.Scale(width / height, 1.0); - if (sweepAngle < 0) - Control.ArcNegative(0, 0, radius, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle)); - else - Control.Arc(0, 0, radius, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle)); - Control.Restore(); - pen.Apply(this); - } - - public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - Control.Save(); - Control.Translate(x + width / 2 + inverseoffset, y + height / 2 + inverseoffset); - double radius = Math.Max(width / 2.0, height / 2.0); - if (width > height) - Control.Scale(1.0, height / width); - else - Control.Scale(width / height, 1.0); - if (sweepAngle < 0) - Control.ArcNegative(0, 0, radius, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle)); - else - Control.Arc(0, 0, radius, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle)); - Control.LineTo(0, 0); - Control.Restore(); - Control.Save(); - brush.Apply(this); - Control.Restore(); - } - - public void FillPath(Brush brush, IGraphicsPath path) - { - Control.Save(); - Control.Translate(inverseoffset, inverseoffset); - path.Apply(Control); - Control.Restore(); - Control.Save(); - Control.FillRule = path.FillMode.ToCairo(); - brush.Apply(this); - Control.Restore(); - } - - public void DrawPath(Pen pen, IGraphicsPath path) - { - Control.Save(); - Control.Translate(offset, offset); - path.Apply(Control); - Control.Restore(); - pen.Apply(this); - } - - public void DrawImage(Image image, float x, float y) - { - ((IImageHandler)image.Handler).DrawImage(this, x, y); - } - - public void DrawImage(Image image, float x, float y, float width, float height) - { - ((IImageHandler)image.Handler).DrawImage(this, x, y, width, height); - } - - public void DrawImage(Image image, RectangleF source, RectangleF destination) - { - ((IImageHandler)image.Handler).DrawImage(this, source, destination); - } - - Pango.Layout CreateLayout() - { - return PangoContext != null ? new Pango.Layout(PangoContext) : Pango.CairoHelper.CreateLayout(Control); - } - - public void DrawText(Font font, SolidBrush brush, float x, float y, string text) - { - using (var layout = CreateLayout ()) - { - font.Apply(layout); - layout.SetText(text); - Control.Save(); - Control.Color = brush.Color.ToCairo(); - Control.MoveTo(x, y); - Pango.CairoHelper.LayoutPath(Control, layout); - Control.Fill(); - Control.Restore(); - } - } - - public SizeF MeasureString(Font font, string text) - { - using (var layout = CreateLayout ()) - { - font.Apply(layout); - layout.SetText(text); - int width, height; - layout.GetPixelSize(out width, out height); - return new SizeF(width, height); - } - } - - protected override void Dispose(bool disposing) - { - if (image != null) - { - Flush(); - image = null; - } - if (surface != null) - { - // Analysis disable once RedundantCast - backward compatibility - ((IDisposable)surface).Dispose(); - surface = null; - } - - base.Dispose(disposing); - } - - public void TranslateTransform(float offsetX, float offsetY) - { - Control.Translate(offsetX, offsetY); - } - - public void RotateTransform(float angle) - { - Control.Rotate(Conversions.DegreesToRadians(angle)); - } - - public void ScaleTransform(float scaleX, float scaleY) - { - Control.Scale(scaleX, scaleY); - } - - public void MultiplyTransform(IMatrix matrix) - { - Control.Transform(matrix.ToCairo()); - } - - public void SaveTransform() - { - ReverseClip(); - Control.Save(); - ApplyClip(); - } - - public void RestoreTransform() - { - Control.Restore(); - ApplyClip(); - } - - void ReverseClip() - { - if (clipBounds != null) - Control.ResetClip(); - } - - void ApplyClip() - { - if (clipPath != null) - { - clipPath.Apply(Control); - Control.Clip(); - } - else if (clipBounds != null) - { - Control.Rectangle(clipBounds.Value.ToCairo()); - Control.Clip(); - } - } - - public RectangleF ClipBounds - { - get { return clipBounds ?? RectangleF.Empty; } - } - - public void SetClip(RectangleF rectangle) - { - ResetClip(); - clipBounds = rectangle; - ApplyClip(); - } - - public void SetClip(IGraphicsPath path) - { - ResetClip(); - clipPath = path; - clipBounds = path.Bounds; - ApplyClip(); - } - - public void ResetClip() - { - clipBounds = null; - Control.ResetClip(); - } - - public void Clear(SolidBrush brush) - { - Control.Save(); - Control.Operator = Cairo.Operator.Clear; - Control.Paint(); - Control.Restore(); - Control.Save(); - if (brush != null) - { - brush.Apply(this); - Control.Paint(); - } - Control.Restore(); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Drawing/GraphicsPathHandler.cs b/Source/Eto.Platform.Gtk/Drawing/GraphicsPathHandler.cs deleted file mode 100644 index 75619cc7f4..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/GraphicsPathHandler.cs +++ /dev/null @@ -1,364 +0,0 @@ -using System; -using Eto.Drawing; -using System.Collections.Generic; -using System.Linq; - -namespace Eto.Platform.GtkSharp.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class GraphicsPathHandler : IGraphicsPathHandler - { - IMatrix transform; - readonly List commands = new List (); - - bool firstFigureClosed; - bool isFirstFigure = true; - - public IEnumerable Points - { - get - { - foreach (var command in commands) { - if (command.Points == null) - continue; - foreach (var point in command.Points) { - if (transform != null) - yield return transform.TransformPoint (point); - else - yield return point; - } - } - } - } - - class CommandExecutor - { - public Cairo.Context Context { get; private set; } - - public bool First { get; private set; } - - public bool ForceConnect { get; set; } - - public CommandExecutor (Cairo.Context context) - { - this.Context = context; - this.First = true; - } - - public bool SetStart (float x, float y) - { - return SetStart (new PointF (x, y)); - } - - public void ResetStart () - { - First = true; - } - - public bool SetStart (PointF point) - { - First = false; - if (ForceConnect) { - ConnectTo (point); - return false; - } - return true; - } - - public void ConnectTo (float x, float y) - { - ConnectTo (new PointF(x, y)); - } - - public void ConnectTo (PointF point) - { - if (First) { - Context.MoveTo (point.X, point.Y); - First = false; - } else - Context.LineTo (point.X, point.Y); - ForceConnect = false; - } - - public void CloseFigure () - { - Context.ClosePath (); - First = true; - Context.NewSubPath (); - } - - } - - abstract class Command - { - public PointF[] Points { get; set; } - - public abstract void Apply (CommandExecutor exec); - } - - delegate void GraphicsPathCommandDelegate (CommandExecutor exec); - - class ActionCommand : Command - { - readonly GraphicsPathCommandDelegate apply; - - public ActionCommand (GraphicsPathCommandDelegate apply) - { - this.apply = apply; - } - - public override void Apply (CommandExecutor exec) - { - apply (exec); - } - } - - public void AddLines (IEnumerable points) - { - var pointArray = points.ToArray (); - Add (exec => { - for (int i=0; i { - if (exec.SetStart (x, y)) - exec.Context.MoveTo (x, y); - }, new PointF (x, y)); - } - - public void LineTo (float x, float y) - { - Add (exec => { - exec.SetStart (x, y); - exec.Context.LineTo (x, y); - }, new PointF (x, y)); - } - - public void AddLine (float startX, float startY, float endX, float endY) - { - Add (exec => { - exec.ConnectTo (startX, startY); - exec.Context.LineTo (endX, endY); - }, new PointF (startX, startY), new PointF (endX, endY)); - } - - void Add (GraphicsPathCommandDelegate apply, params PointF[] points) - { - commands.Add (new ActionCommand (apply) { Points = points }); - } - - public void Apply (Cairo.Context context) - { - var exec = new CommandExecutor (context); - Connect (exec); - } - - void Connect (CommandExecutor exec) - { - if (transform != null) { - exec.Context.Save (); - exec.Context.Transform (transform.ToCairo ()); - } - foreach (var command in commands) { - command.Apply (exec); - } - if (transform != null) { - exec.Context.Restore (); - } - } - - public void AddArc (float x, float y, float width, float height, float startAngle, float sweepAngle) - { - Add (exec => { - // degrees to radians conversion - double startRadians = startAngle * Math.PI / 180.0; - - // x and y radius - float dx = width / 2; - float dy = height / 2; - - // determine the start point - double xs = x + dx + (Math.Cos (startRadians) * dx); - double ys = y + dy + (Math.Sin (startRadians) * dy); - exec.SetStart ((float)xs, (float)ys); - - exec.Context.Save (); - exec.Context.Translate (x + width / 2, y + height / 2); - double radius = Math.Max (width / 2.0, height / 2.0); - if (width > height) - exec.Context.Scale (1.0, height / width); - else - exec.Context.Scale (width / height, 1.0); - - if (sweepAngle < 0) - exec.Context.ArcNegative (0, 0, radius, Conversions.DegreesToRadians (startAngle), Conversions.DegreesToRadians (startAngle + sweepAngle)); - else - exec.Context.Arc (0, 0, radius, Conversions.DegreesToRadians (startAngle), Conversions.DegreesToRadians (startAngle + sweepAngle)); - exec.Context.Restore (); - }, new PointF (x, y), new PointF (x + width, y + height)); - } - - public void AddBezier (PointF start, PointF control1, PointF control2, PointF end) - { - Add (exec => { - exec.ConnectTo (start); - exec.Context.CurveTo (control1.ToCairo (), control2.ToCairo (), end.ToCairo ()); - }, start, end); - } - - public void AddRectangle (float x, float y, float width, float height) - { - Add (exec => { - exec.Context.NewSubPath (); - exec.Context.Rectangle (x, y, width, height); - exec.ResetStart (); - }, new PointF (x, y), new PointF (x + width, y + height)); - isFirstFigure = false; - } - - public void AddPath (IGraphicsPath path, bool connect = false) - { - var handler = path.ToHandler (); - Add (exec => { - if (connect && !handler.firstFigureClosed) { - exec.ForceConnect = true; - handler.Connect (exec); - } else - handler.Apply (exec.Context); - }, handler.Points.ToArray ()); - } - - public void Transform (IMatrix matrix) - { - if (transform != null) - transform.Prepend (matrix); - else - transform = matrix; - } - - public void CloseFigure () - { - Add (exec => exec.CloseFigure()); - if (isFirstFigure) - firstFigureClosed = true; - } - - public void StartFigure () - { - Add (exec => { - exec.Context.NewSubPath (); - exec.ResetStart (); - }); - isFirstFigure = false; - } - - public void AddEllipse (float x, float y, float width, float height) - { - Add (exec => { - exec.Context.NewSubPath (); - exec.Context.Save (); - exec.Context.Translate (x + width / 2, y + height / 2); - double radius = Math.Max (width / 2.0, height / 2.0); - if (width > height) - exec.Context.Scale (1.0, height / width); - else - exec.Context.Scale (width / height, 1.0); - exec.Context.Arc (0, 0, radius, 0, 2 * Math.PI); - exec.Context.Restore (); - exec.ResetStart (); - }, new PointF (x, y), new PointF (x + width, y + height)); - isFirstFigure = false; - } - - public void AddCurve (IEnumerable points, float tension = 0.5f) - { - var pointArray = SplineHelper.SplineCurve (points, tension).ToArray (); - Add (exec => { - exec.SetStart (points.First ()); - SplineHelper.Draw(pointArray, exec.ConnectTo, (c1, c2, end) => exec.Context.CurveTo(c1.ToCairo(), c2.ToCairo(), end.ToCairo())); - }, pointArray); - } - - public void Dispose () - { - } - - public RectangleF Bounds - { - get { - bool first = true; - PointF minPoint = PointF.Empty; - PointF maxPoint = PointF.Empty; - foreach (var point in Points) { - if (first) { - minPoint = maxPoint = point; - first = false; - } else { - minPoint = PointF.Min (point, minPoint); - maxPoint = PointF.Max (point, maxPoint); - } - } - return new RectangleF (minPoint, maxPoint); - } - } - - public bool IsEmpty - { - get { return commands.Count == 0; } - } - - public PointF CurrentPoint - { - get { - // slow to get current point, but no other way? - using (var context = Playback ()) { - return context.CurrentPoint.ToEto (); - } - } - } - - Cairo.Context Playback () - { - using (var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 10, 10)) - { - var context = new Cairo.Context(surface); - Apply(context); - return context; - } - } - - public object ControlObject - { - get { return this; } - } - - public IGraphicsPath Clone() - { - var handler = new GraphicsPathHandler (); - handler.commands.AddRange(commands); - handler.transform = transform != null ? transform.Clone () : null; - handler.firstFigureClosed = firstFigureClosed; - handler.isFirstFigure = isFirstFigure; - return handler; - } - - public FillMode FillMode - { - get; set; - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/IconHandler.cs b/Source/Eto.Platform.Gtk/Drawing/IconHandler.cs deleted file mode 100644 index 9ed751a1b7..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/IconHandler.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.IO; -using Eto.Drawing; -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp.Drawing -{ - public class IconHandler : ImageHandler, IIcon, IGtkPixbuf - { - readonly Dictionary sizes = new Dictionary(); - - public Gdk.Pixbuf Pixbuf { get; set; } - - #region IIcon Members - - public void Create(Stream stream) - { - Pixbuf = new Gdk.Pixbuf(stream); - Control = new Gtk.IconSet(Pixbuf); - } - - public void Create(string fileName) - { - Pixbuf = new Gdk.Pixbuf(fileName); - Control = new Gtk.IconSet(Pixbuf); - } - - #endregion - - public override Size Size - { - get - { - return new Size(Pixbuf.Width, Pixbuf.Height); - } - } - - public override void SetImage(Gtk.Image imageView, Gtk.IconSize? iconSize) - { - if (iconSize != null) - imageView.SetFromIconSet(Control, iconSize.Value); - else - imageView.Pixbuf = Pixbuf; - } - - public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) - { - var context = graphics.Control; - context.Save(); - destination.X += (float)graphics.InverseOffset; - destination.Y += (float)graphics.InverseOffset; - context.Rectangle(destination.ToCairo()); - double scalex = 1; - double scaley = 1; - if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f) - { - scalex = (double)destination.Width / (double)source.Width; - scaley = (double)destination.Height / (double)source.Height; - context.Scale(scalex, scaley); - } - Gdk.CairoHelper.SetSourcePixbuf(context, Pixbuf, (destination.Left / scalex) - source.Left, (destination.Top / scaley) - source.Top); - var pattern = (Cairo.SurfacePattern)context.Source; - pattern.Filter = graphics.ImageInterpolation.ToCairo(); - context.Fill(); - context.Restore(); - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - if (disposing) - { - if (Pixbuf != null) - { - Pixbuf.Dispose(); - Pixbuf = null; - } - } - } - - public Gdk.Pixbuf GetPixbuf(Size maxSize) - { - Gdk.Pixbuf pixbuf = Pixbuf; - if (pixbuf.Width > maxSize.Width && pixbuf.Height > maxSize.Height) - { - if (!sizes.TryGetValue(maxSize, out pixbuf)) - { - pixbuf = Pixbuf.ScaleSimple(maxSize.Width, maxSize.Height, Gdk.InterpType.Bilinear); - sizes[maxSize] = pixbuf; - } - } - - return pixbuf; - } - } -} diff --git a/Source/Eto.Platform.Gtk/Drawing/ImageHandler.cs b/Source/Eto.Platform.Gtk/Drawing/ImageHandler.cs deleted file mode 100644 index 175e6dedd5..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/ImageHandler.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Drawing -{ - public interface IGtkPixbuf - { - Gdk.Pixbuf Pixbuf { get; } - - Gdk.Pixbuf GetPixbuf (Size maxSize); - } - - public interface IImageHandler - { - void DrawImage (GraphicsHandler graphics, float x, float y); - - void DrawImage (GraphicsHandler graphics, float x, float y, float width, float height); - - void DrawImage (GraphicsHandler graphics, RectangleF source, RectangleF destination); - - void SetImage (Gtk.Image imageView, Gtk.IconSize? iconSize); - } - - public abstract class ImageHandler : WidgetHandler, IImage, IImageHandler - where TWidget: Image - { - - public abstract Size Size { get; } - - public abstract void SetImage (Gtk.Image imageView, Gtk.IconSize? iconSize); - - public virtual void DrawImage (GraphicsHandler graphics, float x, float y) - { - DrawImage (graphics, x, y, Size.Width, Size.Height); - } - - public virtual void DrawImage (GraphicsHandler graphics, float x, float y, float width, float height) - { - DrawImage (graphics, new RectangleF (new Point (0, 0), Size), new RectangleF (x, y, width, height)); - } - - public abstract void DrawImage (GraphicsHandler graphics, RectangleF source, RectangleF destination); - } -} diff --git a/Source/Eto.Platform.Gtk/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Platform.Gtk/Drawing/IndexedBitmapHandler.cs deleted file mode 100644 index fc5e4af7bb..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/IndexedBitmapHandler.cs +++ /dev/null @@ -1,200 +0,0 @@ - -#define GTK_2_6 -using System; -using System.Runtime.InteropServices; -using Eto.Drawing; -using System.Linq; - -namespace Eto.Platform.GtkSharp.Drawing -{ - public class IndexedBitmapDataHandler : BitmapData - { - public IndexedBitmapDataHandler (Image image, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) - : base(image, data, scanWidth, bitsPerPixel, controlObject) - { - } - - public override uint TranslateArgbToData (uint argb) - { - return argb; - } - - public override uint TranslateDataToArgb (uint bitmapData) - { - return bitmapData; - } - } - - public class IndexedBitmapHandler : ImageHandler, IIndexedBitmap - { - Size size; - int rowStride; - int bitsPerPixel; - uint[] colors; - - public int RowStride { - get { return rowStride; } - } - - public override Size Size { - get { return size; } - } - - public void Create (int width, int height, int bitsPerPixel) - { - this.bitsPerPixel = bitsPerPixel; - rowStride = width * bitsPerPixel / 8; - int colorCount = (int)Math.Pow (2, bitsPerPixel); - colors = new uint[colorCount]; - for (int i=0; i Color.FromArgb(r)).ToList ()); - } - set { - if (value.Count != colors.Length) - throw new ArgumentException ("Input palette must have the same colors as the output"); - for (int i=0; i 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f) - { - scalex = (double)destination.Width / (double)source.Width; - scaley = (double)destination.Height / (double)source.Height; - context.Scale(scalex, scaley); - } - context.SetSourceSurface(surface, (int)destination.Left, (int)destination.Top); - context.Fill(); - context.Restore(); - } - - - /* - if (graphics == null || graphics.Control == null || graphics.GC == null) - throw new Exception("WHAA?"); - using (var drawable = new Gdk.Pixmap(graphics.Control, source.Right+1, source.Bottom+1)) - using (var gc = new Gdk.GC(drawable)) - { - if (drawable.Colormap == null) - drawable.Colormap = graphics.Control.Colormap; - drawable.DrawIndexedImage(gc, 0, 0, source.Right+1, source.Bottom+1, Gdk.RgbDither.None, Control, this.rowStride, GetPmap()); - if (source.Width != destination.Width || source.Height != destination.Height) - { - // scale da shit - Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, source.Width, source.Height); - pb.GetFromDrawable(drawable, drawable.Colormap, source.X, source.Y, 0, 0, source.Width, source.Height); - - Gdk.Pixbuf pbDest = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height); - pb.Scale(pbDest, 0, 0, destination.Width, destination.Height, 0, 0, (double)destination.Width / (double)source.Width, - (double)destination.Height / (double)source.Height, Gdk.InterpType.Bilinear); - pb.Dispose(); - - - graphics.Control.DrawPixbuf(graphics.GC, pbDest, 0, 0, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); - pbDest.Dispose(); - } - else - { - // no scaling necessary! - graphics.Control.DrawDrawable(graphics.GC, drawable, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height); - } - - }*/ - } - } -} diff --git a/Source/Eto.Platform.Gtk/Drawing/LinearGradientBrushHandler.cs b/Source/Eto.Platform.Gtk/Drawing/LinearGradientBrushHandler.cs deleted file mode 100644 index eb47ead500..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/LinearGradientBrushHandler.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using Eto.Drawing; -using System.Runtime.InteropServices; - -namespace Eto.Platform.GtkSharp.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class LinearGradientBrushHandler : BrushHandler, ILinearGradientBrush - { - [DllImport ("libcairo-2.dll", CallingConvention = CallingConvention.Cdecl)] - internal static extern Cairo.Extend cairo_pattern_get_extend (IntPtr pattern); - - [DllImport ("libcairo-2.dll", CallingConvention = CallingConvention.Cdecl)] - internal static extern void cairo_pattern_set_extend (IntPtr pattern, Cairo.Extend extend); - - class EtoGradient : Cairo.LinearGradient - { - public EtoGradient (double x0, double y0, double x1, double y1) - : base (x0, y0, x1, y1) - { - } - - public Cairo.Matrix Transform { get; set; } - } - - public object Create (Color startColor, Color endColor, PointF startPoint, PointF endPoint) - { - var gradient = new EtoGradient (startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); - cairo_pattern_set_extend (gradient.Pointer, Cairo.Extend.Repeat); - // not in windows?? gradient.Extend = Cairo.Extend.Repeat; - gradient.AddColorStop (0, startColor.ToCairo ()); - gradient.AddColorStop (1, endColor.ToCairo ()); - return gradient; - } - - public object Create (RectangleF rectangle, Color startColor, Color endColor, float angle) - { - throw new NotImplementedException (); - } - - public IMatrix GetTransform (LinearGradientBrush widget) - { - return ((EtoGradient)widget.ControlObject).Transform.ToEto (); - } - - public void SetTransform (LinearGradientBrush widget, IMatrix transform) - { - ((EtoGradient)widget.ControlObject).Transform = transform.ToCairo (); - } - - public GradientWrapMode GetGradientWrap (LinearGradientBrush widget) - { - var gradient = ((Cairo.LinearGradient)widget.ControlObject); - // return gradient.Extend.ToEto (); - return cairo_pattern_get_extend (gradient.Pointer).ToEto (); - } - - public void SetGradientWrap (LinearGradientBrush widget, GradientWrapMode gradientWrap) - { - var gradient = ((Cairo.LinearGradient)widget.ControlObject); - // gradient.Extend = gradientWrap.ToCairo (); - cairo_pattern_set_extend (gradient.Pointer, gradientWrap.ToCairo ()); - } - - public override void Apply (object control, GraphicsHandler graphics) - { - var gradient = ((EtoGradient)control); - if (!object.ReferenceEquals (gradient.Transform, null)) - graphics.Control.Transform (gradient.Transform); - graphics.Control.Pattern = gradient; - graphics.Control.Fill (); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/MatrixHandler.cs b/Source/Eto.Platform.Gtk/Drawing/MatrixHandler.cs deleted file mode 100644 index 1799a2ded1..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/MatrixHandler.cs +++ /dev/null @@ -1,147 +0,0 @@ -using System; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class MatrixHandler : IMatrixHandler - { - Cairo.Matrix control; - - public MatrixHandler () - { - } - - public MatrixHandler (Cairo.Matrix matrix) - { - this.control = matrix; - } - - public float[] Elements - { - get - { - return new float[] { - (float)control.Xx, - (float)control.Yx, - (float)control.Xy, - (float)control.Yy, - (float)control.X0, - (float)control.Y0 - }; - } - } - - public float Xx { get { return (float)control.Xx; } set { control.Xx = value; } } - - public float Xy { get { return (float)control.Xx; } set { control.Xx = value; } } - - public float Yx { get { return (float)control.Yx; } set { control.Yx = value; } } - - public float Yy { get { return (float)control.Yy; } set { control.Yy = value; } } - - public float X0 { get { return (float)control.X0; } set { control.X0 = value; } } - - public float Y0 { get { return (float)control.Y0; } set { control.Y0 = value; } } - - public void Create () - { - control = new Cairo.Matrix (); - } - - public void Create (float xx, float yx, float xy, float yy, float x0, float y0) - { - control = new Cairo.Matrix (xx, yx, xy, yy, x0, y0); - } - - public void Rotate (float angle) - { - control.Rotate (Conversions.DegreesToRadians (angle)); - } - - public void RotateAt (float angle, float centerX, float centerY) - { - angle = Conversions.DegreesToRadians (angle); - var sina = Math.Sin (angle); - var cosa = Math.Cos (angle); - var matrix = new Cairo.Matrix (cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa); - control = Cairo.Matrix.Multiply (matrix, control); - } - - public void Translate (float x, float y) - { - control.Translate (x, y); - } - - public void Scale (float scaleX, float scaleY) - { - control.Scale (scaleX, scaleY); - } - - public void ScaleAt (float scaleX, float scaleY, float centerX, float centerY) - { - var matrix = new Cairo.Matrix (scaleX, 0, 0, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); - control = Cairo.Matrix.Multiply (matrix, control); - } - - public void Skew (float skewX, float skewY) - { - var matrix = new Cairo.Matrix (1, Math.Tan (Conversions.DegreesToRadians (skewX)), Math.Tan (Conversions.DegreesToRadians (skewY)), 1, 0, 0); - control = Cairo.Matrix.Multiply (matrix, control); - } - - public void Append (IMatrix matrix) - { - var cairoMatrix = matrix.ControlObject as Cairo.Matrix; - control.Multiply (cairoMatrix); - } - - public void Prepend (IMatrix matrix) - { - var cairoMatrix = matrix.ControlObject as Cairo.Matrix; - control = Cairo.Matrix.Multiply (cairoMatrix, control); - } - - public PointF TransformPoint (Point point) - { - double x = point.X; - double y = point.Y; - control.TransformPoint (ref x, ref y); - return new PointF ((float)x, (float)y); - } - - public PointF TransformPoint (PointF point) - { - double x = point.X; - double y = point.Y; - control.TransformPoint (ref x, ref y); - return new PointF ((float)x, (float)y); - } - - public void Invert () - { - control.Invert (); - } - - public object ControlObject - { - get { return control; } - } - - public IMatrix Clone () - { - var matrix = new Cairo.Matrix(control.Xx, control.Yx, control.Xy, control.Yy, control.X0, control.Y0); - return new MatrixHandler (matrix); - } - - public void Dispose() - { - // do nothing - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/PenHandler.cs b/Source/Eto.Platform.Gtk/Drawing/PenHandler.cs deleted file mode 100644 index d6c366103d..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/PenHandler.cs +++ /dev/null @@ -1,161 +0,0 @@ -using System; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Drawing -{ - /// - /// Pen handler - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class PenHandler : IPen - { - class PenObject - { - double[] cairodashes; - float thickness; - double cairooffset; - DashStyle dashStyle; - - public Cairo.Color Color { get; set; } - - public float Thickness - { - get { return thickness; } - set { - thickness = value; - SetDashStyle (); - } - } - - public Cairo.LineJoin LineJoin { get; set; } - - public Cairo.LineCap LineCap { get; set; } - - public float MiterLimit { get; set; } - - public DashStyle DashStyle - { - get { return dashStyle; } - set - { - dashStyle = value; - SetDashStyle (); - } - } - - void SetDashStyle () - { - if (dashStyle == null || dashStyle.IsSolid) - cairodashes = null; - else { - var dashes = DashStyle.Dashes; - cairooffset = DashStyle.Offset * Thickness; - - if (LineCap == Cairo.LineCap.Butt) { - cairodashes = Array.ConvertAll (dashes, x => (double)x * Thickness); - } - else { - if (Math.Abs(Thickness - 1) < 0.01f) - cairooffset += Thickness / 2; - cairodashes = new double[dashes.Length]; - for (int i = 0; i < cairodashes.Length; i++) { - var dash = dashes [i] * Thickness; - if ((i % 2) == 1) { - // gap must include square/round thickness - dash += Thickness; - } else { - // dash must exclude square/round thickness - dash -= Thickness; - } - cairodashes [i] = dash; - } - } - } - } - - public void Apply (GraphicsHandler graphics) - { - graphics.Control.Color = Color; - graphics.Control.LineWidth = Thickness; - graphics.Control.LineCap = LineCap; - graphics.Control.LineJoin = LineJoin; - if (cairodashes != null) - graphics.Control.SetDash (cairodashes, cairooffset); - graphics.Control.MiterLimit = MiterLimit; - graphics.Control.Stroke (); - } - } - - public object Create (Color color, float thickness) - { - return new PenObject { - Color = color.ToCairo (), - Thickness = thickness, - MiterLimit = 10f, - LineCap = PenLineCap.Square.ToCairo () - }; - } - - public Color GetColor (Pen widget) - { - return ((PenObject)widget.ControlObject).Color.ToEto (); - } - - public void SetColor (Pen widget, Color color) - { - ((PenObject)widget.ControlObject).Color = color.ToCairo (); - } - - public float GetThickness (Pen widget) - { - return ((PenObject)widget.ControlObject).Thickness; - } - - public void SetThickness (Pen widget, float thickness) - { - ((PenObject)widget.ControlObject).Thickness = thickness; - } - - public PenLineJoin GetLineJoin (Pen widget) - { - return ((PenObject)widget.ControlObject).LineJoin.ToEto (); - } - - public void SetLineJoin (Pen widget, PenLineJoin lineJoin) - { - ((PenObject)widget.ControlObject).LineJoin = lineJoin.ToCairo (); - } - - public PenLineCap GetLineCap (Pen widget) - { - return ((PenObject)widget.ControlObject).LineCap.ToEto (); - } - - public void SetLineCap (Pen widget, PenLineCap lineCap) - { - ((PenObject)widget.ControlObject).LineCap = lineCap.ToCairo (); - } - - public float GetMiterLimit (Pen widget) - { - return ((PenObject)widget.ControlObject).MiterLimit; - } - - public void SetMiterLimit (Pen widget, float miterLimit) - { - ((PenObject)widget.ControlObject).MiterLimit = miterLimit; - } - - public void SetDashStyle (Pen widget, DashStyle dashStyle) - { - ((PenObject)widget.ControlObject).DashStyle = dashStyle; - } - - public void Apply (Pen widget, GraphicsHandler graphics) - { - ((PenObject)widget.ControlObject).Apply (graphics); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/SolidBrushHandler.cs b/Source/Eto.Platform.Gtk/Drawing/SolidBrushHandler.cs deleted file mode 100644 index 1b6fa488fc..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/SolidBrushHandler.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Drawing -{ - /// - /// Handler for the - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class SolidBrushHandler : BrushHandler, ISolidBrush - { - public override void Apply (object control, GraphicsHandler graphics) - { - graphics.Control.Color = (Cairo.Color)control; - graphics.Control.Fill (); - } - - public Color GetColor (SolidBrush widget) - { - return ((Cairo.Color)widget.ControlObject).ToEto (); - } - - public void SetColor (SolidBrush widget, Color color) - { - widget.ControlObject = color.ToCairo (); - } - - public object Create (Color color) - { - return color.ToCairo (); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Drawing/TextureBrushHandler.cs b/Source/Eto.Platform.Gtk/Drawing/TextureBrushHandler.cs deleted file mode 100644 index 7e79722510..0000000000 --- a/Source/Eto.Platform.Gtk/Drawing/TextureBrushHandler.cs +++ /dev/null @@ -1,76 +0,0 @@ -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Drawing -{ - /// - /// Handler for the - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class TextureBrushHandler : BrushHandler, ITextureBrush - { - class TextureBrushObject - { - public Cairo.Matrix Transform { get; set; } - public Gdk.Pixbuf Pixbuf { get; set; } - public float Opacity { get; set; } - - public TextureBrushObject () - { - Opacity = 1.0f; - } - - public void Apply (GraphicsHandler graphics) - { - if (!object.ReferenceEquals (Transform, null)) - graphics.Control.Transform (Transform); - - Gdk.CairoHelper.SetSourcePixbuf (graphics.Control, Pixbuf, 0, 0); - var surfacePattern = graphics.Control.Source as Cairo.SurfacePattern; - if (surfacePattern != null) - surfacePattern.Extend = Cairo.Extend.Repeat; - if (Opacity < 1.0f) - { - graphics.Control.Clip(); - graphics.Control.PaintWithAlpha(Opacity); - } - else - graphics.Control.Fill(); - } - } - - public IMatrix GetTransform (TextureBrush widget) - { - return ((TextureBrushObject)widget.ControlObject).Transform.ToEto (); - } - - public void SetTransform (TextureBrush widget, IMatrix transform) - { - ((TextureBrushObject)widget.ControlObject).Transform = transform.ToCairo (); - } - - public object Create (Image image, float opacity) - { - return new TextureBrushObject { - Pixbuf = image.ToGdk (), - Opacity = opacity - }; - } - - public override void Apply (object control, GraphicsHandler graphics) - { - ((TextureBrushObject)control).Apply (graphics); - } - - public float GetOpacity (TextureBrush widget) - { - return ((TextureBrushObject)widget.ControlObject).Opacity; - } - - public void SetOpacity (TextureBrush widget, float opacity) - { - ((TextureBrushObject)widget.ControlObject).Opacity = opacity; - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Eto.Platform.Gtk.csproj b/Source/Eto.Platform.Gtk/Eto.Platform.Gtk.csproj deleted file mode 100644 index a69f8bc8a5..0000000000 --- a/Source/Eto.Platform.Gtk/Eto.Platform.Gtk.csproj +++ /dev/null @@ -1,267 +0,0 @@ - - - - - Debug - AnyCPU - {1FF7BE58-A6A2-4132-8CAF-AA2EF18122A1} - Library - Eto.Platform.GtkSharp - Eto.Platform.Gtk - - - 512 - True - prompt - 4 - ..\..\.. - ..\..\Libraries - CAIRO;TRACE;GTK2 - - - True - - - ..\..\BuildOutput\Debug\ - CAIRO;DEBUG;TRACE;GTK2 - false - full - 0618,0612 - - - ..\..\BuildOutput\Release\ - true - pdbonly - 0618,0612 - - - - - System - - - System.Data - - - System.Xml - - - - - - ..\..\Libraries\webkit-sharp\webkit-sharp.dll - False - - - - - - - - - - {16289D2F-044C-49EF-83E9-9391AFF8FD2B} - Eto - - - - - - - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - - - - - - - - - - - - - - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - Code - - - Code - - - Code - - - - - - Properties\GlobalAssemblyInfo.cs - - - - - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Drawing\SplineHelper.cs - - - - - - - Code - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Source/Eto.Platform.Gtk/Eto.Platform.Gtk.dll.config b/Source/Eto.Platform.Gtk/Eto.Platform.Gtk.dll.config deleted file mode 100644 index 5c4b402d5b..0000000000 --- a/Source/Eto.Platform.Gtk/Eto.Platform.Gtk.dll.config +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/Source/Eto.Platform.Gtk/Eto.Platform.Gtk3.csproj b/Source/Eto.Platform.Gtk/Eto.Platform.Gtk3.csproj deleted file mode 100644 index 850468e008..0000000000 --- a/Source/Eto.Platform.Gtk/Eto.Platform.Gtk3.csproj +++ /dev/null @@ -1,286 +0,0 @@ - - - - Local - {EECFE22F-A544-4498-AE2D-90C81BD2931A} - Debug - AnyCPU - - - Eto.Platform.Gtk3 - JScript - Grid - IE50 - false - Library - - - Eto.Platform.GtkSharp - - - - - ..\..\BuildOutput\Release\ - CAIRO;TRACE;GTK3 - 285212672 - true - true - 4096 - true - true - pdbonly - 4 - true - 0618,0612 - - - true - ..\..\BuildOutput\Debug\ - CAIRO;DEBUG;TRACE;GTK3 - 285212672 - true - 4096 - full - false - false - false - 4 - false - 0618,0612 - - - - System - - - System.Data - - - System.Xml - - - - - ..\..\Libraries\GtkSharp3\atk-sharp.dll - False - - - ..\..\Libraries\GtkSharp3\cairo-sharp.dll - False - - - ..\..\Libraries\GtkSharp3\gdk-sharp.dll - False - - - ..\..\Libraries\GtkSharp3\gio-sharp.dll - False - - - ..\..\Libraries\GtkSharp3\glib-sharp.dll - False - - - ..\..\Libraries\GtkSharp3\gtk-sharp.dll - False - - - ..\..\Libraries\GtkSharp3\pango-sharp.dll - False - - - ..\..\Libraries\GtkSharp3\webkit-sharp.dll - False - - - - - {16289D2F-044C-49EF-83E9-9391AFF8FD2B} - Eto - - - - - - - - - - - - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - - - - - - - - - - - - - - - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - - - Properties\GlobalAssemblyInfo.cs - - - - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Drawing\SplineHelper.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - PreserveNewest - - - \ No newline at end of file diff --git a/Source/Eto.Platform.Gtk/EtoEnvironmentHandler.cs b/Source/Eto.Platform.Gtk/EtoEnvironmentHandler.cs deleted file mode 100644 index 293cc68241..0000000000 --- a/Source/Eto.Platform.Gtk/EtoEnvironmentHandler.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using Eto; -using System.Reflection; -using System.IO; - -namespace Eto.Platform.GtkSharp -{ - public class EtoEnvironmentHandler : WidgetHandler, IEtoEnvironment - { - static Environment.SpecialFolder Convert (EtoSpecialFolder folder) - { - switch (folder) { - case EtoSpecialFolder.ApplicationSettings: - return Environment.SpecialFolder.ApplicationData; - case EtoSpecialFolder.Documents: - return Environment.SpecialFolder.MyDocuments; - default: - throw new NotSupportedException (); - } - } - - public string GetFolderPath (EtoSpecialFolder folder) - { - switch (folder) { - case EtoSpecialFolder.ApplicationResources: - return Path.GetDirectoryName (Assembly.GetEntryAssembly ().Location); - default: - return Environment.GetFolderPath (Convert (folder)); - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/ApplicationHandler.cs b/Source/Eto.Platform.Gtk/Forms/ApplicationHandler.cs deleted file mode 100644 index c203cbe4d1..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ApplicationHandler.cs +++ /dev/null @@ -1,195 +0,0 @@ -using System; -using Eto.Forms; -using System.Diagnostics; -using System.Threading; -using System.ComponentModel; -using Eto.Platform.GtkSharp.Drawing; -using Eto.Drawing; -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp -{ - public class ApplicationHandler : WidgetHandler, IApplication - { - bool attached; - Gtk.StatusIcon statusIcon; - readonly List invokeResetEvents = new List(); - - protected override void Initialize() - { - base.Initialize(); - Helper.Init(); - } - - public static int MainThreadID { get; set; } - - public void RunIteration() - { - Gtk.Application.RunIteration(); - } - - public void Restart() - { - Gtk.Application.Quit(); - - // TODO: restart! - } - - string badgeLabel; - - public string BadgeLabel - { - get { return badgeLabel; } - set - { - badgeLabel = value; - if (!string.IsNullOrEmpty(badgeLabel)) - { - if (statusIcon == null) - { - statusIcon = new Gtk.StatusIcon(); - statusIcon.Activate += delegate - { - var form = Application.Instance.MainForm; - if (form != null) - form.BringToFront(); - }; - } - var bmp = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, 32, 32); - using (var graphics = new Graphics(new Bitmap(Widget.Generator, new BitmapHandler(bmp)))) - { - graphics.Clear(); - DrawBadgeLabel(graphics, new Size(bmp.Width, bmp.Height), badgeLabel); - } - statusIcon.Pixbuf = bmp; - statusIcon.Visible = true; - } - else if (statusIcon != null) - statusIcon.Visible = false; - } - } - - protected virtual void DrawBadgeLabel(Graphics graphics, Size size, string badgeLabel) - { - var rect = new Rectangle(size); - rect.Inflate(-2, -2); - graphics.FillEllipse(Brushes.Red(Generator), rect); - graphics.DrawEllipse(new Pen(Colors.White, 2, Generator), rect); - var font = new Font(SystemFont.Bold, 10); - var labelSize = graphics.MeasureString(font, badgeLabel); - var labelPosition = ((PointF)(rect.Size - labelSize) / 2) + rect.Location; - graphics.DrawText(font, Colors.White, labelPosition, badgeLabel); - graphics.Flush(); - } - - public void Invoke(Action action) - { - if (Thread.CurrentThread.ManagedThreadId == ApplicationHandler.MainThreadID) - action(); - else - { - var resetEvent = new ManualResetEvent(false); - lock (invokeResetEvents) - invokeResetEvents.Add(resetEvent); - - Gtk.Application.Invoke(delegate - { - try - { - action(); - } - finally - { - resetEvent.Set(); - } - }); - resetEvent.WaitOne(); - lock (invokeResetEvents) - invokeResetEvents.Remove(resetEvent); - } - } - - public void AsyncInvoke(Action action) - { - Gtk.Application.Invoke(delegate - { - action(); - }); - } - - public void Attach(object context) - { - attached = true; - } - - public void OnMainFormChanged() - { - } - - public void Run(string[] args) - { - //if (!Platform.IsWindows) Gdk.Threads.Init(); // do this in windows, and it stalls! ugh - MainThreadID = Thread.CurrentThread.ManagedThreadId; - - Widget.OnInitialized(EventArgs.Empty); - if (!attached) - { - Gtk.Application.Run(); - lock (invokeResetEvents) - { - // set all invokes so threads will continue when run loop exits - foreach (var reset in invokeResetEvents) - reset.Set(); - invokeResetEvents.Clear(); - } - - Gdk.Threads.Leave(); - } - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Application.TerminatingEvent: - // called automatically - break; - default: - base.AttachEvent(id); - break; - } - } - - public void Quit() - { - var args = new CancelEventArgs(); - var mainForm = Widget.MainForm != null ? Widget.MainForm.Handler as IGtkWindow : null; - if (mainForm != null) - args.Cancel = !mainForm.CloseWindow(Widget.OnTerminating); - else - Widget.OnTerminating(args); - - if (!args.Cancel) - Gtk.Application.Quit(); - } - - public void Open(string url) - { - var info = new ProcessStartInfo(url); - Process.Start(info); - } - - public IEnumerable GetSystemCommands() - { - yield break; - } - - public void CreateStandardMenu(MenuItemCollection menu, IEnumerable commands) - { - } - - public Keys CommonModifier { get { return Keys.Control; } } - - public Keys AlternateModifier { get { return Keys.Alt; } } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Cells/CellHandler.cs b/Source/Eto.Platform.Gtk/Forms/Cells/CellHandler.cs deleted file mode 100644 index 2c117421b7..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Cells/CellHandler.cs +++ /dev/null @@ -1,188 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Platform.GtkSharp.Forms.Controls; -using System.Runtime.InteropServices; - -namespace Eto.Platform.GtkSharp.Forms.Cells -{ - public interface ICellDataSource - { - object GetItem(Gtk.TreePath path); - - void EndCellEditing(Gtk.TreePath path, int column); - - void BeginCellEditing(Gtk.TreePath path, int column); - - void SetColumnMap(int dataIndex, int column); - - int RowHeight { get; set; } - - void OnCellFormatting(GridCellFormatEventArgs args); - } - - public interface ICellHandler - { - void BindCell(ICellDataSource source, GridColumnHandler column, int columnIndex, ref int dataIndex); - - void SetEditable(Gtk.TreeViewColumn column, bool editable); - - GLib.Value GetValue(object dataItem, int column, int row); - - void HandleEvent(string eventHandler, bool defaultEvent = true); - - void AddCells(Gtk.TreeViewColumn column); - } - - static class GtkCell - { - [DllImport("gtksharpglue-2", CallingConvention = CallingConvention.Cdecl)] - internal static extern void gtksharp_cellrenderer_invoke_render(IntPtr gtype, IntPtr handle, IntPtr window, IntPtr widget, ref Gdk.Rectangle backgroundArea, ref Gdk.Rectangle cellArea, ref Gdk.Rectangle exposeArea, Gtk.CellRendererState flags); - } - - public abstract class SingleCellHandler : CellHandler - where TControl: Gtk.CellRenderer - where TWidget: Cell - { - public override void AddCells(Gtk.TreeViewColumn column) - { - column.PackStart(Control, true); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Grid.CellEditingEvent: - Control.EditingStarted += Connector.HandleEditingStarted; - break; - default: - base.AttachEvent(id); - break; - } - } - - protected new SingleCellConnector Connector { get { return (SingleCellConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new SingleCellConnector(); - } - - protected class SingleCellConnector : WeakConnector - { - public new SingleCellHandler Handler { get { return (SingleCellHandler)base.Handler; } } - - public void HandleEditingStarted(object o, Gtk.EditingStartedArgs args) - { - Handler.Source.BeginCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); - } - } - } - - public abstract class CellHandler : WidgetHandler, ICell, ICellHandler - where TWidget: Cell - where TControl: Gtk.CellRenderer - { - int? dataIndex; - int itemCol; - int rowCol; - - public GridColumnHandler Column { get; private set; } - - public int ColumnIndex { get; private set; } - - public ICellDataSource Source { get; private set; } - - public bool FormattingEnabled { get; private set; } - - public abstract void AddCells(Gtk.TreeViewColumn column); - - public void BindCell(ICellDataSource source, GridColumnHandler column, int columnIndex, ref int dataIndex) - { - Source = source; - Column = column; - ColumnIndex = columnIndex; - this.dataIndex = dataIndex; - BindCell(ref dataIndex); - BindBase(ref dataIndex); - } - - protected void ReBind() - { - if (dataIndex != null) - { - var dataIndexValue = dataIndex.Value; - BindCell(ref dataIndexValue); - BindBase(ref dataIndexValue); - } - } - - protected void BindBase(ref int dataIndex) - { - if (FormattingEnabled) - { - itemCol = SetColumnMap(dataIndex); - Column.Control.AddAttribute(Control, "item", dataIndex++); - rowCol = SetColumnMap(dataIndex); - Column.Control.AddAttribute(Control, "row", dataIndex++); - } - } - - public void Format(GridCellFormatEventArgs args) - { - Source.OnCellFormatting(args); - } - - protected abstract void BindCell(ref int dataIndex); - - protected int SetColumnMap(int dataIndex) - { - Source.SetColumnMap(dataIndex, ColumnIndex); - return dataIndex; - } - - public abstract void SetEditable(Gtk.TreeViewColumn column, bool editable); - - protected void SetValue(string path, object value) - { - SetValue(new Gtk.TreePath(path), value); - } - - protected void SetValue(Gtk.TreePath path, object value) - { - var item = Source.GetItem(path); - SetValue(item, value); - } - - public abstract void SetValue(object dataItem, object value); - - public GLib.Value GetValue(object dataItem, int dataColumn, int row) - { - if (FormattingEnabled) - { - if (dataColumn == itemCol) - return new GLib.Value(dataItem); - if (dataColumn == rowCol) - return new GLib.Value(row); - } - return GetValueInternal(dataItem, dataColumn, row); - } - - protected abstract GLib.Value GetValueInternal(object dataItem, int dataColumn, int row); - - public override void AttachEvent(string id) - { - switch (id) - { - case Grid.CellFormattingEvent: - FormattingEnabled = true; - ReBind(); - break; - default: - base.AttachEvent(id); - break; - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Cells/CheckBoxCellHandler.cs b/Source/Eto.Platform.Gtk/Forms/Cells/CheckBoxCellHandler.cs deleted file mode 100644 index 7a4227a9c3..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Cells/CheckBoxCellHandler.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Cells -{ - public class CheckBoxCellHandler : SingleCellHandler, ICheckBoxCell - { - class Renderer : Gtk.CellRendererToggle - { - WeakReference handler; - public CheckBoxCellHandler Handler { get { return (CheckBoxCellHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [GLib.Property("item")] - public object Item { get; set; } - - [GLib.Property("row")] - public int Row { get; set; } - #if GTK2 - public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); - - // calling base crashes on windows - GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererToggle.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); - //base.Render (window, widget, background_area, cell_area, expose_area, flags); - } - #else - protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); - base.OnRender (cr, widget, background_area, cell_area, flags); - } -#endif - } - - public CheckBoxCellHandler() - { - Control = new Renderer { Handler = this }; - } - - protected override void Initialize() - { - base.Initialize(); - this.Control.Toggled += Connector.HandleToggled; - } - - protected new CheckBoxCellEventConnector Connector { get { return (CheckBoxCellEventConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new CheckBoxCellEventConnector(); - } - - protected class CheckBoxCellEventConnector : SingleCellConnector - { - public new CheckBoxCellHandler Handler { get { return (CheckBoxCellHandler)base.Handler; } } - - public void HandleToggled(object o, Gtk.ToggledArgs args) - { - Handler.SetValue(args.Path, !Handler.Control.Active); - } - - public void HandleEndCellEditing(object o, Gtk.ToggledArgs args) - { - Handler.Source.EndCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); - } - } - - protected override void BindCell(ref int dataIndex) - { - Column.Control.ClearAttributes(Control); - SetColumnMap(dataIndex); - Column.Control.AddAttribute(Control, "active", dataIndex++); - } - - public override void SetEditable(Gtk.TreeViewColumn column, bool editable) - { - Control.Activatable = editable; - } - - public override void SetValue(object dataItem, object value) - { - if (Widget.Binding != null) - { - Widget.Binding.SetValue(dataItem, value); - } - } - - protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) - { - if (Widget.Binding != null) - { - var ret = Widget.Binding.GetValue(dataItem); - if (ret != null) - return new GLib.Value(ret); - } - return new GLib.Value(false); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Grid.CellEditedEvent: - Control.Toggled += Connector.HandleEndCellEditing; - break; - default: - base.AttachEvent(id); - break; - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Cells/ComboBoxCellHandler.cs b/Source/Eto.Platform.Gtk/Forms/Cells/ComboBoxCellHandler.cs deleted file mode 100644 index e1c1b35146..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Cells/ComboBoxCellHandler.cs +++ /dev/null @@ -1,178 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Cells -{ - public class ComboBoxCellHandler : SingleCellHandler, IComboBoxCell - { - CollectionHandler collection; - readonly Gtk.ListStore listStore; - - class Renderer : Gtk.CellRendererCombo - { - WeakReference handler; - public ComboBoxCellHandler Handler { get { return (ComboBoxCellHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [GLib.Property("item")] - public object Item { get; set; } - - [GLib.Property("row")] - public int Row { get; set; } - #if GTK2 - public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkTextCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); - // calling base crashes on windows - GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererCombo.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); - //base.Render (window, widget, background_area, cell_area, expose_area, flags); - } - #else - protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); - base.OnRender (cr, widget, background_area, cell_area, flags); - } -#endif - } - - public ComboBoxCellHandler() - { - listStore = new Gtk.ListStore(typeof(string), typeof(string)); - Control = new Renderer - { - Handler = this, - Model = listStore, - TextColumn = 0, - HasEntry = false - }; - } - - protected override void Initialize() - { - base.Initialize(); - this.Control.Edited += Connector.HandleEdited; - } - - protected new ComboBoxCellEventConnector Connector { get { return (ComboBoxCellEventConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ComboBoxCellEventConnector(); - } - - protected class ComboBoxCellEventConnector : SingleCellConnector - { - public new ComboBoxCellHandler Handler { get { return (ComboBoxCellHandler)base.Handler; } } - - public void HandleEdited(object o, Gtk.EditedArgs args) - { - Handler.SetValue(args.Path, args.NewText); - } - - public void HandleEndEditing(object o, Gtk.EditedArgs args) - { - Handler.Source.EndCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); - } - } - - protected override void BindCell(ref int dataIndex) - { - Column.Control.ClearAttributes(Control); - SetColumnMap(dataIndex); - Column.Control.AddAttribute(Control, "text", dataIndex++); - } - - public override void SetEditable(Gtk.TreeViewColumn column, bool editable) - { - Control.Editable = editable; - } - - public override void SetValue(object dataItem, object value) - { - if (Widget.Binding != null) - { - Widget.Binding.SetValue(dataItem, value); - } - } - - protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) - { - - if (Widget.Binding != null) - { - var ret = Widget.Binding.GetValue(dataItem); - if (ret != null) - return new GLib.Value(ret); - } - - return new GLib.Value((string)null); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Grid.CellEditedEvent: - Control.Edited += Connector.HandleEndEditing; - break; - default: - base.AttachEvent(id); - break; - } - } - - public class CollectionHandler : DataStoreChangedHandler - { - public ComboBoxCellHandler Handler { get; set; } - - public override void AddItem(IListItem item) - { - Handler.listStore.AppendValues(item.Text, item.Key); - } - - public override void InsertItem(int index, IListItem item) - { - Handler.listStore.InsertWithValues(index, item.Text, item.Key); - } - - public override void RemoveItem(int index) - { - Gtk.TreeIter iter; - if (Handler.listStore.IterNthChild(out iter, index)) - Handler.listStore.Remove(ref iter); - } - - public override void RemoveAllItems() - { - Handler.listStore.Clear(); - } - } - - public IListStore DataStore - { - get { return collection != null ? collection.Collection : null; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler{ Handler = this }; - collection.Register(value); - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Cells/ImageTextCellHandler.cs b/Source/Eto.Platform.Gtk/Forms/Cells/ImageTextCellHandler.cs deleted file mode 100644 index a3bfe7fae2..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Cells/ImageTextCellHandler.cs +++ /dev/null @@ -1,184 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp.Forms.Cells -{ - public class ImageTextCellHandler : CellHandler, IImageTextCell - { - readonly Gtk.CellRendererPixbuf imageCell; - int imageDataIndex; - int textDataIndex; - - class Renderer : Gtk.CellRendererText - { - WeakReference handler; - public ImageTextCellHandler Handler { get { return (ImageTextCellHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [GLib.Property("item")] - public object Item { get; set; } - - [GLib.Property("row")] - public int Row { get; set; } - #if GTK2 - public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkTextCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); - - // calling base crashes on windows /w gtk 2.12.9 - GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererText.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); - //base.Render (window, widget, background_area, cell_area, expose_area, flags); - } - #else - protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); - base.OnRender (cr, widget, background_area, cell_area, flags); - } -#endif - } - - class ImageRenderer : Gtk.CellRendererPixbuf - { - public ImageTextCellHandler Handler { get; set; } - - [GLib.Property("item")] - public object Item { get; set; } - - [GLib.Property("row")] - public int Row { get; set; } - #if GTK2 - protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); - - // calling base crashes on windows /w gtk 2.12.9 - GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererPixbuf.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); - //base.Render (window, widget, background_area, cell_area, expose_area, flags); - } - #else - protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); - base.OnRender (cr, widget, background_area, cell_area, flags); - } -#endif - } - - public ImageTextCellHandler() - { - imageCell = new ImageRenderer { Handler = this }; - Control = new Renderer { Handler = this }; - } - - protected override void Initialize() - { - base.Initialize(); - this.Control.Edited += Connector.HandleEdited; - } - - protected new ImageTextCellEventConnector Connector { get { return (ImageTextCellEventConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ImageTextCellEventConnector(); - } - - protected class ImageTextCellEventConnector : WeakConnector - { - public new ImageTextCellHandler Handler { get { return (ImageTextCellHandler)base.Handler; } } - - public void HandleEdited(object o, Gtk.EditedArgs args) - { - Handler.SetValue(args.Path, args.NewText); - } - - public void HandleEndCellEditing(object o, Gtk.EditedArgs args) - { - Handler.Source.EndCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); - } - } - - public override void AddCells(Gtk.TreeViewColumn column) - { - column.PackStart(imageCell, false); - column.PackStart(Control, true); - } - - protected override void BindCell(ref int dataIndex) - { - Column.Control.ClearAttributes(Control); - imageDataIndex = SetColumnMap(dataIndex); - Column.Control.AddAttribute(imageCell, "pixbuf", dataIndex++); - textDataIndex = SetColumnMap(dataIndex); - Column.Control.AddAttribute(Control, "text", dataIndex++); - BindBase(ref dataIndex); - } - - public override void SetEditable(Gtk.TreeViewColumn column, bool editable) - { - Control.Editable = editable; - } - - public override void SetValue(object dataItem, object value) - { - if (Widget.TextBinding != null) - { - Widget.TextBinding.SetValue(dataItem, value); - } - } - - protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) - { - if (dataColumn == imageDataIndex) - { - if (Widget.ImageBinding != null) - { - var ret = Widget.ImageBinding.GetValue(dataItem); - var image = ret as Image; - if (image != null) - return new GLib.Value(((IGtkPixbuf)image.Handler).GetPixbuf(new Size(16, 16))); - } - return new GLib.Value((Gdk.Pixbuf)null); - } - if (dataColumn == textDataIndex) - { - var ret = Widget.TextBinding.GetValue(dataItem); - if (ret != null) - return new GLib.Value(Convert.ToString(ret)); - } - return new GLib.Value((string)null); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Grid.CellEditedEvent: - Control.Edited += Connector.HandleEndCellEditing; - break; - default: - base.AttachEvent(id); - break; - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Cells/ImageViewCellHandler.cs b/Source/Eto.Platform.Gtk/Forms/Cells/ImageViewCellHandler.cs deleted file mode 100644 index 5197e6cee9..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Cells/ImageViewCellHandler.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp.Forms.Cells -{ - public class ImageViewCellHandler : SingleCellHandler, IImageViewCell - { - class Renderer : Gtk.CellRendererPixbuf - { - WeakReference handler; - public ImageViewCellHandler Handler { get { return (ImageViewCellHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [GLib.Property("item")] - public object Item { get; set; } - - [GLib.Property("row")] - public int Row { get; set; } - -#if GTK2 - public override void GetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void Render (Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); - - // calling base crashes on windows - GtkCell.gtksharp_cellrenderer_invoke_render (Gtk.CellRendererPixbuf.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); - //base.Render (window, widget, background_area, cell_area, expose_area, flags); - } -#else - protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); - base.OnRender (cr, widget, background_area, cell_area, flags); - } -#endif - } - - - public ImageViewCellHandler () - { - Control = new Renderer { Handler = this }; - } - - protected override void BindCell (ref int dataIndex) - { - Column.Control.ClearAttributes (Control); - SetColumnMap (dataIndex); - Column.Control.AddAttribute (Control, "pixbuf", dataIndex++); - } - - public override void SetEditable (Gtk.TreeViewColumn column, bool editable) - { - } - - public override void SetValue (object dataItem, object value) - { - // can't set - } - - protected override GLib.Value GetValueInternal (object dataItem, int dataColumn, int row) - { - if (Widget.Binding != null) { - var ret = Widget.Binding.GetValue (dataItem); - var image = ret as Image; - if (image != null) - return new GLib.Value(((IGtkPixbuf)image.Handler).GetPixbuf (new Size (16, 16))); - } - return new GLib.Value((Gdk.Pixbuf)null); - } - - public override void AttachEvent (string id) - { - switch (id) { - case Grid.CellEditedEvent: - // no editing here - break; - default: - base.AttachEvent (id); - break; - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Cells/TextBoxCellHandler.cs b/Source/Eto.Platform.Gtk/Forms/Cells/TextBoxCellHandler.cs deleted file mode 100644 index dff724a5bb..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Cells/TextBoxCellHandler.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Cells -{ - public class TextBoxCellHandler : SingleCellHandler, ITextBoxCell - { - class Renderer : Gtk.CellRendererText - { - WeakReference handler; - public TextBoxCellHandler Handler { get { return (TextBoxCellHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [GLib.Property("item")] - public object Item { get; set; } - - [GLib.Property("row")] - public int Row { get; set; } - #if GTK2 - public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkTextCellFormatEventArgs(this, Handler.Column.Widget, Item, Row)); - - // calling base crashes on windows - GtkCell.gtksharp_cellrenderer_invoke_render(Gtk.CellRendererText.GType.Val, Handle, window.Handle, widget.Handle, ref background_area, ref cell_area, ref expose_area, flags); - //base.Render (window, widget, background_area, cell_area, expose_area, flags); - } - #else - protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) - { - base.OnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); - height = Math.Max(height, Handler.Source.RowHeight); - } - - protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) - { - if (Handler.FormattingEnabled) - Handler.Format(new GtkGridCellFormatEventArgs (this, Handler.Column.Widget, Item, Row)); - base.OnRender (cr, widget, background_area, cell_area, flags); - } -#endif - } - - public TextBoxCellHandler() - { - Control = new Renderer { Handler = this }; - } - - protected override void Initialize() - { - base.Initialize(); - this.Control.Edited += Connector.HandleEdited; - } - - protected new TextBoxCellEventConnector Connector { get { return (TextBoxCellEventConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new TextBoxCellEventConnector(); - } - - protected class TextBoxCellEventConnector : SingleCellConnector - { - public new TextBoxCellHandler Handler { get { return (TextBoxCellHandler)base.Handler; } } - - public void HandleEdited(object o, Gtk.EditedArgs args) - { - Handler.SetValue(args.Path, args.NewText); - } - - public void HandleEndEditing(object o, Gtk.EditedArgs args) - { - Handler.Source.EndCellEditing(new Gtk.TreePath(args.Path), Handler.ColumnIndex); - } - } - - protected override void BindCell(ref int dataIndex) - { - Column.Control.ClearAttributes(Control); - SetColumnMap(dataIndex); - Column.Control.AddAttribute(Control, "text", dataIndex++); - } - - public override void SetEditable(Gtk.TreeViewColumn column, bool editable) - { - Control.Editable = editable; - } - - public override void SetValue(object dataItem, object value) - { - if (Widget.Binding != null) - { - Widget.Binding.SetValue(dataItem, value); - } - } - - protected override GLib.Value GetValueInternal(object dataItem, int dataColumn, int row) - { - if (Widget.Binding != null) - { - var ret = Widget.Binding.GetValue(dataItem); - if (ret != null) - return new GLib.Value(Convert.ToString(ret)); - } - return new GLib.Value((string)null); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Grid.CellEditedEvent: - Control.Edited += Connector.HandleEndEditing; - break; - default: - base.AttachEvent(id); - break; - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/ClipboardHandler.cs b/Source/Eto.Platform.Gtk/Forms/ClipboardHandler.cs deleted file mode 100644 index a0e86abb8a..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ClipboardHandler.cs +++ /dev/null @@ -1,182 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using System.Linq; -using Eto.Platform.GtkSharp.Drawing; -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp.Forms -{ - public class ClipboardHandler : WidgetHandler, IClipboard - { - delegate void GetClipboardData(ClipboardData data,Gtk.SelectionData selection); - - class ClipboardData - { - public Gtk.TargetEntry Target { get; set; } - - public object Data { get; set; } - - public GetClipboardData GetClipboardData { get; set; } - - public void GetData(Gtk.SelectionData selectionData) - { - if (GetClipboardData != null) - GetClipboardData(this, selectionData); - } - } - - readonly List clipboard = new List(); - - public ClipboardHandler() - { - Control = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false)); - } - - void Update() - { - var targets = clipboard.Select(r => r.Target); - Control.SetWithData(targets.ToArray(), (clip, selectionData, info) => - { - if (info < clipboard.Count) - { - var clipdata = clipboard[(int)info]; - clipdata.GetData(selectionData); - } - }, clip => - { - - }); - } - - void AddEntry(string type, object data, GetClipboardData getData) - { - clipboard.Add(new ClipboardData - { - Target = new Gtk.TargetEntry(type, 0, (uint)clipboard.Count), - Data = data, - GetClipboardData = getData - }); - Update(); - } - - Gtk.SelectionData GetSelectionData(string type) - { - var target = Gdk.Atom.Intern(type, false); - if (Control.WaitIsTargetAvailable(target)) - { - var data = Control.WaitForContents(target); - if (data != null) - return data; - } - return null; - } - - #region IClipboard implementation - - public void SetString(string value, string type) - { - AddEntry(type, value, delegate(ClipboardData data, Gtk.SelectionData selection) - { - selection.Text = data.Data as string; - }); - } - - public string Html - { - set - { - AddEntry("text/html", value, delegate(ClipboardData data, Gtk.SelectionData selection) - { - selection.Text = data.Data as string; - }); - } - get - { - var selection = GetSelectionData("text/html"); - return selection != null ? selection.Text : null; - } - } - - public string Text - { - set - { - AddEntry("UTF8_STRING", value, delegate(ClipboardData data, Gtk.SelectionData selection) - { - selection.Text = data.Data as string; - }); - } - get { return Control.WaitForText(); } - - } - - public Image Image - { - set - { - var pixbuf = value.ControlObject as Gdk.Pixbuf; - /* TODO: AddEntry(type, value, delegate(ClipboardData data, Gtk.SelectionData selection) { - selection = value; - });*/ - if (pixbuf != null) - Control.Image = pixbuf; - else - throw new NotSupportedException(); - } - get - { - var image = Control.WaitForImage(); - if (image != null) - { - var handler = new BitmapHandler(image); - return new Bitmap(Widget.Generator, handler); - } - return null; - } - } - - public void SetData(byte[] value, string type) - { - AddEntry(type, value, delegate(ClipboardData data, Gtk.SelectionData selection) - { - selection.Set(Gdk.Atom.Intern(type, false), 0, value); - }); - } - - public string GetString(string type) - { - var selection = GetSelectionData(type); - return selection != null ? selection.Text : null; - } - - public byte[] GetData(string type) - { - var selection = GetSelectionData(type); - return selection != null && selection.Length > 0 ? selection.Data : null; - } - - public void Clear() - { - Control.Clear(); - clipboard.Clear(); - } - - public string[] Types - { - get - { - //return Control.Data.Keys.OfType ().ToArray (); - return null; - } - } - - #endregion - - #region IWidget implementation - - #endregion - - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/ColorDialogHandler.cs b/Source/Eto.Platform.Gtk/Forms/ColorDialogHandler.cs deleted file mode 100644 index b0d58d7646..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ColorDialogHandler.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms -{ - public class ColorDialogHandler : WidgetHandler, IColorDialog - { - public ColorDialogHandler () - { - Control = new Gtk.ColorSelectionDialog(string.Empty); - - } - - public Eto.Drawing.Color Color { - get { return Control.ColorSelection.CurrentColor.ToEto (); } - set { Control.ColorSelection.CurrentColor = value.ToGdk (); } - } - - public DialogResult ShowDialog (Window parent) - { - if (parent != null) - { - Control.TransientFor = ((Gtk.Window)parent.ControlObject); - Control.Modal = true; - } - - Control.ShowAll (); - var response = (Gtk.ResponseType)Control.Run (); - Control.Hide (); - - if (response == Gtk.ResponseType.Ok) { - Widget.OnColorChanged(EventArgs.Empty); - } - return response.ToEto (); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/ButtonHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/ButtonHandler.cs deleted file mode 100644 index 06e54bf710..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/ButtonHandler.cs +++ /dev/null @@ -1,172 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - /// - /// Button handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class ButtonHandler : GtkControl, IButton - { - Image image; - readonly Gtk.AccelLabel label; - readonly Gtk.Image gtkimage; - readonly Gtk.Table table; - readonly Size defaultSize = Button.DefaultSize; - ButtonImagePosition imagePosition; - - protected override Gtk.Widget FontControl - { - get { return label; } - } - - public ButtonHandler() - { - Control = new Gtk.Button(); - - // need separate widgets as the theme can (and usually) disables images on buttons - // gtk3 can override the theme per button, but gtk2 cannot - table = new Gtk.Table(3, 3, false); - table.ColumnSpacing = 0; - table.RowSpacing = 0; - label = new Gtk.AccelLabel(string.Empty); - label.NoShowAll = true; - table.Attach(label, 1, 2, 1, 2, Gtk.AttachOptions.Expand, Gtk.AttachOptions.Expand, 0, 0); - gtkimage = new Gtk.Image(); - gtkimage.NoShowAll = true; - SetImagePosition(false); - Control.Add(table); - } - - protected override void Initialize() - { - base.Initialize(); - Control.Clicked += Connector.HandleClicked; - Control.SizeAllocated += Connector.HandleButtonSizeAllocated; - } - - protected new ButtonConnector Connector { get { return (ButtonConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ButtonConnector(); - } - - protected class ButtonConnector : GtkControlConnector - { - public new ButtonHandler Handler { get { return (ButtonHandler)base.Handler; } } - - public void HandleClicked(object sender, EventArgs e) - { - Handler.Widget.OnClick(EventArgs.Empty); - } - - public void HandleButtonSizeAllocated(object o, Gtk.SizeAllocatedArgs args) - { - var handler = Handler; - if (handler != null) - { - var c = (Gtk.Button)o; - var size = args.Allocation; - if (size.Width > 1 || size.Height > 1) - { - var defaultSize = handler.defaultSize; - if (defaultSize.Width > size.Width) - size.Width = defaultSize.Width; - if (defaultSize.Height > size.Height) - size.Height = defaultSize.Height; - if (args.Allocation != size) - c.SetSizeRequest(size.Width, size.Height); - } - } - } - } - - public override string Text - { - get { return MnuemonicToString(label.Text); } - set - { - label.TextWithMnemonic = StringToMnuemonic(value); - SetImagePosition(); - } - } - - public Image Image - { - get { return image; } - set - { - image = value; - image.SetGtkImage(gtkimage); - if (value == null) - gtkimage.Hide(); - else - gtkimage.Show(); - } - } - - void SetImagePosition(bool removeImage = true) - { - uint left, top; - bool shouldHideLabel = false; - - switch (ImagePosition) - { - case ButtonImagePosition.Above: - left = 1; - top = 0; - shouldHideLabel = true; - break; - case ButtonImagePosition.Below: - left = 1; - top = 2; - shouldHideLabel = true; - break; - case ButtonImagePosition.Left: - left = 0; - top = 1; - break; - case ButtonImagePosition.Right: - left = 2; - top = 1; - break; - case ButtonImagePosition.Overlay: - left = 1; - top = 1; - break; - default: - throw new NotSupportedException(); - } - shouldHideLabel &= string.IsNullOrEmpty(label.Text); - if (shouldHideLabel) - label.Hide(); - else - label.Show(); - - var right = left + 1; - var bottom = top + 1; - var options = shouldHideLabel ? Gtk.AttachOptions.Expand : Gtk.AttachOptions.Shrink; - if (removeImage) - table.Remove(gtkimage); - table.Attach(gtkimage, left, right, top, bottom, options, options, 0, 0); - - } - - public ButtonImagePosition ImagePosition - { - get { return imagePosition; } - set - { - if (imagePosition != value) - { - imagePosition = value; - SetImagePosition(); - } - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/CheckBoxHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/CheckBoxHandler.cs deleted file mode 100644 index ab6c1cdd60..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/CheckBoxHandler.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class CheckBoxHandler : GtkControl, ICheckBox - { - Font font; - readonly Gtk.EventBox box; - - public override Gtk.Widget ContainerControl - { - get { return box; } - } - - public CheckBoxHandler() - { - Control = new Gtk.CheckButton(); - box = new Gtk.EventBox { Child = Control }; - } - - protected override void Initialize() - { - base.Initialize(); - Control.Toggled += Connector.HandleToggled; - } - - protected new CheckBoxConnector Connector { get { return (CheckBoxConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new CheckBoxConnector(); - } - - protected class CheckBoxConnector : GtkControlConnector - { - bool toggling; - public new CheckBoxHandler Handler { get { return (CheckBoxHandler)base.Handler; } } - - public void HandleToggled(object sender, EventArgs e) - { - var h = Handler; - var c = h.Control; - if (toggling) - return; - - toggling = true; - if (h.ThreeState) - { - if (!c.Inconsistent && c.Active) - c.Inconsistent = true; - else if (c.Inconsistent) - { - c.Inconsistent = false; - c.Active = true; - } - } - h.Widget.OnCheckedChanged(EventArgs.Empty); - toggling = false; - - } - } - - public override string Text - { - get { return MnuemonicToString(Control.Label); } - set { Control.Label = StringToMnuemonic(value); } - } - - public override Font Font - { - get - { - if (font == null) - font = new Font(Widget.Generator, new FontHandler(Control.Child)); - return font; - } - set - { - font = value; - if (font != null) - Control.Child.ModifyFont(((FontHandler)font.Handler).Control); - else - Control.Child.ModifyFont(null); - } - } - - public bool? Checked - { - get { return Control.Inconsistent ? null : (bool?)Control.Active; } - set - { - if (value == null) - Control.Inconsistent = true; - else - { - Control.Inconsistent = false; - Control.Active = value.Value; - } - } - } - - public bool ThreeState - { - get; - set; - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/ComboBoxHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/ComboBoxHandler.cs deleted file mode 100644 index 8772401e58..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/ComboBoxHandler.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class ComboBoxHandler : GtkControl, IComboBox - { - Font font; - CollectionHandler collection; - readonly Gtk.ListStore listStore; - readonly Gtk.CellRendererText text; - - public ComboBoxHandler() - { - listStore = new Gtk.ListStore(typeof(string)); - Control = new Gtk.ComboBox(listStore); - text = new Gtk.CellRendererText(); - Control.PackStart(text, false); - Control.AddAttribute(text, "text", 0); - } - - protected override void Initialize() - { - base.Initialize(); - Control.Changed += Connector.HandleChanged; - } - - protected new ComboBoxConnector Connector { get { return (ComboBoxConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ComboBoxConnector(); - } - - protected class ComboBoxConnector : GtkControlConnector - { - public new ComboBoxHandler Handler { get { return (ComboBoxHandler)base.Handler; } } - - public void HandleChanged(object sender, EventArgs e) - { - Handler.Widget.OnSelectedIndexChanged(EventArgs.Empty); - } - } - - public int SelectedIndex - { - get { return Control.Active; } - set { Control.Active = value; } - } - - public override Font Font - { - get - { - if (font == null) - font = new Font(Widget.Generator, new FontHandler(text.FontDesc)); - return font; - } - set - { - font = value; - text.FontDesc = font != null ? ((FontHandler)font.Handler).Control : null; - } - } - - public class CollectionHandler : DataStoreChangedHandler - { - public ComboBoxHandler Handler { get; set; } - - public override void AddItem(IListItem item) - { - Handler.listStore.AppendValues(item.Text); - } - - public override void InsertItem(int index, IListItem item) - { - Handler.listStore.InsertWithValues(index, item.Text); - } - - public override void RemoveItem(int index) - { - Gtk.TreeIter iter; - if (Handler.listStore.IterNthChild(out iter, index)) - Handler.listStore.Remove(ref iter); - } - - public override void RemoveAllItems() - { - Handler.listStore.Clear(); - } - } - - public IListStore DataStore - { - get { return collection != null ? collection.Collection : null; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler{ Handler = this }; - collection.Register(value); - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/DateTimePickerHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/DateTimePickerHandler.cs deleted file mode 100644 index c1c165ba8d..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/DateTimePickerHandler.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class DateTimePickerHandler : GtkControl, IDateTimePicker - { - public DateTimePickerHandler() - { - Control = new CustomControls.DateComboBox(); - this.Mode = DateTimePicker.DefaultMode; - } - - protected override void Initialize() - { - base.Initialize(); - Control.DateChanged += Connector.HandleDateChanged; - } - - protected new DateTimePickerConnector Connector { get { return (DateTimePickerConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new DateTimePickerConnector(); - } - - protected class DateTimePickerConnector : GtkControlConnector - { - public new DateTimePickerHandler Handler { get { return (DateTimePickerHandler)base.Handler; } } - - public void HandleDateChanged(object sender, EventArgs e) - { - Handler.Widget.OnValueChanged(EventArgs.Empty); - } - } - - protected override Gtk.Widget FontControl - { - get { return Control.Entry; } - } - - public DateTime? Value - { - get { return Control.SelectedDate; } - set { Control.SelectedDate = value; } - } - - public DateTime MinDate - { - get { return Control.MinDate; } - set { Control.MinDate = value; } - } - - public DateTime MaxDate - { - get { return Control.MaxDate; } - set { Control.MaxDate = value; } - } - - public DateTimePickerMode Mode - { - get { return Control.Mode; } - set { Control.Mode = value; } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/DrawableHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/DrawableHandler.cs deleted file mode 100644 index 18249abedd..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/DrawableHandler.cs +++ /dev/null @@ -1,104 +0,0 @@ -using Eto.Drawing; -using Eto.Forms; -using Eto.Platform.GtkSharp.Drawing; -using System; - -namespace Eto.Platform.GtkSharp -{ - public class DrawableHandler : GtkPanel, IDrawable - { - Gtk.VBox content; - - public bool SupportsCreateGraphics { get { return true; } } - - public void Create() - { - Control = new Gtk.EventBox(); -#if GTK2 - Control.ExposeEvent += Connector.HandleExpose; -#else - Control.Drawn += Connector.HandleDrawn; -#endif - Control.Events |= Gdk.EventMask.ExposureMask; - //Control.ModifyBg(Gtk.StateType.Normal, new Gdk.Color(0, 0, 0)); - //Control.DoubleBuffered = false; - Control.CanFocus = false; - Control.CanDefault = true; - Control.Events |= Gdk.EventMask.ButtonPressMask; - - content = new Gtk.VBox(); - - Control.Add(content); - } - - protected override void Initialize() - { - base.Initialize(); - Control.ButtonPressEvent += Connector.HandleDrawableButtonPressEvent; - } - - public bool CanFocus - { - get { return Control.CanFocus; } - set { Control.CanFocus = value; } - } - - protected new DrawableConnector Connector { get { return (DrawableConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new DrawableConnector(); - } - - protected class DrawableConnector : GtkPanelEventConnector - { - public new DrawableHandler Handler { get { return (DrawableHandler)base.Handler; } } - - public void HandleDrawableButtonPressEvent(object o, Gtk.ButtonPressEventArgs args) - { - if (Handler.CanFocus) - Handler.Control.GrabFocus(); - } - -#if GTK2 - public void HandleExpose(object o, Gtk.ExposeEventArgs args) - { - var h = Handler; - Gdk.EventExpose ev = args.Event; - using (var graphics = new Graphics(h.Widget.Generator, new GraphicsHandler(h.Control, ev.Window))) - { - Rectangle rect = ev.Region.Clipbox.ToEto(); - h.Widget.OnPaint(new PaintEventArgs(graphics, rect)); - } - } -#else - public void HandleDrawn(object o, Gtk.DrawnArgs args) - { - var h = Handler; - using (var graphics = new Graphics(h.Widget.Generator, new GraphicsHandler(args.Cr, h.Control.CreatePangoContext(), false))) - { - h.Widget.OnPaint (new PaintEventArgs (graphics, new Rectangle(h.Size))); - } - } -#endif - } - - public void Update(Rectangle rect) - { - using (var graphics = new Graphics(Widget.Generator, new GraphicsHandler(Control, Control.GdkWindow))) - { - Widget.OnPaint(new PaintEventArgs(graphics, rect)); - } - } - - public Graphics CreateGraphics() - { - return new Graphics(Widget.Generator, new GraphicsHandler(Control, Control.GdkWindow)); - } - - protected override void SetContainerContent(Gtk.Widget content) - { - this.content.Add(content); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/GridColumnHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/GridColumnHandler.cs deleted file mode 100644 index ba65253c0d..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/GridColumnHandler.cs +++ /dev/null @@ -1,177 +0,0 @@ -using Eto.Forms; -using Eto.Platform.GtkSharp.Forms.Cells; -using System; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public interface IGridHandler - { - bool IsEventHandled(string handler); - - void ColumnClicked(GridColumnHandler column); - } - - public interface IGridColumnHandler - { - GLib.Value GetValue(object dataItem, int dataColumn, int row); - - void BindCell(IGridHandler grid, ICellDataSource source, int columnIndex, ref int dataIndex); - } - - public class GridColumnHandler : WidgetHandler, IGridColumn, IGridColumnHandler - { - Cell dataCell; - bool autoSize; - bool editable; - bool cellsAdded; - IGridHandler grid; - - public GridColumnHandler() - { - Control = new Gtk.TreeViewColumn(); - AutoSize = true; - Resizable = true; - } - - protected override void Initialize() - { - base.Initialize(); - DataCell = new TextBoxCell(Widget.Generator); - } - - public string HeaderText - { - get { return Control.Title; } - set { Control.Title = value; } - } - - public bool Resizable - { - get { return Control.Resizable; } - set { Control.Resizable = value; } - } - - public bool Sortable - { - get { return Control.Clickable; } - set { Control.Clickable = value; } - } - - public bool AutoSize - { - get - { - return autoSize; - } - set - { - autoSize = value; - Control.Sizing = value ? Gtk.TreeViewColumnSizing.GrowOnly : Gtk.TreeViewColumnSizing.Fixed; - } - } - - void SetCellAttributes() - { - if (dataCell != null) - { - ((ICellHandler)dataCell.Handler).SetEditable(Control, editable); - SetupEvents(); - } - } - - public bool Editable - { - get - { - return editable; - } - set - { - editable = value; - SetCellAttributes(); - } - } - - public int Width - { - get { return Control.Width; } - set { Control.FixedWidth = value; } - } - - public Cell DataCell - { - get - { - return dataCell; - } - set - { - dataCell = value; - } - } - - public bool Visible - { - get { return Control.Visible; } - set { Control.Visible = value; } - } - - public void BindCell(IGridHandler grid, ICellDataSource source, int columnIndex, ref int dataIndex) - { - this.grid = grid; - if (dataCell != null) - { - var cellhandler = (ICellHandler)dataCell.Handler; - if (!cellsAdded) - { - cellhandler.AddCells(Control); - cellsAdded = true; - } - SetCellAttributes(); - cellhandler.BindCell(source, this, columnIndex, ref dataIndex); - } - SetupEvents(); - } - - public void SetupEvents() - { - if (grid == null) - return; - if (grid.IsEventHandled(Grid.CellEditingEvent)) - HandleEvent(Grid.CellEditingEvent); - if (grid.IsEventHandled(Grid.CellEditedEvent)) - HandleEvent(Grid.CellEditedEvent); - if (grid.IsEventHandled(Grid.ColumnHeaderClickEvent)) - HandleEvent(Grid.ColumnHeaderClickEvent); - if (grid.IsEventHandled(Grid.CellFormattingEvent)) - HandleEvent(Grid.CellFormattingEvent); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Grid.ColumnHeaderClickEvent: - var handler = new WeakReference(this); - Control.Clicked += (sender, e) => - { - var h = ((GridColumnHandler)handler.Target); - if (h.grid != null) - h.grid.ColumnClicked(h); - }; - break; - default: - ((ICellHandler)dataCell.Handler).HandleEvent(id); - break; - } - } - - public GLib.Value GetValue(object dataItem, int dataColumn, int row) - { - if (dataCell != null) - return ((ICellHandler)dataCell.Handler).GetValue(dataItem, dataColumn, row); - return new GLib.Value((string)null); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/GridHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/GridHandler.cs deleted file mode 100644 index 96dac69a2e..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/GridHandler.cs +++ /dev/null @@ -1,271 +0,0 @@ -using System; -using Eto.Forms; -using System.Linq; -using System.Collections.Generic; -using Eto.Platform.GtkSharp.Forms.Cells; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public abstract class GridHandler : GtkControl, IGrid, ICellDataSource, IGridHandler - where TWidget : Grid - { - ColumnCollection columns; - ContextMenu contextMenu; - readonly Dictionary columnMap = new Dictionary(); - - protected bool SkipSelectedChange { get; set; } - - protected Gtk.TreeView Tree { get; private set; } - - protected Dictionary ColumnMap { get { return columnMap; } } - - protected GridHandler() - { - Control = new Gtk.ScrolledWindow - { - ShadowType = Gtk.ShadowType.In - }; - } - - protected abstract ITreeModelImplementor CreateModelImplementor(); - - protected void UpdateModel() - { - Tree.Model = new Gtk.TreeModelAdapter(CreateModelImplementor()); - } - - protected override void Initialize() - { - base.Initialize(); - Tree = new Gtk.TreeView(); - UpdateModel(); - Tree.HeadersVisible = true; - - Control.Add(Tree); - - Tree.Events |= Gdk.EventMask.ButtonPressMask; - Tree.ButtonPressEvent += Connector.HandleTreeButtonPressEvent; - - columns = new ColumnCollection { Handler = this }; - columns.Register(Widget.Columns); - } - - protected new GridConnector Connector { get { return (GridConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new GridConnector(); - } - - protected class GridConnector : GtkControlConnector - { - public new GridHandler Handler { get { return (GridHandler)base.Handler; } } - - [GLib.ConnectBefore] - public void HandleTreeButtonPressEvent(object o, Gtk.ButtonPressEventArgs args) - { - var handler = Handler; - if (handler.contextMenu != null && args.Event.Button == 3 && args.Event.Type == Gdk.EventType.ButtonPress) - { - var menu = ((ContextMenuHandler)handler.contextMenu.Handler).Control; - menu.Popup(); - menu.ShowAll(); - } - } - - public void HandleGridSelectionChanged(object sender, EventArgs e) - { - if (!Handler.SkipSelectedChange) - Handler.Widget.OnSelectionChanged(EventArgs.Empty); - } - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Grid.ColumnHeaderClickEvent: - case Grid.CellEditingEvent: - case Grid.CellEditedEvent: - case Grid.CellFormattingEvent: - SetupColumnEvents(); - break; - case Grid.SelectionChangedEvent: - Tree.Selection.Changed += Connector.HandleGridSelectionChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - Tree.AppendColumn(new Gtk.TreeViewColumn()); - } - - void SetupColumnEvents() - { - foreach (var col in Widget.Columns.Select(r => r.Handler).OfType()) - { - col.SetupEvents(); - } - } - - protected virtual void UpdateColumns() - { - columnMap.Clear(); - int columnIndex = 0; - int dataIndex = 0; - foreach (var col in Widget.Columns.Select(r => r.Handler).OfType()) - { - col.BindCell(this, this, columnIndex++, ref dataIndex); - } - } - - class ColumnCollection : EnumerableChangedHandler - { - public GridHandler Handler { get; set; } - - public override void AddItem(GridColumn item) - { - var colhandler = (GridColumnHandler)item.Handler; - Handler.Tree.AppendColumn(colhandler.Control); - Handler.UpdateColumns(); - } - - public override void InsertItem(int index, GridColumn item) - { - var colhandler = (GridColumnHandler)item.Handler; - if (Handler.Tree.Columns.Length > 0) - Handler.Tree.InsertColumn(colhandler.Control, index); - else - Handler.Tree.AppendColumn(colhandler.Control); - Handler.UpdateColumns(); - } - - public override void RemoveItem(int index) - { - var colhandler = (GridColumnHandler)Handler.Widget.Columns[index].Handler; - Handler.Tree.RemoveColumn(colhandler.Control); - Handler.UpdateColumns(); - } - - public override void RemoveAllItems() - { - foreach (var col in Handler.Tree.Columns) - { - Handler.Tree.RemoveColumn(col); - } - Handler.UpdateColumns(); - } - - } - - public bool ShowHeader - { - get { return Tree.HeadersVisible; } - set { Tree.HeadersVisible = value; } - } - - public bool AllowColumnReordering - { - get { return Tree.Reorderable; } - set { Tree.Reorderable = value; } - } - - public int NumberOfColumns - { - get - { - return Widget.Columns.Count; - } - } - - public abstract object GetItem(Gtk.TreePath path); - - public abstract Gtk.TreeIter GetIterAtRow(int row); - - public void SetColumnMap(int dataIndex, int column) - { - columnMap[dataIndex] = column; - } - - public ContextMenu ContextMenu - { - get { return contextMenu; } - set { contextMenu = value; } - } - - public void EndCellEditing(Gtk.TreePath path, int column) - { - var row = path.Indices.Length > 0 ? path.Indices[0] : -1; - var item = GetItem(path); - Widget.OnCellEdited(new GridViewCellArgs(Widget.Columns[column], row, column, item)); - } - - public void BeginCellEditing(Gtk.TreePath path, int column) - { - var row = path.Indices.Length > 0 ? path.Indices[0] : -1; - var item = GetItem(path); - Widget.OnCellEditing(new GridViewCellArgs(Widget.Columns[column], row, column, item)); - } - - public void ColumnClicked(GridColumnHandler column) - { - Widget.OnColumnHeaderClick(new GridColumnEventArgs(column.Widget)); - } - - public bool AllowMultipleSelection - { - get { return Tree.Selection.Mode == Gtk.SelectionMode.Multiple; } - set { Tree.Selection.Mode = value ? Gtk.SelectionMode.Multiple : Gtk.SelectionMode.Browse; } - } - - public virtual IEnumerable SelectedRows - { - get - { - var rows = Tree.Selection.GetSelectedRows(); - foreach (var row in rows) - { - yield return row.Indices[0]; - } - } - } - - public int RowHeight - { - get; - set; - } - - public void SelectAll() - { - Tree.Selection.SelectAll(); - } - - public void SelectRow(int row) - { - Tree.Selection.SelectIter(GetIterAtRow(row)); - } - - public void UnselectRow(int row) - { - Tree.Selection.UnselectIter(GetIterAtRow(row)); - } - - public void UnselectAll() - { - Tree.Selection.UnselectAll(); - } - - public void OnCellFormatting(GridCellFormatEventArgs args) - { - Widget.OnCellFormatting(args); - } - - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/GridViewHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/GridViewHandler.cs deleted file mode 100644 index aeccd954f9..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/GridViewHandler.cs +++ /dev/null @@ -1,121 +0,0 @@ -using Eto.Forms; -using System.Collections.Generic; -using Eto.Platform.GtkSharp.Forms.Cells; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class GridViewHandler : GridHandler, IGridView, ICellDataSource, IGtkListModelHandler - { - GtkListModel model; - CollectionHandler collection; - bool showCellBorders; - - protected override ITreeModelImplementor CreateModelImplementor() - { - model = new GtkListModel { Handler = this }; - return model; - } - - public class CollectionHandler : DataStoreChangedHandler - { - public GridViewHandler Handler { get; set; } - - public override void AddRange(IEnumerable items) - { - Handler.UpdateModel(); - } - - public override void AddItem(object item) - { - var iter = Handler.model.GetIterAtRow(Collection.Count); - var path = Handler.model.GetPathAtRow(Collection.Count); - Handler.Tree.Model.EmitRowInserted(path, iter); - } - - public override void InsertItem(int index, object item) - { - var iter = Handler.model.GetIterAtRow(index); - var path = Handler.model.GetPathAtRow(index); - Handler.Tree.Model.EmitRowInserted(path, iter); - } - - public override void RemoveItem(int index) - { - var path = Handler.model.GetPathAtRow(index); - Handler.Tree.Model.EmitRowDeleted(path); - } - - public override void RemoveAllItems() - { - Handler.UpdateModel(); - } - } - - public IDataStore DataStore - { - get { return collection != null ? collection.Collection : null; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler { Handler = this }; - collection.Register(value); - } - } - - public bool ShowCellBorders - { - get { return showCellBorders; } - set - { - if (showCellBorders != value) - { - showCellBorders = value; - SetBorders(); - } - } - } - - protected override void UpdateColumns() - { - base.UpdateColumns(); - SetBorders(); - } - - void SetBorders() - { - int spacing = showCellBorders ? 10 : 0; - foreach (var column in Tree.Columns) - { - column.Spacing = spacing; - } - } - - public override Gtk.TreeIter GetIterAtRow(int row) - { - return model.GetIterAtRow(row); - } - - public override object GetItem(Gtk.TreePath path) - { - return model.GetItemAtPath(path); - } - - public GLib.Value GetColumnValue(object item, int dataColumn, int row) - { - int column; - if (ColumnMap.TryGetValue(dataColumn, out column)) - { - var colHandler = (IGridColumnHandler)Widget.Columns[column].Handler; - return colHandler.GetValue(item, dataColumn, row); - } - return new GLib.Value((string)null); - } - - public int GetRowOfItem(object item) - { - return collection != null ? collection.IndexOf(item) : -1; - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/GroupBoxHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/GroupBoxHandler.cs deleted file mode 100644 index c800a9b169..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/GroupBoxHandler.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class GroupBoxHandler : GtkPanel, IGroupBox - { - public GroupBoxHandler () - { - Control = new Gtk.Frame (); - } - - protected override Gtk.Widget FontControl - { - get { return Control.LabelWidget; } - } - - public override string Text { - get { return Control.Label; } - set { Control.Label = value; } - } - - public override Size ClientSize { - get { - if (Control.Visible && Control.Child != null) - return Control.Child.Allocation.Size.ToEto (); - else { - var label = Control.LabelWidget; - var size = Size; - size.Height -= label.Allocation.Height + 10; - size.Width -= 10; - return size; - } - } - set { - var label = Control.LabelWidget; - var size = value; - size.Height += label.Allocation.Height + 10; - size.Width += 10; - Size = size; - } - } - - protected override void SetContainerContent(Gtk.Widget content) - { - Control.Add(content); - - /*if (clientSize != null) { - var label = Control.LabelWidget; - Control.SetSizeRequest(clientSize.Value.Width + 10, clientSize.Value.Height + label.Allocation.Height + 10); - clientSize = null; - }*/ - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/ImageViewHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/ImageViewHandler.cs deleted file mode 100644 index 4da6bdc9eb..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/ImageViewHandler.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Platform.GtkSharp.Drawing; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class ImageViewHandler : GtkControl, IImageView - { - Image image; - bool widthSet; - bool heightSet; - - public override Gtk.DrawingArea CreateControl() - { - var control = new Gtk.DrawingArea - { - CanFocus = false, - CanDefault = true - }; -#if GTK2 - control.ExposeEvent += Connector.HandleExpose; -#else - control.Drawn += Connector.HandleDrawn; -#endif - control.Events |= Gdk.EventMask.ExposureMask; - return control; - } - - protected new ImageViewConnector Connector { get { return (ImageViewConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ImageViewConnector(); - } - - protected class ImageViewConnector : GtkControlConnector - { - public new ImageViewHandler Handler { get { return (ImageViewHandler)base.Handler; } } - -#if GTK2 - public void HandleExpose(object o, Gtk.ExposeEventArgs args) - { - Gdk.EventExpose ev = args.Event; - var h = Handler; - var handler = new GraphicsHandler(h.Control, ev.Window); -#else - public void HandleDrawn(object o, Gtk.DrawnArgs args) - { - var h = Handler; - var handler = new GraphicsHandler(args.Cr, h.Control.CreatePangoContext(), false); -#endif - using (var graphics = new Graphics(h.Widget.Generator, handler)) - { - - var widgetSize = new Size(h.Control.Allocation.Width, h.Control.Allocation.Height); - var imageSize = (SizeF)h.image.Size; - var scaleWidth = widgetSize.Width / imageSize.Width; - var scaleHeight = widgetSize.Height / imageSize.Height; - imageSize *= Math.Min(scaleWidth, scaleHeight); - var location = new PointF((widgetSize.Width - imageSize.Width) / 2, (widgetSize.Height - imageSize.Height) / 2); - - var destRect = new Rectangle(Point.Round(location), Size.Truncate(imageSize)); - graphics.DrawImage(h.image, destRect); - } - } - } - - public override Size Size - { - get { return base.Size; } - set - { - base.Size = value; - widthSet = value.Width >= 0; - heightSet = value.Height >= 0; - } - } - - public Image Image - { - get { return image; } - set - { - image = value; - if (image != null && !widthSet || !heightSet) - { - Control.SetSizeRequest(widthSet ? Size.Width : image.Size.Width, heightSet ? Size.Height : image.Size.Height); - } - if (Control.Visible) - Control.QueueDraw(); - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/LabelHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/LabelHandler.cs deleted file mode 100644 index f0e3e4e4e5..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/LabelHandler.cs +++ /dev/null @@ -1,213 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class LabelHandler : GtkControl, ILabel - { - readonly Gtk.EventBox eventBox; - HorizontalAlign horizontalAlign = HorizontalAlign.Left; - VerticalAlign verticalAlign = VerticalAlign.Top; - - public override Gtk.Widget ContainerControl - { - get { return eventBox; } - } - - public override Gtk.Widget EventControl - { - get { return eventBox; } - } - - public class EtoLabel : Gtk.Label - { - int wrapWidth; - -#if GTK2 - protected override void OnSizeRequested(ref Gtk.Requisition requisition) - { - //base.OnSizeRequested (ref requisition); - int width, height; - Layout.GetPixelSize(out width, out height); - requisition.Width = width; - requisition.Height = height; - } -#else - protected override void OnGetPreferredWidth (out int minimum_width, out int natural_width) - { - base.OnGetPreferredWidth (out minimum_width, out natural_width); - //minimum_width = natural_width; // = 500; //this.Layout.Width; - } - - protected override void OnAdjustSizeRequest (Gtk.Orientation orientation, out int minimum_size, out int natural_size) - { - base.OnAdjustSizeRequest (orientation, out minimum_size, out natural_size); - if (orientation == Gtk.Orientation.Horizontal) - minimum_size = natural_size; - } - -#endif - - protected override void OnSizeAllocated(Gdk.Rectangle allocation) - { - base.OnSizeAllocated(allocation); - SetWrapWidth(allocation.Width); - } - - void SetWrapWidth(int width) - { - if (width == 0) - return; - Layout.Width = (int)(width * Pango.Scale.PangoScale); - if (wrapWidth != width) - { - wrapWidth = width; - QueueResize(); - } - } - } - - public LabelHandler() - { - eventBox = new Gtk.EventBox(); - //eventBox.VisibleWindow = false; - Control = new EtoLabel - { - SingleLineMode = false, - LineWrap = true, - LineWrapMode = Pango.WrapMode.Word - }; - Control.SetAlignment(0, 0); - eventBox.Child = Control; - } - - public WrapMode Wrap - { - get - { - if (!Control.LineWrap) - return WrapMode.None; - if (Control.LineWrapMode == Pango.WrapMode.Word) - return WrapMode.Word; - return WrapMode.Character; - } - set - { - switch (value) - { - case WrapMode.None: - Control.Wrap = false; - Control.LineWrap = false; - Control.SingleLineMode = true; - break; - case WrapMode.Word: - Control.Wrap = true; - Control.LineWrapMode = Pango.WrapMode.Word; - Control.LineWrap = true; - Control.SingleLineMode = false; - break; - case WrapMode.Character: - Control.Wrap = true; - Control.LineWrapMode = Pango.WrapMode.Char; - Control.LineWrap = true; - Control.SingleLineMode = false; - break; - default: - throw new NotSupportedException(); - } - } - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - break; - default: - base.AttachEvent(id); - break; - } - } - - public virtual Color TextColor - { - get { return Control.Style.Foreground(Gtk.StateType.Normal).ToEto(); } - set { Control.ModifyFg(Gtk.StateType.Normal, value.ToGdk()); } - } - - public override string Text - { - get { return MnuemonicToString(Control.Text); } - set { Control.TextWithMnemonic = StringToMnuemonic(value); } - } - - public HorizontalAlign HorizontalAlign - { - get { return horizontalAlign; } - set - { - horizontalAlign = value; - SetAlignment(); - } - } - - void SetAlignment() - { - float xalignment; - float yalignment; - Gtk.Justification justify; - switch (horizontalAlign) - { - default: - xalignment = 0F; - justify = Gtk.Justification.Left; - break; - case HorizontalAlign.Center: - xalignment = 0.5F; - justify = Gtk.Justification.Center; - break; - case HorizontalAlign.Right: - xalignment = 1F; - justify = Gtk.Justification.Right; - break; - } - switch (verticalAlign) - { - case VerticalAlign.Middle: - yalignment = 0.5F; - break; - default: - yalignment = 0F; - break; - case VerticalAlign.Bottom: - yalignment = 1F; - break; - } - Control.SetAlignment(xalignment, yalignment); - Control.Justify = justify; - } - - public VerticalAlign VerticalAlign - { - get { return verticalAlign; } - set - { - verticalAlign = value; - SetAlignment(); - } - } - - public override Font Font - { - get { return base.Font; } - set - { - base.Font = value; - Control.Attributes = value != null ? ((FontHandler)value.Handler).Attributes : null; - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/ListBoxHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/ListBoxHandler.cs deleted file mode 100644 index 9e5aa795f1..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/ListBoxHandler.cs +++ /dev/null @@ -1,216 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Platform.GtkSharp.Drawing; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class ListBoxHandler : GtkControl, IListBox, IGtkListModelHandler - { - readonly Gtk.ScrolledWindow scroll; - GtkListModel model; - ContextMenu contextMenu; - CollectionHandler collection; - public static Size MaxImageSize = new Size(16, 16); - - public override Gtk.Widget ContainerControl - { - get { return scroll; } - } - - public ListBoxHandler() - { - model = new GtkListModel{ Handler = this }; - - scroll = new Gtk.ScrolledWindow(); - scroll.ShadowType = Gtk.ShadowType.In; - Control = new Gtk.TreeView(new Gtk.TreeModelAdapter(model)); - Size = new Size(80, 80); - //tree.FixedHeightMode = true; - Control.ShowExpanders = false; - scroll.Add(Control); - - Control.Events |= Gdk.EventMask.ButtonPressMask; - - Control.AppendColumn("Img", new Gtk.CellRendererPixbuf(), "pixbuf", 1); - Control.AppendColumn("Data", new Gtk.CellRendererText(), "text", 0); - Control.HeadersVisible = false; - } - - protected override void Initialize() - { - base.Initialize(); - Control.ButtonPressEvent += Connector.HandleTreeButtonPressEvent; - Control.Selection.Changed += Connector.HandleSelectionChanged; - Control.RowActivated += Connector.HandleTreeRowActivated; - } - - protected new ListBoxEventConnector Connector { get { return (ListBoxEventConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ListBoxEventConnector(); - } - - protected class ListBoxEventConnector : GtkControlConnector - { - public new ListBoxHandler Handler { get { return (ListBoxHandler)base.Handler; } } - - [GLib.ConnectBefore] - public void HandleTreeButtonPressEvent(object o, Gtk.ButtonPressEventArgs args) - { - if (Handler.contextMenu != null && args.Event.Button == 3 && args.Event.Type == Gdk.EventType.ButtonPress) - { - var menu = (Gtk.Menu)Handler.contextMenu.ControlObject; - menu.Popup(); - menu.ShowAll(); - } - } - - public void HandleSelectionChanged(object sender, EventArgs e) - { - Handler.Widget.OnSelectedIndexChanged(EventArgs.Empty); - } - - public void HandleTreeRowActivated(object o, Gtk.RowActivatedArgs args) - { - Handler.Widget.OnActivated(EventArgs.Empty); - } - } - - public override void Focus() - { - Control.GrabFocus(); - } - - public int SelectedIndex - { - get - { - Gtk.TreeIter iter; - - if (Control.Selection != null && Control.Selection.GetSelected(out iter)) - { - var val = model.NodeFromIter(iter); - if (val >= 0) - return val; - } - - return -1; - } - set - { - if (value == -1) - { - if (Control.Selection != null) - Control.Selection.UnselectAll(); - return; - } - var path = new Gtk.TreePath(); - path.AppendIndex(value); - Gtk.TreeViewColumn focus_column = Control.Columns[0]; - - Control.SetCursor(path, focus_column, false); - } - } - - public ContextMenu ContextMenu - { - get { return contextMenu; } - set { contextMenu = value; } - } - - public GLib.Value GetColumnValue(IListItem item, int column, int row) - { - switch (column) - { - case 0: - return new GLib.Value(item != null ? item.Text : (string)null); - case 1: - var imageItem = item as IImageListItem; - if (imageItem != null) - { - var img = imageItem.Image; - if (img != null) - { - var imgHandler = img.Handler as IGtkPixbuf; - if (imgHandler != null) - return new GLib.Value(imgHandler.GetPixbuf(MaxImageSize)); - } - } - return new GLib.Value((Gdk.Pixbuf)null); - default: - throw new InvalidOperationException(); - } - } - - public class CollectionHandler : DataStoreChangedHandler - { - public ListBoxHandler Handler { get; set; } - - public override int IndexOf(IListItem item) - { - return -1; - } - - protected override void OnRegisterCollection(EventArgs e) - { - Handler.model = new GtkListModel{ Handler = Handler }; - Handler.Control.Model = new Gtk.TreeModelAdapter(Handler.model); - } - - protected override void OnUnregisterCollection(EventArgs e) - { - Handler.Control.Model = null; - } - - public override void AddItem(IListItem item) - { - var iter = Handler.model.GetIterAtRow(Collection.Count); - var path = Handler.model.GetPathAtRow(Collection.Count); - Handler.Control.Model.EmitRowInserted(path, iter); - } - - public override void InsertItem(int index, IListItem item) - { - var iter = Handler.model.GetIterAtRow(index); - var path = Handler.model.GetPathAtRow(index); - Handler.Control.Model.EmitRowInserted(path, iter); - } - - public override void RemoveItem(int index) - { - var path = Handler.model.GetPathAtRow(index); - Handler.Control.Model.EmitRowDeleted(path); - } - - public override void RemoveAllItems() - { - Handler.model = new GtkListModel{ Handler = Handler }; - Handler.Control.Model = new Gtk.TreeModelAdapter(Handler.model); - } - } - - public IListStore DataStore - { - get { return collection != null ? collection.Collection : null; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler{ Handler = this }; - collection.Register(value); - } - } - - public int NumberOfColumns - { - get { return 2; } - } - - public int GetRowOfItem(IListItem item) - { - return collection == null ? -1 : collection.IndexOf(item); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/NumericUpDownHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/NumericUpDownHandler.cs deleted file mode 100644 index 178525d1a5..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/NumericUpDownHandler.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class NumericUpDownHandler : GtkControl, INumericUpDown - { - public NumericUpDownHandler() - { - Control = new Gtk.SpinButton(0, 100, 1); - Control.WidthRequest = 80; - Control.Wrap = true; - } - - protected override void Initialize() - { - base.Initialize(); - Control.ValueChanged += Connector.HandleValueChanged; - } - - protected new NumericUpDownConnector Connector { get { return (NumericUpDownConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new NumericUpDownConnector(); - } - - protected class NumericUpDownConnector : GtkControlConnector - { - public new NumericUpDownHandler Handler { get { return (NumericUpDownHandler)base.Handler; } } - - public void HandleValueChanged(object sender, EventArgs e) - { - Handler.Widget.OnValueChanged(EventArgs.Empty); - } - } - public override string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - - public bool ReadOnly - { - get { return !Control.IsEditable; } - set { Control.IsEditable = !value; } - } - - public double Value - { - get { return Control.Value; } - set { Control.Value = value; } - } - - public double MaxValue - { - get { return Control.Adjustment.Upper; } - set { Control.Adjustment.Upper = value; } - } - - public double MinValue - { - get { return Control.Adjustment.Lower; } - set { Control.Adjustment.Lower = value; } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/PanelHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/PanelHandler.cs deleted file mode 100644 index 62f80bbd8b..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/PanelHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class PanelHandler : GtkPanel, IPanel - { - readonly Gtk.VBox box; - - public PanelHandler() - { - Control = new Gtk.EventBox(); - //Control.VisibleWindow = false; // can't use this as it causes overlapping widgets - box = new Gtk.VBox(); - Control.Add(box); - } - - protected override void SetContainerContent(Gtk.Widget content) - { - box.Add(content); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/PasswordBoxHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/PasswordBoxHandler.cs deleted file mode 100644 index 7dd8b447ef..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/PasswordBoxHandler.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class PasswordBoxHandler : GtkControl, IPasswordBox - { - public PasswordBoxHandler() - { - Control = new Gtk.Entry(); - Control.Visibility = false; - Control.SetSizeRequest(20, -1); - Control.ActivatesDefault = true; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - Control.Changed += Connector.HandleTextChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - protected new PasswordBoxConnector Connector { get { return (PasswordBoxConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new PasswordBoxConnector(); - } - - protected class PasswordBoxConnector : GtkControlConnector - { - public new PasswordBoxHandler Handler { get { return (PasswordBoxHandler)base.Handler; } } - - public void HandleTextChanged(object sender, EventArgs e) - { - Handler.Widget.OnTextChanged(EventArgs.Empty); - } - } - - public char PasswordChar - { - get { return Control.InvisibleChar; } - set { Control.InvisibleChar = value; } - } - - public override string Text - { - get { return Control.Text; } - set { Control.Text = value ?? string.Empty; } - } - - public bool ReadOnly - { - get { return !Control.IsEditable; } - set { Control.IsEditable = !value; } - } - - public int MaxLength - { - get { return Control.MaxLength; } - set { Control.MaxLength = value; } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/ProgressBarHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/ProgressBarHandler.cs deleted file mode 100644 index c3904c16ff..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/ProgressBarHandler.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class ProgressBarHandler : GtkControl, IProgressBar - { - int minValue; - int maxValue = 100; - bool indeterminate; - UITimer timer; - public static double UpdateInterval = 0.2; - public static double PulseStep = 0.1; - - public ProgressBarHandler() - { - this.Control = new Gtk.ProgressBar - { - Fraction = 0 - }; - } - - protected new ProgressBarConnector Connector { get { return (ProgressBarConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ProgressBarConnector(); - } - - protected class ProgressBarConnector : GtkControlConnector - { - public new ProgressBarHandler Handler { get { return (ProgressBarHandler)base.Handler; } } - - public void TimerElapsed(object sender, EventArgs e) - { - var timer = (UITimer)sender; - var handler = Handler; - if (handler != null) - handler.Control.Pulse(); - else - timer.Stop(); - } - } - - public bool Indeterminate - { - get { return indeterminate; } - set - { - indeterminate = value; - if (indeterminate) - { - if (timer == null) - { - timer = new UITimer(Widget.Generator); - timer.Elapsed += Connector.TimerElapsed; - } - timer.Interval = UpdateInterval; - Control.PulseStep = PulseStep; - timer.Start(); - } - else if (timer != null) - timer.Stop(); - } - } - - public int MaxValue - { - get { return maxValue; } - set - { - var val = Value; - maxValue = value; - Value = val; - } - } - - public int MinValue - { - get { return minValue; } - set - { - var val = Value; - minValue = value; - Value = val; - } - } - - public int Value - { - get { return (int)((Control.Fraction * MaxValue) + MinValue); } - set - { - Control.Fraction = Math.Max(0, Math.Min(1, ((double)value - MinValue) / (double)MaxValue)); - } - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - if (timer != null) - timer.Stop(); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/RadioButtonHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/RadioButtonHandler.cs deleted file mode 100644 index ef80cb1c6b..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/RadioButtonHandler.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class RadioButtonHandler : GtkControl, IRadioButton - { - Gtk.AccelLabel label; - - protected override Gtk.Widget FontControl - { - get { return label; } - } - - public void Create(RadioButton controller) - { - if (controller != null) - Control = new Gtk.RadioButton(RadioButtonHandler.GetControl(controller)); - else - { - Control = new Gtk.RadioButton((Gtk.RadioButton)null); - // make gtk work like others in that no radio button is initially selected - var inactive = new Gtk.RadioButton(Control); - inactive.Active = true; - } - label = new Gtk.AccelLabel(""); - Control.Add(label); //control.AddMnemonicLabel(label); - Control.Toggled += Connector.HandleCheckedChanged; - } - - protected new RadioButtonConnector Connector { get { return (RadioButtonConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new RadioButtonConnector(); - } - - protected class RadioButtonConnector : GtkControlConnector - { - public new RadioButtonHandler Handler { get { return (RadioButtonHandler)base.Handler; } } - - public void HandleCheckedChanged(object sender, EventArgs e) - { - Handler.Widget.OnCheckedChanged(EventArgs.Empty); - } - } - - public override string Text - { - get { return MnuemonicToString(label.Text); } - set { label.TextWithMnemonic = StringToMnuemonic(value); } - } - - public bool Checked - { - get { return Control.Active; } - set { Control.Active = value; } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/ScrollableHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/ScrollableHandler.cs deleted file mode 100644 index b000e3fffb..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/ScrollableHandler.cs +++ /dev/null @@ -1,245 +0,0 @@ -using System; -using Eto.Drawing; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class ScrollableHandler : GtkPanel, IScrollable - { - readonly Gtk.Viewport vp; - readonly Gtk.HBox hbox; - readonly Gtk.VBox vbox; - BorderType border; - bool expandWidth = true; - bool expandHeight = true; - Gtk.Widget layoutWidget; - #if GTK2 - bool autoSize = true; - #endif - - public BorderType Border - { - get - { - return border; - } - set - { - border = value; - switch (border) - { - case BorderType.Bezel: - Control.ShadowType = Gtk.ShadowType.In; - break; - case BorderType.Line: - Control.ShadowType = Gtk.ShadowType.In; - break; - case BorderType.None: - Control.ShadowType = Gtk.ShadowType.None; - break; - default: - throw new NotSupportedException(); - } - } - } - - public ScrollableHandler() - { - Control = new Gtk.ScrolledWindow(); - vp = new Gtk.Viewport(); - hbox = new Gtk.HBox(); - vbox = new Gtk.VBox(); - vbox.PackStart(hbox, true, true, 0); - vp.Add(vbox); - - // autosize the scrolled window to the size of the content - Control.Add(vp); - vp.ShadowType = Gtk.ShadowType.None; - this.Border = BorderType.Bezel; - } - - protected override void Initialize() - { - base.Initialize(); - #if GTK2 - Control.SizeRequested += Connector.HandleControlSizeRequested; - vp.SizeRequested += Connector.HandleViewportSizeRequested; - #endif - Control.VScrollbar.VisibilityNotifyEvent += Connector.HandleScrollbarVisibilityChanged; - Control.HScrollbar.VisibilityNotifyEvent += Connector.HandleScrollbarVisibilityChanged; - } - - protected new ScrollableConnector Connector { get { return (ScrollableConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ScrollableConnector(); - } - - protected class ScrollableConnector : GtkPanelEventConnector - { - public new ScrollableHandler Handler { get { return (ScrollableHandler)base.Handler; } } -#if GTK2 - public void HandleControlSizeRequested(object o, Gtk.SizeRequestedArgs args) - { - if (Handler.autoSize) - { - args.Requisition = Handler.vp.SizeRequest(); - } - } - - public void HandleViewportSizeRequested(object o, Gtk.SizeRequestedArgs args) - { - var handler = Handler; - if (handler != null) - { - var viewport = (Gtk.Viewport)o; - if (handler.autoSize) - { - var size = viewport.SizeRequest(); - //Console.WriteLine ("Autosizing to {0}x{1}", size.Width, size.Height); - args.Requisition = size; - } - } - } -#endif - public void HandleScrollbarVisibilityChanged(object sender, EventArgs e) - { - Handler.Widget.OnSizeChanged(EventArgs.Empty); - } - - public void HandleScrollableScrollEvent(object o, Gtk.ScrollEventArgs args) - { - var pos = new Point((int)args.Event.X, (int)args.Event.Y); - Handler.Widget.OnScroll(new ScrollEventArgs(pos)); - } - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Scrollable.ScrollEvent: - Control.Events |= Gdk.EventMask.ScrollMask; - Control.ScrollEvent += Connector.HandleScrollableScrollEvent; - break; - default: - base.AttachEvent(id); - break; - } - } - - #if GTK2 - public override Size Size - { - get { return base.Size; } - set - { - base.Size = value; - autoSize = false; - } - } - #endif - - protected override void SetContainerContent(Gtk.Widget content) - { - layoutWidget = content; - hbox.PackStart(content, false, true, 0); - SetPacking(); - } - - void SetPacking() - { - if (layoutWidget != null) - hbox.SetChildPacking(layoutWidget, expandWidth, expandWidth, 0, Gtk.PackType.Start); - vbox.SetChildPacking(hbox, expandHeight, expandHeight, 0, Gtk.PackType.Start); - } - - protected override void SetBackgroundColor(Color? color) - { - if (color != null) - vp.ModifyBg(Gtk.StateType.Normal, color.Value.ToGdk()); - else - vp.ModifyBg(Gtk.StateType.Normal); - } - - public override Size ClientSize - { - get - { - Gdk.Rectangle rect = vp.Allocation; - int spacing = Convert.ToInt32(Control.StyleGetProperty("scrollbar-spacing")) + 1; - return new Size(rect.Width - spacing, rect.Height - spacing); - } - set - { - int spacing = Convert.ToInt32(Control.StyleGetProperty("scrollbar-spacing")) + 1; - vp.SetSizeRequest(value.Width + spacing, value.Height + spacing); - } - } - - public void UpdateScrollSizes() - { - Control.CheckResize(); - vp.CheckResize(); - } - - public Point ScrollPosition - { - get { return new Point((int)vp.Hadjustment.Value, (int)vp.Vadjustment.Value); } - set - { - Size clientSize = ClientSize; - Size scrollSize = ScrollSize; - vp.Hadjustment.Value = Math.Min(value.X, scrollSize.Width - clientSize.Width); - vp.Vadjustment.Value = Math.Min(value.Y, scrollSize.Height - clientSize.Height); - } - } - - public Size ScrollSize - { - get - { - //return scrollSize; - return new Size((int)(vp.Hadjustment.Upper), (int)(vp.Vadjustment.Upper)); - } - set - { - //scrollSize = value; - vp.Hadjustment.Upper = value.Width; - vp.Vadjustment.Upper = value.Height; - } - } - - public Rectangle VisibleRect - { - get { return new Rectangle(ScrollPosition, Size.Min(ScrollSize, ClientSize)); } - } - - public bool ExpandContentWidth - { - get { return expandWidth; } - set - { - if (expandWidth != value) - { - expandWidth = value; - SetPacking(); - } - } - } - - public bool ExpandContentHeight - { - get { return expandHeight; } - set - { - if (expandHeight != value) - { - expandHeight = value; - SetPacking(); - } - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/SearchBoxHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/SearchBoxHandler.cs deleted file mode 100644 index a6919dd4c1..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/SearchBoxHandler.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class SearchBoxHandler : TextBoxHandler, ISearchBox - { - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/SliderHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/SliderHandler.cs deleted file mode 100644 index 78f85cc448..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/SliderHandler.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class SliderHandler : GtkControl, ISlider - { - int min; - int max = 100; - int tick = 1; - Gtk.Scale scale; - - public SliderHandler() - { - this.Control = new Gtk.EventBox(); - //Control.VisibleWindow = false; - scale = new Gtk.HScale(min, max, 1); - this.Control.Child = scale; - } - - protected override void Initialize() - { - base.Initialize(); - scale.ValueChanged += Connector.HandleScaleValueChanged; - } - - protected new SliderConnector Connector { get { return (SliderConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new SliderConnector(); - } - - protected class SliderConnector : GtkControlConnector - { - int? lastValue; - - public new SliderHandler Handler { get { return (SliderHandler)base.Handler; } } - - public void HandleScaleValueChanged(object sender, EventArgs e) - { - var scale = Handler.scale; - var tick = Handler.tick; - var value = (int)scale.Value; - var offset = value % tick; - if (Handler.SnapToTick && offset != 0) - { - if (offset > tick / 2) - scale.Value = value - offset + tick; - else - scale.Value -= offset; - } - else if (lastValue == null || lastValue.Value != value) - { - Handler.Widget.OnValueChanged(EventArgs.Empty); - lastValue = value; - } - } - } - - public int MaxValue - { - get { return max; } - set - { - max = value; - scale.SetRange(min, max); - } - } - - public int MinValue - { - get { return min; } - set - { - min = value; - scale.SetRange(min, max); - } - } - - public int Value - { - get { return (int)scale.Value; } - set { scale.Value = value; } - } - - public bool SnapToTick { get; set; } - - public int TickFrequency - { - get - { - return tick; - } - set - { - tick = value; - // TODO: Only supported from GTK 2.16 - } - } - - public SliderOrientation Orientation - { - get - { - return (scale is Gtk.HScale) ? SliderOrientation.Horizontal : SliderOrientation.Vertical; - } - set - { - if (Orientation != value) - { - scale.ValueChanged -= Connector.HandleScaleValueChanged; - Control.Remove(scale); - scale.Destroy(); - scale.Dispose(); - if (value == SliderOrientation.Horizontal) - scale = new Gtk.HScale(min, max, 1); - else - scale = new Gtk.VScale(min, max, 1); - scale.ValueChanged += Connector.HandleScaleValueChanged; - Control.Child = scale; - scale.ShowAll(); - } - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/SpinnerHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/SpinnerHandler.cs deleted file mode 100644 index ca6a6dc9e0..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/SpinnerHandler.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class SpinnerHandler : GtkControl, ISpinner - { - bool enabled; - public SpinnerHandler() - { - Control = new Gtk.Spinner(); - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - if (enabled) - Control.Start(); - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - if (enabled) - Control.Stop(); - } - - public override bool Enabled - { - get { return enabled; } - set - { - if (enabled != value) - { - enabled = value; - if (Widget.Loaded) - { - if (enabled) - Control.Start(); - else - Control.Stop(); - } - } - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/SplitterHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/SplitterHandler.cs deleted file mode 100644 index 7abaa669a7..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/SplitterHandler.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class SplitterHandler : GtkContainer, ISplitter - { - readonly Gtk.EventBox container; - Control panel1; - Control panel2; - SplitterOrientation orientation; - SplitterFixedPanel fixedPanel; - int? position; - - class EtoHPaned : Gtk.HPaned - { - #if GTK2 - protected override void OnSizeRequested(ref Gtk.Requisition requisition) - { - base.OnSizeRequested(ref requisition); - if (PositionSet && Child1 != null) - { - var childreq = Child1.Requisition; - if (childreq.Width > 0) - requisition.Width += Position - childreq.Width; - } - } - #endif - } - - class EtoVPaned : Gtk.VPaned - { - #if GTK2 - protected override void OnSizeRequested(ref Gtk.Requisition requisition) - { - base.OnSizeRequested(ref requisition); - if (PositionSet && Child1 != null) - { - var childreq = Child1.Requisition; - if (childreq.Height > 0) - requisition.Height += Position - childreq.Height; - } - } - #endif - } - - public override Gtk.Widget ContainerControl - { - get { return container; } - } - - public SplitterHandler() - { - container = new Gtk.EventBox(); - Create(); - } - - public int Position - { - get { return Control.Position; } - set { position = Control.Position = value; } - } - - public SplitterFixedPanel FixedPanel - { - get { return fixedPanel; } - set - { - if (fixedPanel != value) - { - fixedPanel = value; - Create(); - } - } - } - - public SplitterOrientation Orientation - { - get { return (Control is Gtk.HPaned) ? SplitterOrientation.Horizontal : SplitterOrientation.Vertical; } - set - { - if (orientation != value) - { - orientation = value; - Create(); - } - } - } - - void Create() - { - Gtk.Paned old = Control; - if (orientation == SplitterOrientation.Horizontal) - Control = new EtoHPaned(); - else - Control = new EtoVPaned(); - if (container.Child != null) - container.Remove(container.Child); - container.Child = Control; - if (old != null) - { - var child1 = old.Child1; - var child2 = old.Child2; - old.Remove(child2); - old.Remove(child1); - Control.Pack1(child1 ?? EmptyContainer(), fixedPanel != SplitterFixedPanel.Panel1, true); - Control.Pack2(child2 ?? EmptyContainer(), fixedPanel != SplitterFixedPanel.Panel2, true); - old.Destroy(); - } - else - { - Control.Pack1(EmptyContainer(), fixedPanel != SplitterFixedPanel.Panel1, true); - Control.Pack2(EmptyContainer(), fixedPanel != SplitterFixedPanel.Panel2, true); - } - if (position != null) - Control.Position = position.Value; - } - - static Gtk.Widget EmptyContainer() - { - var bin = new Gtk.VBox(); - return bin; - } - - public Control Panel1 - { - get { return panel1; } - set - { - panel1 = value; - var setposition = position != null && (Control.Child1 == null || Control.Child2 == null); - if (Control.Child1 != null) - Control.Remove(Control.Child1); - var widget = panel1 != null ? panel1.GetContainerWidget() : EmptyContainer(); - Control.Pack1(widget, fixedPanel != SplitterFixedPanel.Panel1, true); - if (setposition) - Control.Position = position.Value; - widget.ShowAll(); - } - } - - public Control Panel2 - { - get { return panel2; } - set - { - panel2 = value; - var setposition = position != null && (Control.Child1 == null || Control.Child2 == null); - if (Control.Child2 != null) - Control.Remove(Control.Child2); - var widget = panel2 != null ? panel2.GetContainerWidget() : EmptyContainer(); - Control.Pack2(widget, fixedPanel != SplitterFixedPanel.Panel2, true); - if (setposition) - Control.Position = position.Value; - widget.ShowAll(); - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/TabControlHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/TabControlHandler.cs deleted file mode 100644 index a0925ad4d3..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/TabControlHandler.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class TabControlHandler : GtkContainer, ITabControl - { - public TabControlHandler() - { - Control = new Gtk.Notebook(); - } - - protected override void Initialize() - { - base.Initialize(); - Control.SwitchPage += Connector.HandleSwitchPage; - } - - protected override bool IsTransparentControl - { - get { return false; } - } - - protected override Color DefaultBackgroundColor - { - get { return ContainerContentControl.Style.Base(Gtk.StateType.Normal).ToEto(); } - } - - protected new TabControlConnector Connector { get { return (TabControlConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new TabControlConnector(); - } - - protected class TabControlConnector : GtkControlConnector - { - public new TabControlHandler Handler { get { return (TabControlHandler)base.Handler; } } - - public void HandleSwitchPage(object o, Gtk.SwitchPageArgs args) - { - var handler = Handler; - if (handler != null && handler.Widget.Loaded) - handler.Widget.OnSelectedIndexChanged(EventArgs.Empty); - } - } - - public int SelectedIndex - { - get { return Control.CurrentPage; } - set { Control.CurrentPage = value; } - } - - public void InsertTab(int index, TabPage page) - { - var pageHandler = (TabPageHandler)page.Handler; - - if (Widget.Loaded) - { - pageHandler.ContainerControl.ShowAll(); - pageHandler.LabelControl.ShowAll(); - } - - if (index == -1) - Control.AppendPage(pageHandler.ContainerControl, pageHandler.LabelControl); - else - Control.InsertPage(pageHandler.ContainerControl, pageHandler.LabelControl, index); - } - - public void ClearTabs() - { - while (Control.NPages > 0) - Control.RemovePage(0); - } - - public void RemoveTab(int index, TabPage page) - { - Control.RemovePage(index); - if (Widget.Loaded && Control.NPages == 0) - Widget.OnSelectedIndexChanged(EventArgs.Empty); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/TabPageHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/TabPageHandler.cs deleted file mode 100644 index ed41bbaa2a..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/TabPageHandler.cs +++ /dev/null @@ -1,79 +0,0 @@ -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class TabPageHandler : GtkPanel, ITabPage - { - Gtk.Label label; - readonly Gtk.HBox tab; - Gtk.Image gtkimage; - Image image; - public static Size MaxImageSize = new Size(16, 16); - - public TabPageHandler() - { - Control = new Gtk.VBox(); - tab = new Gtk.HBox(); - label = new Gtk.Label(); - tab.PackEnd(label, true, true, 0); - tab.ShowAll(); - } - - public Gtk.Widget LabelControl - { - get { return tab; } - } - - protected override void SetContainerContent(Gtk.Widget content) - { - Control.PackStart(content, true, true, 0); - } - - public Image Image - { - get { return image; } - set - { - if (gtkimage == null) - { - gtkimage = new Gtk.Image(); - tab.PackStart(gtkimage, true, true, 0); - } - image = value; - if (image != null) - { - var imagehandler = (IGtkPixbuf)image.Handler; - gtkimage.Pixbuf = imagehandler.GetPixbuf(MaxImageSize); - gtkimage.ShowAll(); - } - else - { - gtkimage.Visible = false; - gtkimage.Pixbuf = null; - } - - } - } - - public override string Text - { - get { return MnuemonicToString(label.Text); } - set { label.TextWithMnemonic = StringToMnuemonic(value); } - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - if (disposing) - { - if (label != null) - { - label.Dispose(); - label = null; - } - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/TextAreaHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/TextAreaHandler.cs deleted file mode 100644 index 884f383fa7..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/TextAreaHandler.cs +++ /dev/null @@ -1,226 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class TextAreaHandler : GtkControl, ITextArea - { - bool sendSelectionChanged = true; - readonly Gtk.ScrolledWindow scroll; - Gtk.TextTag tag; - - public override Gtk.Widget ContainerControl - { - get { return scroll; } - } - - public override Size DefaultSize { get { return TextArea.DefaultSize; } } - - public TextAreaHandler() - { - scroll = new Gtk.ScrolledWindow(); - scroll.ShadowType = Gtk.ShadowType.In; - Control = new Gtk.TextView(); - Size = TextArea.DefaultSize; - scroll.Add(Control); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - Control.Buffer.Changed += Connector.HandleBufferChanged; - break; - case TextArea.SelectionChangedEvent: - Control.Buffer.MarkSet += Connector.HandleSelectionChanged; - break; - case TextArea.CaretIndexChangedEvent: - Control.Buffer.MarkSet += Connector.HandleCaretIndexChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - protected new TextAreaConnector Connector { get { return (TextAreaConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new TextAreaConnector(); - } - - protected class TextAreaConnector : GtkControlConnector - { - Range? lastSelection; - int? lastCaretIndex; - public new TextAreaHandler Handler { get { return (TextAreaHandler)base.Handler; } } - - public void HandleBufferChanged(object sender, EventArgs e) - { - Handler.Widget.OnTextChanged(EventArgs.Empty); - } - - public void HandleSelectionChanged(object o, Gtk.MarkSetArgs args) - { - var handler = Handler; - var selection = handler.Selection; - if (handler.sendSelectionChanged && selection != lastSelection) - { - handler.Widget.OnSelectionChanged(EventArgs.Empty); - lastSelection = selection; - } - } - - public void HandleCaretIndexChanged(object o, Gtk.MarkSetArgs args) - { - var handler = Handler; - var caretIndex = handler.CaretIndex; - if (handler.sendSelectionChanged && caretIndex != lastCaretIndex) - { - handler.Widget.OnCaretIndexChanged(EventArgs.Empty); - lastCaretIndex = caretIndex; - } - } - - public void HandleApplyTag(object sender, EventArgs e) - { - var buffer = Handler.Control.Buffer; - var tag = Handler.tag; - buffer.ApplyTag(tag, buffer.StartIter, buffer.EndIter); - } - } - - public override string Text - { - get { return Control.Buffer.Text; } - set - { - Control.Buffer.Text = value; - if (tag != null) - Control.Buffer.ApplyTag(tag, Control.Buffer.StartIter, Control.Buffer.EndIter); - } - } - - public bool ReadOnly - { - get { return !Control.Editable; } - set { Control.Editable = !value; } - } - - public bool Wrap - { - get { return Control.WrapMode != Gtk.WrapMode.None; } - set { Control.WrapMode = value ? Gtk.WrapMode.WordChar : Gtk.WrapMode.None; } - } - - public void Append(string text, bool scrollToCursor) - { - var end = Control.Buffer.EndIter; - Control.Buffer.Insert(ref end, text); - if (scrollToCursor) - { - var mark = Control.Buffer.CreateMark(null, end, false); - Control.ScrollToMark(mark, 0, false, 0, 0); - } - } - - public string SelectedText - { - get - { - Gtk.TextIter start, end; - if (Control.Buffer.GetSelectionBounds(out start, out end)) - { - return Control.Buffer.GetText(start, end, false); - } - return null; - } - set - { - sendSelectionChanged = false; - Gtk.TextIter start, end; - if (Control.Buffer.GetSelectionBounds(out start, out end)) - { - var startOffset = start.Offset; - Control.Buffer.Delete(ref start, ref end); - if (value != null) - { - Control.Buffer.Insert(ref start, value); - start = Control.Buffer.GetIterAtOffset(startOffset); - end = Control.Buffer.GetIterAtOffset(startOffset + value.Length); - Control.Buffer.SelectRange(start, end); - } - } - else if (value != null) - Control.Buffer.InsertAtCursor(value); - if (tag != null) - Control.Buffer.ApplyTag(tag, Control.Buffer.StartIter, Control.Buffer.EndIter); - Widget.OnSelectionChanged(EventArgs.Empty); - sendSelectionChanged = true; - } - } - - public Range Selection - { - get - { - Gtk.TextIter start, end; - if (Control.Buffer.GetSelectionBounds(out start, out end)) - return new Range(start.Offset, end.Offset - start.Offset); - return new Range(Control.Buffer.CursorPosition, 0); - } - set - { - sendSelectionChanged = false; - var start = Control.Buffer.GetIterAtOffset(value.Start); - var end = Control.Buffer.GetIterAtOffset(value.Start + value.Length); - Control.Buffer.SelectRange(start, end); - Widget.OnSelectionChanged(EventArgs.Empty); - sendSelectionChanged = true; - } - } - - public void SelectAll() - { - Control.Buffer.SelectRange(Control.Buffer.StartIter, Control.Buffer.EndIter); - } - - public int CaretIndex - { - get { return Control.Buffer.GetIterAtMark(Control.Buffer.InsertMark).Offset; } - set - { - var ins = Control.Buffer.GetIterAtOffset(value); - Control.Buffer.SelectRange(ins, ins); - } - } - - public override Font Font - { - get { return base.Font; } - set - { - base.Font = value; - if (value != null) - { - if (tag == null) - { - tag = new Gtk.TextTag("font"); - Control.Buffer.TagTable.Add(tag); - Control.Buffer.Changed += Connector.HandleApplyTag; - Control.Buffer.ApplyTag(tag, Control.Buffer.StartIter, Control.Buffer.EndIter); - } - value.Apply(tag); - } - else - { - Control.Buffer.RemoveAllTags(Control.Buffer.StartIter, Control.Buffer.EndIter); - } - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/TextBoxHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/TextBoxHandler.cs deleted file mode 100644 index f92e324560..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/TextBoxHandler.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class TextBoxHandler : GtkControl, ITextBox - { - string placeholderText; - - public TextBoxHandler() - { - Control = new Gtk.Entry(); - Control.SetSizeRequest(100, -1); - Control.ActivatesDefault = true; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - Control.Changed += Connector.HandleTextChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - protected new TextBoxConnector Connector { get { return (TextBoxConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new TextBoxConnector(); - } - - protected class TextBoxConnector : GtkControlConnector - { - public new TextBoxHandler Handler { get { return (TextBoxHandler)base.Handler; } } - - public void HandleTextChanged(object sender, EventArgs e) - { - Handler.Widget.OnTextChanged(EventArgs.Empty); - } - - #if GTK2 - - public void HandleExposeEvent(object o, Gtk.ExposeEventArgs args) - { - var control = Handler.Control; - if (!string.IsNullOrEmpty(control.Text) || args.Event.Window == control.GdkWindow) - return; - - if (Handler.placeholderLayout == null) - { - Handler.placeholderLayout = new Pango.Layout(control.PangoContext); - Handler.placeholderLayout.FontDescription = control.PangoContext.FontDescription.Copy(); - } - Handler.placeholderLayout.SetText(Handler.placeholderText); - - int currentHeight, currentWidth; - args.Event.Window.GetSize(out currentWidth, out currentHeight); - - int width, height; - Handler.placeholderLayout.GetPixelSize(out width, out height); - - var style = control.Style; - var bc = style.Base(Gtk.StateType.Normal); - var tc = style.Text(Gtk.StateType.Normal); - - using (var gc = new Gdk.GC(args.Event.Window)) - { - gc.Copy(style.TextGC(Gtk.StateType.Normal)); - - gc.RgbFgColor = new Gdk.Color((byte)(((int)bc.Red + tc.Red) / 2 / 256), (byte)(((int)bc.Green + (int)tc.Green) / 2 / 256), (byte)((bc.Blue + tc.Blue) / 2 / 256)); - - args.Event.Window.DrawLayout(gc, 2, (currentHeight - height) / 2 + 1, Handler.placeholderLayout); - } - } - #endif - } - #if GTK2 - Pango.Layout placeholderLayout; - public override Eto.Drawing.Font Font - { - get { return base.Font; } - set - { - base.Font = value; - placeholderLayout = null; - } - } - #else - protected override void SetBackgroundColor(Eto.Drawing.Color? color) - { - } - #endif - - public override string Text - { - get { return Control.Text; } - set { Control.Text = value ?? string.Empty; } - } - - public bool ReadOnly - { - get { return !Control.IsEditable; } - set { Control.IsEditable = !value; } - } - - public int MaxLength - { - get { return Control.MaxLength; } - set { Control.MaxLength = value; } - } - - public string PlaceholderText - { - get { return placeholderText; } - set - { -#if GTK2 - if (!string.IsNullOrEmpty(placeholderText)) - Control.ExposeEvent -= Connector.HandleExposeEvent; - placeholderText = value; - if (!string.IsNullOrEmpty(placeholderText)) - Control.ExposeEvent += Connector.HandleExposeEvent; -#else - placeholderText = value; -#endif - } - } - - public void SelectAll() - { - Control.GrabFocus(); - if (!string.IsNullOrEmpty(Control.Text)) - Control.SelectRegion(0, Control.Text.Length); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/TreeGridViewHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/TreeGridViewHandler.cs deleted file mode 100644 index 3121a47389..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/TreeGridViewHandler.cs +++ /dev/null @@ -1,307 +0,0 @@ -using System; -using Eto.Forms; -using System.Collections.Generic; -using Eto.Platform.GtkSharp.Forms.Cells; - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class TreeGridViewHandler : GridHandler, ITreeGridView, ICellDataSource, IGtkListModelHandler> - { - GtkTreeModel> model; - CollectionHandler collection; - bool? selectCollapsingItem; - ITreeGridItem lastSelected; - - protected override void Initialize() - { - base.Initialize(); - - // these are always handled to set the expanded property - Widget.HandleEvent(TreeGridView.ExpandedEvent, TreeGridView.CollapsedEvent, TreeGridView.CollapsingEvent); - } - - protected override ITreeModelImplementor CreateModelImplementor() - { - model = new GtkTreeModel> { Handler = this }; - return model; - } - - public class CollectionHandler : DataStoreChangedHandler> - { - WeakReference handler; - public TreeGridViewHandler Handler { get { return (TreeGridViewHandler)handler.Target; } set { handler = new WeakReference(value); } } - - void ExpandItems(ITreeGridStore store, Gtk.TreePath path) - { - for (int i = 0; i < store.Count; i++) - { - var item = store[i]; - if (item.Expandable && item.Expanded) - { - var newpath = path.Copy(); - newpath.AppendIndex(i); - Handler.Tree.ExpandToPath(newpath); - ExpandItems((ITreeGridStore)item, newpath); - } - } - } - - void ExpandItems() - { - var store = Handler.collection.Collection; - var path = new Gtk.TreePath(); - ExpandItems(store, path); - } - - public override void AddRange(IEnumerable items) - { - Handler.UpdateModel(); - ExpandItems(); - } - - public override void AddItem(ITreeGridItem item) - { - var path = new Gtk.TreePath(); - path.AppendIndex(Collection.Count); - var iter = Handler.model.GetIterFromItem(item, path); - Handler.Tree.Model.EmitRowInserted(path, iter); - } - - public override void InsertItem(int index, ITreeGridItem item) - { - var path = new Gtk.TreePath(); - path.AppendIndex(index); - var iter = Handler.model.GetIterFromItem(item, path); - Handler.Tree.Model.EmitRowInserted(path, iter); - } - - public override void RemoveItem(int index) - { - var path = new Gtk.TreePath(); - path.AppendIndex(index); - Handler.Tree.Model.EmitRowDeleted(path); - } - - public override void RemoveAllItems() - { - Handler.UpdateModel(); - } - } - - public ITreeGridStore DataStore - { - get { return collection != null ? collection.Collection : null; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler { Handler = this }; - collection.Register(value); - } - } - - public ITreeGridItem SelectedItem - { - get - { - Gtk.TreeIter iter; - return Tree.Selection.GetSelected(out iter) ? model.GetItemAtIter(iter) : null; - } - set - { - if (value != null) - { - var path = model.GetPathFromItem(value); - if (path != null) - { - Tree.ExpandToPath(path); - Tree.Selection.SelectPath(path); - Tree.ScrollToCell(path, null, false, 0, 0); - } - } - else - Tree.Selection.UnselectAll(); - } - } - - bool ChildIsSelected(ITreeGridItem item) - { - var node = SelectedItem; - - while (node != null) - { - if (node == item) - return true; - node = node.Parent; - } - return false; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TreeGridView.ExpandingEvent: - Tree.TestExpandRow += Connector.HandleTestExpandRow; - break; - case TreeGridView.ExpandedEvent: - Tree.RowExpanded += Connector.HandleRowExpanded; - break; - case TreeGridView.CollapsingEvent: - Tree.TestCollapseRow += Connector.HandleTestCollapseRow; - break; - case TreeGridView.CollapsedEvent: - Tree.RowCollapsed += Connector.HandleRowCollapsed; - break; - case TreeGridView.SelectedItemChangedEvent: - Tree.Selection.Changed += Connector.HandleSelectionChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - protected new TreeGridViewConnector Connector { get { return (TreeGridViewConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new TreeGridViewConnector(); - } - - protected class TreeGridViewConnector : GridConnector - { - public new TreeGridViewHandler Handler { get { return (TreeGridViewHandler)base.Handler; } } - - public void HandleTestExpandRow(object o, Gtk.TestExpandRowArgs args) - { - var h = Handler; - var e = new TreeGridViewItemCancelEventArgs(h.GetItem(args.Path) as ITreeGridItem); - h.Widget.OnExpanding(e); - args.RetVal = e.Cancel; - } - - public void HandleRowExpanded(object o, Gtk.RowExpandedArgs args) - { - var h = Handler; - var e = new TreeGridViewItemEventArgs(h.GetItem(args.Path) as ITreeGridItem); - e.Item.Expanded = true; - h.Widget.OnExpanded(e); - } - - public void HandleTestCollapseRow(object o, Gtk.TestCollapseRowArgs args) - { - var h = Handler; - var e = new TreeGridViewItemCancelEventArgs(h.GetItem(args.Path) as ITreeGridItem); - h.Widget.OnCollapsing(e); - args.RetVal = e.Cancel; - if (!e.Cancel) - { - h.selectCollapsingItem = !h.AllowMultipleSelection && h.ChildIsSelected(e.Item); - h.SkipSelectedChange = true; - } - } - - public void HandleRowCollapsed(object o, Gtk.RowCollapsedArgs args) - { - var h = Handler; - var e = new TreeGridViewItemEventArgs(h.GetItem(args.Path) as ITreeGridItem); - e.Item.Expanded = false; - h.Widget.OnCollapsed(e); - h.SkipSelectedChange = false; - if (h.selectCollapsingItem == true) - { - h.Tree.Selection.UnselectAll(); - h.Tree.Selection.SelectPath(args.Path); - h.selectCollapsingItem = null; - } - } - - public void HandleSelectionChanged(object sender, EventArgs e) - { - var h = Handler; - var item = h.SelectedItem; - if (!h.SkipSelectedChange && !object.ReferenceEquals(item, h.lastSelected)) - { - h.Widget.OnSelectedItemChanged(EventArgs.Empty); - h.lastSelected = item; - } - } - } - - public override object GetItem(Gtk.TreePath path) - { - return model.GetItemAtPath(path); - } - - public override Gtk.TreeIter GetIterAtRow(int row) - { - throw new NotImplementedException(); - } - - public GLib.Value GetColumnValue(ITreeGridItem item, int dataColumn, int row) - { - int column; - if (ColumnMap.TryGetValue(dataColumn, out column)) - { - var colHandler = (IGridColumnHandler)Widget.Columns[column].Handler; - return colHandler.GetValue(item, dataColumn, row); - } - return new GLib.Value((string)null); - } - - public int GetRowOfItem(ITreeGridItem item) - { - return collection == null ? -1 : collection.IndexOf(item); - } - - int GetCount(Gtk.TreeIter parent, int upToIndex) - { - int rows = upToIndex == -1 ? model.IterNChildren(parent) : upToIndex; - int count = 0; - for (int i = 0; i < rows; i++) - { - Gtk.TreeIter iter; - if (model.IterNthChild(out iter, parent, i)) - { - var childPath = model.GetPath(iter); - - if (Tree.GetRowExpanded(childPath)) - { - count += GetCount(iter, -1); - } - } - count++; - } - return count; - } - - public override IEnumerable SelectedRows - { - get - { - var rows = Tree.Selection.GetSelectedRows(); - foreach (var row in rows) - { - int count = 0; - var path = new Gtk.TreePath(); - count += GetCount(Gtk.TreeIter.Zero, row.Indices[0]); - // slow but works for now - for (int i = 0; i < row.Indices.Length - 1; i++) - { - path.AppendIndex(row.Indices[i]); - Gtk.TreeIter iter; - if (model.GetIter(out iter, path)) - count += GetCount(iter, row.Indices[i + 1]); - } - count += row.Indices.Length - 1; - //count += row.Indices[row.Indices.Length - 1]; - - yield return count; - } - - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/TreeViewHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/TreeViewHandler.cs deleted file mode 100644 index 6dad79fe76..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/TreeViewHandler.cs +++ /dev/null @@ -1,406 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp.Forms -{ - public class TreeViewHandler : GtkControl, ITreeView, IGtkListModelHandler - { - GtkTreeModel model; - CollectionHandler collection; - readonly Gtk.TreeView tree; - ContextMenu contextMenu; - bool cancelExpandCollapseEvents; - readonly Gtk.CellRendererText textCell; - public static Size MaxImageSize = new Size(16, 16); - - public override Gtk.Widget EventControl - { - get { return tree; } - } - - public class CollectionHandler : DataStoreChangedHandler - { - WeakReference handler; - public TreeViewHandler Handler { get { return (TreeViewHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public void ExpandItems(ITreeStore store, Gtk.TreePath path) - { - Handler.cancelExpandCollapseEvents = true; - PerformExpandItems(store, path); - Handler.cancelExpandCollapseEvents = false; - } - - void PerformExpandItems(ITreeStore store, Gtk.TreePath path) - { - var newpath = path.Copy(); - newpath.AppendIndex(0); - for (int i = 0; i < store.Count; i++) - { - var item = store[i]; - if (item.Expandable) - { - if (item.Expanded) - { - Handler.tree.ExpandToPath(newpath); - PerformExpandItems(item, newpath); - } - else - { - Handler.tree.CollapseRow(newpath); - } - } - newpath.Next(); - } - } - - public void ExpandItems() - { - var store = Handler.collection.Collection; - ExpandItems(store, new Gtk.TreePath()); - } - - public override void AddRange(IEnumerable items) - { - Handler.UpdateModel(); - ExpandItems(); - } - - public override void AddItem(ITreeItem item) - { - var path = new Gtk.TreePath(); - path.AppendIndex(Collection.Count); - var iter = Handler.model.GetIterFromItem(item, path); - Handler.tree.Model.EmitRowInserted(path, iter); - } - - public override void InsertItem(int index, ITreeItem item) - { - var path = new Gtk.TreePath(); - path.AppendIndex(index); - var iter = Handler.model.GetIterFromItem(item, path); - Handler.tree.Model.EmitRowInserted(path, iter); - } - - public override void RemoveItem(int index) - { - var path = new Gtk.TreePath(); - path.AppendIndex(index); - Handler.tree.Model.EmitRowDeleted(path); - } - - public override void RemoveAllItems() - { - Handler.UpdateModel(); - } - } - - void UpdateModel() - { - model = new GtkTreeModel { Handler = this }; - tree.Model = new Gtk.TreeModelAdapter(model); - } - - public TreeViewHandler() - { - tree = new Gtk.TreeView(); - UpdateModel(); - tree.HeadersVisible = false; - - var col = new Gtk.TreeViewColumn(); - var pbcell = new Gtk.CellRendererPixbuf(); - col.PackStart(pbcell, false); - col.SetAttributes(pbcell, "pixbuf", 1); - textCell = new Gtk.CellRendererText(); - col.PackStart(textCell, true); - col.SetAttributes(textCell, "text", 0); - tree.AppendColumn(col); - - tree.ShowExpanders = true; - - Control = new Gtk.ScrolledWindow(); - Control.ShadowType = Gtk.ShadowType.In; - Control.Add(tree); - - tree.Events |= Gdk.EventMask.ButtonPressMask; - } - - protected override void Initialize() - { - base.Initialize(); - tree.ButtonPressEvent += Connector.HandleTreeButtonPressEvent; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TreeView.ExpandingEvent: - tree.TestExpandRow += Connector.HandleTestExpandRow; - break; - case TreeView.ExpandedEvent: - tree.RowExpanded += Connector.HandleRowExpanded; - break; - case TreeView.CollapsingEvent: - tree.TestCollapseRow += Connector.HandleTestCollapseRow; - break; - case TreeView.CollapsedEvent: - tree.RowCollapsed += Connector.HandleRowCollapsed; - break; - case TreeView.ActivatedEvent: - tree.RowActivated += Connector.HandleRowActivated; - break; - case TreeView.SelectionChangedEvent: - tree.Selection.Changed += Connector.HandleSelectionChanged; - break; - case TreeView.LabelEditingEvent: - textCell.EditingStarted += Connector.HandleEditingStarted; - break; - case TreeView.LabelEditedEvent: - textCell.Edited += Connector.HandleEdited; - break; - default: - base.AttachEvent(id); - break; - } - } - - public object GetItem(Gtk.TreePath path) - { - return model.GetItemAtPath(path); - } - - protected new TreeViewConnector Connector { get { return (TreeViewConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new TreeViewConnector(); - } - - protected class TreeViewConnector : GtkControlConnector - { - public new TreeViewHandler Handler { get { return (TreeViewHandler)base.Handler; } } - - public void HandleTestExpandRow(object o, Gtk.TestExpandRowArgs args) - { - var handler = Handler; - if (handler.cancelExpandCollapseEvents) - return; - var e = new TreeViewItemCancelEventArgs(handler.GetItem(args.Path) as ITreeItem); - handler.Widget.OnExpanding(e); - args.RetVal = e.Cancel; - } - - public void HandleTestCollapseRow(object o, Gtk.TestCollapseRowArgs args) - { - var handler = Handler; - if (handler.cancelExpandCollapseEvents) - return; - var e = new TreeViewItemCancelEventArgs(handler.GetItem(args.Path) as ITreeItem); - handler.Widget.OnCollapsing(e); - args.RetVal = e.Cancel; - } - - public void HandleRowExpanded(object o, Gtk.RowExpandedArgs args) - { - var handler = Handler; - if (handler.cancelExpandCollapseEvents) - return; - var item = handler.GetItem(args.Path) as ITreeItem; - if (item != null && !item.Expanded) - { - item.Expanded = true; - handler.collection.ExpandItems(item, args.Path); - handler.Widget.OnExpanded(new TreeViewItemEventArgs(item)); - } - } - - public void HandleRowCollapsed(object o, Gtk.RowCollapsedArgs args) - { - var handler = Handler; - if (handler.cancelExpandCollapseEvents) - return; - var item = handler.GetItem(args.Path) as ITreeItem; - if (item != null && item.Expanded) - { - item.Expanded = false; - handler.Widget.OnCollapsed(new TreeViewItemEventArgs(item)); - } - } - - public void HandleRowActivated(object o, Gtk.RowActivatedArgs args) - { - Handler.Widget.OnActivated(new TreeViewItemEventArgs(Handler.model.GetItemAtPath(args.Path))); - } - - public void HandleSelectionChanged(object sender, EventArgs e) - { - Handler.Widget.OnSelectionChanged(EventArgs.Empty); - } - - public void HandleEditingStarted(object o, Gtk.EditingStartedArgs args) - { - var handler = Handler; - var item = handler.model.GetItemAtPath(args.Path); - if (item != null) - { - var itemArgs = new TreeViewItemCancelEventArgs(item); - handler.Widget.OnLabelEditing(itemArgs); - args.RetVal = itemArgs.Cancel; - } - } - - public void HandleEdited(object o, Gtk.EditedArgs args) - { - var handler = Handler; - var item = handler.model.GetItemAtPath(args.Path); - if (item != null) - { - handler.Widget.OnLabelEdited(new TreeViewItemEditEventArgs(item, args.NewText)); - item.Text = args.NewText; - } - } - - [GLib.ConnectBefore] - public void HandleTreeButtonPressEvent(object o, Gtk.ButtonPressEventArgs args) - { - var handler = Handler; - if (handler.contextMenu != null && args.Event.Button == 3 && args.Event.Type == Gdk.EventType.ButtonPress) - { - var menu = ((ContextMenuHandler)handler.contextMenu.Handler).Control; - menu.Popup(); - menu.ShowAll(); - } - } - } - - public ITreeStore DataStore - { - get { return collection != null ? collection.Collection : null; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler { Handler = this }; - collection.Register(value); - } - } - - public ContextMenu ContextMenu - { - get { return contextMenu; } - set { contextMenu = value; } - } - - public ITreeItem SelectedItem - { - get - { - Gtk.TreeIter iter; - if (tree.Selection.GetSelected(out iter)) - { - return model.GetItemAtIter(iter); - } - return null; - } - set - { - if (value != null) - { - var path = model.GetPathFromItem(value); - if (path != null) - { - tree.ExpandToPath(path); - tree.Selection.SelectPath(path); - tree.ScrollToCell(path, null, false, 0, 0); - } - } - else - tree.Selection.UnselectAll(); - } - } - - public GLib.Value GetColumnValue(ITreeItem item, int column, int row) - { - switch (column) - { - case 0: - return new GLib.Value(item.Text); - case 1: - if (item.Image != null) - { - var image = item.Image.Handler as IGtkPixbuf; - if (image != null) - return new GLib.Value(image.GetPixbuf(MaxImageSize)); - } - return new GLib.Value((Gdk.Pixbuf)null); - } - throw new InvalidOperationException(); - } - - public int NumberOfColumns - { - get { return 2; } - } - - public int GetRowOfItem(ITreeItem item) - { - return collection != null ? collection.IndexOf(item) : -1; - } - - public void RefreshData() - { - UpdateModel(); - collection.ExpandItems(); - } - - public void RefreshItem(ITreeItem item) - { - var path = model.GetPathFromItem(item); - if (path != null && path.Depth > 0 && !object.ReferenceEquals(item, collection.Collection)) - { - Gtk.TreeIter iter; - tree.Model.GetIter(out iter, path); - tree.Model.EmitRowChanged(path, iter); - tree.Model.EmitRowHasChildToggled(path, iter); - cancelExpandCollapseEvents = true; - if (item.Expanded) - { - tree.CollapseRow(path); - tree.ExpandRow(path, false); - collection.ExpandItems(item, path); - } - else - tree.CollapseRow(path); - cancelExpandCollapseEvents = false; - } - else - RefreshData(); - } - - public ITreeItem GetNodeAt(PointF point) - { - Gtk.TreePath path; - if (tree.GetPathAtPos((int)point.X, (int)point.Y, out path)) - { - return model.GetItemAtPath(path); - } - return null; - } - - public bool LabelEdit - { - get { return textCell.Editable; } - set { textCell.Editable = value; } - } - - public Color TextColor - { - get { return textCell.ForegroundGdk.ToEto(); } - set { textCell.ForegroundGdk = value.ToGdk(); } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Controls/WebViewHandler.cs b/Source/Eto.Platform.Gtk/Forms/Controls/WebViewHandler.cs deleted file mode 100644 index ddc371d4bf..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Controls/WebViewHandler.cs +++ /dev/null @@ -1,260 +0,0 @@ -using System; -using Eto.Forms; -using System.Web; -using System.Threading; -#if GTK3 -using NewWindowPolicyDecisionRequestedArgs = WebKit.NewWindowPolicyDecisionRequestedArgs; -#endif - -namespace Eto.Platform.GtkSharp.Forms.Controls -{ - public class WebViewHandler : GtkControl, IWebView - { - readonly Gtk.ScrolledWindow scroll; - readonly ManualResetEventSlim returnResetEvent = new ManualResetEventSlim(); - string scriptReturnValue; - const string EtoReturnPrefix = "etoscriptreturn://"; - - public Gtk.ScrolledWindow Scroll - { - get { return scroll; } - } - - public override Gtk.Widget ContainerControl - { - get { return scroll; } - } - - public WebViewHandler() - { - scroll = new Gtk.ScrolledWindow(); - - try - { - Control = new EtoWebView(); - } - catch (Exception ex) - { - throw new EtoException("GTK WebView is only supported on Linux, and requires webkit-sharp", ex); - } - scroll.Add(Control); - } - - protected override void Initialize() - { - base.Initialize(); - Control.PopulatePopup += Connector.HandlePopulatePopup; - HandleEvent(WebView.DocumentLoadingEvent); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case WebView.NavigatedEvent: - HandleEvent(WebView.DocumentLoadedEvent); - break; - case WebView.DocumentLoadedEvent: - Control.LoadFinished += Connector.HandleLoadFinished; - break; - case WebView.DocumentLoadingEvent: -#if GTK2 - Control.NavigationRequested += Connector.HandleNavigationRequested; -#else - Control.NavigationPolicyDecisionRequested += Connector.HandleNavigationPolicyDecisitionRequested; -#endif - break; - case WebView.OpenNewWindowEvent: - // note: requires libwebkitgtk 1.1.4+ - Control.NewWindowPolicyDecisionRequested += Connector.HandleNewWindowPolicyDecisionRequested; - break; - case WebView.DocumentTitleChangedEvent: - Control.TitleChanged += Connector.HandleTitleChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - protected new WebViewConnector Connector { get { return (WebViewConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new WebViewConnector(); - } - - protected class WebViewConnector : GtkControlConnector - { - public new WebViewHandler Handler { get { return (WebViewHandler)base.Handler; } } - - public void HandlePopulatePopup(object o, WebKit.PopulatePopupArgs args) - { - var handler = Handler; - if (handler.BrowserContextMenuEnabled) - return; - // don't allow context menu by default - foreach (var child in args.Menu.Children) - { - args.Menu.Remove(child); - } - } - - public void HandleLoadFinished(object o, WebKit.LoadFinishedArgs args) - { - var handler = Handler; - var uri = args.Frame.Uri != null ? new Uri(args.Frame.Uri) : null; - var e = new WebViewLoadedEventArgs(uri); - if (args.Frame == handler.Control.MainFrame) - handler.Widget.OnNavigated(e); - handler.Widget.OnDocumentLoaded(e); - } -#if GTK2 - public void HandleNavigationRequested(object o, WebKit.NavigationRequestedArgs args) - { - var handler = Handler; - if (args.Request.Uri.StartsWith(EtoReturnPrefix, StringComparison.Ordinal)) - { - // pass back the response to ExecuteScript() - handler.scriptReturnValue = HttpUtility.UrlDecode(args.Request.Uri.Substring(EtoReturnPrefix.Length)); - handler.returnResetEvent.Set(); - args.RetVal = WebKit.NavigationResponse.Ignore; - } - else - { - var e = new WebViewLoadingEventArgs(new Uri(args.Request.Uri), false); - handler.Widget.OnDocumentLoading(e); - args.RetVal = e.Cancel ? WebKit.NavigationResponse.Ignore : WebKit.NavigationResponse.Accept; - } - } - -#else - public void HandleNavigationPolicyDecisitionRequested(object o, WebKit.NavigationPolicyDecisionRequestedArgs args) - { - var handler = Handler; - if (args.Request.Uri.StartsWith(EtoReturnPrefix, StringComparison.Ordinal)) - { - // pass back the response to ExecuteScript() - handler.scriptReturnValue = HttpUtility.UrlDecode(args.Request.Uri.Substring(EtoReturnPrefix.Length)); - handler.returnResetEvent.Set(); - args.PolicyDecision.Ignore(); - } - else - { - var e = new WebViewLoadingEventArgs(new Uri(args.Request.Uri), false); - handler.Widget.OnDocumentLoading(e); - if (e.Cancel) - args.PolicyDecision.Ignore(); - else - args.PolicyDecision.Use(); - } - } -#endif - - public void HandleNewWindowPolicyDecisionRequested(object sender, NewWindowPolicyDecisionRequestedArgs args) - { - var handler = Handler; - var e = new WebViewNewWindowEventArgs(new Uri(args.Request.Uri), args.Frame.Name); - handler.Widget.OnOpenNewWindow(e); - #if GTK2 - if (e.Cancel) - args.Decision.Ignore(); - else - args.Decision.Use(); - #else - if (e.Cancel) - args.PolicyDecision.Ignore(); - else - args.PolicyDecision.Use(); - #endif - args.RetVal = true; - } - - public void HandleTitleChanged(object o, WebKit.TitleChangedArgs args) - { - Handler.Widget.OnDocumentTitleChanged(new WebViewTitleEventArgs(args.Title)); - } - } - - public Uri Url - { - get { return new Uri(Control.Uri); } - set - { - if (value != null) - { - Control.LoadUri(value.AbsoluteUri); - } - else - Control.LoadHtmlString(string.Empty, string.Empty); - } - } - - public string DocumentTitle - { - get - { - return Control.MainFrame.Title; - } - } - - public string ExecuteScript(string script) - { - // no access to DOM or return value, so get return value via URL (limited length, but better than nothing) - var getResultScript = @"try {{ var fn = function () {{ {0} }}; window.location.href = '" + EtoReturnPrefix + @"' + encodeURI(fn()); }} catch (e) {{ window.location.href = '" + EtoReturnPrefix + @"'; }}"; - returnResetEvent.Reset(); - Control.ExecuteScript(string.Format(getResultScript, script)); - while (!returnResetEvent.Wait(0)) - { - Gtk.Application.RunIteration(); - } - return scriptReturnValue; - } - - public void LoadHtml(string html, Uri baseUri) - { - Control.LoadHtmlString(html, baseUri != null ? baseUri.AbsoluteUri : null); - } - - public void Stop() - { - Control.StopLoading(); - } - - public void Reload() - { - Control.Reload(); - } - - public void GoBack() - { - Control.GoBack(); - } - - public void GoForward() - { - Control.GoForward(); - } - - public bool CanGoBack - { - get { return Control.CanGoBack(); } - } - - public bool CanGoForward - { - get { return Control.CanGoForward(); } - } - - public void ShowPrintDialog() - { - Control.ExecuteScript("print();"); - } - - public bool BrowserContextMenuEnabled - { - get; - set; - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/CursorHandler.cs b/Source/Eto.Platform.Gtk/Forms/CursorHandler.cs deleted file mode 100644 index f4ab921f09..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/CursorHandler.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms -{ - public class CursorHandler : WidgetHandler, ICursor - { - - public void Create (CursorType cursor) - { - Control = new Gdk.Cursor(cursor.ToGdk ()); - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/DialogHandler.cs b/Source/Eto.Platform.Gtk/Forms/DialogHandler.cs deleted file mode 100644 index 3040c8a1f8..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/DialogHandler.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class DialogHandler : GtkWindow, IDialog - { - public class MyDialog : Gtk.Dialog - { - #if GTK3 - protected override void OnAdjustSizeAllocation(Gtk.Orientation orientation, out int minimum_size, out int natural_size, out int allocated_pos, out int allocated_size) - { - base.OnAdjustSizeAllocation(orientation, out minimum_size, out natural_size, out allocated_pos, out allocated_size); - if (orientation == Gtk.Orientation.Horizontal) - allocated_size = natural_size; - } - #endif - } - - public DialogHandler() - { - Control = new MyDialog(); -#if GTK2 - Control.AllowShrink = false; - Control.AllowGrow = false; - Control.HasSeparator = false; -#else - Control.Resizable = false; - Control.HasResizeGrip = false; -#endif - } - - protected override void Initialize() - { - base.Initialize(); -#if GTK2 - Control.VBox.PackStart(WindowActionControl, false, true, 0); - Control.VBox.PackStart(WindowContentControl, true, true, 0); -#else - Control.ActionArea.Add(WindowActionControl); - Control.ContentArea.Add(WindowContentControl); -#endif - } - - public Button AbortButton { get; set; } - - public Button DefaultButton { get; set; } - - public DialogDisplayMode DisplayMode { get; set; } - - public DialogResult ShowDialog(Control parent) - { - if (parent != null) - { - Control.TransientFor = ((Gtk.Window)(parent.ParentWindow).ControlObject); - Control.Modal = true; - } - Control.ShowAll(); - - if (DefaultButton != null) - { - var widget = DefaultButton.GetContainerWidget(); - if (widget != null) - { -#if GTK2 - widget.SetFlag(Gtk.WidgetFlags.CanDefault); -#else - widget.CanDefault = true; -#endif - Control.Default = widget; - } - } - // TODO: implement cancel button somehow? - - Control.Run(); - Control.Hide(); - - return Widget.DialogResult; - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/FontDialogHandler.cs b/Source/Eto.Platform.Gtk/Forms/FontDialogHandler.cs deleted file mode 100644 index 72ab84e8ad..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/FontDialogHandler.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Eto.Drawing; -using Eto.Forms; -using System; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp.Forms -{ - public class FontDialogHandler : WidgetHandler, IFontDialog - { - public override Gtk.FontSelectionDialog CreateControl() - { - return new Gtk.FontSelectionDialog(null); - } - - public Font Font - { - get; - set; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case FontDialog.FontChangedEvent: - // handled in ShowDialog - break; - default: - base.AttachEvent(id); - break; - } - } - - public DialogResult ShowDialog(Window parent) - { - if (parent != null) - { - Control.TransientFor = ((Gtk.Window)parent.ControlObject); - Control.Modal = true; - } - if (Font != null) - { - var fontHandler = Font.Handler as FontHandler; - Control.SetFontName(fontHandler.Control.ToString()); - } - else - Control.SetFontName(string.Empty); - - Control.ShowAll(); - var response = (Gtk.ResponseType)Control.Run(); - Control.Hide(); - - if (response == Gtk.ResponseType.Apply || response == Gtk.ResponseType.Ok) - { - Font = new Font(Widget.Generator, new FontHandler(Control.FontName)); - Widget.OnFontChanged(EventArgs.Empty); - return DialogResult.Ok; - } - return DialogResult.Cancel; - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/FormHandler.cs b/Source/Eto.Platform.Gtk/Forms/FormHandler.cs deleted file mode 100644 index b24fe96ca1..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/FormHandler.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class FormHandler : GtkWindow, IForm - { - public FormHandler() - { - Control = new Gtk.Window(Gtk.WindowType.Toplevel); -#if GTK2 - Control.AllowShrink = true; - Control.AllowGrow = true; -#else - Control.Resizable = true; -#endif - Control.SetPosition(Gtk.WindowPosition.Center); - } - - protected override void Initialize() - { - base.Initialize(); - var vbox = new Gtk.VBox(); - vbox.PackStart(WindowActionControl, false, true, 0); - vbox.PackStart(WindowContentControl, true, true, 0); - Control.Add(vbox); - } - - public void Show() - { - Control.ShowAll(); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/GtkContainer.cs b/Source/Eto.Platform.Gtk/Forms/GtkContainer.cs deleted file mode 100644 index 18983ca4a3..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/GtkContainer.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Linq; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public abstract class GtkContainer : GtkControl, IContainer - where TControl: Gtk.Widget - where TWidget: Container - { - public bool RecurseToChildren { get { return true; } } - - public virtual Size ClientSize - { - get { return Size; } - set { Size = value; } - } - - public override void SetBackgroundColor() - { - base.SetBackgroundColor(); - foreach (var child in Widget.Controls.Select(r => r.GetGtkControlHandler()).Where(r => r != null)) - { - child.SetBackgroundColor(); - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Menu/ButtonMenuItemHandler.cs b/Source/Eto.Platform.Gtk/Forms/Menu/ButtonMenuItemHandler.cs deleted file mode 100644 index 93e65e7d09..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Menu/ButtonMenuItemHandler.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using Eto.Drawing; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class ButtonMenuItemHandler : MenuActionItemHandler, IButtonMenuItem - { - string tooltip; - string text; - Keys shortcut; - Image image; - readonly Gtk.AccelLabel label; - - public ButtonMenuItemHandler() - { - Control = new Gtk.ImageMenuItem(); - label = new Gtk.AccelLabel(string.Empty); - label.Xalign = 0; - label.UseUnderline = true; - label.AccelWidget = Control; - Control.Add(label); - } - - protected override void Initialize() - { - base.Initialize(); - Control.Activated += Connector.HandleActivated; - } - - protected new ButtonMenuItemConnector Connector { get { return (ButtonMenuItemConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ButtonMenuItemConnector(); - } - - protected class ButtonMenuItemConnector : WeakConnector - { - public new ButtonMenuItemHandler Handler { get { return (ButtonMenuItemHandler)base.Handler; } } - - public void HandleActivated(object sender, EventArgs e) - { - var handler = Handler; - if (handler.Control.Submenu != null) - handler.ValidateItems (); - handler.Widget.OnClick(e); - } - } - - public bool Enabled - { - get { return Control.Sensitive; } - set { Control.Sensitive = value; } - } - - - public string Text - { - get { return text; } - set - { - text = value; - //string val = (shortcutText.Length > 0) ? text+"\t"+shortcutText : text; - label.Text = GtkControl.StringToMnuemonic(text); - label.UseUnderline = true; - } - } - - public string ToolTip - { - get { return tooltip; } - set - { - tooltip = value; - //label.TooltipText = value; - } - } - - - public Keys Shortcut - { - get { return shortcut; } - set - { - shortcut = value; - } - } - - public Image Image - { - get { return image; } - set - { - image = value; - Control.Image = image.ToGtk (Gtk.IconSize.Menu); - } - } - - public void AddMenu(int index, MenuItem item) - { - if (Control.Submenu == null) Control.Submenu = new Gtk.Menu(); - ((Gtk.Menu)Control.Submenu).Insert((Gtk.Widget)item.ControlObject, index); - } - - public void RemoveMenu(MenuItem item) - { - if (Control.Submenu == null) return; - var menu = (Gtk.Menu)Control.Submenu; - menu.Remove((Gtk.Widget)item.ControlObject); - if (menu.Children.Length == 0) - { - Control.Submenu = null; - } - } - - public void Clear() - { - foreach (Gtk.Widget w in Control.Children) - { - Control.Remove(w); - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Menu/CheckMenuItemHandler.cs b/Source/Eto.Platform.Gtk/Forms/Menu/CheckMenuItemHandler.cs deleted file mode 100644 index b9c8a29f85..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Menu/CheckMenuItemHandler.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class CheckMenuItemHandler : MenuActionItemHandler, ICheckMenuItem - { - string text; - string tooltip; - Keys shortcut; - readonly Gtk.AccelLabel label; - - public CheckMenuItemHandler() - { - Control = new Gtk.CheckMenuItem(); - label = new Gtk.AccelLabel(string.Empty); - label.Xalign = 0; - label.UseUnderline = true; - label.AccelWidget = Control; - Control.Add(label); - } - - protected override void Initialize() - { - base.Initialize(); - Control.Toggled += Connector.HandleToggled; - } - - protected new CheckMenuItemConnector Connector { get { return (CheckMenuItemConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new CheckMenuItemConnector(); - } - - protected class CheckMenuItemConnector : WeakConnector - { - public new CheckMenuItemHandler Handler { get { return (CheckMenuItemHandler)base.Handler; } } - - public void HandleToggled(object sender, EventArgs e) - { - var handler = Handler; - if (!handler.isBeingChecked) - { - handler.isBeingChecked = true; - handler.Control.Active = !handler.Control.Active; // don't let Gtk turn it on/off - handler.isBeingChecked = false; - handler.Widget.OnClick(e); - } - } - } - - public string Text - { - get { return text; } - set - { - text = value; - string val = text; - label.Text = GtkControl.StringToMnuemonic(val); - label.UseUnderline = true; - } - } - - public string ToolTip - { - get { return tooltip; } - set - { - tooltip = value; - //label.TooltipText = value; - } - } - - public Keys Shortcut - { - get { return shortcut; } - set { shortcut = value; } - } - - bool isBeingChecked; - - public bool Checked - { - get { return Control.Active; } - set - { - isBeingChecked = true; - Control.Active = value; - isBeingChecked = false; - } - } - - public bool Enabled - { - get { return Control.Sensitive; } - set { Control.Sensitive = value; } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Menu/ContextMenuHandler.cs b/Source/Eto.Platform.Gtk/Forms/Menu/ContextMenuHandler.cs deleted file mode 100644 index 9e0cc774c9..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Menu/ContextMenuHandler.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class ContextMenuHandler : MenuHandler, IContextMenu - { - - public ContextMenuHandler() - { - Control = new Gtk.Menu(); - } - - public void AddMenu(int index, MenuItem item) - { - Control.Insert((Gtk.Widget)item.ControlObject, index); - - } - - public void RemoveMenu(MenuItem item) - { - Control.Remove((Gtk.Widget)item.ControlObject); - } - - public void Clear() - { - foreach (Gtk.Widget w in Control.Children) - { - Control.Remove(w); - } - } - - public void Show (Control relativeTo) - { - ValidateItems (); - Control.ShowAll (); - Control.Popup (); - } - - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Menu/MenuBarHandler.cs b/Source/Eto.Platform.Gtk/Forms/Menu/MenuBarHandler.cs deleted file mode 100644 index dd4e37e963..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Menu/MenuBarHandler.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - /// - /// Summary description for MenuBarHandler. - /// - public class MenuBarHandler : MenuHandler, IMenuBar - { - - public MenuBarHandler() - { - Control = new Gtk.MenuBar(); - } - - public void AddMenu(int index, MenuItem item) - { - Control.Insert((Gtk.Widget)item.ControlObject, index); - - } - - public void RemoveMenu(MenuItem item) - { - Control.Remove((Gtk.Widget)item.ControlObject); - } - - public void Clear() - { - foreach (Gtk.Widget w in Control.Children) - { - Control.Remove(w); - } - } - - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Menu/MenuHandler.cs b/Source/Eto.Platform.Gtk/Forms/Menu/MenuHandler.cs deleted file mode 100644 index eef517456d..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Menu/MenuHandler.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using Eto.Forms; -using System.Linq; - -namespace Eto.Platform.GtkSharp -{ - public abstract class MenuHandler : WidgetHandler, IMenu - where TWidget: InstanceWidget - { - protected void ValidateItems() - { - var subMenu = Widget as ISubMenuWidget; - if (subMenu != null) - { - foreach (var item in subMenu.Items) - { - item.OnValidate(EventArgs.Empty); - } - } - } - - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Menu/RadioMenuItemHandler.cs b/Source/Eto.Platform.Gtk/Forms/Menu/RadioMenuItemHandler.cs deleted file mode 100644 index 3bc00180f2..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Menu/RadioMenuItemHandler.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - /// - /// Summary description for MenuBarHandler. - /// - public class RadioMenuItemHandler : MenuActionItemHandler, IRadioMenuItem - { - string text; - Keys shortcut; - Gtk.AccelLabel label; - Gtk.Label accelLabel; - bool isActivating; - RadioMenuItemHandler controller; - - public void Create(RadioMenuItem controller) - { - if (controller != null) - { - Control = new Gtk.RadioMenuItem((Gtk.RadioMenuItem)controller.ControlObject); - this.controller = (RadioMenuItemHandler)controller.Handler; - } - else - { - this.controller = this; - Control = new Gtk.RadioMenuItem(string.Empty); - foreach (Gtk.Widget w in Control.Children) - { - Control.Remove(w); - } - } - - var hbox = new Gtk.HBox(false, 4); - label = new Gtk.AccelLabel(string.Empty); - label.Xalign = 0; - label.UseUnderline = true; - label.AccelWidget = Control; - hbox.Add(label); - accelLabel = new Gtk.Label(); - accelLabel.Xalign = 1; - accelLabel.Visible = false; - hbox.Add(accelLabel); - Control.Add(hbox); - } - - protected override void Initialize() - { - base.Initialize(); - Control.Toggled += Connector.HandleToggled; - } - - protected new RadioMenuItemConnector Connector { get { return (RadioMenuItemConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new RadioMenuItemConnector(); - } - - protected class RadioMenuItemConnector : WeakConnector - { - public new RadioMenuItemHandler Handler { get { return (RadioMenuItemHandler)base.Handler; } } - - public void HandleToggled(object sender, EventArgs e) - { - var handler = Handler; - if (!handler.controller.isActivating) - { - handler.Widget.OnClick(e); - } - } - } - - public string Text - { - get { return text; } - set - { - text = value; - label.TextWithMnemonic = text; - } - } - - public string ToolTip - { - get { return label.TooltipText; } - set { label.TooltipText = value; } - } - - public Keys Shortcut - { - get { return shortcut; } - set - { - shortcut = value; - accelLabel.Text = value.ToShortcutString(); - accelLabel.Visible = accelLabel.Text.Length > 0; - } - } - - public bool Checked - { - get { return Control.Active; } - set - { - controller.isActivating = true; - Control.Active = value; - controller.isActivating = false; - } - } - - public bool Enabled - { - get { return Control.Sensitive; } - set { Control.Sensitive = value; } - } - - public void AddMenu(int index, MenuItem item) - { - if (Control.Submenu == null) - Control.Submenu = new Gtk.Menu(); - ((Gtk.Menu)Control.Submenu).Insert((Gtk.Widget)item.ControlObject, index); - } - - public void RemoveMenu(MenuItem item) - { - if (Control.Submenu == null) - return; - var menu = (Gtk.Menu)Control.Submenu; - menu.Remove((Gtk.Widget)item.ControlObject); - if (menu.Children.Length == 0) - { - Control.Submenu = null; - } - } - - public void Clear() - { - foreach (Gtk.Widget w in Control.Children) - { - Control.Remove(w); - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Menu/SeparatorMenuItemHandler.cs b/Source/Eto.Platform.Gtk/Forms/Menu/SeparatorMenuItemHandler.cs deleted file mode 100644 index 43ab83c09d..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Menu/SeparatorMenuItemHandler.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class SeparatorMenuItemHandler : MenuHandler, ISeparatorMenuItem - { - public SeparatorMenuItemHandler() - { - Control = new Gtk.SeparatorMenuItem(); - } - - public void CreateFromCommand(Command command) - { - } - - public string Text - { - get { return null; } - set { throw new NotSupportedException(); } - } - - public string ToolTip - { - get { return null; } - set { throw new NotSupportedException(); } - } - - public Keys Shortcut - { - get { return Keys.None; } - set { throw new NotSupportedException(); } - } - - public bool Enabled - { - get { return false; } - set { } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/MessageBoxHandler.cs b/Source/Eto.Platform.Gtk/Forms/MessageBoxHandler.cs deleted file mode 100644 index 3144a2adb8..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/MessageBoxHandler.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class MessageBoxHandler : WidgetHandler, IMessageBox - { - Gtk.MessageDialog control; - - public string Text { get; set; } - - public string Caption { get; set; } - - public MessageBoxType Type { get; set; } - - public MessageBoxButtons Buttons { get; set; } - - public MessageBoxDefaultButton DefaultButton { get; set; } - - public DialogResult ShowDialog(Control parent) - { - Gtk.Window parentWindow = null; - if (parent != null && parent.ParentWindow != null) - parentWindow = parent.ParentWindow.ControlObject as Gtk.Window; - - control = new Gtk.MessageDialog(parentWindow, Gtk.DialogFlags.Modal, Type.ToGtk(), Buttons.ToGtk(), false, Text); - control.TypeHint = Gdk.WindowTypeHint.Dialog; - var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null); - if (!string.IsNullOrEmpty(caption)) - control.Title = caption; - if (Buttons == MessageBoxButtons.YesNoCancel) - { - // must add cancel manually - var b = (Gtk.Button)control.AddButton(Gtk.Stock.Cancel, (int)Gtk.ResponseType.Cancel); - b.UseStock = true; - } - control.DefaultResponse = DefaultButton.ToGtk(Buttons); - int ret = control.Run(); - control.Destroy(); - var result = ((Gtk.ResponseType)ret).ToEto(); - if (result == DialogResult.None) - { - switch (Buttons) - { - case MessageBoxButtons.OK: - result = DialogResult.Ok; - break; - case MessageBoxButtons.YesNo: - result = DialogResult.No; - break; - case MessageBoxButtons.OKCancel: - case MessageBoxButtons.YesNoCancel: - result = DialogResult.Cancel; - break; - } - } - return result; - } - } - -} diff --git a/Source/Eto.Platform.Gtk/Forms/MouseHandler.cs b/Source/Eto.Platform.Gtk/Forms/MouseHandler.cs deleted file mode 100644 index 52b26a13b4..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/MouseHandler.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class MouseHandler : IMouse - { - public void Initialize () - { - } - - public Widget Widget { get; set; } - - public Eto.Generator Generator { get; set; } - - public PointF Position - { - get - { - int x, y; - Gdk.Display.Default.GetPointer (out x, out y); - return new PointF (x, y); - } - } - - public MouseButtons Buttons - { - get - { - int x, y; - Gdk.ModifierType modifier; - Gdk.Display.Default.GetPointer (out x, out y, out modifier); - return modifier.ToEtoMouseButtons (); - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/OpenFileDialog.cs b/Source/Eto.Platform.Gtk/Forms/OpenFileDialog.cs deleted file mode 100644 index f1bf80ebd8..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/OpenFileDialog.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp -{ - public class OpenFileDialogHandler : GtkFileDialog, IOpenFileDialog - { - public OpenFileDialogHandler() - { - Control = new Gtk.FileChooserDialog(string.Empty, null, Gtk.FileChooserAction.Open); - Control.SetCurrentFolder(System.IO.Directory.GetCurrentDirectory()); - - Control.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); - Control.AddButton(Gtk.Stock.Open, Gtk.ResponseType.Ok); - } - - public bool MultiSelect - { - get { return Control.SelectMultiple; } - set { Control.SelectMultiple = value; } - } - - public IEnumerable Filenames - { - get { return Control.Filenames; } - } - - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/PixelLayoutHandler.cs b/Source/Eto.Platform.Gtk/Forms/PixelLayoutHandler.cs deleted file mode 100644 index c877d0826b..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/PixelLayoutHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public class PixelLayoutHandler : GtkContainer, IPixelLayout - { - public PixelLayoutHandler() - { - Control = new Gtk.Fixed(); - } - - public void Add(Control child, int x, int y) - { - var ctl = child.GetGtkControlHandler(); - - var widget = ctl.ContainerControl; - if (widget.Parent != null) - ((Gtk.Container)widget.Parent).Remove(widget); - Control.Put(widget, x, y); - ctl.CurrentLocation = new Point(x, y); - widget.ShowAll(); - } - - public void Move(Control child, int x, int y) - { - var ctl = child.GetGtkControlHandler(); - if (ctl.CurrentLocation.X != x || ctl.CurrentLocation.Y != y) - { - Control.Move(ctl.ContainerControl, x, y); - - ctl.CurrentLocation = new Point(x, y); - } - } - - public void Remove(Control child) - { - Control.Remove(child.GetContainerWidget()); - } - - public void Update() - { - Control.ResizeChildren(); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/Printing/PrintDialogHandler.cs b/Source/Eto.Platform.Gtk/Forms/Printing/PrintDialogHandler.cs deleted file mode 100644 index 8a6987dbe7..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Printing/PrintDialogHandler.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Printing -{ - public class PrintDialogHandler : WidgetHandler, IPrintDialog - { - PrintSettings settings; - - public PrintDialogHandler () - { - AllowPageRange =true; - } - - public PrintDocument Document { get; set; } - - public class CustomOptions : Gtk.VBox { - public Gtk.CheckButton SelectionOnly { get; private set; } - - public CustomOptions () - { - this.Spacing = 10; - SelectionOnly = new Gtk.CheckButton { Label = "Selection Only" }; - this.PackStart (SelectionOnly, false, false, 10); - } - } - - public DialogResult ShowDialog (Window parent) - { - var parentWindow = parent != null ? (Gtk.Window)parent.ControlObject : null; - Control = new Gtk.PrintUnixDialog(string.Empty, parentWindow); - - if (parent != null) - { - Control.TransientFor = ((Gtk.Window)parent.ControlObject); - Control.Modal = true; - } - - const Gtk.PrintCapabilities caps = Gtk.PrintCapabilities.Preview - | Gtk.PrintCapabilities.Collate - | Gtk.PrintCapabilities.GeneratePdf - | Gtk.PrintCapabilities.Copies - | Gtk.PrintCapabilities.PageSet - | Gtk.PrintCapabilities.GeneratePs - | Gtk.PrintCapabilities.Scale - | Gtk.PrintCapabilities.NumberUp - | Gtk.PrintCapabilities.Reverse; - var printSettingsHandler = (PrintSettingsHandler)PrintSettings.Handler; - - Control.PageSetup = PrintSettings.ToGtkPageSetup (); - Control.PrintSettings = PrintSettings.ToGtkPrintSettings (); - var customOptions = new CustomOptions(); - customOptions.SelectionOnly.Active = printSettingsHandler.SelectionOnly; - - if (AllowSelection) - Control.AddCustomTab (customOptions, new Gtk.Label { Text = "Other Options" }); - - Control.ManualCapabilities = caps; - Control.ShowAll (); - var response = (Gtk.ResponseType)Control.Run (); - Control.Hide (); - - printSettingsHandler.Set(Control.PrintSettings, Control.PageSetup, customOptions.SelectionOnly.Active); - if (response == Gtk.ResponseType.Apply) { - printSettingsHandler.ShowPreview = true; - return DialogResult.Ok; - } - - return response.ToEto (); - } - public PrintSettings PrintSettings { - get { - if (settings == null) settings = new PrintSettings(Widget.Generator); - return settings; - } - set { - settings = value; - } - } - - // not supported in gtk - public bool AllowPageRange { - get; set; - } - - public bool AllowSelection { - get; set; - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Printing/PrintDocumentHandler.cs b/Source/Eto.Platform.Gtk/Forms/Printing/PrintDocumentHandler.cs deleted file mode 100644 index e944248826..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Printing/PrintDocumentHandler.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.GtkSharp.Drawing; - -namespace Eto.Platform.GtkSharp.Forms.Printing -{ - public class PrintDocumentHandler : WidgetHandler, IPrintDocument - { - PrintSettings settings; - - public PrintDocumentHandler () - { - Control = new Gtk.PrintOperation(); - } - - public void Print () - { - var settingsHandler = (PrintSettingsHandler)PrintSettings.Handler; - Control.PrintSettings = settingsHandler.Control; - if (settingsHandler.ShowPreview) - Control.Run (Gtk.PrintOperationAction.Preview, null); - else - Control.Run (Gtk.PrintOperationAction.Print, null); - } - - public override void AttachEvent (string id) - { - switch (id) { - case PrintDocument.PrintingEvent: - Control.BeginPrint += (o, args) => Widget.OnPrinting(EventArgs.Empty); - break; - case PrintDocument.PrintedEvent: - Control.EndPrint += (o, args) => Widget.OnPrinted(EventArgs.Empty); - break; - - case PrintDocument.PrintPageEvent: - Control.DrawPage += (o, args) => { - using (var graphics = new Graphics(Widget.Generator, new GraphicsHandler(args.Context.CairoContext, args.Context.CreatePangoContext ()))) { - var width = args.Context.Width; //.PageSetup.GetPageWidth(Gtk.Unit.Points); - var height = args.Context.Height; //.PageSetup.GetPageHeight(Gtk.Unit.Points); - var e = new PrintPageEventArgs(graphics, new SizeF((float)width, (float)height), args.PageNr); - Widget.OnPrintPage (e); - } - }; - break; - default: - base.AttachEvent (id); - break; - } - } - - public string Name { - get { return Control.JobName; } - set { Control.JobName = value; } - } - - public PrintSettings PrintSettings { - get { - if (settings == null) - settings = Control.PrintSettings.ToEto (Control.DefaultPageSetup, false, Widget.Generator); - return settings; - } - set { - settings = value; - Control.DefaultPageSetup = settings.ToGtkPageSetup (); - Control.PrintSettings = settings.ToGtkPrintSettings (); - } - } - - public int PageCount { - get { return Control.NPages; } - set { Control.NPages = value; } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/Printing/PrintSettingsHandler.cs b/Source/Eto.Platform.Gtk/Forms/Printing/PrintSettingsHandler.cs deleted file mode 100644 index 347adb0219..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/Printing/PrintSettingsHandler.cs +++ /dev/null @@ -1,103 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms.Printing -{ - public static class PrintSettingsExtensions - { - public static PrintSettings ToEto (this Gtk.PrintSettings settings, Gtk.PageSetup setup, bool selectionOnly, Eto.Generator generator) - { - return settings == null ? null : new PrintSettings(generator, new PrintSettingsHandler(settings, setup, selectionOnly)); - } - - public static Gtk.PrintSettings ToGtkPrintSettings (this PrintSettings settings) - { - return settings == null ? null : ((PrintSettingsHandler)settings.Handler).Control; - } - - public static Gtk.PageSetup ToGtkPageSetup (this PrintSettings settings) - { - return settings == null ? null : ((PrintSettingsHandler)settings.Handler).PageSetup; - } - } - - public class PrintSettingsHandler : WidgetHandler, IPrintSettings - { - public bool SelectionOnly { get; set; } - - public Gtk.PageSetup PageSetup { get; set; } - - public bool ShowPreview { get; set; } - - public PrintSettingsHandler () - { - Control = new Gtk.PrintSettings(); - PageSetup = new Gtk.PageSetup(); - MaximumPageRange = new Range(1, 1); - Collate = true; - } - - public PrintSettingsHandler (Gtk.PrintSettings settings, Gtk.PageSetup setup, bool selectionOnly) - { - MaximumPageRange = new Range(1, 1); - Set (settings, setup, selectionOnly); - } - - public void Set (Gtk.PrintSettings settings, Gtk.PageSetup setup, bool selectionOnly) - { - Control = settings; - PageSetup = setup; - SelectionOnly = selectionOnly; - } - - public int Copies { - get { return Control.NCopies; } - set { Control.NCopies = value; } - } - - public Range MaximumPageRange { - get; set; - } - - public Range SelectedPageRange { - get { - int num_ranges; - return Control.GetPageRanges (out num_ranges).ToEto (); - } - set { - Control.SetPageRanges(value.ToGtkPageRange (), 1); - } - } - - public PrintSelection PrintSelection { - get { - if (SelectionOnly) - return PrintSelection.Selection; - return Control.PrintPages.ToEto (); - } - set { - if (value == Eto.Forms.PrintSelection.Selection) - SelectionOnly = true; - else { - Control.PrintPages = value.ToGtk (); - SelectionOnly = false; - } - } - } - - public PageOrientation Orientation { - get { return PageSetup.Orientation.ToEto (); } - set { PageSetup.Orientation = value.ToGtk (); } - } - - public bool Collate { - get { return Control.Collate; } - set { Control.Collate = value; } - } - - public bool Reverse { - get { return Control.Reverse; } - set { Control.Reverse = value; } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/SaveFileDialog.cs b/Source/Eto.Platform.Gtk/Forms/SaveFileDialog.cs deleted file mode 100644 index 0bf49e0f66..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/SaveFileDialog.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class SaveFileDialogHandler : GtkFileDialog, ISaveFileDialog - { - public SaveFileDialogHandler() - { - Control = new Gtk.FileChooserDialog(string.Empty, null, Gtk.FileChooserAction.Save); - Control.DoOverwriteConfirmation = true; - Control.SetCurrentFolder(System.IO.Directory.GetCurrentDirectory()); - - Control.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); - Control.AddButton(Gtk.Stock.Save, Gtk.ResponseType.Ok); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/ScreenHandler.cs b/Source/Eto.Platform.Gtk/Forms/ScreenHandler.cs deleted file mode 100644 index f7438d2731..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ScreenHandler.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp.Forms -{ - public class ScreenHandler : WidgetHandler, IScreen - { - readonly int monitor; - - public ScreenHandler (Gdk.Screen screen, int monitor) - { - this.Control = screen; - this.monitor = monitor; - } - - public float RealScale - { - get { return (float)Control.Resolution / 72f; } - } - - public float Scale - { - get { return (float)Control.Resolution / 72f; } - } - - public RectangleF Bounds - { - get { - return Control.GetMonitorGeometry (monitor).ToEto (); - } - } - - public RectangleF WorkingArea - { - get - { - // todo: available with GTK 3.4 - return Control.GetMonitorGeometry (monitor).ToEto (); - } - } - - public int BitsPerPixel - { - get { return 24; } - } - - public bool IsPrimary - { - get { return monitor == 0; } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/ScreensHandler.cs b/Source/Eto.Platform.Gtk/Forms/ScreensHandler.cs deleted file mode 100644 index 1747108607..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ScreensHandler.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp.Forms -{ - public class ScreensHandler : IScreens - { - public void Initialize () - { - } - - public Widget Widget { get; set; } - - public Eto.Generator Generator { get; set; } - - public IEnumerable Screens - { - get - { - var display = Gdk.Display.Default; - for (int i = 0; i < display.NScreens; i++) { - var screen = display.GetScreen (i); - for (int monitor = 0; monitor < screen.NMonitors; monitor++) { - yield return new Screen (Generator, new ScreenHandler (screen, monitor)); - } - } - } - } - - public Screen PrimaryScreen - { - get - { - return new Screen(Generator, new ScreenHandler(Gdk.Display.Default.DefaultScreen, 0)); - } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/SelectFolderDialogHandler.cs b/Source/Eto.Platform.Gtk/Forms/SelectFolderDialogHandler.cs deleted file mode 100644 index 7925544952..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/SelectFolderDialogHandler.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class SelectFolderDialogHandler : WidgetHandler, ISelectFolderDialog - { - public SelectFolderDialogHandler () - { - Control = new Gtk.FileChooserDialog(string.Empty, null, Gtk.FileChooserAction.SelectFolder); - Control.SetCurrentFolder(System.IO.Directory.GetCurrentDirectory()); - - Control.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); - Control.AddButton(Gtk.Stock.Save, Gtk.ResponseType.Ok); - } - - - public DialogResult ShowDialog (Window parent) - { - if (parent != null) Control.TransientFor = (Gtk.Window)parent.ControlObject; - - int result = Control.Run(); - - Control.Hide (); - - DialogResult response = ((Gtk.ResponseType)result).ToEto (); - if (response == DialogResult.Ok) System.IO.Directory.SetCurrentDirectory(Control.CurrentFolder); - - return response; - } - - public string Title - { - get { return Control.Title; } - set { Control.Title = value; } - } - - public string Directory - { - get { return Control.CurrentFolder; } - set { Control.SetCurrentFolder(value); } - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Forms/TableLayoutHandler.cs b/Source/Eto.Platform.Gtk/Forms/TableLayoutHandler.cs deleted file mode 100644 index 032d37a49b..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/TableLayoutHandler.cs +++ /dev/null @@ -1,209 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using System.Linq; - -namespace Eto.Platform.GtkSharp -{ - public class TableLayoutHandler : GtkContainer, ITableLayout - { - const Gtk.AttachOptions SCALED_OPTIONS = Gtk.AttachOptions.Expand | Gtk.AttachOptions.Shrink | Gtk.AttachOptions.Fill; - Gtk.Alignment align; - Gtk.EventBox box; - bool[] columnScale; - int lastColumnScale; - bool[] rowScale; - int lastRowScale; - Control[,] controls; - Gtk.Widget[,] blank; - - public override Gtk.Widget ContainerControl - { - get { return box; } - } - - public Size Spacing - { - get { return new Size((int)Control.ColumnSpacing, (int)Control.RowSpacing); } - set - { - Control.ColumnSpacing = (uint)value.Width; - Control.RowSpacing = (uint)value.Height; - } - } - - public Padding Padding - { - get - { - uint top, bottom, left, right; - align.GetPadding(out top, out bottom, out left, out right); - return new Padding((int)left, (int)top, (int)right, (int)bottom); - } - set - { - align.SetPadding((uint)value.Top, (uint)value.Bottom, (uint)value.Left, (uint)value.Right); - } - } - - public void Add(Control child, int x, int y) - { - Attach(child, x, y); - if (child != null) - { - var widget = child.GetContainerWidget(); - widget.ShowAll(); - } - } - - public void Move(Control child, int x, int y) - { - Attach(child, x, y); - } - - Gtk.AttachOptions GetColumnOptions(int column) - { - var scale = columnScale[column] || column == lastColumnScale; - return scale ? SCALED_OPTIONS : Gtk.AttachOptions.Fill; - } - - Gtk.AttachOptions GetRowOptions(int row) - { - var scale = rowScale[row] || row == lastRowScale; - return scale ? SCALED_OPTIONS : Gtk.AttachOptions.Fill; - } - - public void CreateControl(int cols, int rows) - { - columnScale = new bool[cols]; - lastColumnScale = cols - 1; - rowScale = new bool[rows]; - lastRowScale = rows - 1; - align = new Gtk.Alignment(0, 0, 1.0F, 1.0F); - Control = new Gtk.Table((uint)rows, (uint)cols, false); - controls = new Control[rows, cols]; - blank = new Gtk.Widget[rows, cols]; - align.Add(Control); - box = new Gtk.EventBox { Child = align }; - - Spacing = TableLayout.DefaultSpacing; - Padding = TableLayout.DefaultPadding; - } - - public void SetColumnScale(int column, bool scale) - { - columnScale[column] = scale; - var lastScale = lastColumnScale; - lastColumnScale = columnScale.Any(r => r) ? -1 : columnScale.Length - 1; - AttachColumn(column); - if (lastScale != lastColumnScale && column != columnScale.Length - 1) - { - AttachColumn(columnScale.Length - 1); - } - } - - public bool GetColumnScale(int column) - { - return columnScale[column]; - } - - void AttachColumn(int column) - { - for (int y = 0; y < controls.GetLength (0); y++) - { - Attach(controls[y, column], column, y); - } - } - - void AttachRow(int row) - { - for (int x = 0; x < controls.GetLength (1); x++) - { - Attach(controls[row, x], x, row); - } - } - - bool Attach(Control child, int x, int y) - { - var old = controls[y, x]; - if (old != null && !object.ReferenceEquals(old, child)) - { - var widget = old.GetContainerWidget(); - if (widget.Parent != null) - Control.Remove(widget); - } - - if (child != null) - { - var blankWidget = blank[y, x]; - if (blankWidget != null) - { - if (blankWidget.Parent != null) - Control.Remove(blankWidget); - blank[y, x] = null; - } - - controls[y, x] = child; - var widget = child.GetContainerWidget(); - if (widget.Parent != null) - ((Gtk.Container)widget.Parent).Remove(widget); - Control.Attach(widget, (uint)x, (uint)x + 1, (uint)y, (uint)y + 1, GetColumnOptions(x), GetRowOptions(y), 0, 0); - widget.ShowAll(); - return true; - } - else - { - controls[y, x] = null; - var blankWidget = blank[y, x]; - if (blankWidget == null) - blankWidget = blank[y, x] = new Gtk.VBox(); - else if (blankWidget.Parent != null) - Control.Remove(blankWidget); - Control.Attach(blankWidget, (uint)x, (uint)x + 1, (uint)y, (uint)y + 1, GetColumnOptions(x), GetRowOptions(y), 0, 0); - } - return false; - } - - public void Remove(Control child) - { - for (int y = 0; y r) ? -1 : rowScale.Length - 1; - AttachRow(row); - if (lastScale != lastRowScale && row != rowScale.Length - 1) - { - AttachRow(rowScale.Length - 1); - } - } - - public bool GetRowScale(int row) - { - return rowScale[row]; - } - - public void Update() - { - Control.ResizeChildren(); - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/ToolBar/ButtonToolItemHandler.cs b/Source/Eto.Platform.Gtk/Forms/ToolBar/ButtonToolItemHandler.cs deleted file mode 100644 index 65bb4c3dbc..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ToolBar/ButtonToolItemHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - - public class ButtonToolItemHandler : ToolItemHandler, IButtonToolItem - { - - #region IToolBarButton Members - - - #endregion - - public override void CreateControl(ToolBarHandler handler, int index) - { - Gtk.Toolbar tb = handler.Control; - - Control = new Gtk.ToolButton(GtkImage, Text); - Control.IsImportant = true; - Control.Sensitive = Enabled; - //Control.TooltipText = this.ToolTip; - //control.CanFocus = false; - tb.Insert(Control, index); - if (tb.Visible) Control.ShowAll(); - Control.Clicked += Connector.HandleClicked; - } - - protected new ButtonToolItemConnector Connector { get { return (ButtonToolItemConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new ButtonToolItemConnector(); - } - - protected class ButtonToolItemConnector : WeakConnector - { - public new ButtonToolItemHandler Handler { get { return (ButtonToolItemHandler)base.Handler; } } - - public void HandleClicked(object sender, EventArgs e) - { - Handler.Widget.OnClick(e); - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/ToolBar/CheckToolItemHandler.cs b/Source/Eto.Platform.Gtk/Forms/ToolBar/CheckToolItemHandler.cs deleted file mode 100644 index f15100d923..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ToolBar/CheckToolItemHandler.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class CheckToolItemHandler : ToolItemHandler, ICheckToolItem - { - bool ischecked; - bool isBeingChecked; - - public bool Checked - { - get { return (Control != null) ? Control.Active : ischecked; } - set - { - if (value != ischecked) - { - isBeingChecked = true; - if (Control != null) - Control.Active = value; - isBeingChecked = false; - ischecked = value; - } - } - } - - public override void CreateControl(ToolBarHandler handler, int index) - { - Gtk.Toolbar tb = handler.Control; - - Control = new Gtk.ToggleToolButton(); - Control.Active = ischecked; - Control.Label = Text; - //Control.TooltipText = this.ToolTip; - Control.IconWidget = GtkImage; - Control.Sensitive = Enabled; - Control.CanFocus = false; - Control.IsImportant = true; - tb.Insert(Control, index); - if (tb.Visible) - Control.ShowAll(); - } - - protected override void Initialize() - { - base.Initialize(); - Control.Toggled += Connector.HandleToggled; - } - - protected new CheckToolItemConnector Connector { get { return (CheckToolItemConnector)base.Connector; } } - - protected override WeakConnector CreateConnector() - { - return new CheckToolItemConnector(); - } - - protected class CheckToolItemConnector : WeakConnector - { - public new CheckToolItemHandler Handler { get { return (CheckToolItemHandler)base.Handler; } } - - public void HandleToggled(object sender, EventArgs e) - { - var handler = Handler; - if (!handler.isBeingChecked) - { - handler.isBeingChecked = true; - handler.Control.Active = handler.ischecked; - handler.isBeingChecked = false; - handler.Widget.OnClick(EventArgs.Empty); - } - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/ToolBar/SeparatorToolItemHandler.cs b/Source/Eto.Platform.Gtk/Forms/ToolBar/SeparatorToolItemHandler.cs deleted file mode 100644 index 59efecef5d..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ToolBar/SeparatorToolItemHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class SeparatorToolItemHandler : ToolItemHandler, ISeparatorToolItem - { - SeparatorToolItemType type; - bool expand; - - public override void CreateControl(ToolBarHandler handler, int index) - { - Gtk.Toolbar tb = handler.Control; - Control = new Gtk.SeparatorToolItem(); - Control.Expand = expand; - tb.Insert(Control, index); - if (tb.Visible) - Control.ShowAll(); - } - - public SeparatorToolItemType Type - { - get { return type; } - set - { - type = value; - expand = type == SeparatorToolItemType.FlexibleSpace; - if (Control != null) - Control.Expand = expand; - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/ToolBar/ToolBarHandler.cs b/Source/Eto.Platform.Gtk/Forms/ToolBar/ToolBarHandler.cs deleted file mode 100644 index f82dd4338c..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ToolBar/ToolBarHandler.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public class ToolBarHandler : WidgetHandler, IToolBar - { - ToolBarDock dock = ToolBarDock.Top; - - public ToolBarHandler() - { - Control = new Gtk.Toolbar(); - //control.ToolbarStyle = Gtk.ToolbarStyle.Both; - } - - public ToolBarDock Dock - { - get { return dock; } - set { dock = value; } - } - - public void AddButton(ToolItem item, int index) - { - ((IToolBarItemHandler)item.Handler).CreateControl(this, index); - } - - public void RemoveButton(ToolItem item) - { - if (item.ControlObject != null) Control.Remove((Gtk.Widget)item.ControlObject); - } - - public void Clear() - { - foreach (Gtk.Widget w in Control.Children) - { - Control.Remove(w); - } - } - - public ToolBarTextAlign TextAlign - { - get - { - switch (Control.ToolbarStyle) - { - case Gtk.ToolbarStyle.BothHoriz: - return ToolBarTextAlign.Right; - default: - return ToolBarTextAlign.Underneath; - } - } - set - { - switch (value) - { - case ToolBarTextAlign.Right: - Control.ToolbarStyle = Gtk.ToolbarStyle.BothHoriz; - break; - default: - Control.ToolbarStyle = Gtk.ToolbarStyle.Both; - break; - } - } - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/ToolBar/ToolItemHandler.cs b/Source/Eto.Platform.Gtk/Forms/ToolBar/ToolItemHandler.cs deleted file mode 100644 index 83e5a7c041..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/ToolBar/ToolItemHandler.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.GtkSharp -{ - public interface IToolBarItemHandler - { - void CreateControl(ToolBarHandler handler, int index); - - } - - public abstract class ToolItemHandler : WidgetHandler, IToolItem, IToolBarItemHandler - where TControl: Gtk.Widget - where TWidget: ToolItem - { - bool enabled = true; - Image image; - - protected Gtk.Image GtkImage { get; set; } - - public abstract void CreateControl(ToolBarHandler handler, int index); - - public string Text { get; set; } - - public string ToolTip { get; set; } - - public Image Image - { - get { return image; } - set - { - image = value; - GtkImage = image.ToGtk (Gtk.IconSize.Button); - } - } - - public bool Enabled - { - get { return enabled; } - set { - enabled = value; - if (Control != null) - Control.Sensitive = value; - } - } - - public void CreateFromCommand(Command command) - { - } - } -} diff --git a/Source/Eto.Platform.Gtk/Forms/UITimerHandler.cs b/Source/Eto.Platform.Gtk/Forms/UITimerHandler.cs deleted file mode 100644 index ae0fd8e7ed..0000000000 --- a/Source/Eto.Platform.Gtk/Forms/UITimerHandler.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp.Forms -{ - public class UITimerHandler : WidgetHandler, IUITimer - { - bool enabled; - bool stopped = true; - - public void Start () - { - if (enabled) return; - enabled = true; - if (!stopped) return; - stopped = false; - GLib.Timeout.Add((uint)(Interval * 1000), delegate { - if (!enabled) { - stopped = true; return false; - } - Widget.OnElapsed(EventArgs.Empty); - return true; - }); - } - - public void Stop () - { - enabled = false; - } - - public double Interval { get; set; } - - protected override void Dispose(bool disposing) - { - base.Dispose (disposing); - enabled = false; - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Generator.cs b/Source/Eto.Platform.Gtk/Generator.cs deleted file mode 100644 index c9b867cdfb..0000000000 --- a/Source/Eto.Platform.Gtk/Generator.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; -using Eto.Drawing; -using Eto.Forms; -using Eto.IO; -using Eto.Platform.GtkSharp.Drawing; -using Eto.Platform.GtkSharp.Forms.Cells; -using Eto.Platform.GtkSharp.Forms.Controls; -using Eto.Platform.GtkSharp.Forms.Printing; -using Eto.Platform.GtkSharp.Forms; -using Eto.Platform.GtkSharp.IO; -using Eto.Forms.ThemedControls; - -namespace Eto.Platform.GtkSharp -{ - static class Helper - { - public static void Init() - { - var args = new string[0]; - if (Gtk.Application.InitCheck(string.Empty, ref args)) - { - Gdk.Threads.Enter(); - } - } - } - - public class Generator : Eto.Generator - { - #if GTK2 - public override string ID { get { return Generators.Gtk; } } - #else - public override string ID { get { return Generators.Gtk3; } } - #endif - public Generator() - { - if (EtoEnvironment.Platform.IsWindows && Environment.Is64BitProcess) - throw new NotSupportedException("Please compile/run GTK in x86 mode (32-bit) on windows"); - - AddTo(this); - } - - public static void AddTo(Eto.Generator g) - { - // Drawing - g.Add(() => new BitmapHandler()); - g.Add(() => new FontFamilyHandler()); - g.Add(() => new FontHandler()); - g.Add(() => new FontsHandler()); - g.Add(() => new GraphicsHandler()); - g.Add(() => new GraphicsPathHandler()); - g.Add(() => new IconHandler()); - g.Add(() => new IndexedBitmapHandler()); - g.Add(() => new MatrixHandler()); - g.Add(() => new PenHandler()); - g.Add(() => new SolidBrushHandler()); - g.Add(() => new TextureBrushHandler()); - g.Add(() => new LinearGradientBrushHandler()); - - // Forms.Cells - g.Add(() => new CheckBoxCellHandler()); - g.Add(() => new ComboBoxCellHandler()); - g.Add(() => new ImageTextCellHandler()); - g.Add(() => new ImageViewCellHandler()); - g.Add(() => new TextBoxCellHandler()); - - // Forms.Controls - g.Add(() => new ButtonHandler()); - g.Add(() => new CheckBoxHandler()); - g.Add(() => new ComboBoxHandler()); - g.Add(() => new DateTimePickerHandler()); - g.Add(() => new DrawableHandler()); - g.Add(() => new GridColumnHandler()); - g.Add(() => new GridViewHandler()); - g.Add(() => new GroupBoxHandler()); - g.Add(() => new ImageViewHandler()); - g.Add(() => new LabelHandler()); - g.Add(() => new ListBoxHandler()); - g.Add(() => new NumericUpDownHandler()); - g.Add(() => new PanelHandler()); - g.Add(() => new PasswordBoxHandler()); - g.Add(() => new ProgressBarHandler()); - g.Add(() => new RadioButtonHandler()); - g.Add(() => new ScrollableHandler()); - g.Add(() => new SearchBoxHandler()); - g.Add(() => new SliderHandler()); - #if GTK3 - g.Add(() => new SpinnerHandler()); - #else - g.Add(() => new ThemedSpinnerHandler()); - #endif - g.Add(() => new SplitterHandler()); - g.Add(() => new TabControlHandler()); - g.Add(() => new TabPageHandler()); - g.Add(() => new TextAreaHandler()); - g.Add(() => new TextBoxHandler()); - g.Add(() => new TreeGridViewHandler()); - g.Add(() => new TreeViewHandler()); - g.Add(() => new WebViewHandler()); - g.Add(() => new ScreensHandler()); - - // Forms.Menu - g.Add(() => new CheckMenuItemHandler()); - g.Add(() => new ContextMenuHandler()); - g.Add(() => new ButtonMenuItemHandler()); - g.Add(() => new MenuBarHandler()); - g.Add(() => new RadioMenuItemHandler()); - g.Add(() => new SeparatorMenuItemHandler()); - - // Forms.Printing - g.Add(() => new PrintDialogHandler()); - g.Add(() => new PrintDocumentHandler()); - g.Add(() => new PrintSettingsHandler()); - - // Forms.ToolBar - g.Add(() => new CheckToolItemHandler()); - g.Add(() => new SeparatorToolItemHandler()); - g.Add(() => new ButtonToolItemHandler()); - g.Add(() => new ToolBarHandler()); - - // Forms - g.Add(() => new ApplicationHandler()); - g.Add(() => new ClipboardHandler()); - g.Add(() => new ColorDialogHandler()); - g.Add(() => new CursorHandler()); - g.Add(() => new DialogHandler()); - g.Add(() => new FontDialogHandler()); - g.Add(() => new FormHandler()); - g.Add(() => new MessageBoxHandler()); - g.Add(() => new OpenFileDialogHandler()); - g.Add(() => new PixelLayoutHandler()); - g.Add(() => new SaveFileDialogHandler()); - g.Add(() => new SelectFolderDialogHandler()); - g.Add(() => new TableLayoutHandler()); - g.Add(() => new UITimerHandler()); - g.Add(() => new MouseHandler()); - - // IO - g.Add(() => new SystemIconsHandler()); - - // General - g.Add(() => new EtoEnvironmentHandler()); - } - } -} diff --git a/Source/Eto.Platform.Gtk/IO/SystemIcons.cs b/Source/Eto.Platform.Gtk/IO/SystemIcons.cs deleted file mode 100644 index 8338f3ee60..0000000000 --- a/Source/Eto.Platform.Gtk/IO/SystemIcons.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Eto.Drawing; -using Eto.IO; - -namespace Eto.Platform.GtkSharp.IO -{ - public class SystemIconsHandler : WidgetHandler, ISystemIcons - { - #region ISystemIcons Members - - public Icon GetFileIcon(string fileName, IconSize size) - { - return null; - } - - public Icon GetStaticIcon(StaticIconType type, IconSize size) - { - return null; - } - - #endregion - - } -} diff --git a/Source/Eto.Platform.Gtk/KeyMap.cs b/Source/Eto.Platform.Gtk/KeyMap.cs deleted file mode 100644 index 4a6570f09d..0000000000 --- a/Source/Eto.Platform.Gtk/KeyMap.cs +++ /dev/null @@ -1,157 +0,0 @@ -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.GtkSharp -{ - public static class KeyMap - { - static readonly Dictionary keymap = new Dictionary(); - static readonly Dictionary inversekeymap = new Dictionary(); - - public static Keys ToEto (this Gdk.Key gkey) - { - Keys key; - return keymap.TryGetValue(gkey, out key) ? key : Keys.None; - } - - public static Key ToEtoKey (this Gdk.ModifierType modifier) - { - Key result = Key.None; - if ((modifier & Gdk.ModifierType.Mod1Mask) > 0) result |= Key.Alt; - if ((modifier & Gdk.ModifierType.ControlMask) > 0) result |= Key.Control; - if ((modifier & Gdk.ModifierType.SuperMask) > 0) result |= Key.Application; - if ((modifier & Gdk.ModifierType.ShiftMask) > 0) result |= Key.Shift; - return result; - } - - public static Gdk.Key ToGdkKey (this Keys key) - { - Gdk.Key result; - if (inversekeymap.TryGetValue(key & Keys.KeyMask, out result)) return result; - return (Gdk.Key)0; - } - - public static Gdk.ModifierType ToGdkModifier (this Keys key) - { - Gdk.ModifierType result = Gdk.ModifierType.None; - if (key.HasFlag(Keys.Alt)) result |= Gdk.ModifierType.Mod1Mask; - if (key.HasFlag(Keys.Control)) result |= Gdk.ModifierType.ControlMask; - if (key.HasFlag(Keys.Application)) result |= Gdk.ModifierType.SuperMask; - if (key.HasFlag(Keys.Shift)) result |= Gdk.ModifierType.ShiftMask; - return result; - } - - static KeyMap() - { - keymap.Add(Gdk.Key.A, Keys.A); - keymap.Add(Gdk.Key.B, Keys.B); - keymap.Add(Gdk.Key.C, Keys.C); - keymap.Add(Gdk.Key.D, Keys.D); - keymap.Add(Gdk.Key.E, Keys.E); - keymap.Add(Gdk.Key.F, Keys.F); - keymap.Add(Gdk.Key.G, Keys.G); - keymap.Add(Gdk.Key.H, Keys.H); - keymap.Add(Gdk.Key.I, Keys.I); - keymap.Add(Gdk.Key.J, Keys.J); - keymap.Add(Gdk.Key.K, Keys.K); - keymap.Add(Gdk.Key.L, Keys.L); - keymap.Add(Gdk.Key.M, Keys.M); - keymap.Add(Gdk.Key.N, Keys.N); - keymap.Add(Gdk.Key.O, Keys.O); - keymap.Add(Gdk.Key.P, Keys.P); - keymap.Add(Gdk.Key.Q, Keys.Q); - keymap.Add(Gdk.Key.R, Keys.R); - keymap.Add(Gdk.Key.S, Keys.S); - keymap.Add(Gdk.Key.T, Keys.T); - keymap.Add(Gdk.Key.U, Keys.U); - keymap.Add(Gdk.Key.V, Keys.V); - keymap.Add(Gdk.Key.W, Keys.W); - keymap.Add(Gdk.Key.X, Keys.X); - keymap.Add(Gdk.Key.Y, Keys.Y); - keymap.Add(Gdk.Key.Z, Keys.Z); - keymap.Add(Gdk.Key.F1, Keys.F1); - keymap.Add(Gdk.Key.F2, Keys.F2); - keymap.Add(Gdk.Key.F3, Keys.F3); - keymap.Add(Gdk.Key.F4, Keys.F4); - keymap.Add(Gdk.Key.F5, Keys.F5); - keymap.Add(Gdk.Key.F6, Keys.F6); - keymap.Add(Gdk.Key.F7, Keys.F7); - keymap.Add(Gdk.Key.F8, Keys.F8); - keymap.Add(Gdk.Key.F9, Keys.F9); - keymap.Add(Gdk.Key.F10, Keys.F10); - keymap.Add(Gdk.Key.F11, Keys.F11); - keymap.Add(Gdk.Key.F12, Keys.F12); - keymap.Add(Gdk.Key.Key_0, Keys.D0); - keymap.Add(Gdk.Key.Key_1, Keys.D1); - keymap.Add(Gdk.Key.Key_2, Keys.D2); - keymap.Add(Gdk.Key.Key_3, Keys.D3); - keymap.Add(Gdk.Key.Key_4, Keys.D4); - keymap.Add(Gdk.Key.Key_5, Keys.D5); - keymap.Add(Gdk.Key.Key_6, Keys.D6); - keymap.Add(Gdk.Key.Key_7, Keys.D7); - keymap.Add(Gdk.Key.Key_8, Keys.D8); - keymap.Add(Gdk.Key.Key_9, Keys.D9); - keymap.Add(Gdk.Key.Up, Keys.Up); - keymap.Add(Gdk.Key.Down, Keys.Down); - keymap.Add(Gdk.Key.Left, Keys.Left); - keymap.Add(Gdk.Key.Right, Keys.Right); - keymap.Add(Gdk.Key.Page_Down, Keys.PageDown); - keymap.Add(Gdk.Key.Page_Up, Keys.PageUp); - keymap.Add(Gdk.Key.Home, Keys.Home); - keymap.Add(Gdk.Key.End, Keys.End); - keymap.Add(Gdk.Key.space, Keys.Space); - keymap.Add(Gdk.Key.Delete, Keys.Delete); - keymap.Add(Gdk.Key.BackSpace, Keys.Backspace); - keymap.Add(Gdk.Key.Insert, Keys.Insert); - keymap.Add(Gdk.Key.Tab, Keys.Tab); - keymap.Add(Gdk.Key.Escape, Keys.Escape); - keymap.Add(Gdk.Key.Return, Keys.Enter); - - keymap.Add(Gdk.Key.period, Keys.Decimal); - keymap.Add(Gdk.Key.comma, Keys.Comma); - keymap.Add(Gdk.Key.equal, Keys.Equal); - keymap.Add(Gdk.Key.minus, Keys.Minus); - keymap.Add(Gdk.Key.backslash, Keys.Backslash); - keymap.Add(Gdk.Key.slash, Keys.ForwardSlash); - keymap.Add(Gdk.Key.division, Keys.Divide); - //keymap.Add(Gdk.Key.dollar, Keys.Dollar); - keymap.Add(Gdk.Key.Menu, Keys.ContextMenu); - - foreach (var val in keymap) - { - inversekeymap.Add(val.Value, val.Key); - } - - keymap.Add((Gdk.Key)0x1000010, Keys.ContextMenu); // os x - keymap.Add(Gdk.Key.a, Keys.A); - keymap.Add(Gdk.Key.b, Keys.B); - keymap.Add(Gdk.Key.c, Keys.C); - keymap.Add(Gdk.Key.d, Keys.D); - keymap.Add(Gdk.Key.e, Keys.E); - keymap.Add(Gdk.Key.f, Keys.F); - keymap.Add(Gdk.Key.g, Keys.G); - keymap.Add(Gdk.Key.h, Keys.H); - keymap.Add(Gdk.Key.i, Keys.I); - keymap.Add(Gdk.Key.j, Keys.J); - keymap.Add(Gdk.Key.k, Keys.K); - keymap.Add(Gdk.Key.l, Keys.L); - keymap.Add(Gdk.Key.m, Keys.M); - keymap.Add(Gdk.Key.n, Keys.N); - keymap.Add(Gdk.Key.o, Keys.O); - keymap.Add(Gdk.Key.p, Keys.P); - keymap.Add(Gdk.Key.q, Keys.Q); - keymap.Add(Gdk.Key.r, Keys.R); - keymap.Add(Gdk.Key.s, Keys.S); - keymap.Add(Gdk.Key.t, Keys.T); - keymap.Add(Gdk.Key.u, Keys.U); - keymap.Add(Gdk.Key.v, Keys.V); - keymap.Add(Gdk.Key.w, Keys.W); - keymap.Add(Gdk.Key.x, Keys.X); - keymap.Add(Gdk.Key.y, Keys.Y); - keymap.Add(Gdk.Key.z, Keys.Z); - - } - - } -} - diff --git a/Source/Eto.Platform.Gtk/MenuActionItemHandler.cs b/Source/Eto.Platform.Gtk/MenuActionItemHandler.cs deleted file mode 100644 index fa320a2760..0000000000 --- a/Source/Eto.Platform.Gtk/MenuActionItemHandler.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.GtkSharp -{ - public interface IMenuActionItemHandler - { - void TriggerValidate(); - } - - public abstract class MenuActionItemHandler : MenuHandler, IMenuActionItemHandler - where TControl: Gtk.MenuItem - where TWidget: MenuItem - { - public override void AttachEvent(string id) - { - switch (id) - { - case MenuItem.ValidateEvent: - // handled by the contextmenu/menubar - break; - default: - base.AttachEvent(id); - break; - } - } - - public void TriggerValidate() - { - if (Control.Submenu != null) - { - Widget.OnValidate(EventArgs.Empty); - } - } - - public void CreateFromCommand(Command command) - { - } - } -} - diff --git a/Source/Eto.Platform.Gtk/Properties/AssemblyInfo.cs b/Source/Eto.Platform.Gtk/Properties/AssemblyInfo.cs deleted file mode 100644 index a4e7149c11..0000000000 --- a/Source/Eto.Platform.Gtk/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,4 +0,0 @@ -using System.Reflection; - -[assembly: AssemblyTitle("Eto.Forms - GTK Platform")] -[assembly: AssemblyDescription("GTK Platform for the Eto.Forms UI Framework")] diff --git a/Source/Eto.Platform.Mac/AppDelegate.cs b/Source/Eto.Platform.Mac/AppDelegate.cs deleted file mode 100644 index 3d01aa0220..0000000000 --- a/Source/Eto.Platform.Mac/AppDelegate.cs +++ /dev/null @@ -1,49 +0,0 @@ -using MonoMac.AppKit; -using MonoMac.Foundation; -using Eto.Forms; -using System.ComponentModel; -using Eto.Platform.Mac.Forms; - -namespace Eto.Platform.Mac -{ - [MonoMac.Foundation.Register("EtoAppDelegate")] - public class AppDelegate : NSApplicationDelegate - { - public override bool ApplicationShouldHandleReopen(NSApplication sender, bool hasVisibleWindows) - { - if (!hasVisibleWindows) - { - var form = Application.Instance.MainForm; - if (form != null) - form.Show(); - } - return true; - } - - public override void DidBecomeActive(NSNotification notification) - { - var form = Application.Instance.MainForm; - if (form != null && !form.Visible) - form.Show(); - } - - public override void DidFinishLaunching(NSNotification notification) - { - var handler = Application.Instance.Handler as ApplicationHandler; - if (handler != null) - handler.Initialize(this); - } - - public override NSApplicationTerminateReply ApplicationShouldTerminate(NSApplication sender) - { - var args = new CancelEventArgs(); - var form = Application.Instance.MainForm == null ? null : Application.Instance.MainForm.Handler as IMacWindow; - if (form != null) - args.Cancel = !form.CloseWindow(Application.Instance.OnTerminating); - else - Application.Instance.OnTerminating(args); - return args.Cancel ? NSApplicationTerminateReply.Cancel : NSApplicationTerminateReply.Now; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Conversions.cs b/Source/Eto.Platform.Mac/Conversions.cs deleted file mode 100644 index 5e5acfe771..0000000000 --- a/Source/Eto.Platform.Mac/Conversions.cs +++ /dev/null @@ -1,304 +0,0 @@ -using System; -using MonoMac.AppKit; -using MonoMac.CoreGraphics; -using Eto.Drawing; -using MonoMac.Foundation; -using Eto.Forms; -using Eto.Platform.Mac.Drawing; -using MonoMac.ImageIO; -using sd = System.Drawing; -using Eto.Platform.Mac.Forms.Printing; - -namespace Eto.Platform.Mac -{ - public static partial class Conversions - { - public static NSColor ToNSUI(this Color color) - { - return NSColor.FromDeviceRgba(color.R, color.G, color.B, color.A); - } - - public static Color ToEto(this NSColor color) - { - if (color == null) - return Colors.Black; - float red, green, blue, alpha; - color.GetRgba(out red, out green, out blue, out alpha); - return new Color(red, green, blue, alpha); - } - - public static NSRange ToNS(this Range range) - { - return new NSRange(range.Start, range.Length); - } - - public static Range ToEto(this NSRange range) - { - return new Range(range.Location, range.Length); - } - - public static NSImageInterpolation ToNS(this ImageInterpolation value) - { - switch (value) - { - case ImageInterpolation.Default: - return NSImageInterpolation.Default; - case ImageInterpolation.None: - return NSImageInterpolation.None; - case ImageInterpolation.Low: - return NSImageInterpolation.Low; - case ImageInterpolation.Medium: - return NSImageInterpolation.Medium; - case ImageInterpolation.High: - return NSImageInterpolation.High; - default: - throw new NotSupportedException(); - } - } - - public static ImageInterpolation ToEto(this NSImageInterpolation value) - { - switch (value) - { - case NSImageInterpolation.None: - return ImageInterpolation.None; - case NSImageInterpolation.Low: - return ImageInterpolation.Low; - case NSImageInterpolation.Medium: - return ImageInterpolation.Medium; - case NSImageInterpolation.Default: - case NSImageInterpolation.High: - return ImageInterpolation.High; - default: - throw new NotSupportedException(); - } - } - - public static NSFontTraitMask ToNS(this FontStyle style) - { - var traits = (NSFontTraitMask)0; - traits |= style.HasFlag(FontStyle.Bold) ? NSFontTraitMask.Bold : NSFontTraitMask.Unbold; - traits |= style.HasFlag(FontStyle.Italic) ? NSFontTraitMask.Italic : NSFontTraitMask.Unitalic; - //if (style.HasFlag (FontStyle.Condensed)) traits |= NSFontTraitMask.Condensed; - //if (style.HasFlag (FontStyle.Light)) traits |= NSFontTraitMask.Narrow; - return traits; - } - - public static FontStyle ToEto(this NSFontTraitMask traits) - { - var style = FontStyle.None; - if (traits.HasFlag(NSFontTraitMask.Bold)) - style |= FontStyle.Bold; - if (traits.HasFlag(NSFontTraitMask.Italic)) - style |= FontStyle.Italic; - //if (traits.HasFlag (NSFontTraitMask.Condensed)) - // style |= FontStyle.Condensed; - //if (traits.HasFlag (NSFontTraitMask.Narrow)) - // style |= FontStyle.Light; - return style; - } - - public static NSPrintingOrientation ToNS(this PageOrientation value) - { - switch (value) - { - case PageOrientation.Landscape: - return NSPrintingOrientation.Landscape; - case PageOrientation.Portrait: - return NSPrintingOrientation.Portrait; - default: - throw new NotSupportedException(); - } - } - - public static PageOrientation ToEto(this NSPrintingOrientation value) - { - switch (value) - { - case NSPrintingOrientation.Landscape: - return PageOrientation.Landscape; - case NSPrintingOrientation.Portrait: - return PageOrientation.Portrait; - default: - throw new NotSupportedException(); - } - } - - public static PointF GetLocation(NSView view, NSEvent theEvent) - { - var loc = view.ConvertPointFromView(theEvent.LocationInWindow, null); - if (!view.IsFlipped) - loc.Y = view.Frame.Height - loc.Y; - return loc.ToEto(); - } - - public static MouseEventArgs GetMouseEvent(NSView view, NSEvent theEvent, bool includeWheel) - { - var pt = Conversions.GetLocation(view, theEvent); - Keys modifiers = KeyMap.GetModifiers(theEvent); - MouseButtons buttons = theEvent.GetMouseButtons(); - SizeF? delta = null; - if (includeWheel) - delta = new SizeF(theEvent.DeltaX, theEvent.DeltaY); - return new MouseEventArgs(buttons, modifiers, pt, delta); - } - - public static MouseButtons GetMouseButtons(this NSEvent theEvent) - { - MouseButtons buttons = MouseButtons.None; - - switch (theEvent.Type) - { - case NSEventType.LeftMouseUp: - case NSEventType.LeftMouseDown: - case NSEventType.LeftMouseDragged: - if ((theEvent.ModifierFlags & NSEventModifierMask.ControlKeyMask) > 0) - buttons |= MouseButtons.Alternate; - else - buttons |= MouseButtons.Primary; - break; - case NSEventType.RightMouseUp: - case NSEventType.RightMouseDown: - case NSEventType.RightMouseDragged: - buttons |= MouseButtons.Alternate; - break; - case NSEventType.OtherMouseUp: - case NSEventType.OtherMouseDown: - case NSEventType.OtherMouseDragged: - buttons |= MouseButtons.Middle; - break; - } - return buttons; - } - - public static CGImage ToCG(this Image image) - { - using (var imageSource = CGImageSource.FromData (image.ToNS ().AsTiff ())) - { - return imageSource.CreateImage(0, null); - } - } - - public static NSImage ToNS(this Image image, int? size = null) - { - if (image == null) - return null; - var source = image.Handler as IImageSource; - if (source == null) - return null; - var nsimage = source.GetImage(); - - if (size != null) - { - var rep = nsimage.BestRepresentation(new sd.RectangleF(0, 0, size.Value, size.Value), null, null); - if (rep.PixelsWide > size.Value || rep.PixelsHigh > size.Value) - { - var max = Math.Max(nsimage.Size.Width, nsimage.Size.Height); - var newsize = new sd.Size((int)(size.Value * nsimage.Size.Width / max), (int)(size.Value * nsimage.Size.Height / max)); - nsimage = nsimage.Resize(newsize); - } - else - { - nsimage = new NSImage(); - nsimage.AddRepresentation(rep); - } - } - return nsimage; - } - - public static NSCellImagePosition ToNS(this ButtonImagePosition value) - { - switch (value) - { - case ButtonImagePosition.Below: - return NSCellImagePosition.ImageBelow; - case ButtonImagePosition.Overlay: - return NSCellImagePosition.ImageOverlaps; - case ButtonImagePosition.Left: - return NSCellImagePosition.ImageLeft; - case ButtonImagePosition.Right: - return NSCellImagePosition.ImageRight; - case ButtonImagePosition.Above: - return NSCellImagePosition.ImageAbove; - default: - throw new NotSupportedException(); - } - } - - public static ButtonImagePosition ToEto(this NSCellImagePosition value) - { - switch (value) - { - case NSCellImagePosition.ImageBelow: - return ButtonImagePosition.Below; - case NSCellImagePosition.ImageOverlaps: - return ButtonImagePosition.Overlay; - case NSCellImagePosition.ImageLeft: - return ButtonImagePosition.Left; - case NSCellImagePosition.ImageRight: - return ButtonImagePosition.Right; - case NSCellImagePosition.ImageAbove: - return ButtonImagePosition.Above; - default: - throw new NotSupportedException(); - } - } - - public static WindowStyle ToEtoWindowStyle(this NSWindowStyle style) - { - return style.HasFlag(NSWindowStyle.Borderless) ? WindowStyle.None : WindowStyle.Default; - } - - public static NSWindowStyle ToNS(this WindowStyle style, NSWindowStyle existing) - { - const NSWindowStyle NONE_STYLE = NSWindowStyle.Borderless; - const NSWindowStyle DEFAULT_STYLE = NSWindowStyle.Titled; - switch (style) - { - case WindowStyle.Default: - return (existing & ~NONE_STYLE) | DEFAULT_STYLE; - case WindowStyle.None: - return (existing & ~DEFAULT_STYLE) | NONE_STYLE; - default: - throw new NotSupportedException(); - } - } - - public static KeyEventArgs ToEtoKeyEventArgs(this NSEvent theEvent) - { - char keyChar = !string.IsNullOrEmpty(theEvent.Characters) ? theEvent.Characters[0] : '\0'; - Keys key = KeyMap.MapKey(theEvent.KeyCode); - KeyEventArgs kpea; - Keys modifiers = KeyMap.GetModifiers(theEvent); - key |= modifiers; - if (key != Keys.None) - { - if (((modifiers & ~(Keys.Shift | Keys.Alt)) == 0)) - kpea = new KeyEventArgs(key, KeyEventType.KeyDown, keyChar); - else - kpea = new KeyEventArgs(key, KeyEventType.KeyDown); - } - else - { - kpea = new KeyEventArgs(key, KeyEventType.KeyDown, keyChar); - } - return kpea; - } - - public static PrintSettings ToEto(this NSPrintInfo value, Eto.Generator generator) - { - return value == null ? null : new PrintSettings(generator, new PrintSettingsHandler(value)); - } - - public static NSPrintInfo ToNS(this PrintSettings settings) - { - return settings == null ? null : ((PrintSettingsHandler)settings.Handler).Control; - } - - public static SizeF ToEtoSize(this NSEdgeInsets insets) - { - return new SizeF(insets.Left + insets.Right, insets.Top + insets.Bottom); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Conversions.ns.cs b/Source/Eto.Platform.Mac/Conversions.ns.cs deleted file mode 100644 index 479c9c94a6..0000000000 --- a/Source/Eto.Platform.Mac/Conversions.ns.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using MonoMac.Foundation; - -namespace Eto.Platform.Mac -{ - public static partial class Conversions - { - static readonly DateTime ReferenceDate = new DateTime (2001, 1, 1, 0, 0, 0); - - public static NSUrl ToNS (this Uri uri) - { - return uri == null ? null : new NSUrl(uri.AbsoluteUri); - } - - public static NSDate ToNS (this DateTime date) - { - return NSDate.FromTimeIntervalSinceReferenceDate ((date.ToUniversalTime () - ReferenceDate).TotalSeconds); - } - - public static NSDate ToNS (this DateTime? date) - { - return date == null ? null : date.Value.ToNS(); - } - - public static DateTime? ToEto (this NSDate date) - { - if (date == null) return null; - return new DateTime ((long)(date.SecondsSinceReferenceDate * TimeSpan.TicksPerSecond + ReferenceDate.Ticks), DateTimeKind.Utc).ToLocalTime (); - } - - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/BitmapHandler.cs b/Source/Eto.Platform.Mac/Drawing/BitmapHandler.cs deleted file mode 100644 index 6a07e50ca9..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/BitmapHandler.cs +++ /dev/null @@ -1,265 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using Eto.Drawing; -using MonoMac.AppKit; -using MonoMac.Foundation; -using MonoMac.CoreGraphics; -using sd = System.Drawing; -using Eto.Platform.Mac.Forms; - -namespace Eto.Platform.Mac.Drawing -{ - /// - /// Bitmap data handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class BitmapDataHandler : BitmapData - { - public BitmapDataHandler(Bitmap bitmap, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) - : base(bitmap, data, scanWidth, bitsPerPixel, controlObject) - { - } - - public static uint ArgbToData(uint argb) - { - return (argb & 0xFF00FF00) | ((argb & 0xFF) << 16) | ((argb & 0xFF0000) >> 16); - } - - public static uint DataToArgb(uint bitmapData) - { - return (bitmapData & 0xFF00FF00) | ((bitmapData & 0xFF) << 16) | ((bitmapData & 0xFF0000) >> 16); - } - - public override uint TranslateArgbToData(uint argb) - { - return (argb & 0xFF00FF00) | ((argb & 0xFF) << 16) | ((argb & 0xFF0000) >> 16); - } - - public override uint TranslateDataToArgb(uint bitmapData) - { - return (bitmapData & 0xFF00FF00) | ((bitmapData & 0xFF) << 16) | ((bitmapData & 0xFF0000) >> 16); - } - - public override bool Flipped { get { return false; } } - } - - /// - /// Bitmap handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class BitmapHandler : ImageHandler, IBitmap - { - NSImageRep rep; - NSBitmapImageRep bmprep; - bool alpha = true; - - public BitmapHandler() - { - } - - public BitmapHandler(NSImage image) - { - Control = image; - } - - public void Create(string fileName) - { - if (!File.Exists(fileName)) - throw new FileNotFoundException("Icon not found", fileName); - Control = new NSImage(fileName); - rep = Control.BestRepresentationForDevice(null); - bmprep = rep as NSBitmapImageRep; - Control.Size = new sd.SizeF(rep.PixelsWide, rep.PixelsHigh); - } - - public void Create(Stream stream) - { - Control = new NSImage(NSData.FromStream(stream)); - rep = Control.BestRepresentationForDevice(null); - bmprep = rep as NSBitmapImageRep; - Control.Size = new sd.SizeF(rep.PixelsWide, rep.PixelsHigh); - } - - public void Create(int width, int height, PixelFormat pixelFormat) - { - switch (pixelFormat) - { - case PixelFormat.Format32bppRgb: - { - alpha = false; - const int numComponents = 4; - const int bitsPerComponent = 8; - const int bitsPerPixel = numComponents * bitsPerComponent; - const int bytesPerPixel = bitsPerPixel / 8; - int bytesPerRow = bytesPerPixel * width; - - rep = bmprep = new NSBitmapImageRep(IntPtr.Zero, width, height, bitsPerComponent, 3, false, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel); - Control = new NSImage(); - Control.AddRepresentation(rep); - break; - } - case PixelFormat.Format24bppRgb: - { - alpha = false; - const int numComponents = 3; - const int bitsPerComponent = 8; - const int bitsPerPixel = numComponents * bitsPerComponent; - const int bytesPerPixel = bitsPerPixel / 8; - int bytesPerRow = bytesPerPixel * width; - - rep = bmprep = new NSBitmapImageRep(IntPtr.Zero, width, height, bitsPerComponent, numComponents, false, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel); - Control = new NSImage(); - Control.AddRepresentation(rep); - break; - } - case PixelFormat.Format32bppRgba: - { - alpha = true; - const int numComponents = 4; - const int bitsPerComponent = 8; - const int bitsPerPixel = numComponents * bitsPerComponent; - const int bytesPerPixel = bitsPerPixel / 8; - int bytesPerRow = bytesPerPixel * width; - - rep = bmprep = new NSBitmapImageRep(IntPtr.Zero, width, height, bitsPerComponent, numComponents, true, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel); - Control = new NSImage(); - Control.AddRepresentation(rep); - break; - } - /*case PixelFormat.Format16bppRgb555: - control = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 5, width, height); - break;*/ - default: - throw new ArgumentOutOfRangeException("pixelFormat", pixelFormat, "Not supported"); - } - } - - public void Create(int width, int height, Graphics graphics) - { - Create(width, height, PixelFormat.Format32bppRgba); - } - - public void Create(Image image, int width, int height, ImageInterpolation interpolation) - { - var source = image.ToNS(); - Control = source.Resize(new sd.Size(width, height), interpolation); - } - - public override NSImage GetImage() - { - return Control; - } - - public BitmapData Lock() - { - return bmprep == null ? null : new BitmapDataHandler(Widget, bmprep.BitmapData, bmprep.BytesPerRow, bmprep.BitsPerPixel, Control); - } - - public void Unlock(BitmapData bitmapData) - { - } - - public void Save(Stream stream, ImageFormat format) - { - NSBitmapImageFileType type; - switch (format) - { - case ImageFormat.Bitmap: - type = NSBitmapImageFileType.Bmp; - break; - case ImageFormat.Gif: - type = NSBitmapImageFileType.Gif; - break; - case ImageFormat.Jpeg: - type = NSBitmapImageFileType.Jpeg; - break; - case ImageFormat.Png: - type = NSBitmapImageFileType.Png; - break; - case ImageFormat.Tiff: - type = NSBitmapImageFileType.Tiff; - break; - default: - throw new NotSupportedException(); - } - var reps = Control.Representations(); - if (reps == null) - throw new InvalidDataException(); - var newrep = reps.OfType().FirstOrDefault(); - if (newrep == null) - { - CGImage img; - img = bmprep != null ? bmprep.CGImage : Control.CGImage; - newrep = new NSBitmapImageRep(img); - } - var data = newrep.RepresentationUsingTypeProperties(type, new NSDictionary()); - var datastream = data.AsStream(); - datastream.CopyTo(stream); - stream.Flush(); - datastream.Dispose(); - } - - public override Size Size - { - get - { - /* - NSImageRep rep = this.rep; - if (rep == null) - rep = Control.BestRepresentationForDevice (null); - if (rep != null) - return new Size(rep.PixelsWide, rep.PixelsHigh); - else - */ - return Control.Size.ToEtoSize(); - } - } - - public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) - { - var sourceRect = new sd.RectangleF(source.X, Control.Size.Height - source.Y - source.Height, source.Width, source.Height); - var destRect = graphics.TranslateView(destination.ToSD(), true, true); - if (alpha) - Control.Draw(destRect, sourceRect, NSCompositingOperation.SourceOver, 1, true, null); - else - Control.Draw(destRect, sourceRect, NSCompositingOperation.Copy, 1, true, null); - } - - public Bitmap Clone(Rectangle? rectangle = null) - { - if (rectangle == null) - return new Bitmap(Generator, new BitmapHandler((NSImage)Control.Copy())); - else - { - var rect = new sd.RectangleF (sd.PointF.Empty, this.Control.Size); - var temp = Control.AsCGImage (ref rect, null, null).WithImageInRect (rectangle.Value.ToSDRectangleF()); - var image = new NSImage (temp, new sd.SizeF (temp.Width, temp.Height)); - return new Bitmap(Generator, new BitmapHandler(image)); - } - } - - public Color GetPixel(int x, int y) - { - if (bmprep == null) - throw new InvalidOperationException(string.Format("Cannot get pixel data for this type of bitmap ({0})", rep.GetType())); - - return bmprep.ColorAt(x, y).ToEto(); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - if (rep != null) - { - rep.SafeDispose(); - rep = null; - } - } - base.Dispose(disposing); - } - } -} diff --git a/Source/Eto.Platform.Mac/Drawing/BrushHandler.cs b/Source/Eto.Platform.Mac/Drawing/BrushHandler.cs deleted file mode 100644 index 6ec6261404..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/BrushHandler.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Eto.Drawing; - -#if OSX - -namespace Eto.Platform.Mac.Drawing -#elif IOS - -namespace Eto.Platform.iOS.Drawing -#endif -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public abstract class BrushHandler : IBrush - { - public abstract void Apply (object control, GraphicsHandler graphics); - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/FontExtensions.cs b/Source/Eto.Platform.Mac/Drawing/FontExtensions.cs deleted file mode 100644 index 1d90d6d5e6..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/FontExtensions.cs +++ /dev/null @@ -1,150 +0,0 @@ -using Eto.Drawing; -using MonoMac.Foundation; -using MonoMac.AppKit; - -#if OSX -namespace Eto.Platform.Mac.Drawing -#elif IOS - -using MonoTouch.UIKit; -using MonoTouch.Foundation; -using NSFont = MonoTouch.UIKit.UIFont; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - public static class FontExtensions - { - #if OSX - static readonly NSString ForegroundColorAttribute = NSAttributedString.ForegroundColorAttributeName; - #elif IOS - static readonly NSString ForegroundColorAttribute = UIStringAttributeKey.ForegroundColor; - #endif - - public static NSFont ToNSFont(this Font font) - { - return font == null ? null : ((FontHandler)font.Handler).Control; - } - - public static void Apply(this Font font, NSMutableAttributedString str) - { - if (font != null) - { - var handler = (FontHandler)font.Handler; - str.AddAttributes(handler.Attributes, new NSRange(0, str.Length)); - } - } - - public static void Apply(this Font font, NSMutableDictionary dic) - { - if (font != null) - { - var handler = (FontHandler)font.Handler; - foreach (var item in handler.Attributes) - dic.Add(item.Key, item.Value); - } - } - - public static NSAttributedString AttributedString(this Font font, NSAttributedString attributedString) - { - if (font != null) - { - var str = attributedString as NSMutableAttributedString ?? new NSMutableAttributedString(attributedString); - font.Apply(str); - return str; - } - return attributedString; - } - - public static NSMutableAttributedString ToMutable(this NSAttributedString attributedString, string text) - { - if (attributedString != null && attributedString.Length > 0) - { - NSRange range; - return new NSMutableAttributedString(text, attributedString.GetAttributes(0, out range)); - } - - return new NSMutableAttributedString(text); - } - - public static NSMutableAttributedString AttributedString(this Font font, string text, NSAttributedString attributedString = null) - { - var mutable = attributedString.ToMutable(text); - font.Apply(mutable); - - return mutable; - } - - public static float LineHeight(this NSFont font) - { - #if OSX - return layout.DefaultLineHeightForFont(font); - #elif IOS - return font.LineHeight; - #endif - /** - var leading = Math.Floor (Math.Max (0, font.Leading) + 0.5f); - var lineHeight = (float)(Math.Floor(font.Ascender + 0.5f) - Math.Floor (font.Descender + 0.5f) + leading); - - if (leading > 0) - return lineHeight; - else - return (float)(lineHeight + Math.Floor(0.2 * lineHeight + 0.5)); - /**/ - } - - static readonly NSTextStorage storage; - static readonly NSLayoutManager layout; - static readonly NSTextContainer container; - - public static NSLayoutManager SharedLayout { get { return layout; } } - - public static SizeF MeasureString(string text, Font font = null, SizeF? availableSize = null) - { - return MeasureString(font.AttributedString(text), availableSize); - } - - public static SizeF MeasureString(NSAttributedString str, SizeF? availableSize = null) - { - SetContainerSize(availableSize); - storage.SetString(str); - return layout.BoundingRectForGlyphRange(new NSRange(0, str.Length), container).Size.ToEto(); - } - - public static void DrawString(NSAttributedString str, PointF point, SizeF? availableSize = null) - { - SetContainerSize(availableSize); - storage.SetString(str); - layout.DrawGlyphs(new NSRange(0, str.Length), point.ToSD()); - } - - public static void DrawString(string text, PointF point, Color color, Font font = null, SizeF? availableSize = null) - { - var str = font.AttributedString(text); - str.AddAttribute(ForegroundColorAttribute, color.ToNSUI(), new NSRange(0, text.Length)); - DrawString(str, point, availableSize); - } - - static void SetContainerSize(SizeF? availableSize) - { - #if OSX - container.ContainerSize = (availableSize ?? SizeF.MaxValue).ToSD(); - #elif IOS - container.Size = (availableSize ?? SizeF.MaxValue).ToSD(); - #endif - } - - static FontExtensions() - { - storage = new NSTextStorage(); - layout = new NSLayoutManager { UsesFontLeading = true }; - #if OSX - layout.BackgroundLayoutEnabled = false; - #endif - container = new NSTextContainer { LineFragmentPadding = 0f }; - layout.UsesFontLeading = true; - layout.AddTextContainer(container); - storage.AddLayoutManager(layout); - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Mac/Drawing/FontFamilyHandler.cs b/Source/Eto.Platform.Mac/Drawing/FontFamilyHandler.cs deleted file mode 100644 index b4adb1f26a..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/FontFamilyHandler.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using Eto.Drawing; -using System.Collections.Generic; -using MonoMac.AppKit; -using MonoMac.Foundation; -using System.Linq; - -namespace Eto.Platform.Mac.Drawing -{ - public class FontFamilyHandler : WidgetHandler, IFontFamily - { - public string MacName { get; set; } - - public string Name { get; set; } - - public NSFontTraitMask TraitMask { get; set; } - - public IEnumerable Typefaces - { - get - { - var descriptors = NSFontManager.SharedFontManager.AvailableMembersOfFontFamily (MacName); - return descriptors.Select (r => new FontTypeface (Widget, new FontTypefaceHandler (r))); - } - } - - public FontFamilyHandler () - { - TraitMask = (NSFontTraitMask)int.MaxValue; - } - - public FontFamilyHandler (string familyName) - { - Create (familyName); - } - - public void Create (string familyName) - { - Name = MacName = familyName; - TraitMask = (NSFontTraitMask)int.MaxValue; - - switch (familyName.ToUpperInvariant()) { - case FontFamilies.MonospaceFamilyName: - MacName = "Courier New"; - break; - case FontFamilies.SansFamilyName: - MacName = "Helvetica"; - break; - case FontFamilies.SerifFamilyName: -#if OSX - MacName = "Times"; -#elif IOS - MacName = "Times New Roman"; -#endif - break; - case FontFamilies.CursiveFamilyName: - MacName = "Papyrus"; - TraitMask = NSFontTraitMask.Condensed | NSFontTraitMask.Unbold | NSFontTraitMask.Unitalic; - break; - case FontFamilies.FantasyFamilyName: - MacName = "Impact"; - break; - } - } - - public FontTypeface GetFace (NSFont font) - { - var postScriptName = font.FontDescriptor.PostscriptName; - var faceHandler = Typefaces.Select (r => r.Handler).OfType ().FirstOrDefault (r => r.PostScriptName == postScriptName); - if (faceHandler == null) - faceHandler = new FontTypefaceHandler (font); - return new FontTypeface (Widget, faceHandler); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/FontHandler.cs b/Source/Eto.Platform.Mac/Drawing/FontHandler.cs deleted file mode 100644 index b5194b173d..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/FontHandler.cs +++ /dev/null @@ -1,257 +0,0 @@ -using System; -using Eto.Drawing; - -#if IOS - -using MonoTouch.UIKit; -using MonoTouch.Foundation; -using NSFont = MonoTouch.UIKit.UIFont; - -namespace Eto.Platform.iOS.Drawing - -#elif OSX - -using MonoMac.AppKit; -using MonoMac.Foundation; - -namespace Eto.Platform.Mac.Drawing -#endif -{ - public class FontHandler : WidgetHandler, IFont - { - FontFamily family; - FontTypeface typeface; - FontStyle? style; - FontDecoration decoration; - NSDictionary _attributes; - - public FontHandler() - { - } - - public FontHandler(NSFont font) - { - Control = font; - } - - public FontHandler(NSFont font, FontStyle style) - { - Control = font; - this.style = style; - } - - public void Create(FontTypeface face, float size, FontDecoration decoration) - { - typeface = face; - family = face.Family; - Control = ((FontTypefaceHandler)face.Handler).CreateFont(size); - this.decoration = decoration; - } - - public void Create(SystemFont systemFont, float? fontSize, FontDecoration decoration) - { - switch (systemFont) - { - case SystemFont.Default: - Control = NSFont.SystemFontOfSize(fontSize ?? NSFont.SystemFontSize); - break; - case SystemFont.Bold: - Control = NSFont.BoldSystemFontOfSize(fontSize ?? NSFont.SystemFontSize); - break; - case SystemFont.Label: -#if IOS - Control = NSFont.SystemFontOfSize(fontSize ?? NSFont.LabelFontSize); -#elif OSX - Control = NSFont.LabelFontOfSize(fontSize ?? NSFont.LabelFontSize + 2); // labels get a size of 12 -#endif - break; -#if DESKTOP - case SystemFont.TitleBar: - Control = NSFont.TitleBarFontOfSize(fontSize ?? NSFont.SystemFontSize); - break; - case SystemFont.ToolTip: - Control = NSFont.ToolTipsFontOfSize(fontSize ?? NSFont.SystemFontSize); - break; - case SystemFont.MenuBar: - Control = NSFont.MenuBarFontOfSize(fontSize ?? NSFont.SystemFontSize); - break; - case SystemFont.Menu: - Control = NSFont.MenuFontOfSize(fontSize ?? NSFont.SystemFontSize); - break; - case SystemFont.Message: - Control = NSFont.MessageFontOfSize(fontSize ?? NSFont.SystemFontSize); - break; - case SystemFont.Palette: - Control = NSFont.PaletteFontOfSize(fontSize ?? NSFont.SmallSystemFontSize); - break; - case SystemFont.StatusBar: - Control = NSFont.SystemFontOfSize(fontSize ?? NSFont.SystemFontSize); - break; -#endif - default: - throw new NotSupportedException(); - } - this.decoration = decoration; - } - - public float LineHeight - { - get - { - return Control.LineHeight(); // LineHeight() is the extension method above - } - } - - public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) - { - this.style = style; - this.family = family; - this.decoration = decoration; -#if OSX - var familyHandler = (FontFamilyHandler)family.Handler; - NSFontTraitMask traits = style.ToNS() & familyHandler.TraitMask; - var font = NSFontManager.SharedFontManager.FontWithFamily(familyHandler.MacName, traits, 5, size); - if (font == null || font.Handle == IntPtr.Zero) - throw new ArgumentOutOfRangeException(string.Empty, string.Format("Could not allocate font with family {0}, traits {1}, size {2}", family.Name, traits, size)); -#elif IOS - string suffix = string.Empty; - var familyHandler = (FontFamilyHandler)family.Handler; - var font = familyHandler.CreateFont (size, style); - /* - var familyString = new StringBuilder(); - switch (family) - { - case FontFamily.Monospace: familyString.Append ("CourierNewPS"); suffix = "MT"; break; - default: - case FontFamily.Sans: familyString.Append ("Helvetica"); italicString = "Oblique"; break; - case FontFamily.Serif: familyString.Append ("TimesNewRomanPS"); suffix = "MT"; break; - } - bold = (style & FontStyle.Bold) != 0; - italic = (style & FontStyle.Italic) != 0; - - if (bold || italic) familyString.Append ("-"); - if (bold) familyString.Append ("Bold"); - if (italic) familyString.Append (italicString); - - familyString.Append (suffix); - var font = UIFont.FromName (familyString.ToString (), size); - */ -#endif - Control = font; - } - - public float Size - { - get { return Control.PointSize; } - } - - public string FamilyName - { - get { return Control.FamilyName; } - } - - public FontFamily Family - { - get - { - if (family == null) - family = new FontFamily(Widget.Generator, new FontFamilyHandler(Control.FamilyName)); - return family; - } - } - - public FontTypeface Typeface - { - get - { - if (typeface == null) - typeface = ((FontFamilyHandler)Family.Handler).GetFace(Control); - return typeface; - } - } - - public FontStyle FontStyle - { - get - { - if (style == null) -#if OSX - style = NSFontManager.SharedFontManager.TraitsOfFont(Control).ToEto(); -#elif IOS - style = Typeface.FontStyle; -#endif - return style.Value; - } - } - - public FontDecoration FontDecoration - { - get { return decoration; } - } - - public float Ascent - { - get { return Control.Ascender; } - } - - public float Descent - { - get { return -Control.Descender; } - } - - public float XHeight - { -#if OSX - get { return Control.XHeight; } -#elif IOS - get { return Control.xHeight; } -#endif - } - - public float Leading - { - get { return Control.Leading; } - } - - public float Baseline - { - get { return Control.LineHeight() - Leading - Descent; } - } - - public NSDictionary Attributes - { - get - { - if (_attributes == null) - CreateAttributes(); - return _attributes ?? (_attributes = CreateAttributes()); - } - } - - static readonly NSObject[] attributeKeys = - { -#if OSX - NSAttributedString.FontAttributeName, - NSAttributedString.UnderlineStyleAttributeName, - NSAttributedString.StrikethroughStyleAttributeName -#elif IOS - UIStringAttributeKey.Font, - UIStringAttributeKey.UnderlineStyle, - UIStringAttributeKey.StrikethroughStyle -#endif - }; - - NSDictionary CreateAttributes() - { - return NSDictionary.FromObjectsAndKeys( - new NSObject[] - { - Control, - new NSNumber((int)(decoration.HasFlag(FontDecoration.Underline) ? NSUnderlineStyle.Single : NSUnderlineStyle.None)), - NSNumber.FromBoolean(decoration.HasFlag(FontDecoration.Strikethrough)) - }, - attributeKeys - ); - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Mac/Drawing/FontTypefaceHandler.cs b/Source/Eto.Platform.Mac/Drawing/FontTypefaceHandler.cs deleted file mode 100644 index 19710861bf..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/FontTypefaceHandler.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using Eto.Drawing; -using MonoMac.AppKit; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; - -namespace Eto.Platform.Mac.Drawing -{ - public class FontTypefaceHandler : WidgetHandler, IFontTypeface - { - readonly string name; - - public string PostScriptName { get; private set; } - - public int Weight { get; private set; } - - public NSFontTraitMask Traits { get; private set; } - // remove when implemented in monomac - static readonly IntPtr AppKit_libraryHandler; - static NSString _NSFontFamilyAttribute; - static NSString _NSFontFaceAttribute; - - static FontTypefaceHandler() - { - AppKit_libraryHandler = Dlfcn.dlopen("/System/Library/Frameworks/AppKit.framework/AppKit", 0); - } - - public static NSString NSFontFamilyAttribute - { - get - { - if (_NSFontFamilyAttribute == null) - _NSFontFamilyAttribute = Dlfcn.GetStringConstant(AppKit_libraryHandler, "NSFontFamilyAttribute"); - return _NSFontFamilyAttribute; - } - } - - public static NSString NSFontFaceAttribute - { - get - { - if (_NSFontFaceAttribute == null) - _NSFontFaceAttribute = Dlfcn.GetStringConstant(AppKit_libraryHandler, "NSFontFaceAttribute"); - return _NSFontFaceAttribute; - } - } - - public FontTypefaceHandler(NSArray descriptor) - { - PostScriptName = (string)new NSString(descriptor.ValueAt(0)); - name = (string)new NSString(descriptor.ValueAt(1)); - Weight = new NSNumber(descriptor.ValueAt(2)).Int32Value; - Traits = (NSFontTraitMask)new NSNumber(descriptor.ValueAt(3)).Int32Value; - } - - public FontTypefaceHandler(NSFont font) - { - var descriptor = font.FontDescriptor; - PostScriptName = descriptor.PostscriptName; - var manager = NSFontManager.SharedFontManager; - Weight = manager.WeightOfFont(font); - Traits = manager.TraitsOfFont(font); - name = (NSString)descriptor.FontAttributes[NSFontFaceAttribute]; - } - - public FontTypefaceHandler(string postScriptName, string name, NSFontTraitMask traits, int weight) - { - PostScriptName = postScriptName; - this.name = name; - Weight = weight; - Traits = traits; - } - - public string Name - { - get { return name; } - } - - public FontStyle FontStyle - { - get { return Traits.ToEto(); } - } - - public NSFont CreateFont(float size) - { - var family = (FontFamilyHandler)Widget.Family.Handler; - return NSFontManager.SharedFontManager.FontWithFamily(family.MacName, Traits, Weight, size); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/FontsHandler.cs b/Source/Eto.Platform.Mac/Drawing/FontsHandler.cs deleted file mode 100644 index e572a008e7..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/FontsHandler.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using Eto.Drawing; -using System.Collections.Generic; -using System.Linq; -#if OSX -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Drawing -#elif IOS -using MonoTouch.UIKit; -using MonoTouch.Foundation; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - public class FontsHandler : WidgetHandler, IFonts - { - readonly string [] availableFontFamilies; - - public FontsHandler () - { -#if OSX - availableFontFamilies = NSFontManager.SharedFontManager.AvailableFontFamilies; -#elif IOS - availableFontFamilies = UIFont.FamilyNames; -#endif - } - - public IEnumerable AvailableFontFamilies - { - get { return availableFontFamilies.Select (r => new FontFamily(Generator, new FontFamilyHandler (r))); } - } - - public bool FontFamilyAvailable (string fontFamily) - { - return availableFontFamilies.Contains (fontFamily, StringComparer.InvariantCultureIgnoreCase); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/GraphicsHandler.cs b/Source/Eto.Platform.Mac/Drawing/GraphicsHandler.cs deleted file mode 100644 index 49db61cd0a..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/GraphicsHandler.cs +++ /dev/null @@ -1,668 +0,0 @@ -using System; -using System.Linq; -using Eto.Drawing; -using SD = System.Drawing; -using System.Collections.Generic; - -#if OSX -using Eto.Platform.Mac.Forms; -using MonoMac.CoreGraphics; -using MonoMac.AppKit; -using GraphicsBase = Eto.Platform.Mac.Forms.MacBase; - -namespace Eto.Platform.Mac.Drawing -#elif IOS -using Eto.Platform.iOS.Forms; -using MonoTouch.CoreGraphics; -using MonoTouch.UIKit; -using MonoTouch.Foundation; -using NSView = MonoTouch.UIKit.UIView; -using GraphicsBase = Eto.WidgetHandler; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - /// - /// Handler for the - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class GraphicsHandler : GraphicsBase, IGraphics -#if IOS - , IGraphicsCreate -#endif - { - #if OSX - NSGraphicsContext graphicsContext; - bool disposeContext; - #endif - readonly NSView view; - float height; - PixelOffsetMode pixelOffsetMode = PixelOffsetMode.None; - float offset = 0.5f; - float inverseoffset; - SD.RectangleF? clipBounds; - IGraphicsPath clipPath; - int transformSaveCount; - Stack transforms; - CGAffineTransform currentTransform = CGAffineTransform.MakeIdentity(); - static readonly CGColorSpace patternColorSpace = CGColorSpace.CreatePattern(null); - - public float Offset { get { return offset; } } - - public float InverseOffset { get { return inverseoffset; } } - - public NSView DisplayView { get; private set; } - - public CGAffineTransform CurrentTransform { get { return currentTransform; } } - - public PixelOffsetMode PixelOffsetMode - { - get { return pixelOffsetMode; } - set - { - pixelOffsetMode = value; - offset = value == PixelOffsetMode.None ? 0.5f : 0f; - inverseoffset = value == PixelOffsetMode.None ? 0f : 0.5f; - } - } - - public GraphicsHandler() - { - } - - #if OSX - - public GraphicsHandler(NSView view) - { - this.view = view; - graphicsContext = NSGraphicsContext.FromWindow(view.Window); - graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true); - disposeContext = true; - Control = graphicsContext.GraphicsPort; - - view.PostsFrameChangedNotifications = true; - AddObserver(NSView.FrameChangedNotification, FrameDidChange, view); - - // if control is in a scrollview, we need to trap when it's scrolled as well - var parent = view.Superview; - while (parent != null) - { - var scroll = parent as NSScrollView; - if (scroll != null) - { - scroll.ContentView.PostsBoundsChangedNotifications = true; - AddObserver(NSView.BoundsChangedNotification, FrameDidChange, scroll.ContentView); - } - parent = parent.Superview; - } - - SetDefaults(); - InitializeContext(view.IsFlipped); - } - - static void FrameDidChange(ObserverActionEventArgs e) - { - var h = e.Handler as GraphicsHandler; - if (h != null && h.Control != null) - { - h.RewindAll(); - - h.Control.RestoreState(); - h.Control.SaveState(); - h.InitializeContext(h.view.IsFlipped); - - h.ReplayAll(); - } - } - - public GraphicsHandler(NSView view, NSGraphicsContext graphicsContext, float height, bool flipped) - { - DisplayView = view; - this.height = height; - this.graphicsContext = flipped != graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true); - Control = this.graphicsContext.GraphicsPort; - SetDefaults(); - InitializeContext(!flipped); - } - - #elif IOS - - public GraphicsHandler(NSView view, CGContext context, float height) - { - this.DisplayView = view; - this.height = height; - this.Control = context; - - SetDefaults(); - InitializeContext(false); - } - - bool shouldEndImageContext = false; - public void Create(Size size, bool useMainScreenScale) - { - this.height = size.Height; - UIGraphics.BeginImageContextWithOptions(size.ToSD(), opaque: true, scale: useMainScreenScale? 0f : 1f); - this.Control = UIGraphics.GetCurrentContext(); - // SetDefaults(); // commented because this turns off subpixel positioning. - InitializeContext(false); // does nothing but included for consistency - shouldEndImageContext = true; - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - if (shouldEndImageContext) - UIGraphics.EndImageContext(); - } - - public Bitmap GetImage() - { - if (shouldEndImageContext) - { - var h = new BitmapHandler(); - h.Create(UIGraphics.GetImageFromCurrentImageContext()); - return new Bitmap(null, h); - } - throw new InvalidOperationException("Can only call GetImage on a Graphics constructed with a specified size"); - } - - #endif - protected override bool DisposeControl { get { return false; } } - - public bool IsRetained { get { return false; } } - - bool antialias; - - public bool AntiAlias - { - get { return antialias; } - set - { - antialias = value; - Control.SetShouldAntialias(value); - } - } - - float scale = 1f; - public float PointsPerPixel { get { return scale; } } - - public ImageInterpolation ImageInterpolation - { - get { return Control.InterpolationQuality.ToEto(); } - set { Control.InterpolationQuality = value.ToCG(); } - } - - public void CreateFromImage(Bitmap image) - { - var handler = image.Handler as BitmapHandler; -#if OSX - var rep = handler.Control.Representations().OfType().FirstOrDefault(); - graphicsContext = NSGraphicsContext.FromBitmap(rep); - this.graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true); - disposeContext = true; - Control = graphicsContext.GraphicsPort; - scale = rep.PixelsWide / handler.Control.Size.Width; -#elif IOS - var cgimage = handler.Control.CGImage; - Control = new CGBitmapContext(handler.Data.MutableBytes, cgimage.Width, cgimage.Height, cgimage.BitsPerComponent, cgimage.BytesPerRow, cgimage.ColorSpace, cgimage.BitmapInfo); - scale = cgimage.Width / handler.Control.Size.Width; -#endif - - height = image.Size.Height; - SetDefaults(); - InitializeContext(true); - } - - public void Reset() - { - // unwind all SaveState's - ResetClip(); - while (transformSaveCount > 0) - { - RestoreTransform(); - } - // initial save state - Control.RestoreState(); - } - - public void Flush() - { -#if OSX - graphicsContext.FlushGraphics(); -#endif - } - - public float ViewHeight - { - get { return view != null ? view.Bounds.Height : height; } - } - - void SetDefaults() - { - Control.InterpolationQuality = CGInterpolationQuality.High; - Control.SetAllowsSubpixelPositioning(false); - } - - void InitializeContext(bool viewFlipped) - { - Control.SaveState(); - - #if OSX - // os x has different flipped states (depending on layers, etc), so compensate to make 0,0 at the top-left - if (view != null) - { - // we have a view (drawing directly to the screen), so adjust to where it is - Control.ClipToRect(view.ConvertRectToView(view.VisibleRect(), null)); - var pos = view.ConvertPointToView(SD.PointF.Empty, null); - if (!viewFlipped) - pos.Y += view.Frame.Height; - currentTransform = new CGAffineTransform(1, 0, 0, -1, pos.X, pos.Y); - Control.ConcatCTM(currentTransform); - } - else - { - // drawing to a bitmap or during a drawRect operation - currentTransform = new CGAffineTransform(1, 0, 0, -1, 0, viewFlipped ? ViewHeight : 0); - if (viewFlipped) - Control.ConcatCTM(currentTransform); - } - #elif IOS - if (viewFlipped) - { - // on ios, we flip the context if we're drawing on a bitmap otherwise we don't need to - currentTransform = new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight); - Control.ConcatCTM(currentTransform); - } - #endif - } - - public SD.PointF TranslateView(SD.PointF point, bool halfers = false, bool inverse = false) - { - if (halfers) - { - if (inverse) - { - point.X += inverseoffset; - point.Y += inverseoffset; - } - else - { - point.X += offset; - point.Y += offset; - } - } - return point; - } - - public SD.RectangleF TranslateView(SD.RectangleF rect, bool halfers = false, bool inverse = false) - { - if (halfers) - { - if (inverse) - { - rect.X += inverseoffset; - rect.Y += inverseoffset; - } - else - { - rect.X += offset; - rect.Y += offset; - } - } - return rect; - } - - void StartDrawing() - { -#if OSX - NSGraphicsContext.GlobalSaveGraphicsState(); - NSGraphicsContext.CurrentContext = graphicsContext; -#elif IOS - UIGraphics.PushContext(Control); -#endif - Control.SaveState(); - } - - void EndDrawing() - { - Control.RestoreState(); -#if OSX - NSGraphicsContext.GlobalRestoreGraphicsState(); -#elif IOS - UIGraphics.PopContext(); -#endif - } - - public void DrawLine(Pen pen, float startx, float starty, float endx, float endy) - { - StartDrawing(); - pen.Apply(this); - Control.StrokeLineSegments(new [] - { - TranslateView(new SD.PointF(startx, starty), true), - TranslateView(new SD.PointF(endx, endy), true) - }); - EndDrawing(); - } - - public void DrawRectangle(Pen pen, float x, float y, float width, float height) - { - StartDrawing(); - var rect = TranslateView(new SD.RectangleF(x, y, width, height), true); - pen.Apply(this); - Control.StrokeRect(rect); - EndDrawing(); - } - - public void FillRectangle(Brush brush, float x, float y, float width, float height) - { - StartDrawing(); - brush.Apply(this); - Control.FillRect(TranslateView(new SD.RectangleF(x, y, width, height), width > 1 || height > 1, true)); - EndDrawing(); - } - - public void DrawEllipse(Pen pen, float x, float y, float width, float height) - { - StartDrawing(); - System.Drawing.RectangleF rect = TranslateView(new System.Drawing.RectangleF(x, y, width, height), true); - pen.Apply(this); - Control.StrokeEllipseInRect(rect); - EndDrawing(); - } - - public void FillEllipse(Brush brush, float x, float y, float width, float height) - { - StartDrawing(); - /* if (width == 1 || height == 1) - { - DrawLine(color, x, y, x+width-1, y+height-1); - return; - }*/ - - brush.Apply(this); - Control.FillEllipseInRect(TranslateView(new SD.RectangleF(x, y, width, height), true, true)); - EndDrawing(); - } - - public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - StartDrawing(); - - var rect = TranslateView(new System.Drawing.RectangleF(x, y, width, height), true); - pen.Apply(this); - var yscale = rect.Height / rect.Width; - var centerY = rect.GetMidY(); - var centerX = rect.GetMidX(); - Control.ConcatCTM(new CGAffineTransform(1.0f, 0, 0, yscale, 0, centerY - centerY * yscale)); - Control.AddArc(centerX, centerY, rect.Width / 2, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle), sweepAngle < 0); - Control.StrokePath(); - EndDrawing(); - } - - public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - StartDrawing(); - - var rect = TranslateView(new System.Drawing.RectangleF(x, y, width, height), true, true); - brush.Apply(this); - var yscale = rect.Height / rect.Width; - var centerY = rect.GetMidY(); - var centerX = rect.GetMidX(); - Control.ConcatCTM(new CGAffineTransform(1.0f, 0, 0, yscale, 0, centerY - centerY * yscale)); - Control.MoveTo(centerX, centerY); - Control.AddArc(centerX, centerY, rect.Width / 2, Conversions.DegreesToRadians(startAngle), Conversions.DegreesToRadians(startAngle + sweepAngle), sweepAngle < 0); - Control.AddLineToPoint(centerX, centerY); - Control.ClosePath(); - Control.FillPath(); - EndDrawing(); - } - - public void FillPath(Brush brush, IGraphicsPath path) - { - StartDrawing(); - - Control.TranslateCTM(inverseoffset, inverseoffset); - Control.BeginPath(); - Control.AddPath(path.ToCG()); - Control.ClosePath(); - brush.Apply(this); - switch (path.FillMode) - { - case FillMode.Alternate: - Control.EOFillPath(); - break; - case FillMode.Winding: - Control.FillPath(); - break; - default: - throw new NotSupportedException(); - } - EndDrawing(); - } - - public void DrawPath(Pen pen, IGraphicsPath path) - { - StartDrawing(); - - Control.TranslateCTM(offset, offset); - pen.Apply(this); - Control.BeginPath(); - Control.AddPath(path.ToCG()); - Control.StrokePath(); - - EndDrawing(); - } - - public void DrawImage(Image image, float x, float y) - { - StartDrawing(); - - var handler = (IImageHandler)image.Handler; - handler.DrawImage(this, x, y); - EndDrawing(); - } - - public void DrawImage(Image image, float x, float y, float width, float height) - { - StartDrawing(); - - var handler = (IImageHandler)image.Handler; - handler.DrawImage(this, x, y, width, height); - EndDrawing(); - } - - public void DrawImage(Image image, RectangleF source, RectangleF destination) - { - StartDrawing(); - - var handler = (IImageHandler)image.Handler; - handler.DrawImage(this, source, destination); - EndDrawing(); - } - - public void DrawText(Font font, SolidBrush brush, float x, float y, string text) - { - if (string.IsNullOrEmpty(text)) - return; - - StartDrawing(); - FontExtensions.DrawString(text, new PointF(x, y), brush.Color, font); - EndDrawing(); - } - - public SizeF MeasureString(Font font, string text) - { - StartDrawing(); - var size = FontExtensions.MeasureString(text, font); - EndDrawing(); - return size; - } - #if OSX - protected override void Dispose(bool disposing) - { - if (disposing) - { - if (disposeContext && graphicsContext != null) - graphicsContext.FlushGraphics(); - Reset(); - if (disposeContext && graphicsContext != null) - graphicsContext.Dispose(); - } - base.Dispose(disposing); - } - #endif - public void TranslateTransform(float offsetX, float offsetY) - { - Control.TranslateCTM(offsetX, offsetY); - currentTransform = CGAffineTransform.Multiply(CGAffineTransform.MakeTranslation(offsetX, offsetY), currentTransform); - } - - public void RotateTransform(float angle) - { - angle = Conversions.DegreesToRadians(angle); - Control.RotateCTM(angle); - currentTransform = CGAffineTransform.Multiply(CGAffineTransform.MakeRotation(angle), currentTransform); - } - - public void ScaleTransform(float scaleX, float scaleY) - { - Control.ScaleCTM(scaleX, scaleY); - currentTransform = CGAffineTransform.Multiply(CGAffineTransform.MakeScale(scaleX, scaleY), currentTransform); - } - - public void MultiplyTransform(IMatrix matrix) - { - var m = matrix.ToCG(); - Control.ConcatCTM(m); - currentTransform = CGAffineTransform.Multiply(m, currentTransform); - } - - public void SaveTransform() - { - RewindClip(); - Control.SaveState(); - transformSaveCount++; - ReplayClip(); - if (transforms == null) - transforms = new Stack(); - transforms.Push(currentTransform); - } - - public void RestoreTransform() - { - if (transformSaveCount <= 0) - throw new InvalidOperationException("No saved transform"); - RewindClip(); - transformSaveCount--; - Control.RestoreState(); - ReplayClip(); - currentTransform = transforms.Pop(); - } - - public RectangleF ClipBounds - { - get { return Control.GetClipBoundingBox().ToEto(); } - } - - public void SetClip(RectangleF rectangle) - { - ResetClip(); - clipBounds = rectangle.ToSD(); - ReplayClip(); - } - - public void SetClip(IGraphicsPath path) - { - ResetClip(); - clipPath = path.Clone(); - ReplayClip(); - } - - void ReplayClip() - { - if (clipPath != null) - { - Control.SaveState(); - Control.AddPath(clipPath.ToCG()); - switch (clipPath.FillMode) - { - case FillMode.Alternate: - Control.EOClip(); - break; - case FillMode.Winding: - Control.Clip(); - break; - default: - throw new NotSupportedException(); - } - } - else if (clipBounds != null) - { - Control.SaveState(); - Control.ClipToRect(clipBounds.Value); - } - } - - void RewindClip() - { - if (clipBounds != null || clipPath != null) - { - Control.RestoreState(); - } - } - - void RewindTransform() - { - for (int i = 0; i < transformSaveCount; i++) - Control.RestoreState(); - } - - void ReplayTransform() - { - // replay transforms - if (transforms != null) - { - foreach (var transform in transforms) - { - Control.ConcatCTM(transform); - Control.SaveState(); - } - } - //Control.ConcatCTM (currentTransform); - } - - void RewindAll() - { - RewindClip(); - RewindTransform(); - } - - void ReplayAll() - { - ReplayTransform(); - ReplayClip(); - } - - public void ResetClip() - { - RewindClip(); - clipBounds = null; - clipPath = null; - } - - public void Clear(SolidBrush brush) - { - var rect = Control.GetClipBoundingBox(); - Control.ClearRect(rect); - if (brush != null) - FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height); - } - - public void SetFillColorSpace() - { - Control.SetFillColorSpace(patternColorSpace); - } - } -} diff --git a/Source/Eto.Platform.Mac/Drawing/GraphicsPathHandler.cs b/Source/Eto.Platform.Mac/Drawing/GraphicsPathHandler.cs deleted file mode 100644 index 9bb392356c..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/GraphicsPathHandler.cs +++ /dev/null @@ -1,270 +0,0 @@ -using System; -using Eto.Drawing; -using System.Collections.Generic; -using sd = System.Drawing; - -#if OSX -using MonoMac.CoreGraphics; -using Eto.Platform.Mac; -namespace Eto.Platform.Mac.Drawing -#elif IOS -using MonoTouch.CoreGraphics; -using Eto.Platform.iOS; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class GraphicsPathHandler : IGraphicsPathHandler - { - public CGPath Control { get; set; } - bool startFigure = true; - PointF? startPoint; - IMatrix transform; - bool isFirstFigure = true; - bool firstFigureClosed; - - public GraphicsPathHandler () - { - Control = new CGPath (); - } - - public GraphicsPathHandler(CGPath path) - { - Control = path; - } - - public void MoveTo (float x, float y) - { - Control.MoveToPoint (x, y); - if (startPoint == null) - startPoint = new PointF(x, y); - startFigure = false; - } - - public void LineTo (float x, float y) - { - Control.AddLineToPoint (x, y); - } - - void ConnectTo (PointF point) - { - ConnectTo (point.X, point.Y); - } - - void ConnectTo (float x, float y) - { - if (Control.IsEmpty || startFigure) - MoveTo (x, y); - else - LineTo (x, y); - } - - public void AddLine (float startX, float startY, float endX, float endY) - { - ConnectTo (startX, startY); - LineTo (endX, endY); - } - - public void AddLines (IEnumerable points) - { - var enumerator = points.GetEnumerator (); - if (!enumerator.MoveNext ()) - return; - ConnectTo(enumerator.Current); - while (enumerator.MoveNext ()) - { - var point = enumerator.Current; - Control.AddLineToPoint(point.X, point.Y); - } - } - - public void AddRectangle (float x, float y, float width, float height) - { - Control.AddRect (new sd.RectangleF (x, y, width, height)); - startFigure = true; - isFirstFigure = false; - } - - public void AddArc (float x, float y, float width, float height, float startAngle, float sweepAngle) - { - var yscale = height / width; - var centerY = y + height / 2; - var affine = new CGAffineTransform (1.0f, 0, 0, yscale, 0, centerY - centerY * yscale); - - if (startFigure) { - // degrees to radians conversion - double startRadians = startAngle * Math.PI / 180.0; - - // x and y radius - double dx = width / 2; - double dy = height / 2; - - // determine the start point - double xs = x + dx + (Math.Cos (startRadians) * dx); - double ys = y + dy + (Math.Sin (startRadians) * dy); - - MoveTo ((float)xs, (float)ys); - } - - Control.AddArc (affine, x+ width / 2, centerY, width / 2, Conversions.DegreesToRadians (startAngle), Conversions.DegreesToRadians (startAngle + sweepAngle), sweepAngle < 0); - } - - public void AddBezier (PointF start, PointF control1, PointF control2, PointF end) - { - ConnectTo (start); - this.AddCurveToPoint (control1, control2, end); - } - - /// - /// Check points early. If an invalid point is passed to AddCurveToPoint, - /// iOS crashes with a SIGABRT leading to a long debugging experience. - /// This provides early diagnostics. - /// - /// - private void Check(float f) - { - if (float.IsInfinity(f) || float.IsNaN(f)) - throw new InvalidOperationException("Invalid point specified to AddCurveToPoint"); - } - - private void Check(PointF p) - { - Check(p.X); - Check(p.Y); - } - - private void AddCurveToPoint(PointF point1, PointF point2, PointF point3) - { - Check(point1); - Check(point2); - Check(point3); - Control.AddCurveToPoint(point1.ToSD(), point2.ToSD(), point3.ToSD()); - } - - public void AddPath (IGraphicsPath path, bool connect = false) - { - if (path.IsEmpty) - return; - - var handler = path.ToHandler (); - if (connect && handler.startPoint != null && !handler.firstFigureClosed) { - var first = true; - handler.Control.Apply (element => { - switch (element.Type) { - case CGPathElementType.AddCurveToPoint: - if (first) - ConnectTo (element.Point3.ToEto()); - this.AddCurveToPoint(element.Point1.ToEto(), element.Point2.ToEto(), element.Point3.ToEto()); - break; - case CGPathElementType.AddLineToPoint: - if (first) - ConnectTo (element.Point1.ToEto()); - Control.AddLineToPoint(element.Point1); - break; - case CGPathElementType.AddQuadCurveToPoint: - if (first) - ConnectTo (element.Point2.ToEto()); - Control.AddQuadCurveToPoint (element.Point1.X, element.Point1.Y, element.Point2.X, element.Point2.Y); - break; - case CGPathElementType.CloseSubpath: - Control.CloseSubpath (); - break; - case CGPathElementType.MoveToPoint: - if (first) - ConnectTo (element.Point1.ToEto()); - else - Control.MoveToPoint (element.Point1); - break; - } - first = false; - }); - } - else { - Control.AddPath(handler.Control); - } - startFigure = handler.startFigure; - } - - public void Transform (IMatrix matrix) - { - if (transform == null) - transform = matrix; - else - transform.Prepend (matrix); - var path = new CGPath (); - path.AddPath (matrix.ToCG (), Control); - Control = path; - } - - public void CloseFigure () - { - Control.CloseSubpath (); - startFigure = true; - firstFigureClosed |= isFirstFigure; - isFirstFigure = false; - } - - public void StartFigure () - { - startFigure = true; - isFirstFigure = false; - } - - public void AddEllipse (float x, float y, float width, float height) - { - Control.AddElipseInRect (new sd.RectangleF (x, y, width, height)); - startFigure = true; - isFirstFigure = false; - } - - public void AddCurve (IEnumerable points, float tension = 0.5f) - { - points = SplineHelper.SplineCurve (points, tension); - SplineHelper.Draw (points, ConnectTo, (c1, c2, end) => this.AddCurveToPoint(c1, c2, end)); - } - - public RectangleF Bounds - { - get { return Control.PathBoundingBox.ToEto(); } - } - - public bool IsEmpty - { - get { return Control.IsEmpty; } - } - - public PointF CurrentPoint - { - get { return Control.CurrentPoint.ToEto(); } - } - - public object ControlObject - { - get { return this; } - } - - public void Dispose () - { - Control.Dispose (); - } - - FillMode fillMode = FillMode.Alternate; - public FillMode FillMode - { - get { return fillMode; } - set { fillMode = value;} - } - - public IGraphicsPath Clone () - { - return new GraphicsPathHandler (new CGPath (Control)); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/IconHandler.cs b/Source/Eto.Platform.Mac/Drawing/IconHandler.cs deleted file mode 100644 index 8aee5e943a..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/IconHandler.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.IO; -using Eto.Drawing; -using MonoMac.AppKit; -using MonoMac.Foundation; -using MonoMac.CoreGraphics; -using sd = System.Drawing; - -namespace Eto.Platform.Mac.Drawing -{ - public class IconHandler : ImageHandler, IIcon - { - public IconHandler() - { - } - - public IconHandler(NSImage image) - { - Control = image; - } - - public void Create(Stream stream) - { - var data = NSData.FromStream(stream); - Control = new NSImage(data); - } - - public void Create(string fileName) - { - if (!File.Exists(fileName)) - throw new FileNotFoundException("Icon not found", fileName); - Control = new NSImage(fileName); - } - - public override Size Size - { - get { return Control.Size.ToEtoSize(); } - } - - public override NSImage GetImage() - { - return Control; - } - - public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) - { - var sourceRect = new sd.RectangleF(source.X, Control.Size.Height - source.Y - source.Height, source.Width, source.Height); - var destRect = graphics.TranslateView(destination.ToSD(), true, true); - Control.Draw(destRect, sourceRect, NSCompositingOperation.SourceOver, 1, true, null); - } - } -} diff --git a/Source/Eto.Platform.Mac/Drawing/ImageHandler.cs b/Source/Eto.Platform.Mac/Drawing/ImageHandler.cs deleted file mode 100644 index 084283f0b5..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/ImageHandler.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Eto.Drawing; -using MonoMac.AppKit; -using MonoMac.Foundation; -using Eto.Platform.Mac.Forms; - -namespace Eto.Platform.Mac.Drawing -{ - interface IImageSource - { - NSImage GetImage(); - } - - interface IImageHandler : IImageSource - { - void DrawImage(GraphicsHandler graphics, float x, float y); - - void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height); - - void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination); - } - - public abstract class ImageHandler : WidgetHandler, IImage, IImageHandler - where TControl: class - where TWidget: Image - { - public abstract Size Size { get; } - - public abstract NSImage GetImage(); - - public virtual void DrawImage(GraphicsHandler graphics, float x, float y) - { - DrawImage(graphics, x, y, Size.Width, Size.Height); - } - - public virtual void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height) - { - DrawImage(graphics, new RectangleF(PointF.Empty, Size), new RectangleF(x, y, width, height)); - } - - public abstract void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination); - - protected override void Dispose(bool disposing) - { - // HACK: Remove when monomac/xammac's Dispose() actually works! - if (disposing && DisposeControl) - { - var obj = Control as NSObject; - if (obj != null) - { - obj.SafeDispose(); - Control = null; - } - } - base.Dispose(disposing); - } - } -} diff --git a/Source/Eto.Platform.Mac/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Platform.Mac/Drawing/IndexedBitmapHandler.cs deleted file mode 100644 index c636323097..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/IndexedBitmapHandler.cs +++ /dev/null @@ -1,169 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Eto.Drawing; -using MonoMac.AppKit; -using System.Linq; - -namespace Eto.Platform.Mac.Drawing -{ - public class IndexedBitmapDataHandler : BitmapData - { - public IndexedBitmapDataHandler(Image image, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) - : base(image, data, scanWidth, bitsPerPixel, controlObject) - { - } - - public override uint TranslateArgbToData(uint argb) - { - return argb; - } - - public override uint TranslateDataToArgb(uint bitmapData) - { - return bitmapData; - } - } - - public class IndexedBitmapHandler : ImageHandler, IIndexedBitmap - { - Size size; - int bytesPerRow; - int bitsPerPixel; - uint[] colors; - BitmapHandler bmp; - IntPtr ptr; - - public int RowStride - { - get { return bytesPerRow; } - } - - public override Size Size - { - get { return size; } - } - - public void Create(int width, int height, int bitsPerPixel) - { - this.bitsPerPixel = bitsPerPixel; - bytesPerRow = width * bitsPerPixel / 8; - int colorCount = (int)Math.Pow(2, bitsPerPixel); - colors = new uint[colorCount]; - for (int i=0; i Color.FromArgb(BitmapDataHandler.DataToArgb(r)))); - } - set - { - if (value.Count != colors.Length) - throw new ArgumentException("Input palette must have the same colors as the output"); - for (int i=0; i size.Width || source.Bottom > size.Height) - throw new Exception("Source rectangle exceeds image size"); - - // we have to draw to a temporary bitmap pixel by pixel - var bd = bmp.Lock(); - unsafe - { - var dest = (byte*)bd.Data; - var src = (byte*)ptr; - var scany = size.Width; - - dest += source.Top * bd.ScanWidth; - dest += source.Left * bd.BytesPerPixel; - - src += source.Top * scany; - src += source.Left; - - int bottom = source.Bottom; - int right = source.Right; - int left = source.Left; - scany = scany - (right - left); - for (int y=source.Top; y < bottom; y++) - { - var destrow = (uint*)dest; - for (int x=left; x < right; x++) - { - *destrow = colors[*src]; - destrow++; - src++; - } - dest += bd.ScanWidth; - src += scany; - } - } - bmp.Unlock(bd); - } - - public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) - { - CopyTo(bmp, Rectangle.Truncate(source)); - bmp.DrawImage(graphics, source, destination); - } - - protected override void Dispose(bool disposing) - { - if (disposing && bmp != null) - { - bmp.Dispose(); - bmp = null; - } - if (ptr != IntPtr.Zero) - { - Marshal.FreeHGlobal(ptr); - ptr = IntPtr.Zero; - } - base.Dispose(disposing); - } - } -} diff --git a/Source/Eto.Platform.Mac/Drawing/LinearGradientBrushHandler.cs b/Source/Eto.Platform.Mac/Drawing/LinearGradientBrushHandler.cs deleted file mode 100644 index 45474d27dd..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/LinearGradientBrushHandler.cs +++ /dev/null @@ -1,181 +0,0 @@ -using Eto.Drawing; -using sd = System.Drawing; - -#if DESKTOP -using MonoMac.CoreGraphics; - -namespace Eto.Platform.Mac.Drawing -#else -using MonoTouch.CoreGraphics; -using MonoTouch.ImageIO; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class LinearGradientBrushHandler : BrushHandler, ILinearGradientBrush - { - class BrushObject - { - CGAffineTransform transform = CGAffineTransform.MakeIdentity(); - CGAffineTransform viewTransform = CGAffineTransform.MakeIdentity(); - readonly float[] alpha = { 1f }; - CGPattern pattern; - GradientWrapMode wrap; - sd.SizeF tileSize; - sd.SizeF sectionSize; - - public CGGradient InverseGradient { get; set; } - - public CGGradient Gradient { get; set; } - - public sd.PointF StartPoint { get; set; } - - public sd.PointF EndPoint { get; set; } - - public GradientWrapMode Wrap - { - get { return wrap; } - set - { - wrap = value; - pattern = null; - } - } - - public void Apply(GraphicsHandler graphics) - { - graphics.SetFillColorSpace(); - - #if OSX - if (graphics.DisplayView != null) - { - // adjust for position of the current view relative to the window - var pos = graphics.DisplayView.ConvertPointToView(sd.PointF.Empty, null); - graphics.Control.SetPatternPhase(new sd.SizeF(pos.X, pos.Y)); - } - #endif - - // make current transform apply to the pattern - var currentTransform = graphics.CurrentTransform; - if (pattern == null || viewTransform != currentTransform) - { - viewTransform = currentTransform; - SetPattern(); - } - - graphics.Control.SetFillPattern(pattern, alpha); - } - - public float Opacity - { - get { return alpha[0]; } - set { alpha[0] = value; } - } - - public CGAffineTransform Transform - { - get { return transform; } - set - { - transform = value; - pattern = null; - } - } - - void DrawPattern(CGContext context) - { - var start = new sd.PointF(0, 0); - var end = start + sectionSize; - - context.ClipToRect(sd.RectangleF.Inflate(new sd.RectangleF(start, tileSize), 4, 4)); - - if (Wrap == GradientWrapMode.Reflect) - { - for (int i = 0; i < 2; i++) - { - context.DrawLinearGradient(Gradient, start, end, 0); - context.DrawLinearGradient(InverseGradient, end, end + sectionSize, 0); - start = start + sectionSize + sectionSize; - end = end + sectionSize + sectionSize; - } - } - else - { - for (int i = 0; i < 2; i++) - { - context.DrawLinearGradient(Gradient, start, end, 0); - start = start + sectionSize; - end = end + sectionSize; - } - } - } - - void SetPattern() - { - sectionSize = new sd.SizeF((EndPoint.X - StartPoint.X) + 1, (EndPoint.Y - StartPoint.Y) + 1); - if (Wrap == GradientWrapMode.Reflect) - tileSize = new sd.SizeF(sectionSize.Width * 4, sectionSize.Height * 4); - else - tileSize = new sd.SizeF(sectionSize.Width * 2, sectionSize.Height * 2); - var rect = new sd.RectangleF(StartPoint, tileSize); - var t = CGAffineTransform.Multiply(transform, viewTransform); - pattern = new CGPattern(rect, t, rect.Width, rect.Height, CGPatternTiling.NoDistortion, true, DrawPattern); - } - } - - public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint) - { - return new BrushObject - { - Gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor [] - { - startColor.ToCGColor(), - endColor.ToCGColor() - }), - InverseGradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor [] - { - endColor.ToCGColor(), - startColor.ToCGColor() - }), - StartPoint = startPoint.ToSD(), - EndPoint = endPoint.ToSD() - }; - } - - public object Create(RectangleF rectangle, Color startColor, Color endColor, float angle) - { - return null; - } - - public IMatrix GetTransform(LinearGradientBrush widget) - { - return ((BrushObject)widget.ControlObject).Transform.ToEto(); - } - - public void SetTransform(LinearGradientBrush widget, IMatrix transform) - { - ((BrushObject)widget.ControlObject).Transform = transform.ToCG(); - } - - public GradientWrapMode GetGradientWrap(LinearGradientBrush widget) - { - return ((BrushObject)widget.ControlObject).Wrap; - } - - public void SetGradientWrap(LinearGradientBrush widget, GradientWrapMode gradientWrap) - { - ((BrushObject)widget.ControlObject).Wrap = gradientWrap; - } - - public override void Apply(object control, GraphicsHandler graphics) - { - ((BrushObject)control).Apply(graphics); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/MatrixHandler.cs b/Source/Eto.Platform.Mac/Drawing/MatrixHandler.cs deleted file mode 100644 index 18b87089ab..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/MatrixHandler.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using Eto.Drawing; -using SD = System.Drawing; - -#if OSX -using MonoMac.CoreGraphics; - -namespace Eto.Platform.Mac.Drawing -#elif IOS -using MonoTouch.CoreGraphics; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - /// - /// Handler for - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class MatrixHandler : IMatrixHandler - { - CGAffineTransform control; - - public CGAffineTransform Control { get { return control; } } - - public MatrixHandler () - { - } - - public MatrixHandler (CGAffineTransform matrix) - { - control = matrix; - } - - public void Create () - { - control = CGAffineTransform.MakeIdentity (); - } - - public void Create (float xx, float yx, float xy, float yy, float dx, float dy) - { - control = new CGAffineTransform (xx, yx, xy, yy, dx, dy); - } - - public float[] Elements - { - get - { - return new float[] { - control.xx, - control.yx, - control.xy, - control.yy, - control.x0, - control.y0 - }; - } - } - - public float X0 { get { return control.x0; } set { control.x0 = value; } } - - public float Y0 { get { return control.y0; } set { control.y0 = value; } } - - public float Xx { get { return control.xx; } set { control.xx = value; } } - - public float Xy { get { return control.xy; } set { control.xy = value; } } - - public float Yx { get { return control.yx; } set { control.yx = value; } } - - public float Yy { get { return control.yy; } set { control.yy = value; } } - - public void Rotate (float angle) - { - control = CGAffineTransform.Multiply (CGAffineTransform.MakeRotation (Conversions.DegreesToRadians (angle)), control); - } - - public void RotateAt (float angle, float centerX, float centerY) - { - angle = Conversions.DegreesToRadians (angle); - var sina = (float)Math.Sin (angle); - var cosa = (float)Math.Cos (angle); - var matrix = new CGAffineTransform(cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa); - control = CGAffineTransform.Multiply (matrix, control); - } - - public void Translate (float x, float y) - { - control = CGAffineTransform.Multiply (CGAffineTransform.MakeTranslation (x, y), control); - } - - public void Scale (float scaleX, float scaleY) - { - control = CGAffineTransform.Multiply (CGAffineTransform.MakeScale (scaleX, scaleY), control); - } - - public void ScaleAt (float scaleX, float scaleY, float centerX, float centerY) - { - var matrix = new CGAffineTransform(scaleX, 0f, 0f, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); - control = CGAffineTransform.Multiply (matrix, control); - } - - public void Skew (float skewX, float skewY) - { - var matrix = new CGAffineTransform (1, (float)Math.Tan (Conversions.DegreesToRadians (skewX)), (float)Math.Tan (Conversions.DegreesToRadians (skewY)), 1, 0, 0); - control = CGAffineTransform.Multiply (matrix, control); - } - - public void Append (IMatrix matrix) - { - var affineMatrix = (CGAffineTransform)matrix.ControlObject; - control.Multiply (affineMatrix); - } - - public void Prepend (IMatrix matrix) - { - var affineMatrix = (CGAffineTransform)matrix.ControlObject; - control = CGAffineTransform.Multiply (affineMatrix, control); - } - - public void Invert () - { - control = control.Invert (); - } - - public PointF TransformPoint (Point p) - { - return control.TransformPoint(p.ToSDPointF()).ToEto(); - } - - public PointF TransformPoint (PointF p) - { - return control.TransformPoint(p.ToSD()).ToEto(); - } - - public object ControlObject - { - get { return control; } - } - - public IMatrix Clone () - { - return new MatrixHandler (control); - } - - public void Dispose() - { - } - } -} diff --git a/Source/Eto.Platform.Mac/Drawing/PenHandler.cs b/Source/Eto.Platform.Mac/Drawing/PenHandler.cs deleted file mode 100644 index a9a961c067..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/PenHandler.cs +++ /dev/null @@ -1,175 +0,0 @@ -using System; -using Eto.Drawing; - -#if OSX -using MonoMac.CoreGraphics; - -namespace Eto.Platform.Mac.Drawing -#elif IOS -using MonoTouch.CoreGraphics; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - /// - /// Pen handler - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class PenHandler : IPen - { - class PenControl { - float[] cgdashes; - DashStyle dashStyle; - CGLineCap lineCap; - float thickness; - float cgoffset; - - public CGColor Color { get; set; } - - public float Thickness - { - get { return thickness; } - set { - thickness = value; - SetDashStyle (); - } - } - - public CGLineJoin LineJoin { get; set; } - - public CGLineCap LineCap - { - get { return lineCap; } - set { - lineCap = value; - SetDashStyle (); - } - } - - public float MiterLimit { get; set; } - - public DashStyle DashStyle - { - get { return dashStyle; } - set { - dashStyle = value; - SetDashStyle (); - } - } - - void SetDashStyle () - { - if (DashStyle == null || DashStyle.IsSolid) { - cgdashes = null; - } else { - // TODO: this is not quite perfect for Square/Round for small thicknesses - - var dashes = DashStyle.Dashes; - cgoffset = DashStyle.Offset * Thickness; - - if (LineCap == CGLineCap.Butt) - cgdashes = Array.ConvertAll (dashes, x => x * Thickness); - else { - if (Math.Abs(Thickness - 1) < 0.01f) - cgoffset += Thickness / 2; - cgdashes = new float[dashes.Length]; - for (int i = 0; i < cgdashes.Length; i++) { - var dash = dashes [i] * Thickness; - if ((i % 2) == 1) { - // gap must include square/round thickness - dash += Thickness; - } else { - // dash must exclude square/round thickness - dash -= Thickness; - } - cgdashes [i] = dash; - } - } - } - } - - public void Apply (GraphicsHandler graphics) - { - graphics.Control.SetStrokeColor (Color); - graphics.Control.SetLineCap (LineCap); - graphics.Control.SetLineJoin (LineJoin); - graphics.Control.SetLineWidth (Thickness); - graphics.Control.SetMiterLimit (MiterLimit); - if (cgdashes != null) - graphics.Control.SetLineDash (cgoffset, cgdashes); - } - } - - public object Create (Color color, float thickness) - { - return new PenControl { - Color = color.ToCGColor (), - Thickness = thickness, - MiterLimit = 10f, - LineCap = PenLineCap.Square.ToCG () - }; - } - - public Color GetColor (Pen widget) - { - return ((PenControl)widget.ControlObject).Color.ToEtoColor (); - } - - public void SetColor (Pen widget, Color color) - { - ((PenControl)widget.ControlObject).Color = color.ToCGColor (); - } - - public float GetThickness (Pen widget) - { - return ((PenControl)widget.ControlObject).Thickness; - } - - public void SetThickness (Pen widget, float thickness) - { - ((PenControl)widget.ControlObject).Thickness = thickness; - } - - public PenLineJoin GetLineJoin (Pen widget) - { - return ((PenControl)widget.ControlObject).LineJoin.ToEto (); - } - - public void SetLineJoin (Pen widget, PenLineJoin lineJoin) - { - ((PenControl)widget.ControlObject).LineJoin = lineJoin.ToCG (); - } - - public PenLineCap GetLineCap (Pen widget) - { - return ((PenControl)widget.ControlObject).LineCap.ToEto (); - } - - public void SetLineCap (Pen widget, PenLineCap lineCap) - { - ((PenControl)widget.ControlObject).LineCap = lineCap.ToCG (); - } - - public float GetMiterLimit (Pen widget) - { - return ((PenControl)widget.ControlObject).MiterLimit; - } - - public void SetMiterLimit (Pen widget, float miterLimit) - { - ((PenControl)widget.ControlObject).MiterLimit = miterLimit; - } - - public void SetDashStyle (Pen widget, DashStyle dashStyle) - { - ((PenControl)widget.ControlObject).DashStyle = dashStyle; - } - - public void Apply (Pen widget, GraphicsHandler graphics) - { - ((PenControl)widget.ControlObject).Apply (graphics); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/SolidBrushHandler.cs b/Source/Eto.Platform.Mac/Drawing/SolidBrushHandler.cs deleted file mode 100644 index 689d1c7910..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/SolidBrushHandler.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Eto.Drawing; - -#if OSX -using MonoMac.CoreGraphics; - -namespace Eto.Platform.Mac.Drawing -#elif IOS -using MonoTouch.CoreGraphics; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class SolidBrushHandler : BrushHandler, ISolidBrush - { - public override void Apply (object control, GraphicsHandler graphics) - { - graphics.Control.SetFillColor ((CGColor)control); - } - - public Color GetColor (SolidBrush widget) - { - return ((CGColor)widget.ControlObject).ToEtoColor (); - } - - public void SetColor (SolidBrush widget, Color color) - { - widget.ControlObject = color.ToCGColor (); - } - - object ISolidBrush.Create (Color color) - { - return color.ToCGColor (); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Drawing/TextureBrushHandler.cs b/Source/Eto.Platform.Mac/Drawing/TextureBrushHandler.cs deleted file mode 100644 index ad071c6710..0000000000 --- a/Source/Eto.Platform.Mac/Drawing/TextureBrushHandler.cs +++ /dev/null @@ -1,137 +0,0 @@ -using Eto.Drawing; -using sd = System.Drawing; - -#if DESKTOP -using MonoMac.CoreGraphics; - -namespace Eto.Platform.Mac.Drawing -#else -using MonoTouch.CoreGraphics; -using MonoTouch.ImageIO; - -namespace Eto.Platform.iOS.Drawing -#endif -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class TextureBrushHandler : BrushHandler, ITextureBrush - { - class BrushObject - { - CGImage image; - CGAffineTransform transform = CGAffineTransform.MakeIdentity(); - CGAffineTransform viewTransform = CGAffineTransform.MakeIdentity(); - readonly float[] alpha = { 1f }; - CGPattern pattern; - - public void Apply(GraphicsHandler graphics) - { - graphics.SetFillColorSpace(); - - #if OSX - if (graphics.DisplayView != null) - { - // adjust for position of the current view relative to the window - var pos = graphics.DisplayView.ConvertPointToView(sd.PointF.Empty, null); - graphics.Control.SetPatternPhase(new sd.SizeF(pos.X, pos.Y)); - } - #endif - - // make current transform apply to the pattern - var currentTransform = graphics.CurrentTransform; - if (pattern == null || viewTransform != currentTransform) - { - viewTransform = currentTransform; - SetPattern(); - } - - graphics.Control.SetFillPattern(pattern, alpha); - } - - public CGImage Image - { - get { return image; } - set - { - image = value; - ClearPattern(); - } - } - - public float Opacity - { - get { return alpha[0]; } - set { alpha[0] = value; } - } - - public CGAffineTransform Transform - { - get { return transform; } - set - { - transform = value; - ClearPattern(); - } - } - - void ClearPattern() - { - if (pattern != null) - pattern.Dispose(); - pattern = null; - } - - void DrawPattern(CGContext context) - { - var destRect = new sd.RectangleF(0, 0, image.Width, image.Height); - context.ConcatCTM(new CGAffineTransform(1, 0, 0, -1, 0, image.Height)); - context.DrawImage(destRect, image); - } - - void SetPattern() - { - var t = CGAffineTransform.Multiply(transform, viewTransform); - ClearPattern(); - pattern = new CGPattern(new sd.RectangleF(0, 0, image.Width, image.Height), t, image.Width, image.Height, CGPatternTiling.NoDistortion, true, DrawPattern); - } - } - - public object Create(Image image, float opacity) - { - return new BrushObject - { - Image = image.ToCG(), - Opacity = opacity - }; - } - - public IMatrix GetTransform(TextureBrush widget) - { - return ((BrushObject)widget.ControlObject).Transform.ToEto(); - } - - public void SetTransform(TextureBrush widget, IMatrix transform) - { - ((BrushObject)widget.ControlObject).Transform = transform.ToCG(); - } - - public override void Apply(object control, GraphicsHandler graphics) - { - ((BrushObject)control).Apply(graphics); - } - - public float GetOpacity(TextureBrush widget) - { - return ((BrushObject)widget.ControlObject).Opacity; - } - - public void SetOpacity(TextureBrush widget, float opacity) - { - ((BrushObject)widget.ControlObject).Opacity = opacity; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Eto.Platform.Mac.csproj b/Source/Eto.Platform.Mac/Eto.Platform.Mac.csproj deleted file mode 100644 index d2a114edeb..0000000000 --- a/Source/Eto.Platform.Mac/Eto.Platform.Mac.csproj +++ /dev/null @@ -1,220 +0,0 @@ - - - - Debug - AnyCPU - {9DD10DFF-5AB3-4E66-B798-CA17911A61E4} - Library - Eto.Platform.Mac - Eto.Platform.Mac - - - $(DefineConstants);OSX;DESKTOP;MONOMAC - false - true - - - full - ..\..\BuildOutput\Debug\ - DEBUG;OSX;DESKTOP;MONOMAC - prompt - 4 - false - true - - - pdbonly - true - ..\..\BuildOutput\Release\ - prompt - 4 - false - OSX;DESKTOP;MONOMAC - true - - - ..\..\.. - - - - - ..\..\Libraries\MonoMac\MonoMac.dll - - - - - - - - - - - - - - - - Code - - - Code - - - Code - - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Properties\GlobalAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {16289D2F-044C-49EF-83E9-9391AFF8FD2B} - Eto - - - - - MonoMac-License.txt - PreserveNewest - - - - - - - - - - - - - - - - - diff --git a/Source/Eto.Platform.Mac/Eto.Platform.XamMac.csproj b/Source/Eto.Platform.Mac/Eto.Platform.XamMac.csproj deleted file mode 100644 index a09df1032c..0000000000 --- a/Source/Eto.Platform.Mac/Eto.Platform.XamMac.csproj +++ /dev/null @@ -1,216 +0,0 @@ - - - - Debug - AnyCPU - {15490F6C-C579-4A86-AD16-8D9B5B41EB87} - {42C0BBD9-55CE-4FC1-8D90-A7348ABAFB23};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Eto.Platform.Mac - Eto.Platform.XamMac - - - - full - false - ..\..\BuildOutput\Debug\ - DEBUG;OSX;DESKTOP;XAMMAC - prompt - 4 - False - True - True - false - false - false - false - false - - - pdbonly - true - ..\..\BuildOutput\Release\ - prompt - 4 - false - true - OSX;DESKTOP;XAMMAC - True - false - false - false - false - false - - - - - - - - - - - - - - - - - Code - - - Code - - - Code - - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Properties\GlobalAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {16289D2F-044C-49EF-83E9-9391AFF8FD2B} - Eto - - - - - - - - - - - - - - - - diff --git a/Source/Eto.Platform.Mac/EtoEnvironmentHandler.cs b/Source/Eto.Platform.Mac/EtoEnvironmentHandler.cs deleted file mode 100644 index cde9e88b39..0000000000 --- a/Source/Eto.Platform.Mac/EtoEnvironmentHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using MonoMac.Foundation; -using System.Linq; - -namespace Eto.Platform.Mac -{ - public class EtoEnvironmentHandler : WidgetHandler, IEtoEnvironment - { - static void Convert (EtoSpecialFolder folder, out NSSearchPathDirectory dir, out NSSearchPathDomain domain) - { - switch (folder) { - case EtoSpecialFolder.ApplicationSettings: - dir = NSSearchPathDirectory.ApplicationSupportDirectory; - domain = NSSearchPathDomain.User; - break; - case EtoSpecialFolder.Documents: - dir = NSSearchPathDirectory.DocumentDirectory; - domain = NSSearchPathDomain.User; - break; - default: - throw new NotSupportedException (); - } - } - - public string GetFolderPath (EtoSpecialFolder folder) - { - NSSearchPathDirectory dir; - NSSearchPathDomain domain; - switch (folder) { - case EtoSpecialFolder.ApplicationResources: - return NSBundle.MainBundle.ResourcePath; - case EtoSpecialFolder.ApplicationSettings: - Convert (folder, out dir, out domain); - var path = NSSearchPath.GetDirectories (dir, domain).FirstOrDefault (); - path = System.IO.Path.Combine (path, NSBundle.MainBundle.BundleIdentifier); - if (!System.IO.Directory.Exists (path)) - System.IO.Directory.CreateDirectory (path); - return path; - default: - Convert (folder, out dir, out domain); - return NSSearchPath.GetDirectories (dir, domain).FirstOrDefault (); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Actions/MacCommand.cs b/Source/Eto.Platform.Mac/Forms/Actions/MacCommand.cs deleted file mode 100644 index 477fa0b4a0..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Actions/MacCommand.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.ObjCRuntime; - -namespace Eto.Platform.Mac.Forms.Actions -{ - public class MacCommand : Command - { - public Selector Selector { get; private set; } - - public MacCommand(string id, string text, string selector) - { - ID = id; - MenuText = ToolBarText = text; - Selector = new Selector(selector); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/ApplicationHandler.cs b/Source/Eto.Platform.Mac/Forms/ApplicationHandler.cs deleted file mode 100644 index d67481a59b..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ApplicationHandler.cs +++ /dev/null @@ -1,283 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; -using Eto.Platform.Mac.Forms.Actions; -using MonoMac.ObjCRuntime; -using System.Collections.Generic; -using System.Linq; - -namespace Eto.Platform.Mac.Forms -{ - public class ApplicationHandler : WidgetHandler, IApplication - { - bool attached; - - internal static bool QueueResizing { get; set; } - - public NSApplicationDelegate AppDelegate { get; set; } - - public bool AddFullScreenMenuItem { get; set; } - - public bool AddPrintingMenuItems { get; set; } - - public bool AllowClosingMainForm { get; set; } - - public static ApplicationHandler Instance - { - get { return Application.Instance == null ? null : Application.Instance.Handler as ApplicationHandler; } - } - - public string BadgeLabel - { - get - { - var badgeLabel = Control.DockTile.BadgeLabel; - return string.IsNullOrEmpty(badgeLabel) ? null : badgeLabel; - } - set - { - Control.DockTile.BadgeLabel = value ?? string.Empty; - } - } - - public bool ShouldCloseForm(Window window, bool wasClosed) - { - if (ReferenceEquals(window, Widget.MainForm)) - { - if (AllowClosingMainForm && wasClosed) - Widget.MainForm = null; - return AllowClosingMainForm; - } - - return true; - } - - public ApplicationHandler() - { - Control = NSApplication.SharedApplication; - } - - static void restart_WillTerminate(object sender, EventArgs e) - { - // re-open after we terminate - var args = new string[] - { - "-c", - "open \"$1\"", - string.Empty, - NSBundle.MainBundle.BundlePath - }; - NSTask.LaunchFromPath("/bin/sh", args); - } - - public void Invoke(Action action) - { - var thread = NSThread.Current; - if (thread != null && thread.IsMainThread) - action(); - else - { - Control.InvokeOnMainThread(() => action()); - } - } - - public void AsyncInvoke(Action action) - { - Control.BeginInvokeOnMainThread(() => action()); - } - - public void Restart() - { - NSApplication.SharedApplication.WillTerminate += restart_WillTerminate; - NSApplication.SharedApplication.Terminate(AppDelegate); - - // only get here if cancelled, remove event to restart - NSApplication.SharedApplication.WillTerminate -= restart_WillTerminate; - } - - public void RunIteration() - { - NSApplication.SharedApplication.NextEvent(NSEventMask.AnyEvent, NSDate.DistantFuture, NSRunLoop.NSDefaultRunLoopMode, true); - } - - public void Attach(object context) - { - attached = true; - } - - public void OnMainFormChanged() - { - } - - public void Run(string[] args) - { - if (!attached) - { - EtoBundle.Init(); - - if (Control.Delegate == null) - Control.Delegate = AppDelegate ?? new AppDelegate(); - NSApplication.Main(args); - } - else - Initialize(Control.Delegate); - } - - public void Initialize(NSApplicationDelegate appdelegate) - { - AppDelegate = appdelegate; - Widget.OnInitialized(EventArgs.Empty); - } - - public void Quit() - { - NSApplication.SharedApplication.Terminate(AppDelegate); - } - - public void Open(string url) - { - NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(url)); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Application.TerminatingEvent: - // handled by app delegate - break; - default: - base.AttachEvent(id); - break; - } - } - - public void EnableFullScreen() - { - if (Control.RespondsToSelector(new Selector("setPresentationOptions:"))) - { - AddFullScreenMenuItem = true; - } - } - - public IEnumerable GetSystemCommands() - { - yield return new Command((sender, e) => NSApplication.SharedApplication.Hide(NSApplication.SharedApplication)) - { - ID = "mac_hide", - MenuText = string.Format("Hide {0}", Widget.Name), - ToolBarText = "Hide", - ToolTip = string.Format("Hides the main {0} window", Widget.Name), - Shortcut = Keys.H | Keys.Application - }; - - yield return new Command((sender, e) => NSApplication.SharedApplication.HideOtherApplications(NSApplication.SharedApplication)) - { - ID = "mac_hideothers", - MenuText = "Hide Others", - ToolBarText = "Hide Others", - ToolTip = "Hides all other application windows", - Shortcut = Keys.H | Keys.Application | Keys.Alt - }; - - yield return new Command((sender, e) => NSApplication.SharedApplication.UnhideAllApplications(NSApplication.SharedApplication)) - { - ID = "mac_showall", - MenuText = "Show All", - ToolBarText = "Show All", - ToolTip = "Show All Windows" - }; - - yield return new MacCommand("mac_performMiniaturize", "Minimize", "performMiniaturize:") { Shortcut = Keys.Application | Keys.M }; - yield return new MacCommand("mac_performZoom", "Zoom", "performZoom:"); - yield return new MacCommand("mac_performClose", "Close", "performClose:") { Shortcut = Keys.Application | Keys.W }; - yield return new MacCommand("mac_arrangeInFront", "Bring All To Front", "arrangeInFront:"); - yield return new MacCommand("mac_cut", "Cut", "cut:") { Shortcut = Keys.Application | Keys.X }; - yield return new MacCommand("mac_copy", "Copy", "copy:") { Shortcut = Keys.Application | Keys.C }; - yield return new MacCommand("mac_paste", "Paste", "paste:") { Shortcut = Keys.Application | Keys.V }; - yield return new MacCommand("mac_pasteAsPlainText", "Paste and Match Style", "pasteAsPlainText:") { Shortcut = Keys.Application | Keys.Alt | Keys.Shift | Keys.V }; - yield return new MacCommand("mac_delete", "Delete", "delete:"); - yield return new MacCommand("mac_selectAll", "Select All", "selectAll:") { Shortcut = Keys.Application | Keys.A }; - yield return new MacCommand("mac_undo", "Undo", "undo:") { Shortcut = Keys.Application | Keys.Z }; - yield return new MacCommand("mac_redo", "Redo", "redo:") { Shortcut = Keys.Application | Keys.Shift | Keys.Z }; - yield return new MacCommand("mac_toggleFullScreen", "Enter Full Screen", "toggleFullScreen:") { Shortcut = Keys.Application | Keys.Control | Keys.F }; - yield return new MacCommand("mac_runPageLayout", "Page Setup...", "runPageLayout:") { Shortcut = Keys.Application | Keys.Shift | Keys.P }; - yield return new MacCommand("mac_print", "Print...", "print:") { Shortcut = Keys.Application | Keys.P }; - } - - public void CreateStandardMenu(MenuItemCollection menu, IEnumerable commands) - { - var lookup = commands.ToLookup(r => r.ID); - var application = menu.GetSubmenu(Widget.Name ?? "Application", 100); - application.Items.AddSeparator(800); - application.Items.AddRange(lookup["mac_hide"], 800); - application.Items.AddRange(lookup["mac_hideothers"], 800); - application.Items.AddRange(lookup["mac_showall"], 800); - application.Items.AddSeparator(801); - - var file = menu.GetSubmenu("&File", 100); - file.Items.AddSeparator(900); - file.Items.AddRange(lookup["mac_performClose"], 900); - - if (AddPrintingMenuItems) - { - file.Items.AddSeparator(1000); - file.Items.AddRange(lookup["mac_runPageLayout"], 1000); - file.Items.AddRange(lookup["mac_print"], 1000); - } - - var edit = menu.GetSubmenu("&Edit", 200); - edit.Items.AddSeparator(100); - edit.Items.AddRange(lookup["mac_undo"], 100); - edit.Items.AddRange(lookup["mac_redo"], 100); - edit.Items.AddSeparator(101); - - edit.Items.AddSeparator(200); - edit.Items.AddRange(lookup["mac_cut"], 200); - edit.Items.AddRange(lookup["mac_copy"], 200); - edit.Items.AddRange(lookup["mac_paste"], 200); - edit.Items.AddRange(lookup["mac_delete"], 200); - edit.Items.AddRange(lookup["mac_selectAll"], 200); - edit.Items.AddSeparator(201); - - var window = menu.GetSubmenu("&Window", 900); - window.Items.AddSeparator(100); - window.Items.AddRange(lookup["mac_performMiniaturize"], 100); - window.Items.AddRange(lookup["mac_performZoom"], 100); - window.Items.AddSeparator(101); - - window.Items.AddSeparator(200); - window.Items.AddRange(lookup["mac_arrangeInFront"], 200); - window.Items.AddSeparator(201); - - if (AddFullScreenMenuItem) - { - var view = menu.GetSubmenu("&View", 300); - view.Items.AddSeparator(900); - view.Items.AddRange(lookup["mac_toggleFullScreen"], 900); - view.Items.AddSeparator(901); - } - - var help = menu.GetSubmenu("&Help", 900); - // always show help menu - help.Trim = false; - } - - public Keys CommonModifier - { - get - { - return Keys.Application; - } - } - - public Keys AlternateModifier - { - get - { - return Keys.Alt; - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Cells/CellHandler.cs b/Source/Eto.Platform.Mac/Forms/Cells/CellHandler.cs deleted file mode 100644 index a687b806c7..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Cells/CellHandler.cs +++ /dev/null @@ -1,85 +0,0 @@ -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public interface ICellHandler - { - NSCell Control { get; } - - Eto.Generator Generator { get; } - - IDataColumnHandler ColumnHandler { get; set; } - - NSObject GetObjectValue (object dataItem); - - void SetObjectValue (object dataItem, NSObject val); - - float GetPreferredSize (object value, System.Drawing.SizeF cellSize, int row, object dataItem); - - void HandleEvent (string handler, bool defaultEvent = false); - - void SetBackgroundColor (NSCell cell, Color color); - - Color GetBackgroundColor (NSCell cell); - - void SetForegroundColor (NSCell cell, Color color); - - Color GetForegroundColor (NSCell cell); - - bool Editable { get; set; } - } - - public abstract class CellHandler : MacObject, ICell, ICellHandler - where TControl: NSCell - where TWidget: Cell - { - public IDataColumnHandler ColumnHandler { get; set; } - NSCell copy; - - NSCell ICellHandler.Control { - get { return Control; } - } - - public virtual bool Editable { - get { return Control.Editable; } - set { - Control.Enabled = Control.Editable = value; - } - } - - public virtual NSObject GetObjectValue (object dataItem) - { - return null; - } - - Eto.Generator ICellHandler.Generator - { - get { return Widget.Generator; } - } - - public abstract void SetBackgroundColor (NSCell cell, Color color); - - public abstract Color GetBackgroundColor (NSCell cell); - - public abstract void SetForegroundColor (NSCell cell, Color color); - - public abstract Color GetForegroundColor (NSCell cell); - - public abstract void SetObjectValue (object dataItem, NSObject value); - - public abstract float GetPreferredSize (object value, System.Drawing.SizeF cellSize, NSCell cell); - - public float GetPreferredSize (object value, System.Drawing.SizeF cellSize, int row, object dataItem) - { - if (copy == null) - copy = Control.Copy () as NSCell; - ColumnHandler.DataViewHandler.OnCellFormatting (ColumnHandler.Widget, dataItem, row, copy); - return GetPreferredSize (value, cellSize, copy); - } - - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Cells/CheckBoxCellHandler.cs b/Source/Eto.Platform.Mac/Forms/Cells/CheckBoxCellHandler.cs deleted file mode 100644 index d7192ffc79..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Cells/CheckBoxCellHandler.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class CheckBoxCellHandler : CellHandler, ICheckBoxCell - { - public class EtoCell : NSButtonCell, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public EtoCell () - { - } - - public EtoCell (IntPtr handle) : base(handle) - { - } - - [Export("copyWithZone:")] - NSObject CopyWithZone (IntPtr zone) - { - var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr (SuperHandle, MacCommon.CopyWithZoneHandle, zone); - return new EtoCell (ptr) { Handler = Handler }; - } - } - - public CheckBoxCellHandler () - { - Control = new EtoCell { Handler = this }; - Control.Title = string.Empty; - Control.SetButtonType (NSButtonType.Switch); - } - - public override void SetBackgroundColor (NSCell cell, Color color) - { - var c = (EtoCell)cell; - c.BackgroundColor = color.ToNSUI (); - } - - public override Color GetBackgroundColor (NSCell cell) - { - var c = (EtoCell)cell; - return c.BackgroundColor.ToEto (); - } - - public override void SetForegroundColor (NSCell cell, Color color) - { - } - - public override Color GetForegroundColor (NSCell cell) - { - return Colors.Transparent; - } - - - public override void SetObjectValue (object dataItem, NSObject value) - { - if (Widget.Binding != null) { - var num = value as NSNumber; - if (num != null) { - var state = (NSCellStateValue)num.IntValue; - bool? boolValue; - switch (state) { - default: - boolValue = null; - break; - case NSCellStateValue.On: - boolValue = true; - break; - case NSCellStateValue.Off: - boolValue = false; - break; - } - Widget.Binding.SetValue(dataItem, boolValue); - } - } - } - - public override NSObject GetObjectValue (object dataItem) - { - if (Widget.Binding != null) { - NSCellStateValue state = NSCellStateValue.Off; - var val = Widget.Binding.GetValue(dataItem); - if (val is bool?) { - var boolVal = (bool?)val; - state = boolVal != null ? boolVal.Value ? NSCellStateValue.On : NSCellStateValue.Off : NSCellStateValue.Mixed; - } - else if (val is bool) { - var boolVal = (bool)val; - state = boolVal ? NSCellStateValue.On : NSCellStateValue.Off; - } - return new NSNumber((int)state); - } - return new NSNumber ((int)NSCellStateValue.Off); - } - - public override float GetPreferredSize (object value, System.Drawing.SizeF cellSize, NSCell cell) - { - return 25; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Cells/ComboBoxCellHandler.cs b/Source/Eto.Platform.Mac/Forms/Cells/ComboBoxCellHandler.cs deleted file mode 100644 index 0c72cd1bbe..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Cells/ComboBoxCellHandler.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using System.Collections.Generic; -using System.Linq; -using Eto.Drawing; -using MonoMac.CoreGraphics; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class ComboBoxCellHandler : CellHandler, IComboBoxCell - { - IListStore dataStore; - - public class EtoCell : NSPopUpButtonCell, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public EtoCell () - { - } - - public EtoCell (IntPtr handle) : base(handle) - { - } - - public NSColor TextColor { get; set; } - - public bool DrawsBackground { get; set; } - - [Export("copyWithZone:")] - NSObject CopyWithZone (IntPtr zone) - { - var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr (SuperHandle, MacCommon.CopyWithZoneHandle, zone); - return new EtoCell (ptr) { Handler = Handler }; - } - - public override void DrawBorderAndBackground (System.Drawing.RectangleF cellFrame, NSView controlView) - { - if (DrawsBackground) { - var nscontext = NSGraphicsContext.CurrentContext; - var context = nscontext.GraphicsPort; - - context.SetFillColor (BackgroundColor.CGColor); - context.FillRect (cellFrame); - } - - base.DrawBorderAndBackground (cellFrame, controlView); - } - - public override System.Drawing.RectangleF DrawTitle (NSAttributedString title, System.Drawing.RectangleF frame, NSView controlView) - { - if (TextColor != null) { - var newtitle = (NSMutableAttributedString)title.MutableCopy(); - var range = new NSRange (0, title.Length); - newtitle.RemoveAttribute (NSAttributedString.ForegroundColorAttributeName, range); - newtitle.AddAttribute (NSAttributedString.ForegroundColorAttributeName, TextColor, range); - title = newtitle; - } - var rect = base.DrawTitle (title, frame, controlView); - return rect; - } - } - - public ComboBoxCellHandler () - { - Control = new EtoCell { Handler = this, ControlSize = NSControlSize.Regular, Bordered = false }; - Control.Title = string.Empty; - } - - public override void SetBackgroundColor (NSCell cell, Color color) - { - var c = (EtoCell)cell; - c.BackgroundColor = color.ToNSUI (); - c.DrawsBackground = color != Colors.Transparent; - } - - public override Color GetBackgroundColor (NSCell cell) - { - var c = (EtoCell)cell; - return c.BackgroundColor.ToEto (); - } - - public override void SetForegroundColor (NSCell cell, Color color) - { - var c = (EtoCell)cell; - c.TextColor = color.ToNSUI (); - } - - public override Color GetForegroundColor (NSCell cell) - { - var c = (EtoCell)cell; - return c.TextColor.ToEto (); - } - - IEnumerable GetItems () - { - if (dataStore == null) - yield break; - for (int i = 0; i < dataStore.Count; i ++) { - var item = dataStore [i]; - yield return item; - } - } - - public IListStore DataStore { - get { return dataStore; } - set { - dataStore = value; - Control.RemoveAllItems (); - Control.AddItems (GetItems ().Select (r => r.Text).ToArray ()); - } - } - - public override void SetObjectValue (object dataItem, NSObject value) - { - if (Widget.Binding != null) { - var row = ((NSNumber)value).Int32Value; - var item = dataStore [row]; - var itemValue = item != null ? item.Key : null; - Widget.Binding.SetValue (dataItem, itemValue); - } - } - - public override NSObject GetObjectValue (object dataItem) - { - if (Widget.Binding != null) { - var val = Widget.Binding.GetValue (dataItem); - var key = Convert.ToString (val); - int found = -1; - int index = 0; - foreach (var item in GetItems ()) { - if (object.Equals (item.Key, key)) { - found = index; - break; - } - index ++; - } - - return new NSNumber (found); - } - return null; - } - - public override float GetPreferredSize (object value, System.Drawing.SizeF cellSize, NSCell cell) - { - return 100; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Cells/ImageTextCellHandler.cs b/Source/Eto.Platform.Mac/Forms/Cells/ImageTextCellHandler.cs deleted file mode 100644 index c29feb0f98..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Cells/ImageTextCellHandler.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class ImageTextCellHandler : CellHandler, IImageTextCell - { - public class EtoCell : MacImageListItemCell, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public EtoCell () - { - } - - public EtoCell (IntPtr handle) : base(handle) - { - } - - [Export("copyWithZone:")] - NSObject CopyWithZone (IntPtr zone) - { - var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr (SuperHandle, MacCommon.CopyWithZoneHandle, zone); - return new EtoCell (ptr) { Handler = Handler }; - } - } - - public ImageTextCellHandler () - { - Control = new EtoCell { - Handler = this, - UsesSingleLineMode = true - }; - } - - public override void SetBackgroundColor (NSCell cell, Color color) - { - var c = (EtoCell)cell; - c.BackgroundColor = color.ToNSUI (); - c.DrawsBackground = color != Colors.Transparent; - } - - public override Color GetBackgroundColor (NSCell cell) - { - var c = (EtoCell)cell; - return c.BackgroundColor.ToEto (); - } - - public override void SetForegroundColor (NSCell cell, Color color) - { - var c = (EtoCell)cell; - c.TextColor = color.ToNSUI (); - } - - public override Color GetForegroundColor (NSCell cell) - { - var c = (EtoCell)cell; - return c.TextColor.ToEto (); - } - - public override NSObject GetObjectValue (object dataItem) - { - var result = new MacImageData(); - if (Widget.TextBinding != null) { - result.Text = (NSString)Convert.ToString (Widget.TextBinding.GetValue (dataItem)); - } - if (Widget.ImageBinding != null) { - var image = Widget.ImageBinding.GetValue (dataItem) as Image; - result.Image = image != null ? ((IImageSource)image.Handler).GetImage () : null; - } - else result.Image = null; - return result; - } - - public override void SetObjectValue (object dataItem, NSObject value) - { - if (Widget.TextBinding != null) { - var str = value as NSString; - if (str != null) - Widget.TextBinding.SetValue (dataItem, str.ToString()); - else - Widget.TextBinding.SetValue (dataItem, null); - } - } - - public override float GetPreferredSize (object value, System.Drawing.SizeF cellSize, NSCell cell) - { - var val = value as MacImageData; - if (val == null) return 0; - - var font = cell.Font ?? NSFont.BoldSystemFontOfSize (NSFont.SystemFontSize); - var str = val.Text; - var attrs = NSDictionary.FromObjectAndKey (font, NSAttributedString.FontAttributeName); - - var size = str.StringSize (attrs).Width + 4 + 16 + MacImageListItemCell.ImagePadding * 2; // for border + image - return size; - - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Cells/ImageViewCellHandler.cs b/Source/Eto.Platform.Mac/Forms/Cells/ImageViewCellHandler.cs deleted file mode 100644 index 497ddac6fa..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Cells/ImageViewCellHandler.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using MonoMac.CoreGraphics; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class ImageViewCellHandler : CellHandler, IImageViewCell - { - public class EtoCell : NSImageCell, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public EtoCell () - { - } - - public EtoCell (IntPtr handle) : base(handle) - { - } - - public Color BackgroundColor { get; set; } - - public bool DrawsBackground { get; set; } - - [Export("copyWithZone:")] - NSObject CopyWithZone (IntPtr zone) - { - var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr ( - SuperHandle, - MacCommon.CopyWithZoneHandle, - zone - ); - return new EtoCell (ptr) { Handler = Handler }; - } - - public override void DrawInteriorWithFrame (System.Drawing.RectangleF cellFrame, NSView inView) - { - - if (DrawsBackground) { - var nscontext = NSGraphicsContext.CurrentContext; - var context = nscontext.GraphicsPort; - context.SetFillColor (BackgroundColor.ToCGColor ()); - context.FillRect (cellFrame); - } - - base.DrawInteriorWithFrame (cellFrame, inView); - } - } - - public override bool Editable { - get { return base.Editable; } - set { Control.Editable = value; } - } - - public ImageViewCellHandler () - { - Control = new EtoCell { Handler = this, Enabled = true }; - } - - public override void SetBackgroundColor (NSCell cell, Color color) - { - var c = (EtoCell)cell; - c.BackgroundColor = color; - c.DrawsBackground = color != Colors.Transparent; - } - - public override Color GetBackgroundColor (NSCell cell) - { - var c = (EtoCell)cell; - return c.BackgroundColor; - } - - public override void SetForegroundColor (NSCell cell, Color color) - { - } - - public override Color GetForegroundColor (NSCell cell) - { - return Colors.Transparent; - } - - public override NSObject GetObjectValue (object dataItem) - { - if (Widget.Binding != null) { - var img = Widget.Binding.GetValue (dataItem) as Image; - if (img != null) { - var imgHandler = ((IImageSource)img.Handler); - return imgHandler.GetImage (); - } - } - return new NSImage (); - } - - public override void SetObjectValue (object dataItem, NSObject value) - { - } - - public override float GetPreferredSize (object value, System.Drawing.SizeF cellSize, NSCell cell) - { - var img = value as Image; - if (img != null) { - return cellSize.Height / (float)img.Size.Height * (float)img.Size.Width; - } - return 16; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Cells/TextBoxCellHandler.cs b/Source/Eto.Platform.Mac/Forms/Cells/TextBoxCellHandler.cs deleted file mode 100644 index 0d07c613b3..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Cells/TextBoxCellHandler.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class TextBoxCellHandler : CellHandler, ITextBoxCell - { - public class EtoCell : NSTextFieldCell, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public EtoCell () - { - } - - public EtoCell (IntPtr handle) : base(handle) - { - } - - [Export("copyWithZone:")] - NSObject CopyWithZone (IntPtr zone) - { - var ptr = Messaging.IntPtr_objc_msgSendSuper_IntPtr (SuperHandle, MacCommon.CopyWithZoneHandle, zone); - return new EtoCell (ptr) { Handler = Handler }; - } - } - - public TextBoxCellHandler () - { - Control = new EtoCell { - Handler = this, - UsesSingleLineMode = true, - Wraps = false, - Scrollable = true - }; - } - - public override void SetBackgroundColor (NSCell cell, Color color) - { - var c = (EtoCell)cell; - c.BackgroundColor = color.ToNSUI (); - c.DrawsBackground = color != Colors.Transparent; - } - - public override Color GetBackgroundColor (NSCell cell) - { - var c = (EtoCell)cell; - return c.BackgroundColor.ToEto (); - } - - public override void SetForegroundColor (NSCell cell, Color color) - { - var c = (EtoCell)cell; - c.TextColor = color.ToNSUI (); - } - - public override Color GetForegroundColor (NSCell cell) - { - var c = (EtoCell)cell; - return c.TextColor.ToEto (); - } - - public override NSObject GetObjectValue (object dataItem) - { - if (Widget.Binding != null) - { - var val = Widget.Binding.GetValue(dataItem); - return val != null ? new NSString(Convert.ToString(val)) : null; - } - return null; - } - - public override void SetObjectValue (object dataItem, NSObject value) - { - if (Widget.Binding != null) { - var str = value as NSString; - if (str != null) - Widget.Binding.SetValue (dataItem, str.ToString()); - else - Widget.Binding.SetValue (dataItem, null); - } - } - - public override float GetPreferredSize (object value, System.Drawing.SizeF cellSize, NSCell cell) - { - var font = cell.Font ?? NSFont.BoldSystemFontOfSize (NSFont.SystemFontSize); - var str = new NSString (Convert.ToString (value)); - var attrs = NSDictionary.FromObjectAndKey (font, NSAttributedString.FontAttributeName); - return str.StringSize (attrs).Width + 8; // for border - - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/ClipboardHandler.cs b/Source/Eto.Platform.Mac/Forms/ClipboardHandler.cs deleted file mode 100644 index c67243442c..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ClipboardHandler.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; -using System.IO; -using Eto.Platform.Mac.Drawing; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms -{ - public class ClipboardHandler : WidgetHandler, IClipboard - { - public ClipboardHandler () - { - Control = NSPasteboard.GeneralPasteboard; - } - - public void SetData (byte[] value, string type) - { - Control.SetDataForType (NSData.FromArray (value), type); - } - - public string Html - { - set { Control.SetStringForType (value, NSPasteboard.NSHtmlType); } - get { return Control.GetStringForType (NSPasteboard.NSHtmlType); } - } - - public void SetString (string value, string type) - { - Control.SetStringForType (value, type); - } - - public string Text - { - set { Control.SetStringForType (value, NSPasteboard.NSStringType); } - get { return Control.GetStringForType (NSPasteboard.NSStringType); } - } - - public Image Image - { - set { - var handler = value.Handler as BitmapHandler; - if (handler != null) { - var data = handler.Control.AsTiff (); - Control.SetDataForType (data, NSPasteboard.NSTiffType); - } - } - get { - var image = new NSImage(Control); - if (image.Handle == IntPtr.Zero) return null; - return new Bitmap(Widget.Generator, new BitmapHandler(image)); - } - } - - public unsafe byte[] GetData (string type) - { - var availableType = Control.GetAvailableTypeFromArray(new string[] { type }); - - if (availableType != null) - { - var data = Control.GetDataForType(availableType); - var bytes = new byte[data.Length]; - var stream = new UnmanagedMemoryStream((byte*)data.Bytes, data.Length); - stream.Read(bytes, 0, (int)data.Length); - return bytes; - } - return null; - } - - public string GetString (string type) - { - return Control.GetStringForType (type); - } - - public string[] Types { - get { return Control.Types; } - } - - public void Clear () - { - Control.ClearContents (); - } - - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/ColorDialogHandler.cs b/Source/Eto.Platform.Mac/Forms/ColorDialogHandler.cs deleted file mode 100644 index af5a8cc7a2..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ColorDialogHandler.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.ObjCRuntime; -using MonoMac.Foundation; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms -{ - interface IColorDialogHandler - { - Color Color { get; set; } - ColorDialog Widget { get; } - NSColorPanel Control { get; } - } - - class ColorHandler : NSWindowDelegate - { - public static ColorHandler Instance { get; set; } - WeakReference handler; - public IColorDialogHandler Handler { get { return (IColorDialogHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [Export("changeColor:")] - public void ChangeColor(NSColorPanel panel) - { - Handler.Color = panel.Color.UsingColorSpace (NSColorSpace.DeviceRGB).ToEto (); - Handler.Widget.OnColorChanged(EventArgs.Empty); - } - - public override void WillClose (NSNotification notification) - { - Handler.Control.SetTarget (null); - Handler.Control.SetAction (null); - ColorHandler.Instance = null; - } - - [Export("modalClosed:")] - public void ModalClosed(NSNotification notification) - { - NSColorPanel.SharedColorPanel.PerformClose (this); - NSNotificationCenter.DefaultCenter.RemoveObserver (this); - } - } - - public class ColorDialogHandler : MacObject, IColorDialog, IColorDialogHandler - { - - public ColorDialogHandler() - { - Control = NSColorPanel.SharedColorPanel; - this.Color = Colors.White; - } - - public Color Color { get; set; } - - #region IDialog implementation - - public DialogResult ShowDialog (Window parent) - { - //Control = new NSColorPanel(); - NSWindow parentWindow; - //Console.WriteLine ("Parent: {0}. {1}, {2}", parent, parent.ControlObject, NSApplication.SharedApplication.ModalWindow); - if (parent != null) { - parentWindow = parent.ParentWindow.ControlObject as NSWindow ?? NSApplication.SharedApplication.KeyWindow; - if (parentWindow != null) - Control.ParentWindow = parentWindow; - } - else parentWindow = NSApplication.SharedApplication.KeyWindow; - - ColorHandler.Instance = new ColorHandler{ Handler = this }; - Control.Delegate = ColorHandler.Instance; - Control.SetTarget (null); - Control.SetAction (null); - Control.Color = Color.ToNSUI (); - - Control.SetTarget (ColorHandler.Instance); - Control.SetAction (new Selector("changeColor:")); - - //Control.Continuous = false; - bool isModal = false; - if (parentWindow != null) { - if (parentWindow == NSApplication.SharedApplication.ModalWindow) - { - //Control.WorksWhenModal = true; - //Control.ParentWindow = parentWindow; - NSNotificationCenter.DefaultCenter.AddObserver(ColorHandler.Instance, new Selector("modalClosed:"), new NSString("NSWindowWillCloseNotification"), parentWindow); - isModal = true; - } - } - - - // work around for modal dialogs wanting to show the color panel.. only works when the panel is key - - //if (isModal) Control.MakeKeyAndOrderFront (parentWindow); - //else Control.OrderFront (parentWindow); - NSApplication.SharedApplication.OrderFrontColorPanel (parentWindow); - if (isModal) Control.MakeKeyWindow(); - //Control.OrderFront (parentWindow); - - - return DialogResult.None; // signal that we are returning right away! - } - - #endregion - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/ButtonHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/ButtonHandler.cs deleted file mode 100644 index 02f6f42fa0..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/ButtonHandler.cs +++ /dev/null @@ -1,226 +0,0 @@ -using System; -using SD = System.Drawing; -using Eto.Drawing; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Controls -{ - /// - /// Button handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class ButtonHandler : MacButton, IButton - { - Image image; - ButtonImagePosition imagePosition; - readonly Size defaultSize; - static readonly Size originalSize; - - class EtoButtonCell : NSButtonCell - { - public Color? Color { get; set; } - - public override void DrawBezelWithFrame(System.Drawing.RectangleF frame, NSView controlView) - { - if (Color != null) - { - MacEventView.Colourize(controlView, Color.Value, delegate - { - base.DrawBezelWithFrame(frame, controlView); - }); - } - else - base.DrawBezelWithFrame(frame, controlView); - } - } - - class EtoButton : NSButton, IMacControl - { - bool setBezel = true; - public WeakReference WeakHandler { get; set; } - - public ButtonHandler Handler - { - get { return (ButtonHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public override void SizeToFit() - { - setBezel = false; - base.SizeToFit(); - - if (Handler.AutoSize) - { - var size = Frame.Size; - if (size.Width < Handler.defaultSize.Width) - size.Width = Handler.defaultSize.Width; - if (size.Height < Handler.defaultSize.Height) - size.Height = Handler.defaultSize.Height; - SetFrameSize(size); - } - setBezel = true; - } - - public override void SetFrameSize(SD.SizeF newSize) - { - base.SetFrameSize(newSize); - if (setBezel) - Handler.SetBezel(); - } - } - - static ButtonHandler() - { - // store the normal size for a rounded button, so we can determine what style to give it based on actual size - var b = new NSButton { BezelStyle = NSBezelStyle.Rounded }; - b.SizeToFit(); - originalSize = b.Frame.Size.ToEtoSize(); - } - - public ButtonHandler() - { - Control = new EtoButton - { - Handler = this, - Cell = new EtoButtonCell (), - Title = string.Empty, - BezelStyle = NSBezelStyle.Rounded, - ImagePosition = NSCellImagePosition.ImageLeft - }; - defaultSize = Button.DefaultSize; - Control.SetButtonType(NSButtonType.MomentaryPushIn); - Control.SetFrameSize(defaultSize.ToSDSizeF()); - Control.Activated += HandleActivated; - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - SetBezel(); - } - - static void HandleActivated(object sender, EventArgs e) - { - var handler = GetHandler(sender) as ButtonHandler; - if (handler != null) - { - handler.Widget.OnClick(EventArgs.Empty); - } - } - - public override void AttachEvent(string id) - { - switch (id) - { - default: - base.AttachEvent(id); - break; - } - } - - public override Color BackgroundColor - { - get - { - var cell = (EtoButtonCell)Control.Cell; - return cell.Color ?? Colors.Transparent; - } - set - { - var cell = (EtoButtonCell)Control.Cell; - cell.Color = value.A > 0 ? (Color?)value : null; - Control.SetNeedsDisplay(); - } - } - - public Image Image - { - get { return image; } - set - { - var oldSize = GetPreferredSize(Size.MaxValue); - image = value; - Control.Image = image.ToNS(); - SetBezel(); - LayoutIfNeeded(oldSize); - } - } - - public override Size Size - { - get { return base.Size; } - set - { - base.Size = value; - SetBezel(); - } - } - - /// - /// Gets the bezel style of the button based on its size and image position - /// - NSBezelStyle GetBezelStyle() - { - var size = Control.Frame.Size.ToEtoSize(); - if (size.Height < 22 || size.Width < 22) - return NSBezelStyle.SmallSquare; - if (size.Height > originalSize.Height) - return NSBezelStyle.RegularSquare; - if (Image == null) - return NSBezelStyle.Rounded; - if (image.Size.Height > 18) - return NSBezelStyle.RegularSquare; - switch (Control.ImagePosition) - { - case NSCellImagePosition.ImageAbove: - case NSCellImagePosition.ImageBelow: - if (!string.IsNullOrEmpty(Text)) - return NSBezelStyle.RegularSquare; - break; - } - return NSBezelStyle.Rounded; - } - - void SetBezel() - { - Control.BezelStyle = GetBezelStyle(); - } - - public override string Text - { - get { return base.Text; } - set - { - base.Text = value; - SetImagePosition(); - } - } - - void SetImagePosition() - { - var position = imagePosition.ToNS(); - if ((position == NSCellImagePosition.ImageAbove || position == NSCellImagePosition.ImageBelow) && string.IsNullOrEmpty(Text)) - position = NSCellImagePosition.ImageOnly; - Control.ImagePosition = position; - SetBezel(); - } - - public ButtonImagePosition ImagePosition - { - get { return imagePosition; } - set - { - if (imagePosition != value) - { - var oldSize = GetPreferredSize(Size.MaxValue); - imagePosition = value; - SetImagePosition(); - LayoutIfNeeded(oldSize); - } - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/CheckBoxHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/CheckBoxHandler.cs deleted file mode 100644 index 7b30f5280f..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/CheckBoxHandler.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class CheckBoxHandler : MacButton, ICheckBox - { - - public class EtoCheckBoxButton : NSButton, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public CheckBoxHandler() - { - Control = new EtoCheckBoxButton { Handler = this, Title = string.Empty }; - Control.SetButtonType(NSButtonType.Switch); - Control.Activated += HandleActivated; - } - - static void HandleActivated(object sender, EventArgs e) - { - var handler = GetHandler(sender) as CheckBoxHandler; - handler.Widget.OnCheckedChanged(EventArgs.Empty); - } - - public bool? Checked - { - get - { - switch (Control.State) - { - case NSCellStateValue.On: - return true; - case NSCellStateValue.Off: - return false; - default: - return null; - } - } - set - { - if (value == null) - Control.State = ThreeState ? NSCellStateValue.Mixed : NSCellStateValue.Off; - else if (value.Value) - Control.State = NSCellStateValue.On; - else - Control.State = NSCellStateValue.Off; - } - } - - public bool ThreeState - { - get { return Control.AllowsMixedState; } - set { Control.AllowsMixedState = value; } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/ComboBoxHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/ComboBoxHandler.cs deleted file mode 100644 index 02610478e5..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/ComboBoxHandler.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using SD = System.Drawing; -using Eto.Forms; -using System.Linq; -using MonoMac.AppKit; -using System.Collections.Generic; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class ComboBoxHandler : MacControl, IComboBox - { - CollectionHandler collection; - - public class EtoPopUpButton : NSPopUpButton, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public ComboBoxHandler() - { - Control = new EtoPopUpButton { Handler = this }; - Control.Activated += HandleActivated; - } - - static void HandleActivated(object sender, EventArgs e) - { - var handler = GetHandler(sender) as ComboBoxHandler; - handler.Widget.OnSelectedIndexChanged(EventArgs.Empty); - } - - class CollectionHandler : DataStoreChangedHandler - { - public ComboBoxHandler Handler { get; set; } - - public override int IndexOf(IListItem item) - { - return Handler.Control.IndexOfItem(item.Text); - } - - public override void AddRange(IEnumerable items) - { - var oldIndex = Handler.Control.IndexOfSelectedItem; - Handler.Control.AddItems(items.Select(r => r.Text).ToArray()); - if (oldIndex == -1) - Handler.Control.SelectItem(-1); - Handler.LayoutIfNeeded(); - } - - public override void AddItem(IListItem item) - { - var oldIndex = Handler.Control.IndexOfSelectedItem; - Handler.Control.AddItem(item.Text); - if (oldIndex == -1) - Handler.Control.SelectItem(-1); - Handler.LayoutIfNeeded(); - } - - public override void InsertItem(int index, IListItem item) - { - var oldIndex = Handler.Control.IndexOfSelectedItem; - Handler.Control.InsertItem(item.Text, index); - if (oldIndex == -1) - Handler.Control.SelectItem(-1); - Handler.LayoutIfNeeded(); - } - - public override void RemoveItem(int index) - { - Handler.Control.RemoveItem(index); - Handler.LayoutIfNeeded(); - } - - public override void RemoveAllItems() - { - Handler.Control.RemoveAllItems(); - Handler.LayoutIfNeeded(); - } - } - - public IListStore DataStore - { - get { return collection == null ? null : collection.Collection; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler { Handler = this }; - collection.Register(value); - } - } - - public int SelectedIndex - { - get { return Control.IndexOfSelectedItem; } - set - { - if (value != SelectedIndex) - { - Control.SelectItem(value); - if (Widget.Loaded) - Widget.OnSelectedIndexChanged(EventArgs.Empty); - } - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/DateTimePickerHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/DateTimePickerHandler.cs deleted file mode 100644 index 4129253931..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/DateTimePickerHandler.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class DateTimePickerHandler : MacControl, IDateTimePicker - { - DateTime? curValue; - DateTimePickerMode mode; - - public class EtoDatePicker : NSDatePicker, IMacControl - { - public override void DrawRect(System.Drawing.RectangleF dirtyRect) - { - if (Handler.curValue != null) - base.DrawRect(dirtyRect); - else - { - // paint with no elements visible - var old = DatePickerElements; - DatePickerElements = 0; - base.DrawRect(dirtyRect); - DatePickerElements = old; - } - } - - public WeakReference WeakHandler { get; set; } - - public DateTimePickerHandler Handler - { - get { return (DateTimePickerHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public DateTimePickerHandler() - { - Control = new EtoDatePicker - { - Handler = this, - TimeZone = NSTimeZone.LocalTimeZone, - Calendar = NSCalendar.CurrentCalendar, - DateValue = DateTime.Now.ToNS() - }; - this.Mode = DateTimePicker.DefaultMode; - // apple+backspace clears the value - Control.ValidateProposedDateValue += HandleValidateProposedDateValue; - } - - protected override void Initialize() - { - base.Initialize(); - Widget.KeyDown += HandleKeyDown; - // when clicking, set the value if it is null - Widget.MouseDown += HandleMouseDown; - } - - static void HandleKeyDown(object sender, KeyEventArgs e) - { - var handler = (DateTimePickerHandler)((Control)sender).Handler; - if (!e.Handled) - { - if (e.KeyData == (Keys.Application | Keys.Backspace)) - { - handler.curValue = null; - handler.Widget.OnValueChanged(EventArgs.Empty); - handler.Control.NeedsDisplay = true; - } - } - } - - static void HandleMouseDown(object sender, MouseEventArgs e) - { - var handler = (DateTimePickerHandler)((Control)sender).Handler; - if (e.Buttons == MouseButtons.Primary) - { - if (handler.curValue == null) - { - handler.curValue = handler.Control.DateValue.ToEto(); - handler.Widget.OnValueChanged(EventArgs.Empty); - handler.Control.NeedsDisplay = true; - } - } - } - - static void HandleValidateProposedDateValue(object sender, NSDatePickerValidatorEventArgs e) - { - var datePickerCell = (NSDatePickerCell)sender; - var handler = GetHandler(datePickerCell.ControlView) as DateTimePickerHandler; - var date = e.ProposedDateValue.ToEto(); - if (date != handler.Control.DateValue.ToEto()) - { - handler.curValue = date; - handler.Widget.OnValueChanged(EventArgs.Empty); - } - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - return SizeF.Max(new Size(mode == DateTimePickerMode.DateTime ? 180 : 120, 10), base.GetNaturalSize(availableSize)); - } - - public DateTimePickerMode Mode - { - get { return mode; } - set - { - mode = value; - switch (mode) - { - case DateTimePickerMode.Date: - Control.DatePickerElements = NSDatePickerElementFlags.YearMonthDateDay; - break; - case DateTimePickerMode.Time: - Control.DatePickerElements = NSDatePickerElementFlags.HourMinuteSecond; - break; - case DateTimePickerMode.DateTime: - Control.DatePickerElements = NSDatePickerElementFlags.YearMonthDateDay | NSDatePickerElementFlags.HourMinuteSecond; - break; - default: - throw new NotSupportedException(); - } - } - } - - public DateTime MinDate - { - get { return Control.MinDate.ToEto() ?? DateTime.MinValue; } - set { Control.MinDate = value.ToNS(); } - } - - public DateTime MaxDate - { - get { return Control.MaxDate.ToEto() ?? DateTime.MaxValue; } - set { Control.MaxDate = value.ToNS(); } - } - - public DateTime? Value - { - get - { - return curValue; - } - set - { - if (value != curValue) - { - curValue = value; - // don't validate otherwise the new value gets overridden when null - Control.ValidateProposedDateValue -= HandleValidateProposedDateValue; - Control.DateValue = (value ?? DateTime.Now).ToNS(); - Control.ValidateProposedDateValue += HandleValidateProposedDateValue; - Widget.OnValueChanged(EventArgs.Empty); - } - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/DrawableHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/DrawableHandler.cs deleted file mode 100644 index 252b4ae9d4..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/DrawableHandler.cs +++ /dev/null @@ -1,117 +0,0 @@ -using sd = System.Drawing; -using Eto.Drawing; -using Eto.Forms; -using Eto.Platform.Mac.Drawing; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class DrawableHandler : MacPanel, IDrawable - { - Brush backgroundBrush; - Color backgroundColor; - - public bool SupportsCreateGraphics { get { return true; } } - - public override NSView ContainerControl { get { return Control; } } - - public class EtoDrawableView : MacEventView - { - Drawable Drawable - { - get { return Widget as Drawable; } - } - - public override void DrawRect(sd.RectangleF dirtyRect) - { - var drawable = Drawable; - if (drawable == null) - return; - if (!IsFlipped) - dirtyRect.Y = Frame.Height - dirtyRect.Y - dirtyRect.Height; - if (dirtyRect.X % 1.0f > 0f) - dirtyRect.Width += 1; - if (dirtyRect.Y % 1.0f > 0f) - dirtyRect.Height += 1; - ApplicationHandler.QueueResizing = true; - drawable.Update(Rectangle.Ceiling(dirtyRect.ToEto())); - ApplicationHandler.QueueResizing = false; - } - - public bool CanFocus { get; set; } - - public override bool AcceptsFirstResponder() - { - return CanFocus; - } - - public override bool AcceptsFirstMouse(NSEvent theEvent) - { - return CanFocus; - } - } - - public Graphics CreateGraphics() - { - return new Graphics(Widget.Generator, new GraphicsHandler(Control)); - } - - public override bool Enabled { get; set; } - - public override Color BackgroundColor - { - get { return backgroundColor; } - set - { - if (backgroundColor != value) - { - backgroundColor = value; - backgroundBrush = backgroundColor.A > 0 ? new SolidBrush(backgroundColor, Widget.Generator) : null; - Invalidate(); - } - } - } - - public void Create() - { - Enabled = true; - Control = new EtoDrawableView { Handler = this }; - } - - public bool CanFocus - { - get { return Control.CanFocus; } - set { Control.CanFocus = value; } - } - - public override void Invalidate() - { - if (!NeedsQueue(Invalidate)) - base.Invalidate(); - } - - public override void Invalidate(Rectangle rect) - { - if (!NeedsQueue(() => Invalidate(rect))) - base.Invalidate(rect); - } - - public void Update(Rectangle rect) - { - var context = NSGraphicsContext.CurrentContext; - if (context != null) - { - var handler = new GraphicsHandler(Control, context, Control.Frame.Height, Control.IsFlipped); - using (var graphics = new Graphics(Widget.Generator, handler)) - { - if (backgroundBrush != null) - graphics.FillRectangle(backgroundBrush, rect); - - var widget = Widget; - if (widget != null) - widget.OnPaint(new PaintEventArgs(graphics, rect)); - } - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/GridColumnHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/GridColumnHandler.cs deleted file mode 100644 index 78a3dd9873..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/GridColumnHandler.cs +++ /dev/null @@ -1,205 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public interface IDataViewHandler - { - bool ShowHeader { get; } - - NSTableView Table { get; } - - object GetItem (int row); - - int RowCount { get; } - - System.Drawing.RectangleF GetVisibleRect (); - - void OnCellFormatting(GridColumn column, object item, int row, NSCell cell); - } - - public interface IDataColumnHandler - { - void Setup (int column); - - NSObject GetObjectValue (object dataItem); - - void SetObjectValue (object dataItem, NSObject val); - - GridColumn Widget { get; } - - IDataViewHandler DataViewHandler { get; } - } - - public class GridColumnHandler : MacObject, IGridColumn, IDataColumnHandler - { - Cell dataCell; - Font font; - - public IDataViewHandler DataViewHandler { get; private set; } - - public int Column { get; private set; } - - public GridColumnHandler () - { - Control = new NSTableColumn (); - Control.ResizingMask = NSTableColumnResizing.None; - Sortable = false; - HeaderText = string.Empty; - Editable = false; - AutoSize = true; - } - - protected override void Initialize () - { - base.Initialize (); - DataCell = new TextBoxCell(Widget.Generator); - } - - public void Loaded (IDataViewHandler handler, int column) - { - Column = column; - DataViewHandler = handler; - } - - public void Resize () - { - var handler = DataViewHandler; - if (AutoSize && handler != null) { - float width = Control.DataCell.CellSize.Width; - var outlineView = handler.Table as NSOutlineView; - if (handler.ShowHeader) - width = Math.Max (Control.HeaderCell.CellSize.Width, width); - - if (dataCell != null) { - /* Auto size based on visible cells only */ - var rect = handler.GetVisibleRect (); - var range = handler.Table.RowsInRect (rect); - - var cellSize = Control.DataCell.CellSize; - var dataCellHandler = ((ICellHandler)dataCell.Handler); - for (int i = range.Location; i < range.Location + range.Length; i++) { - var cellWidth = GetRowWidth (dataCellHandler, i, cellSize) + 4; - if (outlineView != null && Column == 0) - { - cellWidth += (outlineView.LevelForRow(i) + 1) * outlineView.IndentationPerLevel; - } - width = Math.Max (width, cellWidth); - } - } - Control.Width = width; - } - } - - protected virtual float GetRowWidth (ICellHandler cell, int row, System.Drawing.SizeF cellSize) - { - var item = DataViewHandler.GetItem (row); - var val = GetObjectValue (item); - return cell.GetPreferredSize (val, cellSize, row, item); - } - - public string HeaderText { - get { return Control.HeaderCell.StringValue; } - set { Control.HeaderCell.StringValue = value; } - } - - public bool Resizable { - get { - return Control.ResizingMask.HasFlag (NSTableColumnResizing.UserResizingMask); - } - set { - if (value) - Control.ResizingMask |= NSTableColumnResizing.UserResizingMask; - else - Control.ResizingMask &= ~NSTableColumnResizing.UserResizingMask; - } - } - - public bool AutoSize { - get; - set; - } - - public bool Sortable { get; set; } - - public bool Editable { - get { - return Control.Editable; - } - set { - Control.Editable = value; - if (dataCell != null) { - var cellHandler = (ICellHandler)dataCell.Handler; - cellHandler.Editable = value; - } - } - } - - public int Width { - get { return (int)Control.Width; } - set { Control.Width = value; } - } - - public bool Visible { - get { return !Control.Hidden; } - set { Control.Hidden = !value; } - } - - public Cell DataCell { - get { return dataCell; } - set { - dataCell = value; - if (dataCell != null) { - var editable = Editable; - var cellHandler = (ICellHandler)dataCell.Handler; - Control.DataCell = cellHandler.Control; - cellHandler.ColumnHandler = this; - cellHandler.Editable = editable; - } else - Control.DataCell = null; - } - } - - public void Setup (int column) - { - Column = column; - Control.Identifier = new NSString(column.ToString ()); - } - - public NSObject GetObjectValue (object dataItem) - { - return ((ICellHandler)dataCell.Handler).GetObjectValue (dataItem); - } - - public void SetObjectValue (object dataItem, NSObject val) - { - ((ICellHandler)dataCell.Handler).SetObjectValue (dataItem, val); - } - - GridColumn IDataColumnHandler.Widget { - get { return Widget; } - } - - public Font Font - { - get { - if (font == null) - font = new Font (Widget.Generator, new FontHandler (Control.DataCell.Font)); - return font; - } - set { - font = value; - if (font != null) { - var fontHandler = (FontHandler)font.Handler; - Control.DataCell.Font = fontHandler.Control; - } else - Control.DataCell.Font = null; - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/GridHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/GridHandler.cs deleted file mode 100644 index 5d092f7b03..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/GridHandler.cs +++ /dev/null @@ -1,410 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using System.Collections.Generic; -using Eto.Platform.Mac.Forms.Menu; -using System.Linq; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; -using MonoMac.ObjCRuntime; -using sd = System.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public interface IGridHandler - { - Grid Widget { get; } - - NSTableView Table { get; } - } - - class EtoGridScrollView : NSScrollView - { - WeakReference handler; - - public IGridHandler Handler { get { return (IGridHandler)handler.Target; } set { handler = new WeakReference(value); } } - - bool autoSized; - - public override void SetFrameSize(sd.SizeF newSize) - { - base.SetFrameSize(newSize); - if (!autoSized && Handler.Widget.Loaded) - { - var rect = Handler.Table.VisibleRect(); - if (!rect.IsEmpty) - { - foreach (var col in Handler.Widget.Columns) - { - ((GridColumnHandler)col.Handler).Resize(); - } - autoSized = true; - } - } - } - } - - class EtoTableHeaderView : NSTableHeaderView - { - WeakReference handler; - - public IGridHandler Handler { get { return (IGridHandler)handler.Target; } set { handler = new WeakReference(value); } } - - static readonly Selector selConvertPointFromBacking = new Selector("convertPointFromBacking:"); - - public override void MouseDown(NSEvent theEvent) - { - var point = theEvent.LocationInWindow; - if (RespondsToSelector(selConvertPointFromBacking)) - point = ConvertPointFromBacking(point); - else - point = ConvertPointFromBase(point); - var col = GetColumn(point); - if (col >= 0) - { - var column = Handler.Widget.Columns[col]; - if (!column.Sortable) - return; - } - base.MouseDown(theEvent); - } - } - - class MacCellFormatArgs : GridCellFormatEventArgs - { - Font font; - - public ICellHandler CellHandler { get { return Column.DataCell.Handler as ICellHandler; } } - - public NSCell Cell { get; private set; } - - public MacCellFormatArgs(GridColumn column, object item, int row, NSCell cell) - : base(column, item, row) - { - this.Cell = cell; - } - - public override Font Font - { - get - { - return font ?? (font = new Font(CellHandler.Generator, new FontHandler(Cell.Font))); - } - set - { - font = value; - Cell.Font = font != null ? ((FontHandler)font.Handler).Control : null; - } - } - - public override Color BackgroundColor - { - get { return CellHandler.GetBackgroundColor(Cell); } - set { CellHandler.SetBackgroundColor(Cell, value); } - } - - public override Color ForegroundColor - { - get { return CellHandler.GetForegroundColor(Cell); } - set { CellHandler.SetForegroundColor(Cell, value); } - } - } - - public abstract class GridHandler : MacControl, IGrid, IDataViewHandler, IGridHandler - where TControl: NSTableView - where TWidget: Grid - { - ColumnCollection columns; - ContextMenu contextMenu; - - public NSTableView Table - { - get { return Control; } - } - - public NSScrollView ScrollView { get; private set; } - - public override NSView ContainerControl { get { return ScrollView; } } - - protected virtual void PreUpdateColumn(int index) - { - } - - protected virtual void UpdateColumns() - { - } - - protected void UpdateColumnSizes() - { - if (Widget.Loaded) - { - var rect = Table.VisibleRect(); - if (!rect.IsEmpty) - { - foreach (var col in Widget.Columns) - { - ((GridColumnHandler)col.Handler).Resize(); - } - } - } - } - - public GridColumnHandler GetColumn(NSTableColumn tableColumn) - { - var str = tableColumn.Identifier; - if (!string.IsNullOrEmpty(str)) - { - int col; - if (int.TryParse(str, out col)) - { - return GetColumn(col); - } - } - return null; - } - - public GridColumnHandler GetColumn(int column) - { - return Widget.Columns[column].Handler as GridColumnHandler; - //return Widget.Columns.Select (r => r.Handler as GridColumnHandler).First (r => r.Column == column); - } - - class ColumnCollection : EnumerableChangedHandler - { - public GridHandler Handler { get; set; } - - public override void AddItem(GridColumn item) - { - var colhandler = (GridColumnHandler)item.Handler; - Handler.Control.AddColumn(colhandler.Control); - colhandler.Setup(Handler.Control.ColumnCount - 1); - - Handler.UpdateColumns(); - } - - public override void InsertItem(int index, GridColumn item) - { - var outline = Handler.Control; - var columns = new List(outline.TableColumns()); - Handler.PreUpdateColumn(index); - for (int i = index; i < columns.Count; i++) - { - outline.RemoveColumn(columns[i]); - } - var colhandler = (GridColumnHandler)item.Handler; - columns.Insert(index, colhandler.Control); - outline.AddColumn(colhandler.Control); - colhandler.Setup(index); - for (int i = index + 1; i < columns.Count; i++) - { - var col = columns[i]; - var colHandler = Handler.GetColumn(i); - colHandler.Setup(i); - outline.AddColumn(col); - } - Handler.UpdateColumns(); - } - - public override void RemoveItem(int index) - { - var outline = Handler.Control; - var columns = new List(outline.TableColumns()); - Handler.PreUpdateColumn(index); - for (int i = index; i < columns.Count; i++) - { - outline.RemoveColumn(columns[i]); - } - columns.RemoveAt(index); - for (int i = index; i < columns.Count; i++) - { - var col = columns[i]; - var colHandler = Handler.GetColumn(i); - colHandler.Setup(i); - outline.AddColumn(col); - } - Handler.UpdateColumns(); - } - - public override void RemoveAllItems() - { - Handler.PreUpdateColumn(0); - foreach (var col in Handler.Control.TableColumns ()) - Handler.Control.RemoveColumn(col); - Handler.UpdateColumns(); - } - } - - protected GridHandler() - { - ScrollView = new EtoGridScrollView - { - Handler = this, - HasVerticalScroller = true, - HasHorizontalScroller = true, - AutohidesScrollers = true, - BorderType = NSBorderType.BezelBorder, - }; - ScrollView.ContentView.PostsBoundsChangedNotifications = true; - this.AddObserver(NSView.BoundsChangedNotification, HandleScrolled, ScrollView.ContentView); - } - - static void HandleScrolled(ObserverActionEventArgs e) - { - var handler = (GridHandler)e.Handler; - handler.UpdateColumnSizes(); - } - - public override void AttachEvent(string id) - { - switch (id) - { - default: - base.AttachEvent(id); - break; - } - } - - protected override void Initialize() - { - base.Initialize(); - columns = new ColumnCollection { Handler = this }; - columns.Register(Widget.Columns); - - Control.HeaderView = new EtoTableHeaderView { Handler = this }; - ScrollView.DocumentView = Control; - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - - int i = 0; - foreach (var col in Widget.Columns) - { - var colHandler = (GridColumnHandler)col.Handler; - colHandler.Loaded(this, i++); - colHandler.Resize(); - } - } - - public void ResizeAllColumns() - { - foreach (var col in Widget.Columns.Select (r => r.Handler as GridColumnHandler)) - { - col.Resize(); - } - } - - public bool ShowHeader - { - get - { - return Control.HeaderView != null; - } - set - { - if (value && Control.HeaderView == null) - { - Control.HeaderView = new EtoTableHeaderView { Handler = this }; - } - else if (!value && Control.HeaderView != null) - { - Control.HeaderView = null; - } - } - } - - public bool AllowColumnReordering - { - get { return Control.AllowsColumnReordering; } - set { Control.AllowsColumnReordering = value; } - } - - public ContextMenu ContextMenu - { - get { return contextMenu; } - set - { - contextMenu = value; - Control.Menu = contextMenu != null ? ((ContextMenuHandler)contextMenu.Handler).Control : null; - } - } - - public bool AllowMultipleSelection - { - get { return Control.AllowsMultipleSelection; } - set { Control.AllowsMultipleSelection = value; } - } - - public IEnumerable SelectedRows - { - get - { - if (Control.SelectedRows != null && Control.SelectedRows.Count > 0) - return Control.SelectedRows.Select(r => (int)r); - return Enumerable.Empty(); - } - } - - public void SelectAll() - { - Control.SelectAll(Control); - } - - public void SelectRow(int row) - { - Control.SelectRow(row, false); - } - - public void UnselectRow(int row) - { - Control.DeselectRow(row); - } - - public void UnselectAll() - { - Control.DeselectAll(Control); - } - - public int RowHeight - { - get { return (int)Control.RowHeight; } - set { Control.RowHeight = value; } - } - - public abstract object GetItem(int row); - - public virtual int RowCount - { - get { return Control.RowCount; } - } - - Grid IGridHandler.Widget - { - get { return Widget; } - } - - public sd.RectangleF GetVisibleRect() - { - var rect = ScrollView.VisibleRect(); - var loc = ScrollView.ContentView.Bounds.Location; - rect.Offset(loc); - return rect; - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - var width = Widget.Columns.Sum(r => r.Width); - if (width == 0) - width = 100; - var height = RowHeight * 4; - return new Size(width, height); - } - - public void OnCellFormatting(GridColumn column, object item, int row, NSCell cell) - { - Widget.OnCellFormatting(new MacCellFormatArgs(column, item, row, cell)); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/GridViewHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/GridViewHandler.cs deleted file mode 100644 index e1c3f6661b..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/GridViewHandler.cs +++ /dev/null @@ -1,223 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using System.Collections.Generic; -using MonoMac.Foundation; -using Eto.Drawing; -using sd = System.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class GridViewHandler : GridHandler, IGridView - { - CollectionHandler collection; - - public class EtoTableView : NSTableView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public GridViewHandler Handler - { - get { return (GridViewHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - /// - /// The area to the right and below the rows is not filled with the background - /// color. This fixes that. See http://orangejuiceliberationfront.com/themeing-nstableview/ - /// - public override void DrawBackground(sd.RectangleF clipRect) - { - var backgroundColor = Handler.BackgroundColor; - if (backgroundColor != Colors.Transparent) { - backgroundColor.ToNSUI ().Set (); - NSGraphics.RectFill (clipRect); - } else - base.DrawBackground (clipRect); - } - } - - class EtoTableViewDataSource : NSTableViewDataSource - { - WeakReference handler; - public GridViewHandler Handler { get { return (GridViewHandler)(handler != null ? handler.Target : null); } set { handler = new WeakReference(value); } } - - public override int GetRowCount (NSTableView tableView) - { - return (Handler.collection != null && Handler.collection.Collection != null) ? Handler.collection.Collection.Count : 0; - } - - public override NSObject GetObjectValue (NSTableView tableView, NSTableColumn tableColumn, int row) - { - var item = Handler.collection.Collection [row]; - var colHandler = Handler.GetColumn (tableColumn); - return colHandler == null ? null : colHandler.GetObjectValue(item); - } - - public override void SetObjectValue (NSTableView tableView, NSObject theObject, NSTableColumn tableColumn, int row) - { - var item = Handler.collection.Collection [row]; - var colHandler = Handler.GetColumn (tableColumn); - if (colHandler != null) { - colHandler.SetObjectValue (item, theObject); - - Handler.Widget.OnCellEdited (new GridViewCellArgs(colHandler.Widget, row, colHandler.Column, item)); - } - } - } - - class EtoTableDelegate : NSTableViewDelegate - { - WeakReference handler; - public GridViewHandler Handler { get { return (GridViewHandler)(handler != null ? handler.Target : null); } set { handler = new WeakReference(value); } } - - public override bool ShouldEditTableColumn (NSTableView tableView, NSTableColumn tableColumn, int row) - { - var colHandler = Handler.GetColumn (tableColumn); - var item = Handler.collection.Collection [row]; - var args = new GridViewCellArgs (colHandler.Widget, row, colHandler.Column, item); - Handler.Widget.OnCellEditing (args); - return true; - } - - public override void SelectionDidChange (NSNotification notification) - { - Handler.Widget.OnSelectionChanged (EventArgs.Empty); - - // Trigger CellClick - var tableView = Handler.Control; - var row = tableView.SelectedRow; - var col = tableView.SelectedColumn; - if (row >= 0) // && col >= 0) TODO: Fix the column - Handler.Widget.OnCellClick ( - new GridViewCellArgs (null, // TODO: col is always -1 currently, so this does not work: Handler.GetColumn (tableView.ClickedColumn).Widget, - row, col, Handler.collection.Collection [row])); - } - - public override void DidClickTableColumn (NSTableView tableView, NSTableColumn tableColumn) - { - var colHandler = Handler.GetColumn (tableColumn); - Handler.Widget.OnColumnHeaderClick (new GridColumnEventArgs (colHandler.Widget)); - } - - public override void WillDisplayCell (NSTableView tableView, NSObject cell, NSTableColumn tableColumn, int row) - { - var colHandler = Handler.GetColumn (tableColumn); - var item = Handler.GetItem (row); - Handler.OnCellFormatting(colHandler.Widget, item, row, cell as NSCell); - - } - } - - public bool ShowCellBorders - { - get { return Control.IntercellSpacing.Width > 0 || Control.IntercellSpacing.Height > 0; } - set { Control.IntercellSpacing = value ? new sd.SizeF(1, 1) : sd.SizeF.Empty; } - } - - public override void AttachEvent (string id) - { - switch (id) { - case Grid.CellEditingEvent: - // handled by delegate - /* following should work, but internal delegate to trigger event does not work - table.ShouldEditTableColumn = (tableView, tableColumn, row) => { - var id = tableColumn.Identifier as EtoGridColumnIdentifier; - var item = store.GetItem (row); - var args = new GridViewCellArgs(id.Handler.Widget, row, id.Handler.Column, item); - this.Widget.OnBeginCellEdit (args); - return true; - };*/ - break; - case Grid.CellEditedEvent: - // handled after object value is set - break; - case Grid.SelectionChangedEvent: - /* handled by delegate, for now - table.SelectionDidChange += delegate { - Widget.OnSelectionChanged (EventArgs.Empty); - };*/ - break; - case Grid.ColumnHeaderClickEvent: - /* - table.DidClickTableColumn += delegate(object sender, NSTableViewTableEventArgs e) { - var column = Handler.Widget.Columns.First (r => object.ReferenceEquals (r.ControlObject, tableColumn)); - Handler.Widget.OnHeaderClick (new GridColumnEventArgs (column)); - }; - */ - break; - case Grid.CellFormattingEvent: - break; - default: - base.AttachEvent (id); - break; - } - } - - protected override void Initialize () - { - Control = new EtoTableView { - Handler = this, - FocusRingType = NSFocusRingType.None, - DataSource = new EtoTableViewDataSource { Handler = this }, - Delegate = new EtoTableDelegate { Handler = this }, - ColumnAutoresizingStyle = NSTableViewColumnAutoresizingStyle.None - }; - - base.Initialize (); - } - - class CollectionHandler : DataStoreChangedHandler - { - public GridViewHandler Handler { get; set; } - - public override int IndexOf (object item) - { - return -1; // not needed - } - - public override void AddRange (IEnumerable items) - { - Handler.Control.ReloadData (); - } - - public override void AddItem (object item) - { - Handler.Control.ReloadData (); - } - - public override void InsertItem (int index, object item) - { - Handler.Control.ReloadData (); - } - - public override void RemoveItem (int index) - { - Handler.Control.ReloadData (); - } - - public override void RemoveAllItems () - { - Handler.Control.ReloadData (); - } - } - - public IDataStore DataStore { - get { return collection != null ? collection.Collection : null; } - set { - if (collection != null) - collection.Unregister (); - collection = new CollectionHandler{ Handler = this }; - collection.Register (value); - if (Widget.Loaded) - ResizeAllColumns (); - } - } - - public override object GetItem (int row) - { - return collection.Collection [row]; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/GroupBoxHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/GroupBoxHandler.cs deleted file mode 100644 index 4d94bc5914..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/GroupBoxHandler.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using SD = System.Drawing; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class GroupBoxHandler : MacPanel, IGroupBox - { - Font font; - - public class EtoBox : NSBox, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public GroupBoxHandler () - { - Control = new EtoBox { Handler = this }; - Control.Title = string.Empty; - Control.ContentView = new NSView (); - Enabled = true; - } - - public override NSView ContainerControl - { - get { return Control; } - } - - public override NSView ContentControl - { - get { return (NSView)Control.ContentView; } - } - - public override bool Enabled { get; set; } - - public override Size ClientSize { - get { - var view = Control.ContentView as NSView; - return view.Frame.Size.ToEtoSize (); - } - set { - Control.SetFrameFromContentFrame (new System.Drawing.RectangleF (0, 0, value.Width, value.Height)); - } - } - - public Font Font - { - get { - return font ?? (font = new Font (Widget.Generator, new FontHandler (Control.TitleFont))); - } - set { - font = value; - Control.TitleFont = font == null ? null : ((FontHandler)font.Handler).Control; - LayoutIfNeeded (); - } - } - - public virtual string Text { - get { return Control.Title; } - set { Control.Title = value; } - } - - public override SizeF GetPreferredSize (SizeF availableSize) - { - return base.GetPreferredSize (availableSize) + new SizeF (14, Control.TitleFont.LineHeight () + 9); - } - - public override void SetContentSize (SD.SizeF contentSize) - { - Control.SetFrameFromContentFrame (new System.Drawing.RectangleF (0, 0, contentSize.Width, contentSize.Height)); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/ImageViewHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/ImageViewHandler.cs deleted file mode 100644 index dd936cdd50..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/ImageViewHandler.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class ImageViewHandler : MacControl, IImageView - { - Image image; - - public class EtoImageView : NSImageView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public ImageViewHandler () - { - Control = new EtoImageView { Handler = this, ImageScaling = NSImageScale.ProportionallyUpOrDown }; - } - - protected override SizeF GetNaturalSize (SizeF availableSize) - { - return image == null ? Size.Empty : image.Size; - } - - public Image Image { - get { - return image; - } - set { - image = value; - Control.Image = image == null ? null : ((IImageSource)value.Handler).GetImage(); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/LabelHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/LabelHandler.cs deleted file mode 100644 index 823754ec01..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/LabelHandler.cs +++ /dev/null @@ -1,287 +0,0 @@ -using System; -using sd = System.Drawing; -using Eto.Forms; -using Eto.Drawing; -using MonoMac.AppKit; -using Eto.Platform.Mac.Drawing; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using System.Text.RegularExpressions; -using System.Linq; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class LabelHandler : MacView, ILabel - { - static readonly bool supportsSingleLine; - Font font; - readonly NSMutableAttributedString str; - readonly NSMutableParagraphStyle paragraphStyle; - NSColor textColor; - int underlineIndex; - SizeF availableSizeCached; - const NSStringDrawingOptions DrawingOptions = NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin; - - static LabelHandler() - { - supportsSingleLine = ObjCExtensions.ClassInstancesRespondToSelector(Class.GetHandle("NSTextFieldCell"), Selector.GetHandle("setUsesSingleLineMode:")); - } - - public override NSView ContainerControl { get { return Control; } } - - static readonly Selector selAlignmentRectInsets = new Selector("alignmentRectInsets"); - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - if (string.IsNullOrEmpty(Text)) - return Size.Empty; - if (NaturalSize == null || availableSizeCached != availableSize) - { - var insets = Control.RespondsToSelector(selAlignmentRectInsets) ? Control.AlignmentRectInsets.ToEtoSize() : new Size(4, 2); - var size = Control.Cell.CellSizeForBounds(new RectangleF(availableSize).ToSD()).ToEto(); - - NaturalSize = Size.Round(size + insets); - availableSizeCached = availableSize; - } - - return NaturalSize.Value; - } - - public class MyTextFieldCell : NSTextFieldCell - { - public VerticalAlign VerticalAlign { get; set; } - - public override sd.RectangleF DrawingRectForBounds(sd.RectangleF theRect) - { - var rect = base.DrawingRectForBounds(theRect); - var titleSize = CellSizeForBounds(theRect); - - switch (VerticalAlign) - { - case VerticalAlign.Middle: - rect.Y = theRect.Y + (theRect.Height - titleSize.Height) / 2.0F; - break; - case VerticalAlign.Top: - // do nothing! - break; - case VerticalAlign.Bottom: - rect.Y = theRect.Y + (theRect.Height - titleSize.Height); - break; - } - return rect; - } - } - - public class EtoLabel : NSTextField, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public LabelHandler() - { - Enabled = true; - paragraphStyle = new NSMutableParagraphStyle(); - str = new NSMutableAttributedString(); - textColor = NSColor.Text; - underlineIndex = -1; - Control = new EtoLabel - { - Handler = this, - Cell = new MyTextFieldCell(), - DrawsBackground = false, - Bordered = false, - Bezeled = false, - Editable = false, - Selectable = false, - Alignment = NSTextAlignment.Left, - }; - if (supportsSingleLine) - Control.Cell.UsesSingleLineMode = false; - paragraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping; - } - - public Color TextColor - { - get { return textColor.ToEto(); } - set - { - textColor = value.ToNSUI(); - SetAttributes(); - } - } - - public WrapMode Wrap - { - get - { - if (supportsSingleLine && Control.Cell.UsesSingleLineMode) - return WrapMode.None; - if (paragraphStyle.LineBreakMode == NSLineBreakMode.ByWordWrapping) - return WrapMode.Word; - return WrapMode.Character; - } - set - { - switch (value) - { - case WrapMode.None: - if (supportsSingleLine) - Control.Cell.UsesSingleLineMode = true; - paragraphStyle.LineBreakMode = NSLineBreakMode.Clipping; - break; - case WrapMode.Word: - if (supportsSingleLine) - Control.Cell.UsesSingleLineMode = false; - paragraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping; - break; - case WrapMode.Character: - if (supportsSingleLine) - Control.Cell.UsesSingleLineMode = false; - paragraphStyle.LineBreakMode = NSLineBreakMode.CharWrapping; - break; - default: - throw new NotSupportedException(); - } - SetAttributes(); - } - } - - public override bool Enabled { get; set; } - - public string Text - { - get { return str.Value; } - set - { - var oldSize = GetPreferredSize(Size.MaxValue); - if (string.IsNullOrEmpty(value)) - { - str.SetString(new NSMutableAttributedString()); - } - else - { - var match = Regex.Match(value, @"(?<=([^&](?:[&]{2})*)|^)[&](?![&])"); - if (match.Success) - { - var val = value.Remove(match.Index, match.Length).Replace("&&", "&"); - - var matches = Regex.Matches(value, @"[&][&]"); - var prefixCount = matches.Cast().Count(r => r.Index < match.Index); - - str.SetString(new NSAttributedString(val)); - underlineIndex = match.Index - prefixCount; - } - else - { - str.SetString(new NSAttributedString(value.Replace("&&", "&"))); - underlineIndex = -1; - } - } - SetAttributes(); - LayoutIfNeeded(oldSize); - } - } - - public HorizontalAlign HorizontalAlign - { - get - { - switch (paragraphStyle.Alignment) - { - case NSTextAlignment.Center: - return HorizontalAlign.Center; - case NSTextAlignment.Right: - return HorizontalAlign.Right; - default: - return HorizontalAlign.Left; - } - } - set - { - switch (value) - { - case HorizontalAlign.Center: - paragraphStyle.Alignment = NSTextAlignment.Center; - break; - case HorizontalAlign.Right: - paragraphStyle.Alignment = NSTextAlignment.Right; - break; - case HorizontalAlign.Left: - paragraphStyle.Alignment = NSTextAlignment.Left; - break; - } - SetAttributes(); - } - } - - public Font Font - { - get - { - if (font == null) - font = new Font(Widget.Generator, new FontHandler(Control.Font)); - return font; - } - set - { - var oldSize = GetPreferredSize(Size.MaxValue); - font = value; - SetAttributes(); - LayoutIfNeeded(oldSize); - } - } - - public VerticalAlign VerticalAlign - { - get { return ((MyTextFieldCell)Control.Cell).VerticalAlign; } - set { ((MyTextFieldCell)Control.Cell).VerticalAlign = value; } - } - - void SetAttributes(bool force = false) - { - if (Widget.Loaded || force) - { - if (str.Length > 0) - { - var range = new NSRange(0, str.Length); - var attr = new NSMutableDictionary(); - font.Apply(attr); - attr.Add(NSAttributedString.ParagraphStyleAttributeName, paragraphStyle); - attr.Add(NSAttributedString.ForegroundColorAttributeName, textColor); - str.SetAttributes(attr, range); - if (underlineIndex >= 0) - { - var num = (NSNumber)str.GetAttribute(NSAttributedString.UnderlineStyleAttributeName, underlineIndex, out range); - var newStyle = (num != null && (NSUnderlineStyle)num.IntValue == NSUnderlineStyle.Single) ? NSUnderlineStyle.Double : NSUnderlineStyle.Single; - str.AddAttribute(NSAttributedString.UnderlineStyleAttributeName, new NSNumber((int)newStyle), new NSRange(underlineIndex, 1)); - } - } - Control.AttributedStringValue = str; - } - } - - public override void OnLoad(EventArgs e) - { - base.OnLoad(e); - SetAttributes(true); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - break; - default: - base.AttachEvent(id); - break; - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/ListBoxHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/ListBoxHandler.cs deleted file mode 100644 index 964e16b172..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/ListBoxHandler.cs +++ /dev/null @@ -1,238 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; -using System.Collections.Generic; -using Eto.Platform.Mac.Forms.Controls; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class EtoScrollView : NSScrollView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler { get { return WeakHandler.Target; } set { WeakHandler = new WeakReference(value); } } - } - - public class ListBoxHandler : MacControl, IListBox - { - Font font; - readonly NSScrollView scroll; - readonly CollectionHandler collection; - readonly MacImageListItemCell cell; - - public override NSView ContainerControl - { - get { return scroll; } - } - - public NSScrollView Scroll - { - get { return scroll; } - } - - class DataSource : NSTableViewDataSource - { - WeakReference handler; - public ListBoxHandler Handler { get { return (ListBoxHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, int row) - { - return new MacImageData(Handler.collection.Collection[row]); - } - - public override int GetRowCount(NSTableView tableView) - { - return Handler.collection.Collection == null ? 0 : Handler.collection.Collection.Count; - } - } - - class Delegate : NSTableViewDelegate - { - WeakReference handler; - public ListBoxHandler Handler { get { return (ListBoxHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override bool ShouldSelectRow(NSTableView tableView, int row) - { - return true; - } - - public override void SelectionDidChange(NSNotification notification) - { - Handler.Widget.OnSelectedIndexChanged(EventArgs.Empty); - } - } - - class EtoListBoxTableView : NSTableView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public ListBoxHandler Handler - { - get { return (ListBoxHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public override NSMenu MenuForEvent(NSEvent theEvent) - { - if (Handler.ContextMenu != null) - return Handler.ContextMenu.ControlObject as NSMenu; - return base.MenuForEvent(theEvent); - } - } - - public override void PostKeyDown(KeyEventArgs e) - { - if (e.Key == Keys.Enter) - { - Widget.OnActivated(EventArgs.Empty); - e.Handled = true; - } - } - - public ContextMenu ContextMenu - { - get; - set; - } - - public override bool Enabled - { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - - public ListBoxHandler() - { - collection = new CollectionHandler { Handler = this }; - Control = new EtoListBoxTableView { Handler = this }; - - var col = new NSTableColumn(); - col.ResizingMask = NSTableColumnResizing.Autoresizing; - col.Editable = false; - cell = new MacImageListItemCell(); - cell.Wraps = false; - col.DataCell = cell; - Control.AddColumn(col); - - Control.DataSource = new DataSource { Handler = this }; - Control.HeaderView = null; - Control.DoubleClick += HandleDoubleClick; - Control.Delegate = new Delegate { Handler = this }; - - scroll = new EtoScrollView { Handler = this }; - scroll.AutoresizesSubviews = true; - scroll.DocumentView = Control; - scroll.HasVerticalScroller = true; - scroll.HasHorizontalScroller = true; - scroll.AutohidesScrollers = true; - scroll.BorderType = NSBorderType.BezelBorder; - } - - protected override void Initialize() - { - base.Initialize(); - HandleEvent(Eto.Forms.Control.KeyDownEvent); - } - - static void HandleDoubleClick (object sender, EventArgs e) - { - var handler = GetHandler(sender) as ListBoxHandler; - if (handler != null) - handler.Widget.OnActivated(EventArgs.Empty); - } - - public override Font Font - { - get - { - if (font == null) - font = new Font(Widget.Generator, new FontHandler(Control.Font)); - return font; - } - set - { - font = value; - if (font != null) - { - var fontHandler = (FontHandler)font.Handler; - cell.Font = fontHandler.Control; - Control.RowHeight = fontHandler.LineHeight; - } - else - cell.Font = NSFont.SystemFontOfSize(NSFont.SystemFontSize); - } - } - - class CollectionHandler : DataStoreChangedHandler - { - public ListBoxHandler Handler { get; set; } - - public override int IndexOf(IListItem item) - { - return -1; // not needed - } - - public override void AddRange(IEnumerable items) - { - Handler.Control.ReloadData(); - } - - public override void AddItem(IListItem item) - { - Handler.Control.ReloadData(); - } - - public override void InsertItem(int index, IListItem item) - { - Handler.Control.ReloadData(); - } - - public override void RemoveItem(int index) - { - Handler.Control.ReloadData(); - } - - public override void RemoveAllItems() - { - Handler.Control.ReloadData(); - } - } - - public IListStore DataStore - { - get { return collection.Collection; } - set - { - if (collection.Collection != null) - collection.Unregister(); - collection.Register(value); - } - } - - public int SelectedIndex - { - get { return Control.SelectedRow; } - set - { - if (value == -1) - Control.DeselectAll(Control); - else - { - Control.SelectRow(value, false); - Control.ScrollRowToVisible(value); - } - } - } - - public override void Focus() - { - if (Control.Window != null) - Control.Window.MakeFirstResponder(Control); - else - base.Focus(); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/MacButton.cs b/Source/Eto.Platform.Mac/Forms/Controls/MacButton.cs deleted file mode 100644 index a092f9449b..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/MacButton.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public abstract class MacButton : MacControl, ITextControl - where TControl: NSButton - where TWidget: Control - { - - public virtual string Text { - get { - return Control.Title; - } - set { - Control.SetTitleWithMnemonic(value); - LayoutIfNeeded(); - } - } - - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/MacControl.cs b/Source/Eto.Platform.Mac/Forms/Controls/MacControl.cs deleted file mode 100644 index 8576b6c588..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/MacControl.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Eto.Forms; -using MonoMac.AppKit; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; -using sd = System.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public abstract class MacControl : MacView - where TControl: NSControl - where TWidget: Control - { - Font font; - - public override NSView ContainerControl { get { return Control; } } - - public override bool Enabled - { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - - public virtual Font Font - { - get - { - if (font == null) - font = new Font(Widget.Generator, new FontHandler(Control.Font)); - return font; - } - set - { - font = value; - Control.Font = font.ToNSFont(); - Control.AttributedStringValue = font.AttributedString(Control.AttributedStringValue); - LayoutIfNeeded(); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/MacEventView.cs b/Source/Eto.Platform.Mac/Forms/Controls/MacEventView.cs deleted file mode 100644 index 9d1414b5b7..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/MacEventView.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using SD = System.Drawing; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; -using MonoMac.CoreImage; -using Eto.Drawing; -using MonoMac.ObjCRuntime; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class MacEventView : NSView, IMacControl - { - static readonly NSString CIOutputImage = new NSString("outputImage"); - static readonly Selector selConvertSizeToBacking = new Selector("convertSizeToBacking:"); - - public static void Colourize(NSView control, Color color, Action drawAction) - { - var size = control.Frame.Size; - if (size.Width <= 0 || size.Height <= 0) - return; - var image = new NSImage(size); - - image.LockFocusFlipped(!control.IsFlipped); - drawAction(); - image.UnlockFocus(); - - var ciImage = CIImage.FromCGImage(image.CGImage); - - SD.SizeF realSize; - if (control.RespondsToSelector(selConvertSizeToBacking)) - realSize = control.ConvertSizeToBacking(size); - else - realSize = control.ConvertSizeToBase(size); - - var filter2 = new CIColorControls(); - filter2.SetDefaults(); - filter2.Image = ciImage; - filter2.Saturation = 0.0f; - ciImage = (CIImage)filter2.ValueForKey(CIOutputImage); - - var filter3 = new CIColorMatrix(); - filter3.SetDefaults(); - filter3.Image = ciImage; - filter3.RVector = new CIVector(0, color.R, 0); - filter3.GVector = new CIVector(color.G, 0, 0); - filter3.BVector = new CIVector(0, 0, color.B); - ciImage = (CIImage)filter3.ValueForKey(CIOutputImage); - - // create separate context so we can force using the software renderer, which is more than fast enough for this - var ciContext = CIContext.FromContext(NSGraphicsContext.CurrentContext.GraphicsPort, new CIContextOptions { UseSoftwareRenderer = true }); - ciContext.DrawImage(ciImage, new SD.RectangleF(SD.PointF.Empty, size), new SD.RectangleF(SD.PointF.Empty, realSize)); - } - - public WeakReference WeakHandler { get; set; } - - public IMacViewHandler Handler - { - get { return (IMacViewHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public Control Widget - { - get { return Handler == null ? null : Handler.Widget; } - } - - public static bool KeyDown(Control control, NSEvent theEvent) - { - if (control != null) - { - var kpea = theEvent.ToEtoKeyEventArgs(); - control.OnKeyDown(kpea); - if (!kpea.Handled) - { - var handler = control.Handler as IMacViewHandler; - if (handler != null) - handler.PostKeyDown(kpea); - } - - return kpea.Handled; - } - return false; - } - - public static bool KeyUp(Control control, NSEvent theEvent) - { - if (control != null) - { - var kpea = theEvent.ToEtoKeyEventArgs(); - control.OnKeyUp(kpea); - return kpea.Handled; - } - return false; - } - - public override void ResetCursorRects() - { - var cursor = Handler.Cursor; - if (cursor != null) - { - AddCursorRect(new SD.RectangleF(SD.PointF.Empty, Frame.Size), cursor.ControlObject as NSCursor); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/MacImageAndTextCell.cs b/Source/Eto.Platform.Mac/Forms/Controls/MacImageAndTextCell.cs deleted file mode 100644 index 28376fd8ce..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/MacImageAndTextCell.cs +++ /dev/null @@ -1,209 +0,0 @@ -using System; -using MonoMac.AppKit; -using SD = System.Drawing; -using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using Eto.Platform.Mac.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class MacImageData : NSObject, ICloneable - { - public MacImageData () - { - } - - public MacImageData (IListItem item) - { - SetItem (item); - } - - public MacImageData (IntPtr handle) - : base(handle) - { - } - - public MacImageData (MacImageData value) - { - this.Text = value.Text; - this.Image = value.Image; - } - - public override string Description { - get { return (string)Text ?? string.Empty; } - } - - public NSImage Image { get; set; } - - public NSString Text { get; set; } - - - public void SetItem (IListItem value) - { - var imgitem = value as IImageListItem; - if (imgitem != null && imgitem.Image != null) - Image = ((IImageSource)imgitem.Image.Handler).GetImage(); - Text = (NSString)value.Text; - } - - [Export("copyWithZone:")] - public virtual NSObject CopyWithZone (IntPtr zone) - { - var clone = (MacImageData)Clone(); - clone.Retain(); - return clone; - } - - #region ICloneable implementation - - public virtual object Clone () - { - return new MacImageData (this); - } - - #endregion - } - - public class MacImageListItemCell : NSTextFieldCell - { - public const int ImagePadding = 2; - NSShadow textShadow; - NSShadow textHighlightShadow; - NSColor groupColor = NSColor.FromCalibratedRgba (0x6F / (float)0xFF, 0x7E / (float)0xFF, 0x8B / (float)0xFF, 1.0F); - //light shade: NSColor.FromCalibratedRgba (0x82 / (float)0xFF, 0x90 / (float)0xFF, 0x9D / (float)0xFF, 1.0F); - - static readonly IntPtr selDrawInRectFromRectOperationFractionRespectFlippedHints = Selector.GetHandle ("drawInRect:fromRect:operation:fraction:respectFlipped:hints:"); - - - public MacImageListItemCell () - { - } - - public NSColor GroupColor - { - get { return groupColor; } - set { groupColor = value; } - } - - public bool UseTextShadow - { - get; set; - } - - public void SetGroupItem (bool isGroupItem, NSTableView tableView, float? groupSize = null, float? normalSize = null) - { - if (isGroupItem) - Font = NSFont.BoldSystemFontOfSize(groupSize ?? NSFont.SystemFontSize); - else if (Highlighted) - Font = NSFont.BoldSystemFontOfSize (normalSize ?? NSFont.SystemFontSize); - else - Font = NSFont.SystemFontOfSize (normalSize ?? NSFont.SystemFontSize); - - if (Highlighted) - TextColor = NSColor.Highlight; - else if (!tableView.Window.IsKeyWindow) - TextColor = NSColor.DisabledControlText; - else if (isGroupItem) - TextColor = GroupColor; - else - TextColor = NSColor.ControlText; - - } - - public NSShadow TextShadow - { - get { - if (textShadow == null) { - textShadow = new NSShadow(); - textShadow.ShadowColor = NSColor.FromDeviceWhite (1F, 0.5F); - textShadow.ShadowOffset = new SD.SizeF(0F, -1.0F); - textShadow.ShadowBlurRadius = 0F; - } - return textShadow; - } - set { textShadow = value; } - } - - public NSShadow TextHighlightShadow - { - get { - if (textHighlightShadow == null) { - textHighlightShadow = new NSShadow(); - textHighlightShadow.ShadowColor = NSColor.FromDeviceWhite (0F, 0.5F); - textHighlightShadow.ShadowOffset = new SD.SizeF(0F, -1.0F); - textHighlightShadow.ShadowBlurRadius = 2F; - } - return textHighlightShadow; - } - set { textShadow = value; } - } - - public MacImageListItemCell (IntPtr handle) - : base(handle) - { - } - - public override SD.SizeF CellSizeForBounds (SD.RectangleF bounds) - { - var size = base.CellSizeForBounds (bounds); - var data = ObjectValue as MacImageData; - if (data != null && data.Image != null) { - var imageSize = data.Image.Size; - var newHeight = Math.Min (imageSize.Height, size.Height); - var newWidth = imageSize.Width * newHeight / imageSize.Height; - size.Width += newWidth + ImagePadding; - } - size.Width = Math.Min (size.Width, bounds.Width); - return size; - } - - public override void DrawInteriorWithFrame (SD.RectangleF cellFrame, NSView inView) - { - var data = ObjectValue as MacImageData; - if (data != null) { - - if (data.Image != null) { - var imageSize = data.Image.Size; - if (imageSize.Width > 0 && imageSize.Height > 0) { - var newHeight = Math.Min (imageSize.Height, cellFrame.Height); - var newWidth = imageSize.Width * newHeight / imageSize.Height; - - var imageRect = new SD.RectangleF (cellFrame.X, cellFrame.Y, newWidth, newHeight); - imageRect.Y += (cellFrame.Height - newHeight) / 2; - - if (data.Image.RespondsToSelector (new Selector (selDrawInRectFromRectOperationFractionRespectFlippedHints))) - // 10.6+ - data.Image.Draw (imageRect, new SD.RectangleF (SD.PointF.Empty, data.Image.Size), NSCompositingOperation.SourceOver, 1, true, null); - else { - // 10.5- - #pragma warning disable 618 - data.Image.Flipped = ControlView.IsFlipped; - #pragma warning restore 618 - data.Image.Draw (imageRect, new SD.RectangleF (SD.PointF.Empty, data.Image.Size), NSCompositingOperation.SourceOver, 1); - } - cellFrame.Width -= newWidth + ImagePadding; - cellFrame.X += newWidth + ImagePadding; - } - } - } - - SD.SizeF titleSize = AttributedStringValue.Size; - - // test to see if the text height is bigger then the cell, if it is, - // don't try to center it or it will be pushed up out of the cell! - if (titleSize.Height < cellFrame.Size.Height) { - cellFrame.Y = cellFrame.Y + (cellFrame.Size.Height - titleSize.Height) / 2; - } - - if (UseTextShadow) { - var str = new NSMutableAttributedString(StringValue); - str.AddAttribute (NSAttributedString.ShadowAttributeName, Highlighted ? TextHighlightShadow : TextShadow, new NSRange(0, str.Length)); - AttributedStringValue = str; - } - - base.DrawInteriorWithFrame (cellFrame, inView); - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/MacText.cs b/Source/Eto.Platform.Mac/Forms/Controls/MacText.cs deleted file mode 100644 index 438c836106..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/MacText.cs +++ /dev/null @@ -1,25 +0,0 @@ -using MonoMac.AppKit; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public abstract class MacText : MacControl, ITextControl - where TControl: NSTextField - where TWidget: TextControl - { - public override Color BackgroundColor - { - get { return Control.BackgroundColor.ToEto(); } - set { Control.BackgroundColor = value.ToNSUI(); } - } - - public virtual string Text - { - get { return Control.AttributedStringValue.Value; } - set { Control.AttributedStringValue = Font.AttributedString(value ?? string.Empty, Control.AttributedStringValue); } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/NumericUpDownHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/NumericUpDownHandler.cs deleted file mode 100644 index df023e4f07..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/NumericUpDownHandler.cs +++ /dev/null @@ -1,231 +0,0 @@ -using System; -using Eto.Forms; -using SD = System.Drawing; -using MonoMac.AppKit; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; -using MonoMac.Foundation; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class NumericUpDownHandler : MacView, INumericUpDown - { - readonly NSTextField text; - readonly NSStepper stepper; - Font font; - Size? naturalSize; - - public override NSView ContainerControl { get { return Control; } } - - public class EtoTextField : NSTextField, IMacControl - { - public WeakReference WeakHandler { get; set; } - } - - class EtoNumericUpDownView : MacEventView - { - public override void SetFrameSize(System.Drawing.SizeF newSize) - { - base.SetFrameSize(newSize); - var views = Subviews; - var text = views[0]; - var splitter = views[1]; - var offset = (newSize.Height - text.Frame.Height) / 2; - text.SetFrameOrigin(new SD.PointF(0, offset)); - text.SetFrameSize(new SD.SizeF(newSize.Width - splitter.Frame.Width, text.Frame.Height)); - offset = (newSize.Height - splitter.Frame.Height) / 2; - splitter.SetFrameOrigin(new SD.PointF(newSize.Width - splitter.Frame.Width, offset)); - } - } - - class EtoStepper : NSStepper - { - public override bool AcceptsFirstResponder() - { - return false; - } - } - - public override object EventObject - { - get { return text; } - } - - public NumericUpDownHandler() - { - this.Control = new EtoNumericUpDownView - { - Handler = this, - AutoresizesSubviews = false - }; - text = new EtoTextField - { - WeakHandler = new WeakReference(this), - Bezeled = true, - Editable = true - }; - text.Changed += HandleTextChanged; - - stepper = new EtoStepper(); - stepper.Activated += HandleStepperActivated; - MinValue = 0; - MaxValue = 100; - Value = 0; - Control.AddSubview(text); - Control.AddSubview(stepper); - } - - static void HandleStepperActivated(object sender, EventArgs e) - { - var handler = GetHandler(((NSView)sender).Superview) as NumericUpDownHandler; - if (handler != null) - { - var val = handler.stepper.DoubleValue; - if (Math.Abs(val) < 1E-10) - { - handler.text.IntValue = 0; - } - else - { - handler.text.DoubleValue = handler.stepper.DoubleValue; - } - handler.Widget.OnValueChanged(EventArgs.Empty); - } - } - - static void HandleTextChanged(object sender, EventArgs e) - { - var handler = GetHandler(((NSView)((NSNotification)sender).Object).Superview) as NumericUpDownHandler; - if (handler != null) - { - handler.stepper.DoubleValue = handler.text.DoubleValue; - handler.Widget.OnValueChanged(EventArgs.Empty); - } - } - - protected override void Initialize() - { - base.Initialize(); - var size = GetNaturalSize(Size.MaxValue); - Control.Frame = new System.Drawing.RectangleF(0, 0, size.Width, size.Height); - HandleEvent(Eto.Forms.Control.KeyDownEvent); - } - - public override void PostKeyDown(KeyEventArgs e) - { - base.PostKeyDown(e); - if (e.KeyData == Keys.Down) - { - var val = Value; - var newval = Math.Max(val - 1, MinValue); - if (newval < val) - { - Value = newval; - Widget.OnValueChanged(EventArgs.Empty); - } - e.Handled = true; - } - else if (e.KeyData == Keys.Up) - { - var val = Value; - var newval = Math.Min(val + 1, MaxValue); - if (newval > val) - { - Value = newval; - Widget.OnValueChanged(EventArgs.Empty); - } - e.Handled = true; - } - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - if (naturalSize == null) - { - text.SizeToFit(); - stepper.SizeToFit(); - var naturalHeight = Math.Max(text.Frame.Height, stepper.Frame.Height); - naturalSize = new Size(80, (int)naturalHeight); - } - return naturalSize.Value; - } - - public bool ReadOnly - { - get { return text.Enabled; } - set - { - text.Enabled = value; - stepper.Enabled = value; - } - } - - public double Value - { - get { return text.DoubleValue; } - set - { - if (Math.Abs(value) < 1E-10) - { - stepper.IntValue = text.IntValue = 0; - } - else - { - stepper.DoubleValue = text.DoubleValue = value; - } - } - } - - public double MinValue - { - get - { - return stepper.MinValue; - } - set - { - stepper.MinValue = value; - } - } - - public double MaxValue - { - get - { - return stepper.MaxValue; - } - set - { - stepper.MaxValue = value; - } - } - - public override bool Enabled - { - get - { - return stepper.Enabled; - } - set - { - stepper.Enabled = value; - text.Enabled = value; - } - } - - public Font Font - { - get - { - return font ?? (font = new Font(Widget.Generator, new FontHandler(text.Font))); - } - set - { - font = value; - text.Font = font == null ? null : font.ControlObject as NSFont; - text.SizeToFit(); - LayoutIfNeeded(); - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/PanelHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/PanelHandler.cs deleted file mode 100644 index b87f0b0ba6..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/PanelHandler.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class PanelHandler : MacPanel, IPanel - { - public PanelHandler() - { - Control = new MacEventView{ Handler = this }; - } - - public override NSView ContainerControl { get { return Control; } } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/PasswordBoxHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/PasswordBoxHandler.cs deleted file mode 100644 index 5d6d36bc7a..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/PasswordBoxHandler.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using Eto.Platform.Mac.Forms.Controls; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class PasswordBoxHandler : MacText, IPasswordBox, ITextBoxWithMaxLength - { - class EtoTextField : NSSecureTextField, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public PasswordBoxHandler Handler - { - get { return (PasswordBoxHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public override bool HasFocus - { - get - { - if (Widget.ParentWindow == null) - return false; - return ((IMacWindow)Widget.ParentWindow.Handler).FieldEditorObject == Control; - } - } - - public override NSTextField CreateControl() - { - return new EtoTextField - { - Handler = this, - Bezeled = true, - Editable = true, - Selectable = true, - Formatter = new EtoFormatter { Handler = this } - }; - } - - protected override void Initialize() - { - base.Initialize(); - Control.Cell.Scrollable = true; - Control.Cell.Wraps = false; - Control.Cell.UsesSingleLineMode = true; - - MaxLength = -1; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - Control.Changed += HandleChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - static void HandleChanged(object sender, EventArgs e) - { - var handler = GetHandler(sender) as PasswordBoxHandler; - if (handler != null) - handler.Widget.OnTextChanged(EventArgs.Empty); - } - - public bool ReadOnly - { - get { return !Control.Editable; } - set { Control.Editable = !value; } - } - - public int MaxLength - { - get; - set; - } - - public Char PasswordChar - { // not supported on OSX - get { return '\0'; } - set { } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/ProgressBarHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/ProgressBarHandler.cs deleted file mode 100644 index 255a226b7e..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/ProgressBarHandler.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class ProgressBarHandler : MacView, IProgressBar - { - public class EtoSlider : NSProgressIndicator, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - } - - public override NSView ContainerControl { get { return Control; } } - - public ProgressBarHandler () - { - Control = new EtoSlider { Handler = this, Indeterminate = false }; - - MinValue = 0; - MaxValue = 100; - } - - protected override SizeF GetNaturalSize (SizeF availableSize) - { - return new Size (80, 30); - } - - public override bool Enabled { - get { return true; } - set { } - } - - public bool Indeterminate { - get { return Control.Indeterminate; } - set { - Control.Indeterminate = value; - if (value) - Control.StartAnimation (Control); - else - Control.StopAnimation (Control); - } - } - - public int MaxValue { - get { return (int)Control.MaxValue; } - set { - Control.MaxValue = value; - } - } - - public int MinValue { - get { return (int)Control.MinValue; } - set { - Control.MinValue = value; - } - } - - public int Value { - get { return (int)Control.DoubleValue; } - set { Control.DoubleValue = value; } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/RadioButtonHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/RadioButtonHandler.cs deleted file mode 100644 index 486e584ec5..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/RadioButtonHandler.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using System.Collections.Generic; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class RadioButtonHandler : MacButton, IRadioButton - { - List group; - - public event EventHandler Activated; - - public class EtoRadioButton : NSButton, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public RadioButtonHandler() - { - Control = new EtoRadioButton { Handler = this, Title = string.Empty }; - Control.SetButtonType(NSButtonType.Radio); - Control.Activated += HandleActivated; - } - - static void HandleActivated(object sender, EventArgs e) - { - var handler = GetHandler(sender) as RadioButtonHandler; - if (handler != null) - { - if (handler.Activated != null) - handler.Activated(handler, e); - handler.Widget.OnClick(EventArgs.Empty); - handler.Widget.OnCheckedChanged(EventArgs.Empty); - - if (handler.Control.AcceptsFirstResponder() && handler.Control.Window != null) - handler.Control.Window.MakeFirstResponder(handler.Control); - } - } - - public void Create(RadioButton controller) - { - - if (controller != null) - { - var controllerInner = (RadioButtonHandler)controller.Handler; - if (controllerInner.group == null) - { - controllerInner.group = new List(); - controllerInner.group.Add(controller); - controllerInner.Activated += controllerInner.control_RadioSwitch; - } - controllerInner.group.Add(Widget); - Activated += controllerInner.control_RadioSwitch; - } - } - - void control_RadioSwitch(object sender, EventArgs e) - { - if (group != null) - { - foreach (RadioButton item in group) - { - var c = (NSButton)item.ControlObject; - var ischecked = (item.Handler == sender); - c.State = ischecked ? NSCellStateValue.On : NSCellStateValue.Off; - } - } - } - - public bool Checked - { - get { return Control.State == NSCellStateValue.On; } - set - { - if (value != Checked) - { - Control.State = value ? NSCellStateValue.On : NSCellStateValue.Off; - Widget.OnCheckedChanged(EventArgs.Empty); - if (Activated != null) - Activated(this, EventArgs.Empty); - - } - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/ScrollableHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/ScrollableHandler.cs deleted file mode 100644 index 49d8c7cbad..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/ScrollableHandler.cs +++ /dev/null @@ -1,340 +0,0 @@ -// can't use flipped right now - bug in monomac/xam.mac that causes crashing since FlippedView gets disposed incorrectly -// has something to do with using layers (background colors) at the same time -//#define USE_FLIPPED - -using System; -using SD = System.Drawing; -using Eto.Drawing; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class ScrollableHandler : MacPanel, IScrollable - { - bool expandContentWidth = true; - bool expandContentHeight = true; - Point scrollPosition; - - public override NSView ContainerControl { get { return Control; } } - - class EtoScrollView : NSScrollView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public ScrollableHandler Handler - { - get { return (ScrollableHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public override void ResetCursorRects() - { - var cursor = Handler.Cursor; - if (cursor != null) - AddCursorRect(new SD.RectangleF(SD.PointF.Empty, Frame.Size), cursor.ControlObject as NSCursor); - } - } - - class FlippedView : NSView - { - public WeakReference WeakHandler { get; set; } - - public ScrollableHandler Handler - { - get { return (ScrollableHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - #if USE_FLIPPED - public override bool IsFlipped - { - get { return true; } - } - #endif - #if !USE_FLIPPED - public override void SetFrameSize(SD.SizeF newSize) - { - base.SetFrameSize(newSize); - Handler.SetPosition(Handler.scrollPosition, true); - } - #endif - } - - public ScrollableHandler() - { - Enabled = true; - Control = new EtoScrollView - { - Handler = this, - BackgroundColor = NSColor.Control, - BorderType = NSBorderType.BezelBorder, - DrawsBackground = false, - HasVerticalScroller = true, - HasHorizontalScroller = true, - AutohidesScrollers = true, - DocumentView = new FlippedView { Handler = this } - }; - - // only draw dirty regions, instead of entire scroll area - Control.ContentView.CopiesOnScroll = true; - } - - protected override void Initialize() - { - base.Initialize(); - if (!ContentControl.IsFlipped) - // need to keep the scroll position as it scrolls instead of calculating - HandleEvent(Scrollable.ScrollEvent); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Scrollable.ScrollEvent: - Control.ContentView.PostsBoundsChangedNotifications = true; - AddObserver(NSView.BoundsChangedNotification, e => - { - var handler = e.Handler as ScrollableHandler; - if (handler != null) - { - var view = handler.ContentControl; - if (!view.IsFlipped) - { - var contentBounds = handler.Control.ContentView.Bounds; - if (contentBounds.Height > 0) - handler.scrollPosition = new Point((int)contentBounds.X, (int)(view.Frame.Height - contentBounds.Height - contentBounds.Y)); - } - handler.Widget.OnScroll(new ScrollEventArgs(handler.ScrollPosition)); - } - }, Control.ContentView); - break; - default: - base.AttachEvent(id); - break; - } - } - - public BorderType Border - { - get - { - switch (Control.BorderType) - { - case NSBorderType.BezelBorder: - return BorderType.Bezel; - case NSBorderType.LineBorder: - return BorderType.Line; - case NSBorderType.NoBorder: - return BorderType.None; - default: - throw new NotSupportedException(); - } - } - set - { - switch (value) - { - case BorderType.Bezel: - Control.BorderType = NSBorderType.BezelBorder; - break; - case BorderType.Line: - Control.BorderType = NSBorderType.LineBorder; - break; - case BorderType.None: - Control.BorderType = NSBorderType.NoBorder; - break; - default: - throw new NotSupportedException(); - } - } - } - - public override NSView ContentControl - { - get { return (NSView)Control.DocumentView; } - } - - public override void LayoutChildren() - { - base.LayoutChildren(); - UpdateScrollSizes(); - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - UpdateScrollSizes(); - } - - Size GetBorderSize() - { - return Border == BorderType.None ? Size.Empty : new Size(2, 2); - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - return SizeF.Min(availableSize, base.GetNaturalSize(availableSize) + GetBorderSize()); - } - - protected override SD.RectangleF GetContentBounds() - { - var contentSize = Content.GetPreferredSize(SizeF.MaxValue); - - if (ExpandContentWidth) - contentSize.Width = Math.Max(ClientSize.Width, contentSize.Width); - if (ExpandContentHeight) - contentSize.Height = Math.Max(ClientSize.Height, contentSize.Height); - return new RectangleF(contentSize).ToSD(); - } - - protected override NSViewResizingMask ContentResizingMask() - { - return ContentControl.IsFlipped ? base.ContentResizingMask() : (NSViewResizingMask)0; - } - - void InternalSetFrameSize(SD.SizeF size) - { - var view = ContentControl; - if (!view.IsFlipped) - { - var ctl = Content.GetContainerView(); - if (ctl != null) - { - var clientHeight = Control.DocumentVisibleRect.Size.Height; - ctl.Frame = new SD.RectangleF(new SD.PointF(0, Math.Max(0, clientHeight - size.Height)), size); - size.Height = Math.Max(clientHeight, size.Height); - } - } - if (size != view.Frame.Size) - { - view.SetFrameSize(size); - } - } - - public void UpdateScrollSizes() - { - InternalSetFrameSize(GetContentBounds().Size); - } - - public override Color BackgroundColor - { - get - { - return Control.BackgroundColor.ToEto(); - } - set - { - Control.BackgroundColor = value.ToNSUI(); - Control.DrawsBackground = value.A > 0; - } - } - - public Point ScrollPosition - { - get - { - var view = ContentControl; - if (Widget.Loaded && view.IsFlipped) - { - return Control.ContentView.Bounds.Location.ToEtoPoint(); - } - return scrollPosition; - } - set - { - SetPosition(value, false); - } - } - - void SetPosition(Point value, bool force) - { - if (Widget.Loaded || force) - { - var view = ContentControl; - if (view.IsFlipped) - Control.ContentView.ScrollToPoint(value.ToSDPointF()); - else if (Control.ContentView.Frame.Height > 0) - Control.ContentView.ScrollToPoint(new SD.PointF(value.X, Math.Max(0, view.Frame.Height - Control.ContentView.Frame.Height - value.Y))); - Control.ReflectScrolledClipView(Control.ContentView); - } - scrollPosition = value; - } - - public Size ScrollSize - { - get { return ContentControl.Frame.Size.ToEtoSize(); } - set - { - InternalSetFrameSize(value.ToSDSizeF()); - } - } - - public override Size ClientSize - { - get - { - return Control.DocumentVisibleRect.Size.ToEtoSize(); - } - set - { - - } - } - - public override bool Enabled { get; set; } - - public override void SetContentSize(SD.SizeF contentSize) - { - if (MinimumSize != Size.Empty) - { - contentSize.Width = Math.Max(contentSize.Width, MinimumSize.Width); - contentSize.Height = Math.Max(contentSize.Height, MinimumSize.Height); - } - if (ExpandContentWidth) - contentSize.Width = Math.Max(ClientSize.Width, contentSize.Width); - if (ExpandContentHeight) - contentSize.Height = Math.Max(ClientSize.Height, contentSize.Height); - InternalSetFrameSize(contentSize); - } - - #if !USE_FLIPPED - public override void OnSizeChanged(EventArgs e) - { - base.OnSizeChanged(e); - SetPosition(scrollPosition, true); - } - #endif - - public Rectangle VisibleRect - { - get { return new Rectangle(ScrollPosition, Size.Min(ScrollSize, ClientSize)); } - } - - public bool ExpandContentWidth - { - get { return expandContentWidth; } - set - { - if (expandContentWidth != value) - { - expandContentWidth = value; - UpdateScrollSizes(); - } - } - } - - public bool ExpandContentHeight - { - get { return expandContentHeight; } - set - { - if (expandContentHeight != value) - { - expandContentHeight = value; - UpdateScrollSizes(); - } - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/SearchBoxHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/SearchBoxHandler.cs deleted file mode 100644 index 678db7171d..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/SearchBoxHandler.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using Eto.Drawing; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Controls -{ - /// - /// TODO: Try to eliminate code duplication between this class - /// and TextBoxHandler. - /// - public class SearchBoxHandler : MacText, ISearchBox, ITextBoxWithMaxLength - { - class EtoTextField : NSSearchField, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public SearchBoxHandler Handler - { - get { return (SearchBoxHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public override bool HasFocus - { - get - { - if (Widget.ParentWindow == null) - return false; - return ((IMacWindow)Widget.ParentWindow.Handler).FieldEditorObject == Control; - } - } - - public override NSSearchField CreateControl() - { - return new EtoTextField - { - Handler = this, - Bezeled = true, - Editable = true, - Selectable = true, - Formatter = new EtoFormatter{ Handler = this } - }; - } - - protected override void Initialize() - { - base.Initialize(); - Control.Cell.Scrollable = true; - Control.Cell.Wraps = false; - Control.Cell.UsesSingleLineMode = true; - - MaxLength = -1; - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - var size = base.GetNaturalSize(availableSize); - size.Width = Math.Max(100, size.Height); - return size; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - Control.Changed += HandleTextChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - static void HandleTextChanged(object sender, EventArgs e) - { - var handler = GetHandler(sender) as SearchBoxHandler; - if (handler != null) - { - handler.Widget.OnTextChanged(EventArgs.Empty); - } - } - - public bool ReadOnly - { - get { return !Control.Editable; } - set { Control.Editable = !value; } - } - - public int MaxLength - { - get; - set; - } - - public string PlaceholderText - { - get { return Control.Cell.PlaceholderString; } - set { Control.Cell.PlaceholderString = value ?? string.Empty; } - } - - public void SelectAll() - { - Control.SelectText(Control); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/SliderHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/SliderHandler.cs deleted file mode 100644 index b21ba86c81..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/SliderHandler.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class SliderHandler : MacControl, ISlider - { - SliderOrientation orientation; - - public class EtoSlider : NSSlider, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public SliderHandler() - { - Control = new EtoSlider { Handler = this }; - Control.Activated += HandleActivated; - MinValue = 0; - MaxValue = 100; - } - - static void HandleActivated(object sender, EventArgs e) - { - var handler = GetHandler(sender) as SliderHandler; - if (handler != null) - { - var newval = (int)Math.Round(handler.Control.DoubleValue); - if (newval != handler.Control.IntValue) - handler.Control.IntValue = newval; - - handler.Widget.OnValueChanged(EventArgs.Empty); - } - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - return Orientation == SliderOrientation.Horizontal ? new Size(80, 30) : new Size(30, 80); - } - - public int MaxValue - { - get { return (int)Control.MaxValue; } - set - { - var old = TickFrequency; - Control.MaxValue = value; - TickFrequency = old; - } - } - - public int MinValue - { - get { return (int)Control.MinValue; } - set - { - var old = TickFrequency; - Control.MinValue = value; - TickFrequency = old; - } - } - - public int Value - { - get { return Control.IntValue; } - set { Control.IntValue = value; } - } - - public bool SnapToTick - { - get { return Control.AllowsTickMarkValuesOnly; } - set { Control.AllowsTickMarkValuesOnly = value; } - } - - public int TickFrequency - { - get - { - if (Control.TickMarksCount > 1) - return ((MaxValue - MinValue) / (Control.TickMarksCount - 1)); - return MaxValue - MinValue; - } - set - { - Control.TickMarksCount = ((MaxValue - MinValue) / value) + 1; - } - } - - public SliderOrientation Orientation - { - get - { - return orientation; - } - set - { - orientation = value; - // wha?!?! no way to do this other than change size or sumthun? - var size = Control.Frame.Size; - if (value == SliderOrientation.Vertical) - { - size.Height = size.Width + 1; - } - else - size.Width = size.Height + 1; - Control.SetFrameSize(size); - LayoutIfNeeded(); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/SpinnerHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/SpinnerHandler.cs deleted file mode 100644 index 3ca2a45fa6..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/SpinnerHandler.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class SpinnerHandler : MacView, ISpinner - { - bool enabled; - readonly NSView view; - - public override NSView ContainerControl { get { return view; } } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - return new SizeF(16, 16); - } - - public SpinnerHandler() - { - Control = new NSProgressIndicator - { - Style = NSProgressIndicatorStyle.Spinning, - ControlSize = NSControlSize.Regular - }; - view = new MacEventView { Handler = this }; - view.AddSubview(Control); - } - protected override void Initialize() - { - base.Initialize(); - HandleEvent(Eto.Forms.Control.SizeChangedEvent); - } - - public override void OnSizeChanged(EventArgs e) - { - base.OnSizeChanged(e); - var size = Math.Max(Size.Width, Size.Height); - if (size <= 8) - Control.ControlSize = NSControlSize.Mini; - else if (size <= 20) - Control.ControlSize = NSControlSize.Small; - else if (size <= 30) - Control.ControlSize = NSControlSize.Regular; - Control.SizeToFit(); - Control.CenterInParent(); - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - if (enabled) - Control.StartAnimation(Control); - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - if (enabled) - Control.StopAnimation(Control); - } - - public override bool Enabled - { - get { return enabled; } - set - { - if (enabled != value) - { - enabled = value; - if (Widget.Loaded) - { - if (enabled) - Control.StartAnimation(Control); - else - Control.StopAnimation(Control); - } - } - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/SplitterHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/SplitterHandler.cs deleted file mode 100644 index 6f44785ecf..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/SplitterHandler.cs +++ /dev/null @@ -1,317 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using Eto.Drawing; -using sd = System.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class SplitterHandler : MacView, ISplitter - { - Control panel1; - Control panel2; - int? position; - SplitterFixedPanel fixedPanel; - - public bool RecurseToChildren { get { return true; } } - - public override NSView ContainerControl { get { return Control; } } - - public virtual Size ClientSize { get { return Size; } set { Size = value; } } - - public override void AttachEvent(string id) - { - switch (id) - { - case Splitter.PositionChangedEvent: - // handled by delegate - break; - default: - base.AttachEvent(id); - break; - } - } - - static void ResizeSubviews(SplitterHandler handler, sd.SizeF oldSize) - { - var splitView = handler.Control; - var dividerThickness = splitView.DividerThickness; - var panel1Rect = splitView.Subviews[0].Frame; - var panel2Rect = splitView.Subviews[1].Frame; - var newFrame = splitView.Frame; - - if (oldSize.IsEmpty) - oldSize = newFrame.Size; - - if (splitView.IsVertical) - { - panel2Rect.Height = panel1Rect.Height = newFrame.Height; - panel1Rect.Location = new sd.PointF(0, 0); - if (handler.position == null) - { - panel1Rect.Width = Math.Max(0, newFrame.Width / 2); - panel2Rect.Width = Math.Max(0, newFrame.Width - panel1Rect.Width - dividerThickness); - } - else - { - var pos = handler.position.Value; - switch (handler.fixedPanel) - { - case SplitterFixedPanel.Panel1: - panel1Rect.Width = Math.Max(0, Math.Min(newFrame.Width - dividerThickness, pos)); - panel2Rect.Width = Math.Max(0, newFrame.Width - panel1Rect.Width - dividerThickness); - break; - case SplitterFixedPanel.Panel2: - panel2Rect.Width = Math.Max(0, Math.Min(newFrame.Width - dividerThickness, oldSize.Width - pos - dividerThickness)); - panel1Rect.Width = Math.Max(0, newFrame.Width - panel2Rect.Width - dividerThickness); - break; - case SplitterFixedPanel.None: - var oldscale = newFrame.Width / oldSize.Width; - panel1Rect.Width = Math.Max(0, Math.Min(newFrame.Width - dividerThickness, pos * oldscale)); - panel2Rect.Width = Math.Max(0, newFrame.Width - panel1Rect.Width - dividerThickness); - break; - } - } - panel2Rect.X = Math.Min(panel1Rect.Width + dividerThickness, newFrame.Width); - } - else - { - panel2Rect.X = 0; - panel2Rect.Width = panel1Rect.Width = newFrame.Width; - panel1Rect.Location = new sd.PointF(0, 0); - if (handler.position == null) - { - panel1Rect.Height = Math.Max(0, newFrame.Height / 2); - panel2Rect.Height = Math.Max(0, newFrame.Height - panel1Rect.Height - dividerThickness); - } - else - { - var pos = handler.position.Value; - switch (handler.fixedPanel) - { - case SplitterFixedPanel.Panel1: - panel1Rect.Height = Math.Max(0, Math.Min(newFrame.Height - dividerThickness, pos)); - panel2Rect.Height = Math.Max(0, newFrame.Height - panel1Rect.Height - dividerThickness); - break; - case SplitterFixedPanel.Panel2: - panel2Rect.Height = Math.Max(0, Math.Min(newFrame.Height - dividerThickness, oldSize.Height - pos - dividerThickness)); - panel1Rect.Height = Math.Max(0, newFrame.Height - panel2Rect.Height - dividerThickness); - break; - case SplitterFixedPanel.None: - var oldscale = newFrame.Height / oldSize.Height; - panel1Rect.Height = Math.Max(0, Math.Min(newFrame.Height - dividerThickness, pos * oldscale)); - panel2Rect.Height = Math.Max(0, newFrame.Height - panel1Rect.Height - dividerThickness); - break; - } - } - panel2Rect.Y = Math.Min(panel1Rect.Height + dividerThickness, newFrame.Height); - } - - splitView.Subviews[0].Frame = panel1Rect; - splitView.Subviews[1].Frame = panel2Rect; - } - - class SVDelegate : NSSplitViewDelegate - { - WeakReference handler; - - public SplitterHandler Handler { get { return (SplitterHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override void Resize(NSSplitView splitView, sd.SizeF oldSize) - { - SplitterHandler.ResizeSubviews(Handler, oldSize); - } - - public override float ConstrainSplitPosition(NSSplitView splitView, float proposedPosition, int subviewDividerIndex) - { - return Handler.Enabled ? proposedPosition : Handler.Position; - } - - public override void DidResizeSubviews(MonoMac.Foundation.NSNotification notification) - { - var subview = Handler.Control.Subviews[0]; - if (subview != null && Handler.position != null && Handler.Widget.Loaded && Handler.Widget.ParentWindow != null && Handler.Widget.ParentWindow.Loaded) - { - Handler.position = Handler.Control.IsVertical ? (int)subview.Frame.Width : (int)subview.Frame.Height; - Handler.Widget.OnPositionChanged(EventArgs.Empty); - } - } - } - // stupid hack for OSX 10.5 so that mouse down/drag/up events fire in children properly.. - class EtoSplitView : NSSplitView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public SplitterHandler Handler - { - get { return (SplitterHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - public override void MouseDown(NSEvent theEvent) - { - var cursor = NSCursor.CurrentCursor; - if (cursor == NSCursor.ResizeLeftCursor || cursor == NSCursor.ResizeRightCursor || cursor == NSCursor.ResizeLeftRightCursor - || cursor == NSCursor.ResizeUpCursor || cursor == NSCursor.ResizeDownCursor || cursor == NSCursor.ResizeUpDownCursor) - base.MouseDown(theEvent); - } - - public override void MouseDragged(NSEvent theEvent) - { - var cursor = NSCursor.CurrentCursor; - if (cursor == NSCursor.ResizeLeftCursor || cursor == NSCursor.ResizeRightCursor || cursor == NSCursor.ResizeLeftRightCursor - || cursor == NSCursor.ResizeUpCursor || cursor == NSCursor.ResizeDownCursor || cursor == NSCursor.ResizeUpDownCursor) - base.MouseDragged(theEvent); - } - - public override void MouseUp(NSEvent theEvent) - { - var cursor = NSCursor.CurrentCursor; - if (cursor == NSCursor.ResizeLeftCursor || cursor == NSCursor.ResizeRightCursor || cursor == NSCursor.ResizeLeftRightCursor - || cursor == NSCursor.ResizeUpCursor || cursor == NSCursor.ResizeDownCursor || cursor == NSCursor.ResizeUpDownCursor) - base.MouseUp(theEvent); - } - } - - public SplitterHandler() - { - Enabled = true; - Control = new EtoSplitView { Handler = this }; - Control.DividerStyle = NSSplitViewDividerStyle.Thin; - Control.AddSubview(new NSView { AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable }); - Control.AddSubview(new NSView { AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable }); - Control.IsVertical = true; - Control.Delegate = new SVDelegate { Handler = this }; - } - - public int Position - { - get { return position ?? 0; } - set - { - position = value; - if (Widget.Loaded) - Control.ResizeSubviewsWithOldSize(sd.SizeF.Empty); - } - } - - public SplitterOrientation Orientation - { - get - { - return Control.IsVertical ? SplitterOrientation.Horizontal : SplitterOrientation.Vertical; - } - set - { - Control.IsVertical = value == SplitterOrientation.Horizontal; - if (Widget.Loaded) - Control.ResizeSubviewsWithOldSize(sd.SizeF.Empty); - } - } - - public override bool Enabled { get; set; } - - public SplitterFixedPanel FixedPanel - { - get { return fixedPanel; } - set - { - fixedPanel = value; - if (Widget.Loaded) - Control.ResizeSubviewsWithOldSize(sd.SizeF.Empty); - } - } - - public Control Panel1 - { - get { return panel1; } - set - { - if (panel1 != value) - { - var view = value.GetContainerView(); - Control.ReplaceSubviewWith(Control.Subviews[0], view ?? new NSView()); - panel1 = value; - } - } - } - - public Control Panel2 - { - get { return panel2; } - set - { - if (panel2 != value) - { - var view = value.GetContainerView(); - Control.ReplaceSubviewWith(Control.Subviews[1], view ?? new NSView()); - panel2 = value; - } - } - } - - void SetInitialSplitPosition() - { - if (position == null) - { - switch (fixedPanel) - { - case SplitterFixedPanel.Panel1: - var size1 = panel1.GetPreferredSize(SizeF.MaxValue); - position = (int)(Orientation == SplitterOrientation.Horizontal ? size1.Width : size1.Height); - break; - case SplitterFixedPanel.Panel2: - var size2 = panel2.GetPreferredSize(SizeF.MaxValue); - if (Orientation == SplitterOrientation.Horizontal) - position = (int)(Control.Frame.Width - size2.Width - Control.DividerThickness); - else - position = (int)(Control.Frame.Height - size2.Height - Control.DividerThickness); - break; - } - } - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - SetInitialSplitPosition(); - Control.ResizeSubviewsWithOldSize(sd.SizeF.Empty); - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - var size = new SizeF(); - - var p1size = panel1.GetPreferredSize(availableSize); - var p2size = panel2.GetPreferredSize(availableSize); - if (Control.IsVertical) - { - if (position != null) - { - switch (FixedPanel) - { - case SplitterFixedPanel.None: - case SplitterFixedPanel.Panel1: - p1size.Width = Math.Max(p1size.Width, position.Value); - break; - case SplitterFixedPanel.Panel2: - p2size.Width = Math.Max(p2size.Width, Size.Width - position.Value); - break; - } - } - if (position != null) - p1size.Width = position.Value; - size.Width = p1size.Width + p2size.Width + Control.DividerThickness; - size.Height = Math.Max(p1size.Height, p2size.Height); - } - else - { - if (position != null) - p1size.Height = position.Value; - size.Height = p1size.Height + p2size.Height + Control.DividerThickness; - size.Width = Math.Max(p1size.Width, p2size.Width); - } - return size; - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/TabControlHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/TabControlHandler.cs deleted file mode 100644 index 4a89e93ffb..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/TabControlHandler.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Linq; -using Eto.Forms; -using MonoMac.AppKit; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class TabControlHandler : MacView, ITabControl - { - bool disableSelectedIndexChanged; - - public bool RecurseToChildren { get { return true; } } - - public override NSView ContainerControl { get { return Control; } } - - public class EtoTabView : NSTabView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - // CWEN: should have some form of implementation here - public virtual Size ClientSize { get { return Size; } set { Size = value; } } - - public TabControlHandler () - { - Enabled = true; - Control = new EtoTabView { Handler = this }; - } - - public override void OnLoadComplete (EventArgs e) - { - base.OnLoadComplete (e); - Control.ShouldSelectTabViewItem += HandleShouldSelectTabViewItem; - Control.DidSelect += HandleDidSelect; - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - Control.ShouldSelectTabViewItem -= HandleShouldSelectTabViewItem; - Control.DidSelect -= HandleDidSelect; - } - - static bool HandleShouldSelectTabViewItem(NSTabView tabView, NSTabViewItem item) - { - var handler = ((EtoTabView)tabView).WeakHandler.Target as TabControlHandler; - var tab = handler.Widget.TabPages.FirstOrDefault (r => ((TabPageHandler)r.Handler).TabViewItem == item); - return tab == null || tab.Enabled; - } - - static void HandleDidSelect (object sender, NSTabViewItemEventArgs e) - { - var handler = GetHandler(sender) as TabControlHandler; - if (handler != null) - { - if (!handler.disableSelectedIndexChanged) - handler.Widget.OnSelectedIndexChanged(EventArgs.Empty); - } - } - - public int SelectedIndex - { - get { return Control.Selected == null ? -1 : Control.IndexOf(Control.Selected); } - set { Control.SelectAt (value); } - } - - public override bool Enabled { get; set; } - - public void InsertTab (int index, TabPage page) - { - if (index == -1) - Control.Add (((TabPageHandler)page.Handler).TabViewItem); - else - Control.Insert (((TabPageHandler)page.Handler).TabViewItem, index); - } - - public void ClearTabs () - { - foreach (var tab in Control.Items) - Control.Remove (tab); - } - - public void RemoveTab (int index, TabPage page) - { - disableSelectedIndexChanged = true; - try { - var isSelected = SelectedIndex == index; - Control.Remove (((TabPageHandler)page.Handler).TabViewItem); - if (isSelected && Control.Items.Length > 0) - SelectedIndex = Math.Min (index, Control.Items.Length - 1); - if (Widget.Loaded) - Widget.OnSelectedIndexChanged (EventArgs.Empty); - } finally { - disableSelectedIndexChanged = false; - } - } - - protected override SizeF GetNaturalSize (SizeF availableSize) - { - var size = base.GetNaturalSize(availableSize); - foreach (var tab in Widget.TabPages.Where(r => r.Visible)) { - size = SizeF.Max (size, tab.GetPreferredSize(availableSize)); - } - return size; - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/TabPageHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/TabPageHandler.cs deleted file mode 100644 index 9da7e98d81..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/TabPageHandler.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using SD = System.Drawing; -using MonoMac.Foundation; -using Eto.Drawing; -using MonoMac.ObjCRuntime; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class TabPageHandler : MacPanel, ITabPage - { - const int ICON_PADDING = 2; - Image image; - static readonly IntPtr selDrawInRectFromRectOperationFractionRespectFlippedHints = Selector.GetHandle ("drawInRect:fromRect:operation:fraction:respectFlipped:hints:"); - - public override NSView ContainerControl { get { return Control; } } - - public NSTabViewItem TabViewItem { get; private set; } - - class MyTabViewItem : NSTabViewItem - { - WeakReference handler; - public TabPageHandler Handler { get { return (TabPageHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override void DrawLabel (bool shouldTruncateLabel, SD.RectangleF labelRect) - { - if (Handler.image != null) { - var nsimage = (NSImage)Handler.image.ControlObject; - - if (nsimage.RespondsToSelector(new Selector(selDrawInRectFromRectOperationFractionRespectFlippedHints))) - nsimage.Draw (new SD.RectangleF (labelRect.X, labelRect.Y, labelRect.Height, labelRect.Height), new SD.RectangleF (SD.PointF.Empty, nsimage.Size), NSCompositingOperation.SourceOver, 1, true, null); - else { - #pragma warning disable 618 - nsimage.Flipped = View.IsFlipped; - #pragma warning restore 618 - nsimage.Draw (new SD.RectangleF (labelRect.X, labelRect.Y, labelRect.Height, labelRect.Height), new SD.RectangleF (SD.PointF.Empty, nsimage.Size), NSCompositingOperation.SourceOver, 1); - } - - labelRect.X += labelRect.Height + ICON_PADDING; - labelRect.Width -= labelRect.Height + ICON_PADDING; - base.DrawLabel (shouldTruncateLabel, labelRect); - } - base.DrawLabel (shouldTruncateLabel, labelRect); - } - - public override SD.SizeF SizeOfLabel (bool computeMin) - { - var size = base.SizeOfLabel (computeMin); - if (Handler.image != null) { - size.Width += size.Height + ICON_PADDING; - } - return size; - } - } - - public TabPageHandler () - { - TabViewItem = new MyTabViewItem { - Handler = this, - Identifier = new NSString (Guid.NewGuid ().ToString ()), - View = new MacEventView { Handler = this } - }; - Control = TabViewItem.View; - Enabled = true; - } - - public string Text { - get { return TabViewItem.Label; } - set { TabViewItem.Label = value; } - } - - public Image Image { - get { return image; } - set { - image = value; - if (image != null) { - } - } - } - - public override NSView ContentControl - { - get { return TabViewItem.View; } - } - - public override bool Enabled { get; set; } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/TextAreaHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/TextAreaHandler.cs deleted file mode 100644 index 67d7e04906..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/TextAreaHandler.cs +++ /dev/null @@ -1,254 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; -using sd = System.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class TextAreaHandler : MacView, ITextArea - { - int? lastCaretIndex; - Range? lastSelection; - - public class EtoTextView : NSTextView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public NSScrollView Scroll { get; private set; } - - public override NSView ContainerControl - { - get { return Scroll; } - } - // Remove use of delegate when events work correctly in MonoMac - public class EtoDelegate : NSTextViewDelegate - { - WeakReference handler; - - public TextAreaHandler Handler { get { return (TextAreaHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override void TextDidChange(NSNotification notification) - { - Handler.Widget.OnTextChanged(EventArgs.Empty); - } - - public override void DidChangeSelection(NSNotification notification) - { - var selection = Handler.Selection; - if (selection != Handler.lastSelection) - { - Handler.Widget.OnSelectionChanged(EventArgs.Empty); - Handler.lastSelection = selection; - } - var caretIndex = Handler.CaretIndex; - if (caretIndex != Handler.lastCaretIndex) - { - Handler.Widget.OnCaretIndexChanged(EventArgs.Empty); - Handler.lastCaretIndex = caretIndex; - } - } - } - - public TextAreaHandler() - { - Control = new EtoTextView - { - Handler = this, - Delegate = new EtoDelegate { Handler = this }, - AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable, - HorizontallyResizable = true, - VerticallyResizable = true, - Editable = true, - Selectable = true, - AllowsUndo = true, - MinSize = sd.SizeF.Empty, - MaxSize = new sd.SizeF(float.MaxValue, float.MaxValue) - }; - Control.TextContainer.WidthTracksTextView = true; - - Scroll = new EtoScrollView - { - Handler = this, - AutoresizesSubviews = true, - HasVerticalScroller = true, - HasHorizontalScroller = true, - AutohidesScrollers = true, - BorderType = NSBorderType.BezelBorder, - DocumentView = Control - }; - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - return TextArea.DefaultSize; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - /*Control.TextDidChange += (sender, e) => { - Widget.OnTextChanged (EventArgs.Empty); - };*/ - break; - case TextArea.SelectionChangedEvent: - /*Control.DidChangeSelection += (sender, e) => { - var selection = this.Selection; - if (selection != lastSelection) { - Widget.OnSelectionChanged (EventArgs.Empty); - lastSelection = selection; - } - };*/ - break; - case TextArea.CaretIndexChangedEvent: - /*Control.DidChangeSelection += (sender, e) => { - var caretIndex = Handler.CaretIndex; - if (caretIndex != lastCaretIndex) { - Handler.Widget.OnCaretIndexChanged (EventArgs.Empty); - lastCaretIndex = caretIndex; - } - };*/ - break; - default: - base.AttachEvent(id); - break; - } - } - - public bool ReadOnly - { - get { return !Control.Editable; } - set { Control.Editable = !value; } - } - - public override bool Enabled - { - get { return Control.Selectable; } - set - { - Control.Selectable = value; - if (!value) - { - Control.TextColor = NSColor.DisabledControlText; - Control.BackgroundColor = NSColor.ControlBackground; - } - else - { - Control.TextColor = NSColor.ControlText; - Control.BackgroundColor = NSColor.TextBackground; - } - } - } - - public string Text - { - get - { - return Control.Value; - } - set - { - Control.TextStorage.SetString(font.AttributedString(value ?? string.Empty)); - Control.DisplayIfNeeded(); - } - } - - Font font; - - public Font Font - { - get - { - if (font == null) - font = new Font(Widget.Generator, new FontHandler(Control.Font)); - return font; - } - set - { - font = value; - Control.TextStorage.SetString(font.AttributedString(Control.Value)); - LayoutIfNeeded(); - } - } - - public bool Wrap - { - get - { - return Control.TextContainer.WidthTracksTextView; - } - set - { - if (value) - { - Control.TextContainer.WidthTracksTextView = true; - } - else - { - Control.TextContainer.WidthTracksTextView = false; - Control.TextContainer.ContainerSize = new sd.SizeF(float.MaxValue, float.MaxValue); - } - } - } - - public string SelectedText - { - get - { - var range = Control.SelectedRange; - if (range.Location >= 0 && range.Length > 0) - return Control.Value.Substring(range.Location, range.Length); - return null; - } - set - { - var range = Control.SelectedRange; - Control.TextStorage.DeleteRange(range); - if (value != null) - { - range.Length = value.Length; - Control.TextStorage.Insert(new NSAttributedString(value), range.Location); - Control.SelectedRange = range; - } - } - } - - public Range Selection - { - get { return Control.SelectedRange.ToEto(); } - set { Control.SelectedRange = value.ToNS(); } - } - - public void SelectAll() - { - Control.SelectAll(Control); - } - - public int CaretIndex - { - get { return Control.SelectedRange.Location; } - set { Control.SelectedRange = new NSRange(value, 0); } - } - - public void Append(string text, bool scrollToCursor) - { - var range = new NSRange(Control.Value.Length, 0); - Control.Replace(range, text); - range = new NSRange(Control.Value.Length, 0); - Control.SelectedRange = range; - if (scrollToCursor) - Control.ScrollRangeToVisible(range); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/TextBoxHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/TextBoxHandler.cs deleted file mode 100644 index ef20d347f7..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/TextBoxHandler.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; -using Eto.Platform.Mac.Forms.Controls; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public interface ITextBoxWithMaxLength - { - int MaxLength { get; set; } - } - - public class EtoFormatter : NSFormatter - { - WeakReference handler; - - public ITextBoxWithMaxLength Handler { get { return (ITextBoxWithMaxLength)handler.Target; } set { handler = new WeakReference(value); } } - - public override string StringFor(NSObject value) - { - if (value == null) - return string.Empty; - var str = (NSString)value; - //if (str != null && value.Handle != IntPtr.Zero) - return str.ToString(); - } - - [Export("getObjectValue:forString:errorDescription:")] - public bool GetObjectValue(ref IntPtr obj, IntPtr value, ref IntPtr error) - { - obj = value; - return true; - } - - [Export("isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:")] - public bool IsPartialStringValid(ref NSString value, IntPtr proposedSelRange, NSString origString, NSRange origSelRange, ref IntPtr error) - { - if (Handler.MaxLength >= 0) - { - int size = value.Length; - if (size > Handler.MaxLength) - { - return false; - } - } - return true; - } - - [Export("attributedStringForObjectValue:withDefaultAttributes:")] - public NSAttributedString AttributedStringForObjectValue(IntPtr anObject, NSDictionary attributes) - { - return null; - } - } - - public class EtoTextField : NSTextField, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public TextBoxHandler Handler - { - get { return (TextBoxHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public class TextBoxHandler : MacText, ITextBox, ITextBoxWithMaxLength - { - - public override bool HasFocus - { - get - { - if (Widget.ParentWindow == null) - return false; - return ((IMacWindow)Widget.ParentWindow.Handler).FieldEditorObject == Control; - } - } - - public override EtoTextField CreateControl() - { - return new EtoTextField - { - Handler = this, - Bezeled = true, - Editable = true, - Selectable = true, - Formatter = new EtoFormatter{ Handler = this } - }; - } - - protected override void Initialize() - { - base.Initialize(); - Control.Cell.Scrollable = true; - Control.Cell.Wraps = false; - Control.Cell.UsesSingleLineMode = true; - - MaxLength = -1; - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - var size = base.GetNaturalSize(availableSize); - size.Width = Math.Max(100, size.Height); - return size; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TextControl.TextChangedEvent: - Control.Changed += HandleTextChanged; - break; - default: - base.AttachEvent(id); - break; - } - } - - static void HandleTextChanged (object sender, EventArgs e) - { - var h = GetHandler(sender) as TextBoxHandler; - h.Widget.OnTextChanged(EventArgs.Empty); - } - - public bool ReadOnly - { - get { return !Control.Editable; } - set { Control.Editable = !value; } - } - - public int MaxLength - { - get; - set; - } - - public string PlaceholderText - { - get { return ((NSTextFieldCell)Control.Cell).PlaceholderString; } - set { ((NSTextFieldCell)Control.Cell).PlaceholderString = value ?? string.Empty; } - } - - public void SelectAll() - { - Control.SelectText(Control); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Controls/TreeGridViewHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/TreeGridViewHandler.cs deleted file mode 100644 index f4961cfaf8..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/TreeGridViewHandler.cs +++ /dev/null @@ -1,417 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using System.Collections.Generic; -using System.Linq; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class TreeGridViewHandler : GridHandler, ITreeGridView, IDataViewHandler - { - ITreeGridStore store; - readonly Dictionary cachedItems = new Dictionary (); - readonly Dictionary topitems = new Dictionary (); - - class EtoTreeItem : NSObject - { - Dictionary items; - - public EtoTreeItem () - { - } - - public EtoTreeItem (IntPtr ptr) - : base(ptr) - { - } - - public EtoTreeItem (EtoTreeItem value) - { - this.Item = value.Item; - this.items = value.items; - } - - public ITreeGridItem Item { get; set; } - - public Dictionary Items { - get { - if (items == null) - items = new Dictionary (); - return items; - } - } - } - - bool ChildIsSelected (ITreeGridItem item) - { - var node = SelectedItem; - - while (node != null) { - if (node == item) - return true; - node = node.Parent; - } - return false; - } - - class EtoOutlineDelegate : NSOutlineViewDelegate - { - WeakReference handler; - public TreeGridViewHandler Handler { get { return (TreeGridViewHandler)handler.Target; } set { handler = new WeakReference(value); } } - - bool? collapsedItemIsSelected; - ITreeGridItem lastSelected; - bool skipSelectionChanged; - - public override void SelectionDidChange (NSNotification notification) - { - if (!skipSelectionChanged) { - Handler.Widget.OnSelectionChanged (EventArgs.Empty); - var item = Handler.SelectedItem; - if (!object.ReferenceEquals (item, lastSelected)) { - Handler.Widget.OnSelectedItemChanged (EventArgs.Empty); - lastSelected = item; - } - } - } - - public override void ItemDidCollapse (NSNotification notification) - { - var myitem = notification.UserInfo [(NSString)"NSObject"] as EtoTreeItem; - if (myitem != null) { - myitem.Item.Expanded = false; - Handler.Widget.OnCollapsed (new TreeGridViewItemEventArgs (myitem.Item)); - if (collapsedItemIsSelected == true) { - Handler.SelectedItem = myitem.Item; - collapsedItemIsSelected = null; - skipSelectionChanged = false; - } - } - } - - public override bool ShouldExpandItem (NSOutlineView outlineView, NSObject item) - { - var myitem = item as EtoTreeItem; - if (myitem != null) { - var args = new TreeGridViewItemCancelEventArgs (myitem.Item); - Handler.Widget.OnExpanding (args); - return !args.Cancel; - } - return true; - } - - public override bool ShouldCollapseItem (NSOutlineView outlineView, NSObject item) - { - var myitem = item as EtoTreeItem; - if (myitem != null) { - var args = new TreeGridViewItemCancelEventArgs (myitem.Item); - Handler.Widget.OnCollapsing (args); - if (!args.Cancel && !Handler.AllowMultipleSelection) { - collapsedItemIsSelected = Handler.ChildIsSelected (myitem.Item); - skipSelectionChanged = collapsedItemIsSelected ?? false; - } - else - collapsedItemIsSelected = null; - return !args.Cancel; - } - collapsedItemIsSelected = null; - return true; - } - - public override void ItemDidExpand (NSNotification notification) - { - var myitem = notification.UserInfo [(NSString)"NSObject"] as EtoTreeItem; - if (myitem != null) { - myitem.Item.Expanded = true; - Handler.Widget.OnExpanded (new TreeGridViewItemEventArgs (myitem.Item)); - Handler.UpdateColumnSizes(); - } - } - - public override void DidClickTableColumn (NSOutlineView outlineView, NSTableColumn tableColumn) - { - var column = Handler.GetColumn (tableColumn); - Handler.Widget.OnColumnHeaderClick (new GridColumnEventArgs (column.Widget)); - } - - public override void WillDisplayCell (NSOutlineView outlineView, NSObject cell, NSTableColumn tableColumn, NSObject item) - { - var colHandler = Handler.GetColumn (tableColumn); - var myitem = item as EtoTreeItem; - if (myitem != null) { - Handler.OnCellFormatting(colHandler.Widget, myitem.Item, -1, cell as NSCell); - } - } - } - - class EtoDataSource : NSOutlineViewDataSource - { - WeakReference handler; - public TreeGridViewHandler Handler { get { return (TreeGridViewHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override NSObject GetObjectValue (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) - { - var colHandler = Handler.GetColumn (tableColumn); - if (colHandler != null) { - var myitem = (EtoTreeItem)item; - return colHandler.GetObjectValue (myitem.Item); - } - return null; - } - - public override void SetObjectValue (NSOutlineView outlineView, NSObject theObject, NSTableColumn tableColumn, NSObject item) - { - var colHandler = Handler.GetColumn (tableColumn); - if (colHandler != null) { - var myitem = (EtoTreeItem)item; - colHandler.SetObjectValue (myitem.Item, theObject); - } - } - - public override bool ItemExpandable (NSOutlineView outlineView, NSObject item) - { - var myitem = item as EtoTreeItem; - return myitem != null && myitem.Item.Expandable; - } - - public override NSObject GetChild (NSOutlineView outlineView, int childIndex, NSObject item) - { - Dictionary items; - var myitem = item as EtoTreeItem; - items = myitem == null ? Handler.topitems : myitem.Items; - - EtoTreeItem etoItem; - if (!items.TryGetValue (childIndex, out etoItem)) { - var parentItem = myitem != null ? (ITreeGridStore)myitem.Item : Handler.store; - etoItem = new EtoTreeItem{ Item = parentItem [childIndex] }; - Handler.cachedItems.Add (etoItem.Item, etoItem); - items.Add (childIndex, etoItem); - } - return etoItem; - } - - public override int GetChildrenCount (NSOutlineView outlineView, NSObject item) - { - if (Handler.store == null) - return 0; - - if (item == null) - return Handler.store.Count; - - var myitem = item as EtoTreeItem; - return ((ITreeGridStore)myitem.Item).Count; - } - } - - public class EtoOutlineView : NSOutlineView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public object Handler - { - get { return WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - } - - public override object EventObject { - get { return Control; } - } - - public override void AttachEvent (string id) - { - switch (id) { - case TreeGridView.ExpandedEvent: - case TreeGridView.ExpandingEvent: - case TreeGridView.CollapsedEvent: - case TreeGridView.CollapsingEvent: - case TreeGridView.SelectedItemChangedEvent: - case Grid.SelectionChangedEvent: - case Grid.ColumnHeaderClickEvent: - // handled in delegate - break; - default: - base.AttachEvent (id); - break; - } - } - - protected override void Initialize () - { - Control = new EtoOutlineView { - Handler = this, - Delegate = new EtoOutlineDelegate{ Handler = this }, - DataSource = new EtoDataSource{ Handler = this }, - //HeaderView = null, - //AutoresizesOutlineColumn = true, - //AllowsColumnResizing = false, - AllowsColumnReordering = false, - FocusRingType = NSFocusRingType.None, - ColumnAutoresizingStyle = NSTableViewColumnAutoresizingStyle.None - }; - - base.Initialize (); - } - - public ITreeGridStore DataStore { - get { return store; } - set { - store = value; - topitems.Clear (); - cachedItems.Clear (); - Control.ReloadData (); - ExpandItems (null); - if (Widget.Loaded) - ResizeAllColumns (); - } - } - - static IEnumerable GetParents (ITreeGridItem item) - { - var parent = item.Parent; - while (parent != null) { - yield return parent; - parent = parent.Parent; - } - } - - EtoTreeItem GetCachedItem (ITreeGridItem item) - { - EtoTreeItem myitem; - return cachedItems.TryGetValue(item, out myitem) ? myitem : null; - } - - int CountRows (ITreeGridItem item) - { - if (!item.Expanded) - return 0; - - var rows = 0; - var container = item as IDataStore; - if (container != null) { - rows += container.Count; - for (int i = 0; i < container.Count; i++) - { - rows += CountRows (container[i]); - } - } - return rows; - } - - int FindRow (IDataStore container, ITreeGridItem item) - { - int row = 0; - for (int i = 0; i < container.Count; i++) { - var current = container [i]; - if (object.ReferenceEquals (current, item)) { - return row; - } - row ++; - row += CountRows (current); - } - return -1; - } - - int? ExpandToItem (ITreeGridItem item) - { - var parents = GetParents (item).Reverse (); - IDataStore lastParent = null; - var row = 0; - foreach (var parent in parents) { - if (lastParent != null) { - var foundRow = FindRow (lastParent, parent); - if (foundRow == -1) - return null; - row += foundRow; - var foundItem = Control.ItemAtRow (row) as EtoTreeItem; - if (foundItem == null) - return null; - Control.ExpandItem (foundItem); - foundItem.Item.Expanded = true; - row ++; - } - lastParent = parent as IDataStore; - } - if (lastParent != null) { - var foundRow = FindRow (lastParent, item); - if (foundRow == -1) - return null; - - return foundRow + row; - } - return null; - } - - public ITreeGridItem SelectedItem { - get { - var row = Control.SelectedRow; - if (row == -1) - return null; - var myitem = (EtoTreeItem)Control.ItemAtRow(row); - return myitem.Item; - } - set { - if (value == null) - Control.SelectRow (-1, false); - else { - - EtoTreeItem myitem; - if (cachedItems.TryGetValue (value, out myitem)) { - var cachedRow = Control.RowForItem (myitem); - if (cachedRow >= 0) { - Control.ScrollRowToVisible (cachedRow); - Control.SelectRow (cachedRow, false); - return; - } - } - - var row = ExpandToItem (value); - if (row != null) { - Control.ScrollRowToVisible (row.Value); - Control.SelectRow (row.Value, false); - } - } - } - } - - void ExpandItems (NSObject parent) - { - var ds = Control.DataSource; - var count = ds.GetChildrenCount (Control, parent); - for (int i=0; i 0) - Control.OutlineTableColumn = ((GridColumnHandler)Widget.Columns[0].Handler).Control; - } - else if (Widget.Columns.Count == 0) - Control.OutlineTableColumn = null; - } - - public override object GetItem (int row) - { - var item = Control.ItemAtRow(row) as EtoTreeItem; - return item != null ? item.Item : null; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/TreeViewHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/TreeViewHandler.cs deleted file mode 100644 index cf9dd0336e..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/TreeViewHandler.cs +++ /dev/null @@ -1,596 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using System.Collections.Generic; -using Eto.Platform.Mac.Forms.Menu; -using System.Linq; -using sd = System.Drawing; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class TreeViewHandler : MacControl, ITreeView - { - ITreeStore top; - ContextMenu contextMenu; - readonly Dictionary cachedItems = new Dictionary(); - readonly Dictionary topitems = new Dictionary(); - bool selectionChanging; - bool raiseExpandEvents = true; - readonly NSTableColumn column; - - public NSScrollView Scroll { get; private set; } - - public class EtoTreeItem : MacImageData - { - Dictionary items; - ITreeItem item; - - public EtoTreeItem() - { - } - - public EtoTreeItem(IntPtr ptr) - : base(ptr) - { - } - - public EtoTreeItem(EtoTreeItem value) - : base (value) - { - this.Item = value.Item; - this.items = value.items; - } - - public ITreeItem Item - { - get { return item; } - set - { - item = value; - if (item.Image != null) - Image = Item.Image.ControlObject as NSImage; - Text = (NSString)item.Text; - } - } - - public Dictionary Items - { - get - { - if (items == null) - items = new Dictionary(); - return items; - } - } - - public override object Clone() - { - return new EtoTreeItem(this); - } - } - - public class EtoOutlineDelegate : NSOutlineViewDelegate - { - WeakReference handler; - public TreeViewHandler Handler { get { return (TreeViewHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override bool ShouldEditTableColumn(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) - { - var myitem = item as EtoTreeItem; - if (myitem != null) - { - var args = new TreeViewItemCancelEventArgs(myitem.Item); - Handler.Widget.OnLabelEditing(args); - return !args.Cancel; - } - return true; - } - - public override void WillDisplayCell(NSOutlineView outlineView, NSObject cell, NSTableColumn tableColumn, NSObject item) - { - var c = cell as NSTextFieldCell; - if (c != null && - Handler.textColor != null) - c.TextColor = Handler.textColor.Value.ToNSUI(); - } - - public override void SelectionDidChange(NSNotification notification) - { - if (!Handler.selectionChanging) - Handler.Widget.OnSelectionChanged(EventArgs.Empty); - } - - public override void ItemDidCollapse(NSNotification notification) - { - if (Handler.raiseExpandEvents) - { - var myitem = notification.UserInfo[(NSString)"NSObject"] as EtoTreeItem; - if (myitem != null && myitem.Item.Expanded) - { - myitem.Item.Expanded = false; - Handler.Widget.OnCollapsed(new TreeViewItemEventArgs(myitem.Item)); - } - } - } - - public override bool ShouldExpandItem(NSOutlineView outlineView, NSObject item) - { - if (Handler.raiseExpandEvents) - { - var myitem = item as EtoTreeItem; - if (myitem != null && !myitem.Item.Expanded) - { - var args = new TreeViewItemCancelEventArgs(myitem.Item); - Handler.Widget.OnExpanding(args); - return !args.Cancel; - } - } - return true; - } - - public override bool ShouldCollapseItem(NSOutlineView outlineView, NSObject item) - { - if (Handler.raiseExpandEvents) - { - var myitem = item as EtoTreeItem; - if (myitem != null && myitem.Item.Expanded) - { - var args = new TreeViewItemCancelEventArgs(myitem.Item); - Handler.Widget.OnCollapsing(args); - return !args.Cancel; - } - } - return true; - } - - public override void ItemDidExpand(NSNotification notification) - { - if (Handler.raiseExpandEvents) - { - var myitem = notification.UserInfo[(NSString)"NSObject"] as EtoTreeItem; - if (myitem != null && !myitem.Item.Expanded) - { - myitem.Item.Expanded = true; - Handler.Widget.OnExpanded(new TreeViewItemEventArgs(myitem.Item)); - Handler.ExpandItems(myitem); - } - } - } - } - - public class EtoDataSource : NSOutlineViewDataSource - { - WeakReference handler; - public TreeViewHandler Handler { get { return (TreeViewHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override NSObject GetObjectValue(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) - { - var myitem = item as EtoTreeItem; - return myitem; - } - - public override bool ItemExpandable(NSOutlineView outlineView, NSObject item) - { - var myitem = item as EtoTreeItem; - return myitem != null && myitem.Item.Expandable; - } - - public override NSObject GetChild(NSOutlineView outlineView, int childIndex, NSObject item) - { - Dictionary items; - var myitem = item as EtoTreeItem; - items = myitem == null ? Handler.topitems : myitem.Items; - - EtoTreeItem etoItem; - if (!items.TryGetValue(childIndex, out etoItem)) - { - var parentItem = myitem != null ? myitem.Item : Handler.top; - etoItem = new EtoTreeItem { Item = parentItem [childIndex] }; - Handler.cachedItems[etoItem.Item] = etoItem; - items[childIndex] = etoItem; - } - return etoItem; - } - - public override int GetChildrenCount(NSOutlineView outlineView, NSObject item) - { - if (Handler.top == null) - return 0; - - if (item == null) - return Handler.top.Count; - - var myitem = item as EtoTreeItem; - return myitem.Item.Count; - } - - public override void SetObjectValue(NSOutlineView outlineView, NSObject theObject, NSTableColumn tableColumn, NSObject item) - { - var myitem = item as EtoTreeItem; - if (myitem != null) - { - var args = new TreeViewItemEditEventArgs(myitem.Item, (string)(NSString)theObject); - Handler.Widget.OnLabelEdited(args); - if (!args.Cancel) - myitem.Item.Text = args.Label; - } - } - } - - public class EtoOutlineView : NSOutlineView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public TreeViewHandler Handler - { - get { return (TreeViewHandler)WeakHandler.Target; } - set { WeakHandler = new WeakReference(value); } - } - - /// - /// The area to the right and below the rows is not filled with the background - /// color. This fixes that. See http://orangejuiceliberationfront.com/themeing-nstableview/ - /// - public override void DrawBackground(sd.RectangleF clipRect) - { - var backgroundColor = Handler.BackgroundColor; - if (backgroundColor != Colors.Transparent) { - backgroundColor.ToNSUI ().Set (); - NSGraphics.RectFill (clipRect); - } else - base.DrawBackground (clipRect); - } - } - - public override NSView ContainerControl - { - get { return Scroll; } - } - - public TreeViewHandler() - { - Control = new EtoOutlineView - { - Handler = this, - Delegate = new EtoOutlineDelegate{ Handler = this }, - DataSource = new EtoDataSource{ Handler = this }, - HeaderView = null, - AutoresizesOutlineColumn = true, - AllowsColumnResizing = false, - FocusRingType = NSFocusRingType.None, - ColumnAutoresizingStyle = NSTableViewColumnAutoresizingStyle.FirstColumnOnly - }; - column = new NSTableColumn - { - DataCell = new MacImageListItemCell { - UsesSingleLineMode = true, - Editable = true - }, - Editable = false - }; - - - Control.AddColumn(column); - Control.OutlineTableColumn = column; - - Scroll = new EtoScrollView - { - Handler = this, - HasVerticalScroller = true, - HasHorizontalScroller = true, - AutohidesScrollers = true, - BorderType = NSBorderType.BezelBorder, - DocumentView = Control - }; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TreeView.ExpandedEvent: - case TreeView.ExpandingEvent: - case TreeView.CollapsedEvent: - case TreeView.CollapsingEvent: - case TreeView.SelectionChangedEvent: - // handled in delegate - break; - case TreeView.ActivatedEvent: - Widget.KeyDown += (sender, e) => { - if (!column.Editable && e.KeyData == Keys.Enter) - { - Widget.OnActivated(new TreeViewItemEventArgs(SelectedItem)); - } - }; - Control.DoubleClick += HandleDoubleClick; - break; - case TreeView.LabelEditedEvent: - case TreeView.LabelEditingEvent: - // handled in delegate - break; - case TreeView.NodeMouseClickEvent: - /* TODO */ - // Control.NodeMouseClick += (s, e) => - // { - // this.Widget.OnNodeMouseClick( - // Generator.Convert(e)); - // }; - break; - - default: - base.AttachEvent(id); - break; - } - } - - static void HandleDoubleClick (object sender, EventArgs e) - { - var handler = GetHandler(sender) as TreeViewHandler; - if (handler != null) - { - if (handler.column.Editable) - handler.Control.EditColumn(handler.Control.ClickedColumn, handler.Control.ClickedRow, new NSEvent(), true); - else - handler.Widget.OnActivated(new TreeViewItemEventArgs(handler.SelectedItem)); - } - } - - public ITreeStore DataStore - { - get { return top; } - set - { - top = value; - topitems.Clear(); - cachedItems.Clear(); - Control.ReloadData(); - ExpandItems(null); - } - } - - public ITreeItem SelectedItem - { - get - { - var row = Control.SelectedRow; - if (row == -1) - return null; - var myitem = Control.ItemAtRow(row) as EtoTreeItem; - return myitem == null ? null : myitem.Item; - } - set - { - PerformSelect(value, true); - } - } - - void PerformSelect(ITreeItem item, bool scrollToRow) - { - if (item == null) - Control.SelectRow(-1, false); - else - { - - EtoTreeItem myitem; - if (cachedItems.TryGetValue(item, out myitem)) - { - var cachedRow = Control.RowForItem(myitem); - if (cachedRow >= 0) - { - if (scrollToRow) - Control.ScrollRowToVisible(cachedRow); - Control.SelectRow(cachedRow, false); - return; - } - } - - var row = ExpandToItem(item); - if (row != null) - { - if (scrollToRow) - Control.ScrollRowToVisible(row.Value); - Control.SelectRow(row.Value, false); - } - } - } - - public ContextMenu ContextMenu - { - get { return contextMenu; } - set - { - contextMenu = value; - Control.Menu = contextMenu == null ? null : ((ContextMenuHandler)contextMenu.Handler).Control; - } - } - - static IEnumerable GetParents(ITreeItem item) - { - var parent = item.Parent; - while (parent != null) - { - yield return parent; - parent = parent.Parent; - } - } - - int CountRows(ITreeItem item) - { - if (!item.Expanded) - return 0; - - var rows = 0; - var container = item; - if (container != null) - { - rows += container.Count; - for (int i = 0; i < container.Count; i++) - { - rows += CountRows(container[i]); - } - } - return rows; - } - - int FindRow(IDataStore container, ITreeItem item) - { - int row = 0; - for (int i = 0; i < container.Count; i++) - { - var current = container[i]; - if (object.ReferenceEquals(current, item)) - { - return row; - } - row ++; - row += CountRows(current); - } - return -1; - } - - int? ExpandToItem(ITreeItem item) - { - var parents = GetParents(item).Reverse(); - IDataStore lastParent = null; - var row = 0; - foreach (var parent in parents) - { - if (lastParent != null) - { - var foundRow = FindRow(lastParent, parent); - if (foundRow == -1) - return null; - row += foundRow; - var foundItem = Control.ItemAtRow(row) as EtoTreeItem; - if (foundItem == null) - return null; - Control.ExpandItem(foundItem); - foundItem.Item.Expanded = true; - row ++; - } - lastParent = parent; - } - if (lastParent != null) - { - var foundRow = FindRow(lastParent, item); - if (foundRow == -1) - return null; - - return foundRow + row; - } - return null; - } - - void SetItemExpansion(NSObject parent) - { - raiseExpandEvents = false; - var item = parent as EtoTreeItem; - if (item != null && item.Item.Expandable && item.Item.Expanded != Control.IsItemExpanded(item)) - { - if (item.Item.Expanded) - Control.ExpandItem(item); - else - Control.CollapseItem(item, false); - } - raiseExpandEvents = true; - } - - void ExpandItems(NSObject parent) - { - raiseExpandEvents = false; - var item = parent as EtoTreeItem; - PerformExpandItems(item); - raiseExpandEvents = true; - } - - void PerformExpandItems(NSObject parent) - { - var ds = Control.DataSource; - var count = ds.GetChildrenCount(Control, parent); - for (int i=0; i= 0) - topitems.Remove(row); - myitem.Items.Clear(); - SetItemExpansion(myitem); - Control.ReloadItem(myitem, true); - ExpandItems(myitem); - } - else - RefreshData(); - } - - public ITreeItem GetNodeAt(PointF point) - { - var row = Control.GetRow(point.ToSD()); - if (row >= 0) - { - var item = Control.ItemAtRow(row) as EtoTreeItem; - if (item != null) - return item.Item; - } - return null; - } - - Color? textColor; - public Color TextColor - { - get { return textColor ?? Colors.Transparent; } - set { textColor = value; } - } - - public bool LabelEdit - { - get { return column.Editable; } - set { column.Editable = value; } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Controls/WebViewHandler.cs b/Source/Eto.Platform.Mac/Forms/Controls/WebViewHandler.cs deleted file mode 100644 index dce65a3dae..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Controls/WebViewHandler.cs +++ /dev/null @@ -1,334 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using System.Linq; -using Eto.Drawing; -using wk = MonoMac.WebKit; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Controls -{ - public class WebViewHandler : MacView, IWebView - { - static readonly Selector selIgnore = new Selector("ignore"); - static readonly Selector selUse = new Selector("use"); - - public override NSView ContainerControl { get { return Control; } } - - NewWindowHandler newWindowHandler; - - public WebViewHandler() - { - Enabled = true; - Control = new EtoWebView - { - Handler = this, - UIDelegate = new UIDelegate { Handler = this } - }; - } - - protected override void Initialize() - { - base.Initialize(); - HandleEvent(WebView.OpenNewWindowEvent); // needed to provide default implementation - HandleEvent(WebView.DocumentLoadingEvent); - } - - public class EtoWebView : wk.WebView, IMacControl - { - public WeakReference WeakHandler { get; set; } - - public WebViewHandler Handler { get { return (WebViewHandler)WeakHandler.Target; } set { WeakHandler = new WeakReference(value); } } - } - - public class NewWindowHandler : NSObject - { - public WebViewHandler Handler { get { return WebView.Handler; } set { WebView.Handler = value; } } - - public EtoWebView WebView { get; set; } - - public NewWindowHandler() - { - WebView = new EtoWebView(); - WebView.WeakUIDelegate = this; - WebView.WeakPolicyDelegate = this; - WebView.WeakResourceLoadDelegate = this; - } - - [Export("webView:decidePolicyForNavigationAction:request:frame:decisionListener:")] - public void DecidePolicyForNavigation(wk.WebView webView, NSDictionary action, NSUrlRequest request, wk.WebFrame frame, NSObject listener) - { - var url = (NSUrl)action.ObjectForKey(new NSString("WebActionOriginalURLKey")); - var args = new WebViewNewWindowEventArgs(new Uri(url.AbsoluteString), frame.Name); - Handler.Widget.OnOpenNewWindow(args); - if (!args.Cancel) - NSWorkspace.SharedWorkspace.OpenUrl(url); - listener.PerformSelector(selIgnore, null, 0); - } - } - - class PromptDialog : Dialog - { - readonly TextBox textBox; - readonly Label prompt; - - public string Prompt - { - get { return prompt.Text; } - set { prompt.Text = value; } - } - - public string Value - { - get { return textBox.Text; } - set { textBox.Text = value; } - } - - public PromptDialog(Eto.Generator generator) - : base(generator) - { - this.MinimumSize = new Size(400, 0); - var layout = new DynamicLayout(padding: new Padding(20, 10)); - layout.BeginVertical(padding: Padding.Empty, spacing: new Size(10, 10)); - layout.Add(prompt = new Label()); - layout.Add(textBox = new TextBox(), yscale: true); - layout.BeginVertical(padding: Padding.Empty); - layout.AddRow(null, CancelButton(), OkButton()); - layout.EndVertical(); - - Content = layout; - } - - Control CancelButton() - { - var button = new Button { Text = "Cancel" }; - AbortButton = button; - button.Click += (sender, e) => Close(DialogResult.Cancel); - return button; - } - - Control OkButton() - { - var button = new Button { Text = "OK" }; - DefaultButton = button; - button.Click += (sender, e) => Close(DialogResult.Ok); - return button; - } - } - - public class UIDelegate : wk.WebUIDelegate - { - WeakReference handler; - - public WebViewHandler Handler { get { return (WebViewHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override void UIRunJavaScriptAlertPanelMessage(wk.WebView sender, string withMessage, wk.WebFrame initiatedByFrame) - { - MessageBox.Show(Handler.Widget, withMessage); - } - - public override bool UIRunJavaScriptConfirmationPanel(wk.WebView sender, string withMessage, wk.WebFrame initiatedByFrame) - { - return MessageBox.Show(Handler.Widget, withMessage, MessageBoxButtons.YesNo) == DialogResult.Yes; - } - - public override string UIRunJavaScriptTextInputPanelWithFrame(wk.WebView sender, string prompt, string defaultText, wk.WebFrame initiatedByFrame) - { - var dialog = new PromptDialog(Handler.Widget.Generator) - { - Prompt = prompt, - Value = defaultText, - Title = Handler.DocumentTitle - }; - var result = dialog.ShowDialog(Handler.Widget); - return (result == DialogResult.Ok) ? dialog.Value : string.Empty; - } - - public override NSMenuItem[] UIGetContextMenuItems(wk.WebView sender, NSDictionary forElement, NSMenuItem[] defaultMenuItems) - { - return Handler.BrowserContextMenuEnabled ? defaultMenuItems : null; - } - - public override void UIRunOpenPanelForFileButton(wk.WebView sender, wk.WebOpenPanelResultListener resultListener) - { - var openDlg = new OpenFileDialog(); - if (openDlg.ShowDialog(Handler.Widget.ParentWindow) == DialogResult.Ok) - { - resultListener.ChooseFilenames(openDlg.Filenames.ToArray()); - } - } - - public override void UIPrintFrameView(wk.WebView sender, wk.WebFrameView frameView) - { - const float margin = 24f; - var printOperation = frameView.GetPrintOperation(new NSPrintInfo - { - VerticallyCentered = false, - LeftMargin = margin, - RightMargin = margin, - TopMargin = margin, - BottomMargin = margin - }); - printOperation.PrintPanel.Options = - NSPrintPanelOptions.ShowsCopies | - NSPrintPanelOptions.ShowsOrientation | - NSPrintPanelOptions.ShowsPageSetupAccessory | - NSPrintPanelOptions.ShowsPageRange | - NSPrintPanelOptions.ShowsPaperSize | - NSPrintPanelOptions.ShowsPreview | - NSPrintPanelOptions.ShowsPrintSelection | - NSPrintPanelOptions.ShowsScaling; - printOperation.RunOperation(); - } - - public override wk.WebView UICreateWebView(wk.WebView sender, NSUrlRequest request) - { - Handler.newWindowHandler = new NewWindowHandler { Handler = Handler }; - return Handler.newWindowHandler.WebView; - } - } - - public override void AttachEvent(string id) - { - switch (id) - { - case WebView.NavigatedEvent: - HandleEvent(WebView.DocumentLoadedEvent); - break; - case WebView.DocumentLoadedEvent: - Control.FinishedLoad += HandleFinishedLoad; - break; - case WebView.DocumentLoadingEvent: - Control.DecidePolicyForNavigation += HandleDecidePolicyForNavigation; - break; - case WebView.OpenNewWindowEvent: - Control.DecidePolicyForNewWindow += HandleDecidePolicyForNewWindow; - break; - case WebView.DocumentTitleChangedEvent: - Control.ReceivedTitle += HandleReceivedTitle; - break; - default: - base.AttachEvent(id); - break; - } - } - - static void HandleReceivedTitle(object sender, wk.WebFrameTitleEventArgs e) - { - var handler = GetHandler(e.ForFrame.WebView) as WebViewHandler; - if (handler != null) - { - handler.Widget.OnDocumentTitleChanged(new WebViewTitleEventArgs(e.Title)); - } - } - - static void HandleDecidePolicyForNewWindow(object sender, wk.WebNewWindowPolicyEventArgs e) - { - var handler = GetHandler(sender) as WebViewHandler; - if (handler != null) - { - var args = new WebViewNewWindowEventArgs(new Uri(e.Request.Url.AbsoluteString), e.NewFrameName); - handler.Widget.OnOpenNewWindow(args); - if (!args.Cancel) - NSWorkspace.SharedWorkspace.OpenUrl(e.Request.Url); - e.DecisionToken.PerformSelector(selIgnore, null, 0); - } - } - - static void HandleDecidePolicyForNavigation(object sender, wk.WebNavigationPolicyEventArgs e) - { - var handler = GetHandler(e.Frame.WebView) as WebViewHandler; - if (handler != null) - { - var args = new WebViewLoadingEventArgs(new Uri(e.Request.Url.AbsoluteString), e.Frame == handler.Control.MainFrame); - handler.Widget.OnDocumentLoading(args); - if (args.Cancel) - e.DecisionToken.PerformSelector(selIgnore, null, 0); - else - e.DecisionToken.PerformSelector(selUse, null, 0); - } - } - - static void HandleFinishedLoad(object sender, wk.WebFrameEventArgs e) - { - var handler = GetHandler(e.ForFrame.WebView) as WebViewHandler; - if (handler != null) - { - var args = new WebViewLoadedEventArgs(handler.Url); - if (e.ForFrame == handler.Control.MainFrame) - handler.Widget.OnNavigated(args); - handler.Widget.OnDocumentLoaded(args); - } - } - - public Uri Url - { - get { return new Uri(Control.MainFrameUrl); } - set - { - Control.MainFrameUrl = value == null ? null : value.AbsoluteUri; - } - } - - public string DocumentTitle - { - get { return Control.MainFrameTitle; } - } - - public string ExecuteScript(string script) - { - var fullScript = string.Format("var fn = function () {{ {0} }}; fn();", script); - return Control.StringByEvaluatingJavaScriptFromString(fullScript); - } - - public void LoadHtml(string html, Uri baseUri) - { - Control.MainFrame.LoadHtmlString(html, baseUri.ToNS()); - } - - public void Stop() - { - Control.MainFrame.StopLoading(); - } - - public void Reload() - { - Control.Reload(Control); - } - - public void GoBack() - { - Control.GoBack(); - } - - public void GoForward() - { - Control.GoForward(); - } - - public override bool Enabled { get; set; } - - public bool CanGoBack - { - get { return Control.CanGoBack(); } - } - - public bool CanGoForward - { - get { return Control.CanGoForward(); } - } - - public void ShowPrintDialog() - { - Control.Print(Control); - } - - public bool BrowserContextMenuEnabled - { - get; - set; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/CursorHandler.cs b/Source/Eto.Platform.Mac/Forms/CursorHandler.cs deleted file mode 100644 index 4fea5cb9e9..0000000000 --- a/Source/Eto.Platform.Mac/Forms/CursorHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; - -namespace Eto.Platform.Mac.Forms -{ - public class CursorHandler : WidgetHandler, ICursor - { - public void Create (CursorType cursor) - { - switch (cursor) { - case CursorType.Arrow: - Control = NSCursor.ArrowCursor; - break; - case CursorType.Crosshair: - Control = NSCursor.CrosshairCursor; - break; - case CursorType.Default: - Control = NSCursor.CurrentSystemCursor; - break; - case CursorType.HorizontalSplit: - Control = NSCursor.ResizeLeftRightCursor; - break; - case CursorType.IBeam: - Control = NSCursor.IBeamCursor; - break; - case CursorType.Move: - Control = NSCursor.OpenHandCursor; - break; - case CursorType.Pointer: - Control = NSCursor.PointingHandCursor; - break; - case CursorType.VerticalSplit: - Control = NSCursor.ResizeUpDownCursor; - break; - default: - throw new NotSupportedException(); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/DialogHandler.cs b/Source/Eto.Platform.Mac/Forms/DialogHandler.cs deleted file mode 100644 index a8395bde96..0000000000 --- a/Source/Eto.Platform.Mac/Forms/DialogHandler.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using SD = System.Drawing; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; - -namespace Eto.Platform.Mac.Forms -{ - public class DialogHandler : MacWindow, IDialog - { - Button button; - MacModal.ModalHelper session; - - protected override bool DisposeControl { get { return false; } } - - class DialogWindow : MyWindow { - public new DialogHandler Handler - { - get { return base.Handler as DialogHandler; } - set { base.Handler = value; } - } - - public DialogWindow() - : base(new SD.Rectangle(0,0,200,200), NSWindowStyle.Closable | NSWindowStyle.Titled, NSBackingStore.Buffered, false) - { - } - - [Export("cancelOperation:")] - public void CancelOperation(IntPtr sender) - { - if (Handler.AbortButton != null) - Handler.AbortButton.OnClick (EventArgs.Empty); - } - } - - public DialogDisplayMode DisplayMode { get; set; } - - public Button AbortButton { get; set; } - - public Button DefaultButton - { - get { return button; } - set - { - button = value; - - if (button != null) { - var b = button.ControlObject as NSButton; - Control.DefaultButtonCell = b == null ? null : b.Cell; - } - else - Control.DefaultButtonCell = null; - } - } - - public DialogHandler () - { - var dlg = new DialogWindow(); - dlg.Handler = this; - Control = dlg; - ConfigureWindow (); - } - - public DialogResult ShowDialog (Control parent) - { - if (parent != null && parent.ParentWindow != null) { - var nswindow = parent.ParentWindow.ControlObject as NSWindow; - if (nswindow != null) - Control.ParentWindow = nswindow; - } - Control.MakeKeyWindow (); - Widget.OnShown (EventArgs.Empty); - - Widget.Closed += HandleClosed; - switch (DisplayMode) { - case DialogDisplayMode.Attached: - MacModal.RunSheet (Control, out session); - break; - default: - MacModal.Run (Control, out session); - break; - } - return Widget.DialogResult; - } - - void HandleClosed (object sender, EventArgs e) - { - if (session != null) - session.Stop (); - Widget.Closed -= HandleClosed; - } - - public override void Close () - { - if (session != null && session.IsSheet) { - session.Stop (); - } - else - base.Close (); - } - - } -} diff --git a/Source/Eto.Platform.Mac/Forms/FontDialogHandler.cs b/Source/Eto.Platform.Mac/Forms/FontDialogHandler.cs deleted file mode 100644 index b85d088a99..0000000000 --- a/Source/Eto.Platform.Mac/Forms/FontDialogHandler.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.ObjCRuntime; -using Eto.Drawing; -using MonoMac.Foundation; -using Eto.Platform.Mac.Drawing; - -namespace Eto.Platform.Mac.Forms -{ - class FontDialogHelper : NSWindowDelegate - { - public static FontDialogHelper Instance { get; set; } - - public FontDialogHandler Handler { get; set; } - - [Export("changeFont:")] - public void ChangeFont(NSFontManager sender) - { - var font = sender.ConvertFont(NSFont.SystemFontOfSize(NSFont.SystemFontSize)); - Handler.Font = font != null ? new Font(Handler.Widget.Generator, new FontHandler(font)) : null; - Handler.Widget.OnFontChanged(EventArgs.Empty); - } - - public override void WillClose(NSNotification notification) - { - Handler.Manager.Target = null; - Handler.Manager.Action = null; - FontDialogHelper.Instance = null; - } - - public override void DidResignKey(NSNotification notification) - { - Handler.Control.PerformClose(this); - } - - [Export("changeAttributes:")] - void ChangeAttributes(NSObject sender) - { - } - - [Export("validModesForFontPanel:")] - NSFontPanelMode ValidModesForFontPanel(NSFontPanel fontPanel) - { - return NSFontPanelMode.SizeMask | NSFontPanelMode.FaceMask | NSFontPanelMode.CollectionMask; - } - - [Export("modalClosed:")] - public void ModalClosed(NSNotification notification) - { - Handler.Control.PerformClose(this); - NSNotificationCenter.DefaultCenter.RemoveObserver(this); - } - } - - public class FontDialogHandler : MacObject, IFontDialog - { - public NSFontManager Manager - { - get { return NSFontManager.SharedFontManager; } - } - - public FontDialogHandler() - { - Control = NSFontPanel.SharedFontPanel; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case FontDialog.FontChangedEvent: - // handled by helper - break; - default: - base.AttachEvent(id); - break; - } - } - - public DialogResult ShowDialog(Window parent) - { - NSWindow parentWindow; - if (parent != null) - { - parentWindow = parent.ParentWindow.ControlObject as NSWindow ?? NSApplication.SharedApplication.KeyWindow; - if (parentWindow != null) - Control.ParentWindow = parentWindow; - } - else - parentWindow = NSApplication.SharedApplication.KeyWindow; - - FontDialogHelper.Instance = new FontDialogHelper { Handler = this }; - - Manager.Target = null; - Manager.Action = null; - if (Font != null) - { - var fontHandler = (FontHandler)Font.Handler; - Manager.SetSelectedFont(fontHandler.Control, false); - } - else - Manager.SetSelectedFont(NSFont.SystemFontOfSize(NSFont.SystemFontSize), false); - - Control.Delegate = FontDialogHelper.Instance; - Manager.Target = FontDialogHelper.Instance; - Manager.Action = new Selector("changeFont:"); - - if (parentWindow != null) - { - if (parentWindow == NSApplication.SharedApplication.ModalWindow) - { - NSNotificationCenter.DefaultCenter.AddObserver(FontDialogHelper.Instance, new Selector("modalClosed:"), new NSString("NSWindowWillCloseNotification"), parentWindow); - } - } - - Manager.OrderFrontFontPanel(parentWindow); - //if (isModal) Control.MakeKeyWindow(); - Control.MakeKeyAndOrderFront(parentWindow); - - return DialogResult.None; // signal that we are returning right away! - } - - public Font Font - { - get; - set; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/FormHandler.cs b/Source/Eto.Platform.Mac/Forms/FormHandler.cs deleted file mode 100644 index bd27a1b715..0000000000 --- a/Source/Eto.Platform.Mac/Forms/FormHandler.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using SD = System.Drawing; - -namespace Eto.Platform.Mac.Forms -{ - public class FormHandler : MacWindow, IForm - { - protected override bool DisposeControl { get { return false; } } - - public FormHandler() - { - Control = new MyWindow(new SD.Rectangle(0, 0, 200, 200), - NSWindowStyle.Resizable | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled, - NSBackingStore.Buffered, false); - ConfigureWindow(); - } - - public void Show() - { - if (WindowState == WindowState.Minimized) - Control.MakeKeyWindow(); - else - Control.MakeKeyAndOrderFront(ApplicationHandler.Instance.AppDelegate); - if (!Control.IsVisible) - Widget.OnShown(EventArgs.Empty); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/MacCommon.cs b/Source/Eto.Platform.Mac/Forms/MacCommon.cs deleted file mode 100644 index 8e8b60b825..0000000000 --- a/Source/Eto.Platform.Mac/Forms/MacCommon.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using MonoMac.ObjCRuntime; -using MonoMac.Foundation; - -namespace Eto.Platform.Mac.Forms -{ - public static class MacCommon - { - public static IntPtr CopyWithZoneHandle = Selector.GetHandle("copyWithZone:"); - - public static IntPtr ReleaseHandle = Selector.GetHandle("release"); - - public static void SafeDispose(this NSObject obj) - { - if (obj != null) - { - var count = obj.RetainCount; - var handle = obj.Handle; - - obj.Dispose(); - // HACK: release handle since Dispose() won't do it properly yet - if (handle != IntPtr.Zero && ApplicationHandler.Instance != null && count > 2) - Messaging.void_objc_msgSend(handle, ReleaseHandle); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/MacContainer.cs b/Source/Eto.Platform.Mac/Forms/MacContainer.cs deleted file mode 100644 index 8afb9964a7..0000000000 --- a/Source/Eto.Platform.Mac/Forms/MacContainer.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using Eto.Forms; -using SD = System.Drawing; -using MonoMac.AppKit; -using System.Linq; -using Eto.Drawing; - -#if IOS -using NSResponder = MonoTouch.UIKit.UIResponder; -using Eto.Platform.iOS.Forms; -#endif - -namespace Eto.Platform.Mac.Forms -{ - public interface IMacContainer : IMacControlHandler - { - void SetContentSize(SD.SizeF contentSize); - - void LayoutParent(bool updateSize = true); - - void LayoutChildren(); - - void LayoutAllChildren(); - - bool InitialLayout { get; } - } - - public abstract class MacContainer : -#if OSX - MacView, -#elif IOS - IosView, -#endif - IContainer, IMacContainer - where TControl: NSResponder - where TWidget: Container - { - public bool RecurseToChildren { get { return true; } } - - public virtual Size ClientSize { get { return Size; } set { Size = value; } } - - public override bool Enabled { get; set; } - - public bool InitialLayout { get; private set; } - - protected override void Initialize() - { - base.Initialize(); - Enabled = true; - } - - public virtual void Update() - { - LayoutChildren(); - } - - public bool NeedsQueue(Action update = null) - { - #if DESKTOP - if (ApplicationHandler.QueueResizing) - { - ApplicationHandler.Instance.AsyncInvoke(update ?? Update); - return true; - } - #endif - return false; - } - - public virtual void SetContentSize(SD.SizeF contentSize) - { - } - - public virtual void LayoutChildren() - { - } - - public void LayoutAllChildren() - { - //Console.WriteLine("Layout all children: {0}\n {1}", this.GetType().Name, new StackTrace()); - LayoutChildren(); - foreach (var child in Widget.Controls.Select (r => r.GetMacContainer()).Where(r => r != null)) - { - child.LayoutAllChildren(); - } - } - - public override void OnLoad(EventArgs e) - { - base.OnLoad(e); - var parent = Widget.Parent.GetMacContainer(); - if (parent == null || parent.InitialLayout) - { - InitialLayout = true; - LayoutAllChildren(); - } - } - - public void LayoutParent(bool updateSize = true) - { - if (NeedsQueue(() => LayoutParent(updateSize))) - return; - var container = Widget.Parent.GetMacContainer(); - if (container != null) - { - // traverse up the tree to update everything we own - container.LayoutParent(updateSize); - return; - } - if (updateSize) - { - if (AutoSize) - { - var size = GetPreferredSize(Size.MaxValue); - SetContentSize(size.ToSD()); - } - } - - // layout everything! - LayoutAllChildren(); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/MacControlExtensions.cs b/Source/Eto.Platform.Mac/Forms/MacControlExtensions.cs deleted file mode 100644 index e9b779e5b2..0000000000 --- a/Source/Eto.Platform.Mac/Forms/MacControlExtensions.cs +++ /dev/null @@ -1,82 +0,0 @@ -using Eto.Drawing; -using Eto.Forms; -using MonoMac.AppKit; -using sd = System.Drawing; - -#if IOS -using NSView = MonoTouch.UIKit.UIView; -using NSControl = MonoTouch.UIKit.UIControl; -#endif -namespace Eto.Platform.Mac.Forms -{ - public static class MacControlExtensions - { - public static SizeF GetPreferredSize(this Control control, SizeF availableSize) - { - if (control == null) - return Size.Empty; - var mh = control.GetMacControl(); - if (mh != null) - { - return mh.GetPreferredSize(availableSize); - } - - var c = control.ControlObject as NSControl; - if (c != null) - { - c.SizeToFit(); - return c.Frame.Size.ToEto(); - } - var child = control.ControlObject as Control; - return child == null ? SizeF.Empty : child.GetPreferredSize(availableSize); - - } - - public static IMacContainer GetMacContainer(this Control control) - { - if (control == null) - return null; - var container = control.Handler as IMacContainer; - if (container != null) - return container; - var child = control.ControlObject as Control; - return child == null ? null : child.GetMacContainer(); - } - - public static IMacControlHandler GetMacControl(this Control control) - { - if (control == null) - return null; - var container = control.Handler as IMacControlHandler; - if (container != null) - return container; - var child = control.ControlObject as Control; - return child == null ? null : child.GetMacControl(); - } - - public static NSView GetContainerView(this Control control) - { - if (control == null) - return null; - var containerHandler = control.Handler as IMacControlHandler; - if (containerHandler != null) - return containerHandler.ContainerControl; - var childControl = control.ControlObject as Control; - if (childControl != null) - return childControl.GetContainerView(); - return control.ControlObject as NSView; - } - - public static void CenterInParent(this NSView view) - { - var super = view.Superview; - if (super != null) - { - var superFrame = super.Frame; - var size = view.Frame.Size; - view.SetFrameOrigin(new sd.PointF((superFrame.Width - size.Width) / 2, (superFrame.Height - size.Height) / 2)); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/MacObject.cs b/Source/Eto.Platform.Mac/Forms/MacObject.cs deleted file mode 100644 index 8beab05619..0000000000 --- a/Source/Eto.Platform.Mac/Forms/MacObject.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using MonoMac.Foundation; -using MonoTouch.Foundation; - -namespace Eto.Platform.Mac.Forms -{ - public class MacObject : MacBase - where TControl: NSObject - where TWidget: InstanceWidget - { - public virtual object EventObject - { - get { return Control; } - } - - public new void AddMethod (IntPtr selector, Delegate action, string arguments, object control = null) - { - base.AddMethod (selector, action, arguments, control ?? EventObject); - } - - public new NSObject AddObserver (NSString key, Action action, NSObject control = null) - { - return base.AddObserver (key, action, control ?? Control); - } - - public new void AddControlObserver (NSString key, Action action, NSObject control = null) - { - base.AddControlObserver (key, action, control ?? Control); - } - - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/MacPanel.cs b/Source/Eto.Platform.Mac/Forms/MacPanel.cs deleted file mode 100644 index c4fb8478b9..0000000000 --- a/Source/Eto.Platform.Mac/Forms/MacPanel.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using Eto.Forms; -using Eto.Drawing; -using SD = System.Drawing; -using MonoTouch.UIKit; - -#if IOS -using NSResponder = MonoTouch.UIKit.UIResponder; -using NSView = MonoTouch.UIKit.UIView; -#elif OSX -using MonoMac.AppKit; -using Eto.Platform.Mac.Forms.Menu; -#endif - -namespace Eto.Platform.Mac.Forms -{ -#if IOS - public static class UIViewExtensions - { - /// - /// See http://stackoverflow.com/a/2596519/90291 - /// - /// - /// - public static UIViewController GetViewController(this UIView view) - { - return view.NextResponder as UIViewController; - } - - /// - /// An extension method that adds a subview to a parent view. - /// Also adds the subview's view controller to the parent's view - /// controller, creating it if needed, provided the parent view controller - /// exists. - /// - /// - /// - public static void ContainerAddSubView(this UIView parent, UIView child) - { - var parentViewController = parent.GetViewController(); - var childViewController = child.GetViewController(); - - if (parentViewController != null) - { - if (childViewController == null) - childViewController = new Eto.Platform.iOS.Forms.RotatableViewController { View = child }; - parentViewController.AddChildViewController(childViewController); - } - // Note: pass through to AddSubView below. - // Adding a child view controller still requires adding the subview. - // see http://stackoverflow.com/questions/10143903/do-i-have-to-call-addsubview-after-calling-addchildviewcontroller - parent.AddSubview(child); - } - } -#endif - - public abstract class MacPanel : MacContainer, IPanel - where TControl: NSResponder - where TWidget: Panel - { - Control content; - Padding padding; - - public Padding Padding - { - get { return padding; } - set - { - padding = value; - LayoutParent(); - } - } - - #if OSX - protected virtual NSViewResizingMask ContentResizingMask() - { - return NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; - } - #endif - - public Control Content - { - get { return content; } - set - { - if (content != null) - { - var oldContent = content.GetContainerView(); - oldContent.RemoveFromSuperview(); - } - - content = value; - var control = value.GetContainerView(); - if (control != null) - { - var container = ContentControl; -#if OSX - control.AutoresizingMask = ContentResizingMask(); - container.AddSubview(control); // default -#elif IOS - control.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; - container.ContainerAddSubView(control); -#endif - } - - if (Widget.Loaded) - { - LayoutParent(); - } - } - } - -#if OSX - ContextMenu contextMenu; - public ContextMenu ContextMenu - { - get { return contextMenu; } - set - { - contextMenu = value; - Control.Menu = contextMenu != null ? ((ContextMenuHandler)contextMenu.Handler).Control : null; - } - } -#endif - protected override SizeF GetNaturalSize(SizeF availableSize) - { - if (content == null || !content.Visible) - return Padding.Size; - - var contentControl = content.GetMacControl(); - if (contentControl != null) - return contentControl.GetPreferredSize(availableSize) + Padding.Size; - return Padding.Size; - } - - protected virtual SD.RectangleF GetContentBounds() - { - return ContentControl.Bounds; - } - - public override void LayoutChildren() - { - base.LayoutChildren(); - - if (content == null) - return; - - NSView childControl = content.GetContainerView(); - var frame = GetContentBounds(); - - if (frame.Width > padding.Horizontal && frame.Height > padding.Vertical) - { - frame.X = padding.Left; - frame.Width -= padding.Horizontal; - frame.Y = padding.Bottom; - frame.Height -= padding.Vertical; - } - else - { - frame.X = 0; - frame.Y = 0; - } - - if (childControl.Frame != frame) - childControl.Frame = frame; - } - - public override void SetContentSize(SD.SizeF contentSize) - { - base.SetContentSize(contentSize); - if (MinimumSize != Size.Empty) - { - contentSize.Width = Math.Max(contentSize.Width, MinimumSize.Width); - contentSize.Height = Math.Max(contentSize.Height, MinimumSize.Height); - } - if (Widget.Content != null) - { - var child = Widget.Content.Handler as IMacContainer; - if (child != null) - { - child.SetContentSize(contentSize); - } - } - } - - bool isResizing; - void HandleSizeChanged (object sender, EventArgs e) - { - if (!isResizing) - { - isResizing = true; - LayoutChildren(); - isResizing = false; - } - } - - public override void OnLoad(EventArgs e) - { - base.OnLoad(e); - LayoutChildren(); - Widget.SizeChanged += HandleSizeChanged; - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - Widget.SizeChanged -= HandleSizeChanged; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/MacWindow.cs b/Source/Eto.Platform.Mac/Forms/MacWindow.cs deleted file mode 100644 index 2fae7655ce..0000000000 --- a/Source/Eto.Platform.Mac/Forms/MacWindow.cs +++ /dev/null @@ -1,783 +0,0 @@ -using System; -using System.ComponentModel; -using System.Linq; -using SD = System.Drawing; -using Eto.Drawing; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using Eto.Platform.Mac.Forms.Controls; -using System.Threading; - -namespace Eto.Platform.Mac.Forms -{ - public class MyWindow : NSWindow, IMacControl - { - SD.RectangleF oldFrame; - bool zoom; - - public WeakReference WeakHandler { get; set; } - - public IMacWindow Handler { get { return (IMacWindow)WeakHandler.Target; } set { WeakHandler = new WeakReference(value); } } - - public MyWindow(SD.Rectangle rect, NSWindowStyle style, NSBackingStore store, bool flag) - : base(rect, style, store, flag) - { - } - - public override void Center() - { - // implement centering to parent if there is a parent window for this one.. - if (ParentWindow != null) - { - var parentFrame = ParentWindow.Frame; - var frame = Frame; - var location = new SD.PointF((parentFrame.Width - frame.Width) / 2 + parentFrame.X, (parentFrame.Height - frame.Height) / 2 + parentFrame.Y); - SetFrameOrigin(location); - } - else - base.Center(); - } - - public override void Zoom(NSObject sender) - { - if (zoom) - { - SetFrame(oldFrame, true, true); - zoom = false; - } - else - { - oldFrame = Frame; - base.Zoom(sender); - zoom = true; - } - Handler.Widget.OnWindowStateChanged(EventArgs.Empty); - } - } - - public interface IMacWindow - { - Rectangle? RestoreBounds { get; set; } - - Window Widget { get; } - - NSMenu MenuBar { get; } - - NSObject FieldEditorObject { get; set; } - - Size MinimumSize { get; } - - bool CloseWindow(Action closing = null); - - NSWindow Control { get; } - } - - public class CustomFieldEditor : NSTextView - { - WeakReference widget; - - public Control Widget { get { return (Control)widget.Target; } set { widget = new WeakReference(value); } } - - public CustomFieldEditor() - { - FieldEditor = true; - } - - public CustomFieldEditor(IntPtr handle) - : base(handle) - { - } - - public override void KeyDown(NSEvent theEvent) - { - if (!MacEventView.KeyDown(Widget, theEvent)) - { - base.KeyDown(theEvent); - } - } - } - - public abstract class MacWindow : MacPanel, IWindow, IMacContainer, IMacWindow - where TControl: MyWindow - where TWidget: Window - { - CustomFieldEditor fieldEditor; - MenuBar menuBar; - Icon icon; - ToolBar toolBar; - Rectangle? restoreBounds; - bool setInitialSize; - WindowState? initialState; - bool maximizable = true; - bool topmost; - bool setInitialPosition = true; - Point? oldLocation; - - public override NSView ContainerControl { get { return Control.ContentView; } } - - public override object EventObject { get { return Control; } } - - static readonly Selector selSetStyleMask = new Selector("setStyleMask:"); - - public NSObject FieldEditorObject { get; set; } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - if (Content != null && Content.Visible) - { - var contentControl = Content.GetMacControl(); - if (contentControl != null) - { - return contentControl.GetPreferredSize(availableSize); - } - } - return new Size(200, 200); - } - - public override Size MinimumSize - { - get { return base.MinimumSize; } - set - { - base.MinimumSize = value; - if (value != Size.Empty) - { - Control.WillResize = (sender, frameSize) => - { - if (value != Size.Empty) - { - return new SD.SizeF(Math.Max(frameSize.Width, value.Width), Math.Max(frameSize.Height, value.Height)); - } - return frameSize; - }; - } - else - Control.WillResize = null; - } - } - - public NSMenu MenuBar - { - get { return menuBar == null ? null : menuBar.ControlObject as NSMenu; } - } - - protected MacWindow() - { - AutoSize = true; - } - - protected override void Initialize() - { - base.Initialize(); - Control.DidBecomeKey += delegate - { - if (MenuBar != null) - { - NSApplication.SharedApplication.MainMenu = MenuBar; - } - }; - Control.ShouldZoom = (window, newFrame) => - { - if (!Maximizable) - return false; - if (!window.IsZoomed && window.Screen != null) - { - RestoreBounds = Widget.Bounds; - } - return true; - }; - Control.WillMiniaturize += delegate - { - RestoreBounds = Widget.Bounds; - }; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Window.ClosedEvent: - Control.WillClose += delegate - { - if (ApplicationHandler.Instance.ShouldCloseForm(Widget, true)) - Widget.OnClosed(EventArgs.Empty); - }; - break; - case Window.ClosingEvent: - Control.WindowShouldClose = sender => - { - var args = new CancelEventArgs(); - if (ApplicationHandler.Instance.ShouldCloseForm(Widget, false)) - Widget.OnClosing(args); - return !args.Cancel; - }; - break; - case Window.WindowStateChangedEvent: - Control.DidMiniaturize += delegate - { - Widget.OnWindowStateChanged(EventArgs.Empty); - }; - Control.DidDeminiaturize += delegate - { - Widget.OnWindowStateChanged(EventArgs.Empty); - }; - break; - case Eto.Forms.Control.ShownEvent: - // handled when shown - break; - case Eto.Forms.Control.GotFocusEvent: - Control.DidBecomeKey += delegate - { - Widget.OnGotFocus(EventArgs.Empty); - }; - break; - case Eto.Forms.Control.LostFocusEvent: - Control.DidResignKey += delegate - { - Widget.OnLostFocus(EventArgs.Empty); - }; - break; - case Eto.Forms.Control.SizeChangedEvent: - { - Size? oldSize = null; - AddControlObserver((NSString)"frame", e => - { - var widget = (Window)e.Widget; - var newSize = widget.Size; - if (oldSize != newSize) - { - widget.OnSizeChanged(EventArgs.Empty); - oldSize = newSize; - } - }); - } - break; - case Window.LocationChangedEvent: - { - AddControlObserver((NSString)"frame", e => - { - var handler = e.Handler as MacWindow; - if (handler != null) - { - var old = oldLocation; - oldLocation = null; - var newLocation = handler.Location; - if (old != newLocation) - { - oldLocation = newLocation; - handler.Widget.OnLocationChanged(EventArgs.Empty); - } - } - }); - // WillMove is only called when the user moves the window via the mouse - Control.WillMove += HandleWillMove; - } - break; - default: - base.AttachEvent(id); - break; - } - } - - void CreateCursorRect() - { - if (Cursor != null) - { - Control.ContentView.DiscardCursorRects(); - Control.ContentView.AddCursorRect(new SD.RectangleF(SD.PointF.Empty, Control.Frame.Size), Cursor.ControlObject as NSCursor); - } - else - Control.ContentView.DiscardCursorRects(); - } - - /// - /// Tracks movement of the window until the mouse up button is found - /// - static void HandleWillMove(object sender, EventArgs e) - { - var handler = GetHandler(sender) as MacWindow; - if (handler == null) - return; - handler.oldLocation = null; - // find offset of mouse cursor to location of window - var moveOffset = Size.Round((SizeF)(Mouse.GetPosition(handler.Generator) - handler.Location)); - - ThreadPool.QueueUserWorkItem(a => - { - bool tracking = true; - while (tracking) - { - NSApplication.SharedApplication.InvokeOnMainThread(() => - { - var newLocation = Point.Round(Mouse.GetPosition(handler.Generator) - moveOffset); - if (handler.oldLocation != newLocation) - { - handler.Widget.OnLocationChanged(EventArgs.Empty); - handler.oldLocation = newLocation; - } - // check for mouse up event - tracking = NSApplication.SharedApplication.NextEventEx(NSEventMask.LeftMouseUp, null, NSRunLoop.NSRunLoopEventTracking, false) == null; - }); - } - handler.oldLocation = null; - }); - } - - protected void ConfigureWindow() - { - Control.Handler = this; - Control.ContentView = new NSView(); - //Control.ContentMinSize = new System.Drawing.SizeF(0, 0); - Control.ContentView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; - Control.ReleasedWhenClosed = false; - Control.HasShadow = true; - Control.ShowsResizeIndicator = true; - Control.AutorecalculatesKeyViewLoop = true; - //Control.Delegate = new MacWindowDelegate{ Handler = this }; - Control.WillReturnFieldEditor = (sender, forObject) => - { - FieldEditorObject = forObject; - var control = forObject as IMacControl; - if (control != null) - { - var handler = control.WeakHandler.Target as IMacViewHandler; - if (handler != null && handler.IsEventHandled(Eto.Forms.Control.KeyDownEvent)) - { - if (fieldEditor == null) - fieldEditor = new CustomFieldEditor(); - fieldEditor.Widget = handler.Widget; - return fieldEditor; - } - } - return null; - }; - } - - public override NSView ContentControl { get { return Control.ContentView; } } - - public virtual string Title { get { return Control.Title; } set { Control.Title = value ?? ""; } } - // Control.Title throws an exception if value is null - void SetButtonStates() - { - var button = Control.StandardWindowButton(NSWindowButton.ZoomButton); - if (button != null) - button.Enabled = Maximizable && Resizable; - } - - public bool Resizable - { - get { return Control.StyleMask.HasFlag(NSWindowStyle.Resizable); } - set - { - if (Control.RespondsToSelector(selSetStyleMask)) - { - if (value) - Control.StyleMask |= NSWindowStyle.Resizable; - else - Control.StyleMask &= ~NSWindowStyle.Resizable; - SetButtonStates(); - } - } - } - - public bool Minimizable - { - get { return Control.StyleMask.HasFlag(NSWindowStyle.Miniaturizable); } - set - { - if (Control.RespondsToSelector(selSetStyleMask)) - { - if (value) - Control.StyleMask |= NSWindowStyle.Miniaturizable; - else - Control.StyleMask &= ~NSWindowStyle.Miniaturizable; - SetButtonStates(); - } - } - } - - public bool Maximizable - { - get { return maximizable; } - set - { - if (maximizable != value) - { - maximizable = value; - HandleEvent(Window.WindowStateChangedEvent); - SetButtonStates(); - } - } - } - - public bool ShowInTaskbar - { - get; - set; - } - - public bool Topmost - { - get { return topmost; } - set - { - if (topmost != value) - { - topmost = value; - Control.Level = value ? NSWindowLevel.PopUpMenu : NSWindowLevel.Normal; - } - } - } - - public override Size Size - { - get - { - return Control.Frame.Size.ToEtoSize(); - } - set - { - var oldFrame = Control.Frame; - var newFrame = oldFrame.SetSize(value); - newFrame.Y = Math.Max(0, oldFrame.Y - (value.Height - oldFrame.Height)); - Control.SetFrame(newFrame, true); - AutoSize = false; - } - } - - public MenuBar Menu - { - get - { - return menuBar; - } - set - { - menuBar = value; - if (Control.IsKeyWindow) - { - NSApplication.SharedApplication.MainMenu = (NSMenu)value.ControlObject; - } - } - } - - public bool CloseWindow(Action closing = null) - { - var args = new CancelEventArgs(); - Widget.OnClosing(args); - if (!args.Cancel && closing != null) - closing(args); - if (!args.Cancel) - { - Widget.OnClosed(EventArgs.Empty); - } - return !args.Cancel; - } - - public virtual void Close() - { - Control.Close(); - } - - public ToolBar ToolBar - { - get - { - return toolBar; - } - set - { - toolBar = value; - Control.Toolbar = (NSToolbar)toolBar.ControlObject; - } - } - - public Icon Icon - { - get { return icon; } - set - { - icon = value; - // don't really do anything here.. no where to put it - } - } - - public override void Focus() - { - Control.BecomeFirstResponder(); - } - - public string Id { get; set; } - - public override Size ClientSize - { - get { return Control.ContentView.Frame.Size.ToEtoSize(); } - set - { - var oldFrame = Control.Frame; - var oldSize = Control.ContentView.Frame; - Control.SetFrameOrigin(new SD.PointF(oldFrame.X, Math.Max(0, oldFrame.Y - (value.Height - oldSize.Height)))); - Control.SetContentSize(value.ToSDSizeF()); - AutoSize = false; - } - } - - public override bool HasFocus - { - get { return Control.IsKeyWindow; } - } - - public override bool Visible - { - get { return Control.IsVisible; } - set - { - if (value && !Control.IsVisible) - Control.MakeKeyAndOrderFront(NSApplication.SharedApplication); - if (!value && Control.IsVisible) - Control.PerformClose(NSApplication.SharedApplication); - // huh? - } - } - - public override Cursor Cursor - { - get { return base.Cursor; } - set - { - base.Cursor = value; - CreateCursorRect(); - } - } - - public virtual Point Location - { - get - { - if (oldLocation != null) - return oldLocation.Value; - // translate location relative to the top left corner of main screen - var mainFrame = NSScreen.Screens[0].Frame; - var frame = Control.Frame; - return new Point((int)frame.X, (int)(mainFrame.Height - frame.Y - frame.Height)); - } - set - { - // location is relative to the main screen, translate to bottom left, inversed - var mainFrame = NSScreen.Screens[0].Frame; - var frame = Control.Frame; - var point = new SD.PointF(value.X, mainFrame.Height - value.Y - frame.Height); - Control.SetFrameOrigin(point); - if (Control.Screen == null) - { - // ensure that the control lands on a screen - point.X = Math.Min(Math.Max(mainFrame.X, point.X), mainFrame.Right - frame.Width); - point.Y = Math.Min(Math.Max(mainFrame.Y, point.Y), mainFrame.Bottom - frame.Height); - - Control.SetFrameOrigin(point); - } - setInitialPosition = false; - } - } - - public WindowState WindowState - { - get - { - if (initialState != null) - return initialState.Value; - if (Control.IsMiniaturized) - return WindowState.Minimized; - if (Control.IsZoomed) - return WindowState.Maximized; - return WindowState.Normal; - } - set - { - if (!Widget.Loaded) - { - initialState = value; - return; - } - switch (value) - { - case WindowState.Maximized: - if (Control.IsMiniaturized) - Control.Deminiaturize(Control); - if (!Control.IsZoomed) - Control.PerformZoom(Control); - break; - case WindowState.Minimized: - if (!Control.IsMiniaturized) - Control.Miniaturize(Control); - break; - case WindowState.Normal: - if (Control.IsZoomed) - Control.Zoom(Control); - if (Control.IsMiniaturized) - Control.Deminiaturize(Control); - break; - } - } - } - - public Rectangle? RestoreBounds - { - get { return WindowState == WindowState.Normal ? null : restoreBounds; } - set { restoreBounds = value; } - } - - public double Opacity - { - get { return Control.IsOpaque ? 1.0 : Control.AlphaValue; } - set - { - Control.IsOpaque = Math.Abs(value - 1.0) < 0.01f; - Control.AlphaValue = (float)value; - } - } - - public override void OnLoad(EventArgs e) - { - base.OnLoad(e); - if (AutoSize) - { - var size = GetPreferredSize(Size.MaxValue); - SetContentSize(size.ToSD()); - setInitialSize = true; - - PositionWindow(); - } - else - { - PositionWindow(); - } - } - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - if (initialState != null) - { - WindowState = initialState.Value; - initialState = null; - } - } - - protected virtual void PositionWindow() - { - if (setInitialPosition) - { - Control.Center(); - setInitialPosition = false; - } - } - - #region IMacContainer implementation - - public override void SetContentSize(SD.SizeF contentSize) - { - if (MinimumSize != Size.Empty) - { - contentSize.Width = Math.Max(contentSize.Width, MinimumSize.Width); - contentSize.Height = Math.Max(contentSize.Height, MinimumSize.Height); - } - - if (Widget.Loaded) - { - var diffy = ClientSize.Height - (int)contentSize.Height; - var diffx = ClientSize.Width - (int)contentSize.Width; - var frame = Control.Frame; - if (diffx < 0 || !setInitialSize) - { - frame.Width -= diffx; - } - if (diffy < 0 || !setInitialSize) - { - frame.Y += diffy; - frame.Height -= diffy; - } - Control.SetFrame(frame, false, false); - } - else - Control.SetContentSize(contentSize); - } - - #endregion - - #region IMacWindow implementation - - Rectangle? IMacWindow.RestoreBounds - { - get - { - return restoreBounds; - } - set - { - restoreBounds = value; - } - } - - Window IMacWindow.Widget - { - get { return Widget; } - } - - NSWindow IMacWindow.Control - { - get { return Control; } - } - - #endregion - - public Screen Screen - { - get { return new Screen(Generator, new ScreenHandler(Control.Screen)); } - } - - public override PointF PointFromScreen(PointF point) - { - var sdpoint = point.ToSD(); - sdpoint = Control.ConvertBaseToScreen(sdpoint); - sdpoint.Y = Control.Screen.Frame.Height - sdpoint.Y; - return sdpoint.ToEto(); - } - - public override PointF PointToScreen(PointF point) - { - var sdpoint = point.ToSD(); - sdpoint = Control.ConvertBaseToScreen(sdpoint); - sdpoint.Y = Control.Screen.Frame.Height - sdpoint.Y; - return sdpoint.ToEto(); - } - - public WindowStyle WindowStyle - { - get { return Control.StyleMask.ToEtoWindowStyle(); } - set - { - if (Control.RespondsToSelector(selSetStyleMask)) - { - Control.StyleMask = value.ToNS(Control.StyleMask); - } - } - } - - public void BringToFront() - { - Control.OrderFront(Control); - Control.MakeKeyWindow(); - } - - public void SendToBack() - { - Control.OrderBack(Control); - var window = NSApplication.SharedApplication.Windows.FirstOrDefault(r => r != Control); - if (window != null) - window.MakeKeyWindow(); - Control.ResignKeyWindow(); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Menu/CheckMenuItemHandler.cs b/Source/Eto.Platform.Mac/Forms/Menu/CheckMenuItemHandler.cs deleted file mode 100644 index 8db7364af8..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Menu/CheckMenuItemHandler.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac -{ - public class CheckMenuItemHandler : MenuHandler, ICheckMenuItem, IMenuActionHandler - { - public CheckMenuItemHandler () - { - Control = new NSMenuItem (); - Enabled = true; - Control.Target = new MenuActionHandler{ Handler = this }; - Control.Action = MenuActionHandler.selActivate; - } - - public void HandleClick () - { - Widget.OnClick (EventArgs.Empty); - } - - #region IMenuItem Members - - public bool Enabled { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - - public string Text { - get { return Control.Title; } - set { Control.SetTitleWithMnemonic (value); } - } - - public string ToolTip { - get { return Control.ToolTip; } - set { Control.ToolTip = value ?? string.Empty; } - } - - public Keys Shortcut { - get { return KeyMap.Convert (Control.KeyEquivalent, Control.KeyEquivalentModifierMask); } - set { - Control.KeyEquivalent = KeyMap.KeyEquivalent (value); - Control.KeyEquivalentModifierMask = KeyMap.KeyEquivalentModifierMask (value); - } - } - - public bool Checked { - get { return Control.State == NSCellStateValue.On; } - set { Control.State = value ? NSCellStateValue.On : NSCellStateValue.Off; } - } - - #endregion - - MenuItem IMenuActionHandler.Widget { - get { return Widget; } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Menu/ContextMenuHandler.cs b/Source/Eto.Platform.Mac/Forms/Menu/ContextMenuHandler.cs deleted file mode 100644 index 515a920d5d..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Menu/ContextMenuHandler.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms.Menu -{ - public class ContextMenuHandler : WidgetHandler, IContextMenu - { - public ContextMenuHandler () - { - Control = new NSMenu (); - Control.AutoEnablesItems = false; - Control.ShowsStateColumn = true; - } - - public void AddMenu (int index, MenuItem item) - { - Control.InsertItem ((NSMenuItem)item.ControlObject, index); - } - - public void RemoveMenu (MenuItem item) - { - Control.RemoveItem ((NSMenuItem)item.ControlObject); - } - - public void Clear () - { - Control.RemoveAllItems (); - } - - public void Show (Control relativeTo) - { - NSEvent nsevent = NSApplication.SharedApplication.CurrentEvent; - if (nsevent == null) { - var location = NSEvent.CurrentMouseLocation; - location = NSApplication.SharedApplication.KeyWindow.ConvertScreenToBase (location); - - var time = DateTime.Now.ToOADate(); - var windowNumber = NSApplication.SharedApplication.KeyWindow.WindowNumber; - - nsevent = NSEvent.MouseEvent(NSEventType.RightMouseDown, location, 0, time, windowNumber, null, 0, 0, 0.1f); - } - var view = relativeTo != null ? relativeTo.ControlObject as NSView : null; - NSMenu.PopUpContextMenu(Control, nsevent, view); - } - - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Menu/MenuActionHandler.cs b/Source/Eto.Platform.Mac/Forms/Menu/MenuActionHandler.cs deleted file mode 100644 index 0ae7dd7a58..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Menu/MenuActionHandler.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; -using MonoMac.AppKit; -using Eto.Forms; - -namespace Eto.Platform.Mac -{ - public interface IMenuActionHandler - { - void HandleClick(); - - bool Enabled { get; } - - MenuItem Widget { get; } - } - - [Register("EtoMenuActionHandler")] - public class MenuActionHandler : NSObject - { - internal static Selector selActivate = new Selector("activate:"); - WeakReference handler; - - public IMenuActionHandler Handler { get { return (IMenuActionHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [Export("activate:")] - public void Activate(NSObject sender) - { - var h = Handler; - if (h != null) - h.HandleClick(); - } - - [Export("validateMenuItem:")] - public bool ValidateMenuItem(NSMenuItem item) - { - var h = Handler; - if (h != null) - { - h.Widget.OnValidate(EventArgs.Empty); - return h.Enabled; - } - return false; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Menu/MenuBarHandler.cs b/Source/Eto.Platform.Mac/Forms/Menu/MenuBarHandler.cs deleted file mode 100644 index e52cd7ff5c..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Menu/MenuBarHandler.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac -{ - public class MenuBarHandler : WidgetHandler, IMenuBar, IMenu - { - - public MenuBarHandler() - { - Control = new NSMenu(); - Control.AutoEnablesItems = false; - Control.ShowsStateColumn = true; - } - - public void AddMenu(int index, MenuItem item) - { - var itemHandler = item.Handler as IMenuHandler; - if (itemHandler != null) - itemHandler.EnsureSubMenu(); - Control.InsertItem((NSMenuItem)item.ControlObject, index); - } - - public void RemoveMenu(MenuItem item) - { - Control.RemoveItem((NSMenuItem)item.ControlObject); - } - - public void Clear() - { - Control.RemoveAllItems(); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Menu/MenuHandler.cs b/Source/Eto.Platform.Mac/Forms/Menu/MenuHandler.cs deleted file mode 100644 index 1f6f1bb4ac..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Menu/MenuHandler.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Eto.Forms; -using MonoMac.AppKit; -using Eto.Platform.Mac.Forms.Actions; - -namespace Eto.Platform.Mac -{ - public interface IMenuHandler - { - void EnsureSubMenu(); - } - - public abstract class MenuHandler : WidgetHandler, IMenu, IMenuHandler - where TControl: NSMenuItem - where TWidget: Menu - { - public void EnsureSubMenu() - { - if (!Control.HasSubmenu) - Control.Submenu = new NSMenu { AutoEnablesItems = true, ShowsStateColumn = true, Title = Control.Title }; - } - - public virtual void AddMenu(int index, MenuItem item) - { - EnsureSubMenu(); - Control.Submenu.InsertItem((NSMenuItem)item.ControlObject, index); - } - - public virtual void RemoveMenu(MenuItem item) - { - if (Control.Submenu == null) - return; - Control.Submenu.RemoveItem((NSMenuItem)item.ControlObject); - } - - public virtual void Clear() - { - Control.Submenu = null; - } - - public void CreateFromCommand(Command command) - { - var m = command as MacCommand; - if (m != null) - { - Control.Target = null; - Control.Action = m.Selector; - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Menu/RadioMenuItemHandler.cs b/Source/Eto.Platform.Mac/Forms/Menu/RadioMenuItemHandler.cs deleted file mode 100644 index e136caa310..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Menu/RadioMenuItemHandler.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using System.Collections.Generic; - -namespace Eto.Platform.Mac -{ - public class RadioMenuItemHandler : MenuHandler, IRadioMenuItem, IMenuActionHandler - { - List radioGroup; - - public RadioMenuItemHandler() - { - Control = new NSMenuItem(); - Enabled = true; - //control.SetButtonType(NSButtonType.Radio); - Control.Target = new MenuActionHandler { Handler = this }; - Control.Action = MenuActionHandler.selActivate; - } - - public void HandleClick() - { - Widget.OnClick(EventArgs.Empty); - - if (radioGroup != null) - { - foreach (RadioMenuItem item in radioGroup) - { - item.Checked = (item.ControlObject == Control); - } - } - } - - public void Create(RadioMenuItem controller) - { - if (controller != null) - { - var controllerInner = (RadioMenuItemHandler)controller.Handler; - if (controllerInner.radioGroup == null) - { - controllerInner.radioGroup = new List(); - controllerInner.radioGroup.Add(controller); - } - controllerInner.radioGroup.Add(Widget); - radioGroup = controllerInner.radioGroup; - } - } - - public bool Enabled - { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - - public string Text - { - get { return Control.Title; } - set { Control.SetTitleWithMnemonic(value); } - } - - public string ToolTip - { - get { return Control.ToolTip; } - set { Control.ToolTip = value ?? string.Empty; } - } - - public Keys Shortcut - { - get { return KeyMap.Convert(Control.KeyEquivalent, Control.KeyEquivalentModifierMask); } - set - { - Control.KeyEquivalent = KeyMap.KeyEquivalent(value); - Control.KeyEquivalentModifierMask = KeyMap.KeyEquivalentModifierMask(value); - } - } - - public bool Checked - { - get { return Control.State == NSCellStateValue.On; } - set { Control.State = value ? NSCellStateValue.On : NSCellStateValue.Off; } - } - - MenuItem IMenuActionHandler.Widget - { - get { return Widget; } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Menu/SeparatorMenuItem.cs b/Source/Eto.Platform.Mac/Forms/Menu/SeparatorMenuItem.cs deleted file mode 100644 index 0454ab9889..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Menu/SeparatorMenuItem.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac -{ - public class SeparatorMenuItemHandler : MenuHandler, ISeparatorMenuItem - { - public SeparatorMenuItemHandler () - { - Control = NSMenuItem.SeparatorItem; - } - - public bool Enabled { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - - public string Text { - get { return string.Empty; } - set { throw new NotSupportedException (); } - } - - public Keys Shortcut { - get { return Keys.None; } - set { throw new NotSupportedException (); } - } - - public string ToolTip { - get { return string.Empty; } - set { throw new NotSupportedException (); } - } - - } -} diff --git a/Source/Eto.Platform.Mac/Forms/MessageBoxHandler.cs b/Source/Eto.Platform.Mac/Forms/MessageBoxHandler.cs deleted file mode 100644 index 42080238b1..0000000000 --- a/Source/Eto.Platform.Mac/Forms/MessageBoxHandler.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms -{ - public class MessageBoxHandler : WidgetHandler, IMessageBox - { - public string Text { get; set; } - - public string Caption { get; set; } - - public MessageBoxType Type { get; set; } - - public MessageBoxButtons Buttons { get; set; } - - public MessageBoxDefaultButton DefaultButton { get; set; } - - public DialogResult ShowDialog(Control parent) - { - var alert = new NSAlert(); - - AddButtons(alert); - - alert.AlertStyle = Convert(Type); - alert.MessageText = Caption ?? string.Empty; - alert.InformativeText = Text ?? string.Empty; - var ret = MacModal.Run(alert, parent); - switch (Buttons) - { - default: - return DialogResult.Ok; - case MessageBoxButtons.OKCancel: - return (ret == 1000) ? DialogResult.Ok : DialogResult.Cancel; - case MessageBoxButtons.YesNo: - return (ret == 1000) ? DialogResult.Yes : DialogResult.No; - case MessageBoxButtons.YesNoCancel: - return (ret == 1000) ? DialogResult.Yes : (ret == 1001) ? DialogResult.Cancel : DialogResult.No; - } - } - - void AddButtons(NSAlert alert) - { - var OkButton = "OK"; - var CancelButton = "Cancel"; - var YesButton = "Yes"; - var NoButton = "No"; - - switch (Buttons) - { - case MessageBoxButtons.OK: - alert.AddButton(OkButton); - break; - case MessageBoxButtons.OKCancel: - { - var ok = alert.AddButton(OkButton); - var cancel = alert.AddButton(CancelButton); - switch (DefaultButton) - { - case MessageBoxDefaultButton.OK: - ok.BecomeFirstResponder(); - break; - case MessageBoxDefaultButton.Cancel: - case MessageBoxDefaultButton.Default: - cancel.BecomeFirstResponder(); - break; - } - } - break; - case MessageBoxButtons.YesNo: - { - var yes = alert.AddButton(YesButton); - var no = alert.AddButton(NoButton); - switch (DefaultButton) - { - case MessageBoxDefaultButton.Yes: - yes.BecomeFirstResponder(); - break; - case MessageBoxDefaultButton.No: - case MessageBoxDefaultButton.Default: - no.BecomeFirstResponder(); - break; - } - } - break; - case MessageBoxButtons.YesNoCancel: - { - var yes = alert.AddButton(YesButton); - var cancel = alert.AddButton(CancelButton); - var no = alert.AddButton(NoButton); - switch (DefaultButton) - { - case MessageBoxDefaultButton.Yes: - yes.BecomeFirstResponder(); - break; - case MessageBoxDefaultButton.No: - no.BecomeFirstResponder(); - break; - case MessageBoxDefaultButton.Cancel: - case MessageBoxDefaultButton.Default: - cancel.BecomeFirstResponder(); - break; - } - } - break; - } - } - - static NSAlertStyle Convert(MessageBoxType type) - { - switch (type) - { - case MessageBoxType.Information: - case MessageBoxType.Question: - return NSAlertStyle.Informational; - case MessageBoxType.Warning: - return NSAlertStyle.Warning; - case MessageBoxType.Error: - return NSAlertStyle.Critical; - default: - throw new NotSupportedException(); - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/MouseHandler.cs b/Source/Eto.Platform.Mac/Forms/MouseHandler.cs deleted file mode 100644 index 6b576ddeca..0000000000 --- a/Source/Eto.Platform.Mac/Forms/MouseHandler.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms -{ - public class MouseHandler : IMouse - { - public void Initialize () - { - } - public Widget Widget { get; set; } - - public Eto.Generator Generator { get; set; } - - public Eto.Drawing.PointF Position - { - get - { - var mouseLocation = NSEvent.CurrentMouseLocation; - var origin = NSScreen.Screens[0].Frame.Bottom; - mouseLocation.Y = origin - mouseLocation.Y; - return mouseLocation.ToEto(); - } - } - - public MouseButtons Buttons - { - get - { - var current = NSEvent.CurrentPressedMouseButtons; - var buttons = MouseButtons.None; - if ((current & 1) != 0) - buttons |= MouseButtons.Primary; - if ((current & 2) != 0) - buttons |= MouseButtons.Alternate; - if ((current & 4) != 0) - buttons |= MouseButtons.Middle; - return buttons; - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/OpenFileDialog.cs b/Source/Eto.Platform.Mac/Forms/OpenFileDialog.cs deleted file mode 100644 index dc19509d25..0000000000 --- a/Source/Eto.Platform.Mac/Forms/OpenFileDialog.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Linq; -using Eto.Forms; -using MonoMac.AppKit; -using System.Collections.Generic; - -namespace Eto.Platform.Mac.Forms -{ - public class OpenFileDialogHandler : MacFileDialog, IOpenFileDialog - { - - public OpenFileDialogHandler() - { - Control = NSOpenPanel.OpenPanel; - } - - public bool MultiSelect - { - get { return Control.AllowsMultipleSelection; } - set { Control.AllowsMultipleSelection = value; } - } - - public IEnumerable Filenames - { - get { return Control.Urls.Select(a => a.Path); } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/PixelLayoutHandler.cs b/Source/Eto.Platform.Mac/Forms/PixelLayoutHandler.cs deleted file mode 100644 index 8884a8d160..0000000000 --- a/Source/Eto.Platform.Mac/Forms/PixelLayoutHandler.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using Eto.Drawing; -using SD = System.Drawing; -using System.Collections.Generic; -using System.Linq; -using Eto.Platform.Mac.Forms.Controls; - -namespace Eto.Platform.Mac.Forms -{ - public class PixelLayoutHandler : MacContainer, IPixelLayout - { - readonly Dictionary points = new Dictionary(); - - public override NSView ContainerControl { get { return Control; } } - - public PixelLayoutHandler() - { - Control = new MacEventView { Handler = this }; - } - - public SD.RectangleF GetPosition(Control control) - { - PointF point; - if (points.TryGetValue(control, out point)) - { - var frameSize = ((NSView)control.ControlObject).Frame.Size; - return new SD.RectangleF(point.ToSD(), frameSize); - } - return control.GetContainerView().Frame; - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - SizeF size = SizeF.Empty; - foreach (var item in points.Where(r => r.Key.Visible)) - { - var frameSize = item.Key.GetPreferredSize(availableSize); - size = SizeF.Max(size, frameSize + new SizeF(item.Value)); - } - return size; - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - LayoutChildren(); - Widget.SizeChanged += HandleSizeChanged; - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - Widget.SizeChanged -= HandleSizeChanged; - } - - void HandleSizeChanged (object sender, EventArgs e) - { - LayoutChildren(); - } - - void SetPosition(Control control, PointF point, float frameHeight, bool flipped) - { - var offset = ((IMacViewHandler)control.Handler).PositionOffset; - var childView = control.GetContainerView(); - - var preferredSize = control.GetPreferredSize(Control.Frame.Size.ToEtoSize()); - - SD.PointF origin; - if (flipped) - origin = new System.Drawing.PointF( - point.X + offset.Width, - point.Y + offset.Height - ); - else - origin = new System.Drawing.PointF( - point.X + offset.Width, - frameHeight - (preferredSize.Height + point.Y + offset.Height) - ); - - var frame = new SD.RectangleF(origin, preferredSize.ToSD()); - if (frame != childView.Frame) - { - childView.Frame = frame; - } - } - - public override void LayoutChildren() - { - if (NeedsQueue()) - return; - var controlPoints = points.ToArray(); - var frameHeight = Control.Frame.Height; - var flipped = Control.IsFlipped; - foreach (var item in controlPoints) - { - SetPosition(item.Key, item.Value, frameHeight, flipped); - } - } - - public void Add(Control child, int x, int y) - { - var location = new Point(x, y); - points[child] = location; - var childView = child.GetContainerView(); - if (Widget.Loaded) - { - var frameHeight = Control.Frame.Height; - SetPosition(child, location, frameHeight, Control.IsFlipped); - } - Control.AddSubview(childView); - if (Widget.Loaded) - LayoutParent(); - } - - public void Move(Control child, int x, int y) - { - var location = new Point(x, y); - if (points[child] != location) - { - points[child] = location; - if (Widget.Loaded) - { - var frameHeight = Control.Frame.Height; - SetPosition(child, location, frameHeight, Control.IsFlipped); - LayoutParent(); - } - } - } - - public void Remove(Control child) - { - var childView = child.GetContainerView(); - points.Remove(child); - childView.RemoveFromSuperview(); - if (Widget.Loaded) - LayoutParent(); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/Printing/PrintDialogHandler.cs b/Source/Eto.Platform.Mac/Forms/Printing/PrintDialogHandler.cs deleted file mode 100644 index d7f12e6ec0..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Printing/PrintDialogHandler.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; - -namespace Eto.Platform.Mac.Forms.Printing -{ - public class PrintDialogHandler : WidgetHandler, IPrintDialog - { - PrintSettings settings; - - public PrintDialogHandler() - { - Control = new NSPrintPanel(); - } - - class SheetHelper : NSObject - { - [Export("printPanelDidEnd:returnCode:contextInfo:")] - public void PrintPanelDidEnd(NSPrintPanel printPanel, int returnCode, IntPtr contextInfo) - { - NSApplication.SharedApplication.StopModalWithCode(returnCode); - } - } - - public PrintDocument Document { get; set; } - - public DialogResult ShowDialog(Window parent) - { - int ret; - var docHandler = Document != null ? Document.Handler as PrintDocumentHandler : null; - - if (docHandler != null) - { - Control.Options |= NSPrintPanelOptions.ShowsPreview; - ret = docHandler.Print(true, parent, Control) ? 1 : 0; - } - else - { - var printInfo = settings.ToNS(); - if (parent != null) - { - var parentHandler = (IMacWindow)parent.Handler; - var closeSheet = new SheetHelper(); - Control.BeginSheet(printInfo, parentHandler.Control, closeSheet, new Selector("printPanelDidEnd:returnCode:contextInfo:"), IntPtr.Zero); - ret = NSApplication.SharedApplication.RunModalForWindow(parentHandler.Control); - } - else - ret = Control.RunModalWithPrintInfo(printInfo); - } - - return ret == 1 ? DialogResult.Ok : DialogResult.Cancel; - } - - public PrintSettings PrintSettings - { - get - { - if (settings == null) - settings = Control.PrintInfo.ToEto(Widget.Generator); - return settings; - } - set - { - settings = value; - } - } - - public bool AllowCopies - { - get { return Control.Options.HasFlag(NSPrintPanelOptions.ShowsCopies); } - set - { - if (value) - Control.Options |= NSPrintPanelOptions.ShowsCopies; - else - Control.Options &= ~NSPrintPanelOptions.ShowsCopies; - } - } - - public bool AllowPageRange - { - get { return Control.Options.HasFlag(NSPrintPanelOptions.ShowsPageRange); } - set - { - if (value) - Control.Options |= NSPrintPanelOptions.ShowsPageRange; - else - Control.Options &= ~NSPrintPanelOptions.ShowsPageRange; - } - } - - public bool AllowSelection - { - get { return Control.Options.HasFlag(NSPrintPanelOptions.ShowsPrintSelection); } - set - { - if (value) - Control.Options |= NSPrintPanelOptions.ShowsPrintSelection; - else - Control.Options &= ~NSPrintPanelOptions.ShowsPrintSelection; - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Printing/PrintDocumentHandler.cs b/Source/Eto.Platform.Mac/Forms/Printing/PrintDocumentHandler.cs deleted file mode 100644 index 0d445e7f08..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Printing/PrintDocumentHandler.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; -using Eto.Drawing; -using Eto.Platform.Mac.Drawing; -using MonoMac.ObjCRuntime; -using sd = System.Drawing; - -namespace Eto.Platform.Mac.Forms.Printing -{ - public class PrintDocumentHandler : WidgetHandler, IPrintDocument - { - PrintSettings printSettings; - - [Register("PrintView")] - public class PrintView : NSView - { - public PrintView() - { - } - - public PrintView(IntPtr handle) - : base(handle) - { - } - - public PrintView(NSCoder coder) - : base(coder) - { - } - - public PrintDocumentHandler Handler { get; set; } - - public override string PrintJobTitle - { - get { return Handler.Name ?? string.Empty; } - } - - public override sd.RectangleF RectForPage(int pageNumber) - { - var operation = NSPrintOperation.CurrentOperation; - if (Frame.Size != operation.PrintInfo.PaperSize) - SetFrameSize(operation.PrintInfo.PaperSize); - return new sd.RectangleF(new sd.PointF(0, 0), operation.PrintInfo.PaperSize); - //return this.Frame; - } - - static readonly IntPtr selCurrentContext = Selector.GetHandle("currentContext"); - static readonly IntPtr classNSGraphicsContext = Class.GetHandle("NSGraphicsContext"); - - public override void DrawRect(sd.RectangleF dirtyRect) - { - var operation = NSPrintOperation.CurrentOperation; - - var context = new NSGraphicsContext(Messaging.IntPtr_objc_msgSend(classNSGraphicsContext, selCurrentContext)); - // this causes monomac to hang for some reason: - //var context = NSGraphicsContext.CurrentContext; - - using (var graphics = new Graphics(Handler.Widget.Generator, new GraphicsHandler(this, context, Frame.Height, IsFlipped))) - { - Handler.Widget.OnPrintPage(new PrintPageEventArgs(graphics, operation.PrintInfo.PaperSize.ToEto(), operation.CurrentPage - 1)); - } - } - - public override bool KnowsPageRange(ref NSRange aRange) - { - aRange = new NSRange(1, Handler.PageCount); - return true; - } - } - - public PrintDocumentHandler() - { - Control = new PrintView { Handler = this }; - } - - public void Print() - { - Print(false, null, null); - } - - class SheetHelper : NSObject - { - public bool Success { get; set; } - - [Export("printOperationDidRun:success:contextInfo:")] - public void PrintOperationDidRun(IntPtr printOperation, bool success, IntPtr contextInfo) - { - Success = success; - NSApplication.SharedApplication.StopModalWithCode(success ? 1 : 0); - } - } - - public bool Print(bool showPanel, Window parent, NSPrintPanel panel) - { - var op = NSPrintOperation.FromView(Control); - if (printSettings != null) - op.PrintInfo = printSettings.ToNS(); - if (panel != null) - op.PrintPanel = panel; - op.ShowsPrintPanel = showPanel; - if (parent != null) - { - var parentHandler = (IMacWindow)parent.Handler; - var closeSheet = new SheetHelper(); - op.RunOperationModal(parentHandler.Control, closeSheet, new Selector("printOperationDidRun:success:contextInfo:"), IntPtr.Zero); - NSApplication.SharedApplication.RunModalForWindow(parentHandler.Control); - return closeSheet.Success; - } - return op.RunOperation(); - } - - public string Name { get; set; } - - public int PageCount { get; set; } - - public PrintSettings PrintSettings - { - get - { - if (printSettings == null) - printSettings = new PrintSettings(Widget.Generator); - return printSettings; - } - set - { - printSettings = value; - //Control.PrintInfo = printSettings == null ? null : ((PrintSettingsHandler)printSettings.Handler).Control; - } - } - - public override void AttachEvent(string id) - { - switch (id) - { - case PrintDocument.PrintPageEvent: - break; - default: - base.AttachEvent(id); - break; - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/Printing/PrintSettingsHandler.cs b/Source/Eto.Platform.Mac/Forms/Printing/PrintSettingsHandler.cs deleted file mode 100644 index cf4475f7e8..0000000000 --- a/Source/Eto.Platform.Mac/Forms/Printing/PrintSettingsHandler.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.Foundation; - -namespace Eto.Platform.Mac.Forms.Printing -{ - public class PrintSettingsHandler : WidgetHandler, IPrintSettings - { - int lastSelectedPage; - int firstSelectedPage; - - public PrintSettingsHandler(NSPrintInfo info) - { - Control = info; - } - - public PrintSettingsHandler() - { - Control = new NSPrintInfo(); - MaximumPageRange = new Range(1, 1); - SelectedPageRange = new Range(1, 1); - } - - public int Copies - { - get { return (int)(NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMCopies"]; } - set { Control.PrintSettings["com_apple_print_PrintSettings_PMCopies"] = new NSNumber(value); } - } - - public Range MaximumPageRange - { - get - { - var range = ((NSArray)Control.PrintSettings["com_apple_print_PrintSettings_PMPageRange"]); - var firstPage = new NSNumber(range.ValueAt(0)).Int32Value; - var lastPage = new NSNumber(range.ValueAt(1)).Int32Value; - return new Range(firstPage, lastPage - firstPage + 1); - } - set - { - var array = NSArray.FromNSObjects(new NSNumber(value.Start), new NSNumber(value.End)); - Control.PrintSettings["com_apple_print_PrintSettings_PMPageRange"] = array; - } - } - - public Range SelectedPageRange - { - get - { - if (IsAllPages) - { - return new Range(firstSelectedPage, lastSelectedPage - firstSelectedPage + 1); - } - else - { - var firstPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"]).Int32Value; - var lastPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"]).Int32Value; - return new Range(firstPage, lastPage - firstPage + 1); - } - } - set - { - lastSelectedPage = value.End; - firstSelectedPage = value.Start; - - if (!IsAllPages) - { - var firstPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"]).Int32Value; - if (value.Start < firstPage) - { - Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"] = new NSNumber(value.Start); - Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"] = new NSNumber(value.End); - } - else - { - Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"] = new NSNumber(value.End); - Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"] = new NSNumber(value.Start); - } - } - } - } - - public PageOrientation Orientation - { - get { return Control.Orientation.ToEto(); } - set { Control.Orientation = value.ToNS(); } - } - - public bool Collate - { - get { return ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMCopyCollate"]).BoolValue; } - set { Control.PrintSettings["com_apple_print_PrintSettings_PMCopyCollate"] = new NSNumber(value); } - } - - bool IsAllPages - { - get - { - var lastPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"]).Int32Value; - var firstPage = ((NSNumber)Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"]).Int32Value; - return firstPage == 1 && lastPage == Int32.MaxValue; - } - } - - public PrintSelection PrintSelection - { - get - { - if (Control.SelectionOnly) - return PrintSelection.Selection; - return IsAllPages ? PrintSelection.AllPages : PrintSelection.SelectedPages; - } - set - { - switch (value) - { - case Eto.Forms.PrintSelection.AllPages: - Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"] = new NSNumber(Int32.MaxValue); - Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"] = new NSNumber(1); - Control.SelectionOnly = false; - break; - case Eto.Forms.PrintSelection.SelectedPages: - Control.PrintSettings["com_apple_print_PrintSettings_PMLastPage"] = new NSNumber(lastSelectedPage); - Control.PrintSettings["com_apple_print_PrintSettings_PMFirstPage"] = new NSNumber(firstSelectedPage); - Control.SelectionOnly = false; - break; - case Eto.Forms.PrintSelection.Selection: - Control.SelectionOnly = true; - break; - } - } - } - - public bool Reverse - { - get - { - var order = (NSString)Control.PrintSettings["OutputOrder"]; - return order != null && order == "Reverse"; - } - set { Control.PrintSettings["OutputOrder"] = new NSString(value ? "Reverse" : "Normal"); } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/SaveFileDialogHandler.cs b/Source/Eto.Platform.Mac/Forms/SaveFileDialogHandler.cs deleted file mode 100644 index 15d9c97e51..0000000000 --- a/Source/Eto.Platform.Mac/Forms/SaveFileDialogHandler.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using SD = System.Drawing; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; - -namespace Eto.Platform.Mac.Forms -{ - [Register("MySavePanel")] - class MySavePanel : NSSavePanel - { - public IMacFileDialog Handler { get; set; } - - public MySavePanel () - { - } - - public MySavePanel (IntPtr handle) - : base(handle) - { - - } - - [Export ("initWithCoder:")] - public MySavePanel (NSCoder coder) - : base(coder) - { - } - - [Obsolete] - public override string RequiredFileType { - get { - var ext = Handler.GetDefaultExtension (); - return !string.IsNullOrEmpty(ext) ? ext : base.RequiredFileType; - } - set { - base.RequiredFileType = value; - } - } - - /* - protected override void Dispose (bool disposing) - { - base.Dispose (disposing); - }*/ - - } - - public class SaveFileDialogHandler : MacFileDialog, ISaveFileDialog - { - public override string FileName { - get { - return base.FileName; - } - set { - Control.NameFieldStringValue = value; - } - } - - public SaveFileDialogHandler () - { - //MySavePanel.Sa - Control = NSSavePanel.SavePanel; //new MySavePanel{ Handler = this }; - Control.AllowsOtherFileTypes = true; - Control.CanSelectHiddenExtension = true; - } - - - } -} diff --git a/Source/Eto.Platform.Mac/Forms/ScreenHandler.cs b/Source/Eto.Platform.Mac/Forms/ScreenHandler.cs deleted file mode 100644 index 8805e2801c..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ScreenHandler.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using MonoMac.AppKit; -using Eto.Forms; -using MonoMac.ObjCRuntime; -using Eto.Drawing; - -namespace Eto.Platform.Mac.Forms -{ - public class ScreenHandler : WidgetHandler, IScreen - { - public ScreenHandler (NSScreen screen) - { - this.Control = screen; - } - - static readonly Selector selBackingScaleFactor = new Selector ("backingScaleFactor"); - -#pragma warning disable 612, 618 - public float RealScale - { - get - { - if (Control.RespondsToSelector(selBackingScaleFactor)) - return Control.BackingScaleFactor; - return Control.UserSpaceScaleFactor; - } - } -#pragma warning restore 612, 618 - - public float Scale - { - get { return 1f; } - } - - public RectangleF Bounds - { - get - { - var bounds = Control.Frame; - var origin = NSScreen.Screens[0].Frame.Bottom; - bounds.Y = origin - bounds.Height - bounds.Y; - return bounds.ToEto(); - - } - } - - public RectangleF WorkingArea - { - get - { - var workingArea = Control.VisibleFrame; - var origin = NSScreen.Screens[0].Frame.Bottom; - workingArea.Y = origin - workingArea.Height - workingArea.Y; - return workingArea.ToEto(); - } - } - - public int BitsPerPixel - { - get { return NSGraphics.BitsPerPixelFromDepth (Control.Depth); } - } - - public bool IsPrimary - { - get { return Control == NSScreen.Screens[0]; } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/ScreensHandler.cs b/Source/Eto.Platform.Mac/Forms/ScreensHandler.cs deleted file mode 100644 index b42a3bbfeb..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ScreensHandler.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Eto.Forms; -using System.Collections.Generic; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms -{ - public class ScreensHandler : IScreens, IWidget - { - public void Initialize () - { - } - - public Widget Widget { get; set; } - - public Eto.Generator Generator { get; set; } - - public IEnumerable Screens - { - get - { - foreach (var screen in NSScreen.Screens) - { - yield return new Screen (Generator, new ScreenHandler (screen)); - } - } - } - - public Screen PrimaryScreen - { - get - { - var screen = NSScreen.Screens[0]; - return new Screen (Generator, new ScreenHandler (screen)); - } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/SelectFolderDialogHandler.cs b/Source/Eto.Platform.Mac/Forms/SelectFolderDialogHandler.cs deleted file mode 100644 index ffb1195477..0000000000 --- a/Source/Eto.Platform.Mac/Forms/SelectFolderDialogHandler.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using MonoMac.Foundation; - -namespace Eto.Platform.Mac.Forms -{ - public class SelectFolderDialogHandler : WidgetHandler, ISelectFolderDialog - { - public SelectFolderDialogHandler () - { - Control = new NSOpenPanel(); - Control.CanChooseDirectories = true; - Control.CanChooseFiles = false; - Control.CanCreateDirectories = true; - } - - public DialogResult ShowDialog (Window parent) - { - var ret = Control.RunModal(); - return ret == 1 ? DialogResult.Ok : DialogResult.Cancel; - } - - public string Title { - get { - return Control.Title; - } - set { - Control.Title = value; - } - } - - public string Directory { - get { - return Control.DirectoryUrl.Path; - } - set { - Control.DirectoryUrl = new NSUrl(value); - } - } - - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/TableLayoutHandler.cs b/Source/Eto.Platform.Mac/Forms/TableLayoutHandler.cs deleted file mode 100644 index 3cd58a6091..0000000000 --- a/Source/Eto.Platform.Mac/Forms/TableLayoutHandler.cs +++ /dev/null @@ -1,346 +0,0 @@ -using System; -using Eto.Forms; -using System.Linq; -using Eto.Drawing; -using sd = System.Drawing; - -#if IOS -using MonoTouch.UIKit; -using NSView = MonoTouch.UIKit.UIView; -using IMacView = Eto.Platform.iOS.Forms.IIosView; -using MacContainer = Eto.Platform.iOS.Forms.IosLayout; - -#elif OSX -using MonoMac.AppKit; -using Eto.Platform.Mac.Forms.Controls; -using MacContainer = Eto.Platform.Mac.Forms.MacContainer; -#endif -namespace Eto.Platform.Mac.Forms -{ - public class TableLayoutHandler : MacContainer, ITableLayout - { - Control[,] views; - bool[] xscaling; - bool[] yscaling; - int lastxscale; - int lastyscale; - Size spacing; - Padding padding; - sd.SizeF oldFrameSize; - - public override NSView ContainerControl { get { return Control; } } - - public Size Spacing - { - get { return spacing; } - set - { - spacing = value; - if (Widget.Loaded) - LayoutParent(); - } - } - - public Padding Padding - { - get { return padding; } - set - { - padding = value; - if (Widget.Loaded) - LayoutParent(); - } - } - - public TableLayoutHandler() - { -#if OSX - Control = new MacEventView { Handler = this }; -#elif IOS - Control = new NSView(); -#endif - } - - protected override void Initialize() - { - base.Initialize(); - - Spacing = TableLayout.DefaultSpacing; - Padding = TableLayout.DefaultPadding; - Widget.SizeChanged += HandleSizeChanged; - } - - bool isResizing; - - void HandleSizeChanged(object sender, EventArgs e) - { - if (!isResizing) - { - isResizing = true; - LayoutChildren(); - isResizing = false; - } - } - - public override void OnLoad(EventArgs e) - { - base.OnLoad(e); - LayoutChildren(); - } - - protected override SizeF GetNaturalSize(SizeF availableSize) - { - if (views == null) - return SizeF.Empty; - var heights = new float[views.GetLength(0)]; - var widths = new float[views.GetLength(1)]; - float totalxpadding = Padding.Horizontal + Spacing.Width * (widths.Length - 1); - float totalypadding = Padding.Vertical + Spacing.Height * (heights.Length - 1); - var requiredx = totalxpadding; - var requiredy = totalypadding; - - for (int y = 0; y < heights.Length; y++) - { - heights[y] = 0; - } - for (int x = 0; x < widths.Length; x++) - { - widths[x] = 0; - } - - for (int y = 0; y < heights.Length; y++) - for (int x = 0; x < widths.Length; x++) - { - var view = views[y, x]; - if (view != null && view.Visible) - { - var size = view.GetPreferredSize(Size.MaxValue); - if (size.Width > widths[x]) - { - requiredx += size.Width - widths[x]; - widths[x] = size.Width; - } - if (size.Height > heights[y]) - { - requiredy += size.Height - heights[y]; - heights[y] = size.Height; - } - } - } - return new SizeF(requiredx, requiredy); - } - - public override void LayoutChildren() - { - if (!Widget.Loaded) - return; - if (NeedsQueue()) - return; - var heights = new float[views.GetLength(0)]; - var widths = new float[views.GetLength(1)]; - var controlFrame = ContentControl.Frame; - float totalxpadding = Padding.Horizontal + Spacing.Width * (widths.Length - 1); - float totalypadding = Padding.Vertical + Spacing.Height * (heights.Length - 1); - var totalx = controlFrame.Width - totalxpadding; - var totaly = controlFrame.Height - totalypadding; - var requiredx = totalxpadding; - var requiredy = totalypadding; - var numx = 0; - var numy = 0; - - for (int y = 0; y < heights.Length; y++) - { - heights[y] = 0; - if (yscaling[y] || lastyscale == y) - numy++; - } - for (int x = 0; x < widths.Length; x++) - { - widths[x] = 0; - if (xscaling[x] || lastxscale == x) - numx++; - } - - var availableSize = Size.Max(Size.Empty, Control.Frame.Size.ToEtoSize() - new Size((int)requiredx, (int)requiredy)); - for (int y = 0; y < heights.Length; y++) - for (int x = 0; x < widths.Length; x++) - { - var view = views[y, x]; - if (view != null && view.Visible) - { - var size = view.GetPreferredSize(availableSize); - if (!xscaling[x] && lastxscale != x && widths[x] < size.Width) - { - requiredx += size.Width - widths[x]; - widths[x] = size.Width; - } - if (!yscaling[y] && lastyscale != y && heights[y] < size.Height) - { - requiredy += size.Height - heights[y]; - heights[y] = size.Height; - } - } - } - if (controlFrame.Width < requiredx) - { - totalx = requiredx - totalxpadding; - } - if (controlFrame.Height < requiredy) - { - totaly = requiredy - totalypadding; - } - - for (int y = 0; y < heights.Length; y++) - if (!yscaling[y] && lastyscale != y) - totaly -= heights[y]; - for (int x = 0; x < widths.Length; x++) - if (!xscaling[x] && lastxscale != x) - totalx -= widths[x]; - - var chunkx = (numx > 0) ? (float)Math.Truncate(Math.Max(totalx, 0) / numx) : totalx; - var chunky = (numy > 0) ? (float)Math.Truncate(Math.Max(totaly, 0) / numy) : totaly; - -#if OSX - bool flipped = Control.IsFlipped; -#elif IOS - bool flipped = !Control.Layer.GeometryFlipped; -#endif - float starty = Padding.Top; - for (int x = 0; x < widths.Length; x++) - { - if (xscaling[x] || lastxscale == x) - { - widths[x] = Math.Min(chunkx, totalx); - totalx -= chunkx; - } - } - - for (int y = 0; y < heights.Length; y++) - { - if (yscaling[y] || lastyscale == y) - { - heights[y] = Math.Min(chunky, totaly); - totaly -= chunky; - } - float startx = Padding.Left; - for (int x = 0; x < widths.Length; x++) - { - var view = views[y, x]; - if (view != null && view.Visible) - { - var nsview = view.GetContainerView(); - var frame = nsview.Frame; - var oldframe = frame; - frame.Width = widths[x]; - frame.Height = heights[y]; - frame.X = Math.Max(0, startx); - frame.Y = flipped ? starty : controlFrame.Height - starty - frame.Height; - if (frame != oldframe) - nsview.Frame = frame; - else if (oldframe.Right > oldFrameSize.Width || oldframe.Bottom > oldFrameSize.Height - || frame.Right > oldFrameSize.Width || frame.Bottom > oldFrameSize.Height) - nsview.SetNeedsDisplay(); - //Console.WriteLine("*** x:{2} y:{3} view: {0} size: {1} totalx:{4} totaly:{5}", view, view.Size, x, y, totalx, totaly); - } - startx += widths[x] + Spacing.Width; - } - starty += heights[y] + Spacing.Height; - } - oldFrameSize = controlFrame.Size; - } - - public void Add(Control child, int x, int y) - { - var current = views[y, x]; - if (current != null) - { - var currentView = current.GetContainerView(); - if (currentView != null) - currentView.RemoveFromSuperview(); - } - views[y, x] = child; - if (child != null) - { - var view = child.GetContainerView(); - if (Widget.Loaded) - LayoutParent(); - Control.AddSubview(view); - } - else if (Widget.Loaded) - LayoutParent(); - } - - public void Move(Control child, int x, int y) - { - var current = views[y, x]; - if (current != null) - { - var currentView = current.GetContainerView(); - if (currentView != null) - currentView.RemoveFromSuperview(); - } - for (int yy = 0; yy < views.GetLength(0); yy++) - for (int xx = 0; xx < views.GetLength(1); xx++) - { - if (object.ReferenceEquals(views[yy, xx], child)) - views[yy, xx] = null; - } - - views[y, x] = child; - if (Widget.Loaded) - LayoutParent(); - } - - public void Remove(Control child) - { - for (int y = 0; y < views.GetLength(0); y++) - for (int x = 0; x < views.GetLength(1); x++) - { - if (object.ReferenceEquals(views[y, x], child)) - { - var view = child.GetContainerView(); - view.RemoveFromSuperview(); - views[y, x] = null; - if (Widget.Loaded) - LayoutParent(); - return; - } - } - } - - public void CreateControl(int cols, int rows) - { - views = new Control[rows, cols]; - xscaling = new bool[cols]; - lastxscale = cols - 1; - yscaling = new bool[rows]; - lastyscale = rows - 1; - } - - public void SetColumnScale(int column, bool scale) - { - xscaling[column] = scale; - lastxscale = xscaling.Any(r => r) ? -1 : xscaling.Length - 1; - if (Widget.Loaded) - LayoutParent(); - } - - public bool GetColumnScale(int column) - { - return xscaling[column]; - } - - public void SetRowScale(int row, bool scale) - { - yscaling[row] = scale; - lastyscale = yscaling.Any(r => r) ? -1 : yscaling.Length - 1; - if (Widget.Loaded) - LayoutParent(); - } - - public bool GetRowScale(int row) - { - return yscaling[row]; - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/ToolBar/ButtonToolItemHandler.cs b/Source/Eto.Platform.Mac/Forms/ToolBar/ButtonToolItemHandler.cs deleted file mode 100644 index e96b108899..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ToolBar/ButtonToolItemHandler.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac -{ - - public class ButtonToolItemHandler : ToolItemHandler, IButtonToolItem - { - public override void InvokeButton() - { - Widget.OnClick(EventArgs.Empty); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/ToolBar/CheckToolItemHandler.cs b/Source/Eto.Platform.Mac/Forms/ToolBar/CheckToolItemHandler.cs deleted file mode 100644 index b66330b1a5..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ToolBar/CheckToolItemHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac -{ - - public class CheckToolItemHandler : ToolItemHandler, ICheckToolItem - { - bool isChecked; - ToolBarHandler toolbarHandler; - - public bool Checked - { - get { return isChecked; } - set { - isChecked = value; - if (isChecked && Control != null && toolbarHandler != null && toolbarHandler.Control != null) - toolbarHandler.Control.SelectedItemIdentifier = Identifier; - } - } - - protected override void Initialize () - { - base.Initialize (); - Selectable = true; - } - - public override void ControlAdded (ToolBarHandler toolbar) - { - base.ControlAdded (toolbar); - toolbarHandler = toolbar; - if (isChecked) - toolbar.Control.SelectedItemIdentifier = Identifier; - } - - public override void InvokeButton() - { - Widget.OnClick(EventArgs.Empty); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/ToolBar/SeparatorToolItemHandler.cs b/Source/Eto.Platform.Mac/Forms/ToolBar/SeparatorToolItemHandler.cs deleted file mode 100644 index a3ab6b9aeb..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ToolBar/SeparatorToolItemHandler.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Eto.Forms; -using MonoMac.AppKit; -using System; - -namespace Eto.Platform.Mac -{ - public class SeparatorToolItemHandler : WidgetHandler, ISeparatorToolItem, IToolBarBaseItemHandler - { - public SeparatorToolItemHandler() - { - Type = SeparatorToolItemType.Divider; - } - - public virtual string Identifier - { - get - { - switch (Type) - { - default: - return NSToolbar.NSToolbarSeparatorItemIdentifier; - case SeparatorToolItemType.Space: - return NSToolbar.NSToolbarSpaceItemIdentifier; - case SeparatorToolItemType.FlexibleSpace: - return NSToolbar.NSToolbarFlexibleSpaceItemIdentifier; - } - - } - } - - public bool Selectable - { - get { return false; } - } - - public SeparatorToolItemType Type { get; set; } - - public void ControlAdded(ToolBarHandler toolbar) - { - } - - public void CreateFromCommand(Command command) - { - } - - public string Text - { - get { return null; } - set { throw new NotSupportedException(); } - } - - public string ToolTip - { - get { return null; } - set { throw new NotSupportedException(); } - } - - public Eto.Drawing.Image Image - { - get { return null; } - set { throw new NotSupportedException(); } - } - - public bool Enabled - { - get { return false; } - set { throw new NotSupportedException(); } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/ToolBar/ToolBarHandler.cs b/Source/Eto.Platform.Mac/Forms/ToolBar/ToolBarHandler.cs deleted file mode 100644 index 86c1d783e4..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ToolBar/ToolBarHandler.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.AppKit; -using System.Linq; -using System.Collections.Generic; - -namespace Eto.Platform.Mac -{ - public class ToolBarHandler : WidgetHandler, IToolBar - { - ToolBarDock dock = ToolBarDock.Top; - readonly List items = new List(); - - class TBDelegate : NSToolbarDelegate - { - WeakReference handler; - - public ToolBarHandler Handler { get { return (ToolBarHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public override string[] SelectableItemIdentifiers(NSToolbar toolbar) - { - return Handler.items.Where(r => r.Selectable).Select(r => r.Identifier).ToArray(); - } - - public override void WillAddItem(MonoMac.Foundation.NSNotification notification) - { - - } - - public override void DidRemoveItem(MonoMac.Foundation.NSNotification notification) - { - } - - public override NSToolbarItem WillInsertItem(NSToolbar toolbar, string itemIdentifier, bool willBeInserted) - { - var item = Handler.items.FirstOrDefault(r => r.Identifier == itemIdentifier); - return item == null ? null : item.Control; - } - - public override string[] DefaultItemIdentifiers(NSToolbar toolbar) - { - return Handler.items.Select(r => r.Identifier).ToArray(); - } - - public override string[] AllowedItemIdentifiers(NSToolbar toolbar) - { - return Handler.items.Select(r => r.Identifier) - .Union( - new string[] - { - NSToolbar.NSToolbarSeparatorItemIdentifier, - NSToolbar.NSToolbarSpaceItemIdentifier, - NSToolbar.NSToolbarFlexibleSpaceItemIdentifier, - NSToolbar.NSToolbarCustomizeToolbarItemIdentifier - }).ToArray(); - } - } - - public ToolBarHandler() - { - Control = new NSToolbar("main"); - Control.SizeMode = NSToolbarSizeMode.Default; - Control.Visible = true; - Control.ShowsBaselineSeparator = true; - //Control.AllowsUserCustomization = true; - Control.DisplayMode = NSToolbarDisplayMode.IconAndLabel; - Control.Delegate = new TBDelegate { Handler = this }; - } - - public ToolBarDock Dock - { - get { return dock; } - set { dock = value; } - } - - public void AddButton(ToolItem item, int index) - { - var handler = (IToolBarBaseItemHandler)item.Handler; - items.Insert(index, handler); - Control.InsertItem(handler.Identifier, index); - if (handler != null) - handler.ControlAdded(this); - //Control.ValidateVisibleItems(); - } - - public void RemoveButton(ToolItem item) - { - var handler = item.Handler as IToolBarBaseItemHandler; - var index = items.IndexOf(handler); - items.Remove(handler); - //var handler = item.Handler as IToolBarItemHandler; - Control.RemoveItem(index); - //Control.ValidateVisibleItems(); - } - - public ToolBarTextAlign TextAlign - { - get - { - /*switch (control.TextAlign) - { - case SWF.ToolBarTextAlign.Right: - return ToolBarTextAlign.Right; - default: - case SWF.ToolBarTextAlign.Underneath: - return ToolBarTextAlign.Underneath; - } - */ - return ToolBarTextAlign.Underneath; - } - set - { - switch (value) - { - case ToolBarTextAlign.Right: - //control.TextAlign = SWF.ToolBarTextAlign.Right; - break; - } - } - } - - public void Clear() - { - for (int i = Control.Items.Length - 1; i >=0; i--) - { - Control.RemoveItem(i); - } - items.Clear(); - // allow menu items to be GC'd - var newitems = Control.Items; - - //Control.ValidateVisibleItems(); - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/ToolBar/ToolItemHandler.cs b/Source/Eto.Platform.Mac/Forms/ToolBar/ToolItemHandler.cs deleted file mode 100644 index 13214ccb9d..0000000000 --- a/Source/Eto.Platform.Mac/Forms/ToolBar/ToolItemHandler.cs +++ /dev/null @@ -1,245 +0,0 @@ -using System; -using Eto.Forms; -using MonoMac.Foundation; -using MonoMac.AppKit; -using Eto.Drawing; -using MonoMac.ObjCRuntime; -using sd = System.Drawing; -using Eto.Platform.Mac.Forms.Actions; - -namespace Eto.Platform.Mac -{ - public interface IToolBarBaseItemHandler - { - string Identifier { get; } - - NSToolbarItem Control { get; } - - bool Selectable { get; } - - void ControlAdded(ToolBarHandler toolbar); - } - - public interface IToolBarItemHandler : IToolBarBaseItemHandler - { - void OnClick(); - - bool Enabled { get; } - - NSButton Button { get; } - - MacToolBarItemStyle ToolBarItemStyle {get; set;} - } - - class ToolBarItemHandlerTarget : NSObject - { - WeakReference handler; - - public IToolBarItemHandler Handler { get { return (IToolBarItemHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [Export("validateToolbarItem:")] - public bool ValidateToolbarItem(NSToolbarItem item) - { - return Handler.Enabled; - } - - [Export("action")] - public bool Action() - { - Handler.OnClick(); - return true; - } - } - - /// - /// A toolbar item can be displayed in three ways. - /// To set a non-default style, create a custom style handler - /// for the Mac platform that sets the style to one of these types. - /// - public enum MacToolBarItemStyle - { - /// - /// The default appearance, with 32x32 icons. - /// Does not have a View. - /// - Default, - /// - /// A small button with a rounded bezel. - /// - StandardButton, - /// - /// A large button. Similar in appearance to Default, - /// but uses a Button as the View. - /// - LargeButton - } - - public abstract class ToolItemHandler : WidgetHandler, IToolItem, IToolBarItemHandler - where TControl: NSToolbarItem - where TWidget: ToolItem - { - Image image; - NSButton button; - NSMenuItem menuItem; - Color? tint; - - private sd.SizeF ButtonSize - { - get { - if (toolBarItemStyle == MacToolBarItemStyle.Default) - return new sd.SizeF (42, 32); - else if (toolBarItemStyle == MacToolBarItemStyle.StandardButton) - return new sd.SizeF (42, 24); - else // large button - return new sd.SizeF (42, 32); - } - } - - public int ImageSize { get { return (toolBarItemStyle == MacToolBarItemStyle.StandardButton) ? 20 : 32; } } - - MacToolBarItemStyle toolBarItemStyle; - public MacToolBarItemStyle ToolBarItemStyle - { - get { return toolBarItemStyle; } - set { - toolBarItemStyle = value; // set the value first because ButtonSize and ImageSize depend on it. - button = null; - if (value == MacToolBarItemStyle.StandardButton || value == MacToolBarItemStyle.LargeButton) { - button = new NSButton { - BezelStyle = NSBezelStyle.TexturedRounded, - Bordered = toolBarItemStyle == MacToolBarItemStyle.StandardButton, // no border or bezel in the large button style - Frame = new sd.RectangleF(sd.PointF.Empty, ButtonSize), - Target = Control.Target, - Action = Control.Action, - }; - if (value == MacToolBarItemStyle.LargeButton) - button.SetButtonType (NSButtonType.MomentaryChange); // prevents a flash in the large button view. See the comment at the bottom of http://yellowfieldtechnologies.wordpress.com/2011/11/18/nspopover-from-nstoolbaritem/#comments - Control.View = button; - } - SetImage (); - } - } - - public NSButton Button - { - get { return button; } - } - - public Color? Tint - { - get { return tint; } - set - { - tint = value; - } - } - - public string Identifier { get; set; } - - protected ToolItemHandler() - { - this.Identifier = Guid.NewGuid().ToString(); - } - - public void UseStandardButton(bool grayscale) - { - this.ToolBarItemStyle = MacToolBarItemStyle.StandardButton; - if (grayscale) - Tint = Colors.Gray; - } - - public override TControl CreateControl() - { - return (TControl)new NSToolbarItem(Identifier); - } - - static readonly Selector selAction = new Selector("action"); - - protected override void Initialize() - { - base.Initialize(); - Control.Target = new ToolBarItemHandlerTarget { Handler = this }; - Control.Action = selAction; - Control.Autovalidates = false; - - menuItem = new NSMenuItem(string.Empty); - menuItem.Action = Control.Action; - menuItem.Target = Control.Target; - Control.MenuFormRepresentation = menuItem; - Control.Enabled = true; - - this.ToolBarItemStyle = MacToolBarItemStyle.Default; - } - - public virtual void ControlAdded(ToolBarHandler toolbar) - { - } - - public virtual void InvokeButton() - { - } - - public string Text - { - get { return Control.Label; } - set { Control.Label = menuItem.Title = value ?? string.Empty; } - } - - public string ToolTip - { - get { return Control.ToolTip; } - set { - if (menuItem != null) - menuItem.ToolTip = value ?? string.Empty; - if (button != null) - button.ToolTip = value ?? string.Empty; - } - } - - public Image Image - { - get { return image; } - set - { - image = value; - SetImage(); - } - } - - void SetImage() - { - var nsimage = image.ToNS(ImageSize); - if (tint != null && nsimage != null) - nsimage = nsimage.Tint(tint.Value.ToNSUI()); - Control.Image = nsimage; - } - - public virtual bool Enabled - { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - - public virtual bool Selectable { get; set; } - - public void OnClick() - { - InvokeButton(); - } - - NSToolbarItem IToolBarBaseItemHandler.Control - { - get { return Control; } - } - - public void CreateFromCommand(Command command) - { - var m = command as MacCommand; - if (m != null) - { - Control.Target = null; - Control.Action = m.Selector; - } - } - } -} diff --git a/Source/Eto.Platform.Mac/Forms/UITimerHandler.cs b/Source/Eto.Platform.Mac/Forms/UITimerHandler.cs deleted file mode 100644 index b845c81a59..0000000000 --- a/Source/Eto.Platform.Mac/Forms/UITimerHandler.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using Eto.Forms; -#if IOS -using MonoTouch.Foundation; -#else -using MonoMac.Foundation; -#endif - -#if IOS -namespace Eto.Platform.iOS.Forms - -#elif OSX -namespace Eto.Platform.Mac.Forms -#endif -{ - public class UITimerHandler : WidgetHandler, IUITimer - { - double interval = UITimer.DefaultInterval; - - class Helper - { - WeakReference handler; - public UITimerHandler Handler { get { return (UITimerHandler)handler.Target; } set { handler = new WeakReference(value); } } - - public void Elapsed() - { - var h = Handler; - if (h != null) - { - h.Widget.OnElapsed(EventArgs.Empty); - } - } - } - - public void Start () - { - Stop(); - var helper = new Helper { Handler = this }; - Control = NSTimer.CreateRepeatingTimer(interval, helper.Elapsed); - NSRunLoop.Current.AddTimer(Control, NSRunLoopMode.Default); - } - - public void Stop () - { - if (Control != null) - { - Control.Invalidate(); - Control.Dispose (); - Control = null; - } - } - - public double Interval - { - get { return interval; } - set { interval = value; } - } - } -} - diff --git a/Source/Eto.Platform.Mac/Forms/iosCompatibility.cs b/Source/Eto.Platform.Mac/Forms/iosCompatibility.cs deleted file mode 100644 index bc2eada541..0000000000 --- a/Source/Eto.Platform.Mac/Forms/iosCompatibility.cs +++ /dev/null @@ -1,16 +0,0 @@ -using MonoMac.AppKit; - -namespace Eto.Platform.Mac.Forms -{ - public static class IosCompatibility - { - /// - /// Compatibility with ios - /// - public static void SetNeedsDisplay(this NSView view) - { - view.NeedsDisplay = true; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Generator.cs b/Source/Eto.Platform.Mac/Generator.cs deleted file mode 100644 index 978f8d2d40..0000000000 --- a/Source/Eto.Platform.Mac/Generator.cs +++ /dev/null @@ -1,147 +0,0 @@ -using System; -using Eto.Drawing; -using Eto.Forms; -using Eto.IO; -using MonoMac.AppKit; -using Eto.Platform.Mac.Drawing; -using MonoMac.Foundation; -using Eto.Platform.Mac.IO; -using Eto.Platform.Mac.Forms.Controls; -using Eto.Platform.Mac.Forms.Printing; -using Eto.Platform.Mac.Forms; -using Eto.Platform.Mac.Forms.Menu; -using Eto.Platform.Mac.Threading; -using Eto.Threading; - -namespace Eto.Platform.Mac -{ - [Preserve(AllMembers = true)] - public class Generator : Eto.Generator - { - #if XAMMAC - public override string ID { get { return Generators.XamMac; } } - -#else - public override string ID { get { return Generators.Mac; } } - #endif - static bool initialized; - - public Generator() - { - if (!initialized) - { - NSApplication.Init(); - // until everything is marked as thread safe correctly in monomac - // e.g. overriding NSButtonCell.DrawBezelWithFrame will throw an exception - NSApplication.CheckForIllegalCrossThreadCalls = false; - - initialized = true; - } - AddTo(this); - } - - public static void AddTo(Eto.Generator g) - { - // Drawing - g.Add(() => new BitmapHandler()); - g.Add(() => new FontFamilyHandler()); - g.Add(() => new FontHandler()); - g.Add(() => new FontsHandler()); - g.Add(() => new GraphicsHandler()); - g.Add(() => new GraphicsPathHandler()); - g.Add(() => new IconHandler()); - g.Add(() => new IndexedBitmapHandler()); - g.Add(() => new MatrixHandler()); - g.Add(() => new PenHandler()); - g.Add(() => new SolidBrushHandler()); - g.Add(() => new TextureBrushHandler()); - g.Add(() => new LinearGradientBrushHandler()); - - // Forms.Cells - g.Add(() => new CheckBoxCellHandler()); - g.Add(() => new ComboBoxCellHandler()); - g.Add(() => new ImageTextCellHandler()); - g.Add(() => new ImageViewCellHandler()); - g.Add(() => new TextBoxCellHandler()); - - // Forms.Controls - g.Add(() => new ButtonHandler()); - g.Add(() => new CheckBoxHandler()); - g.Add(() => new ComboBoxHandler()); - g.Add(() => new DateTimePickerHandler()); - g.Add(() => new DrawableHandler()); - g.Add(() => new GridColumnHandler()); - g.Add(() => new GridViewHandler()); - g.Add(() => new GroupBoxHandler()); - g.Add(() => new ImageViewHandler()); - g.Add(() => new LabelHandler()); - g.Add(() => new ListBoxHandler()); - g.Add(() => new NumericUpDownHandler()); - g.Add(() => new PanelHandler()); - g.Add(() => new PasswordBoxHandler()); - g.Add(() => new ProgressBarHandler()); - g.Add(() => new RadioButtonHandler()); - g.Add(() => new ScrollableHandler()); - g.Add(() => new SearchBoxHandler()); - g.Add(() => new SliderHandler()); - g.Add(() => new SpinnerHandler()); - g.Add(() => new SplitterHandler()); - g.Add(() => new TabControlHandler()); - g.Add(() => new TabPageHandler()); - g.Add(() => new TextAreaHandler()); - g.Add(() => new TextBoxHandler()); - g.Add(() => new TreeGridViewHandler()); - g.Add(() => new TreeViewHandler()); - g.Add(() => new WebViewHandler()); - g.Add(() => new ScreensHandler()); - - // Forms.Menu - g.Add(() => new CheckMenuItemHandler()); - g.Add(() => new ContextMenuHandler()); - g.Add(() => new ImageMenuItemHandler()); - g.Add(() => new MenuBarHandler()); - g.Add(() => new RadioMenuItemHandler()); - g.Add(() => new SeparatorMenuItemHandler()); - - // Forms.Printing - g.Add(() => new PrintDialogHandler()); - g.Add(() => new PrintDocumentHandler()); - g.Add(() => new PrintSettingsHandler()); - - // Forms.ToolBar - g.Add(() => new CheckToolItemHandler()); - g.Add(() => new SeparatorToolItemHandler()); - g.Add(() => new ButtonToolItemHandler()); - g.Add(() => new ToolBarHandler()); - - // Forms - g.Add(() => new ApplicationHandler()); - g.Add(() => new ClipboardHandler()); - g.Add(() => new ColorDialogHandler()); - g.Add(() => new CursorHandler()); - g.Add(() => new DialogHandler()); - g.Add(() => new FontDialogHandler()); - g.Add(() => new FormHandler()); - g.Add(() => new MessageBoxHandler()); - g.Add(() => new OpenFileDialogHandler()); - g.Add(() => new PixelLayoutHandler()); - g.Add(() => new SaveFileDialogHandler()); - g.Add(() => new SelectFolderDialogHandler()); - g.Add(() => new TableLayoutHandler()); - g.Add(() => new UITimerHandler()); - g.Add(() => new MouseHandler()); - - // IO - g.Add(() => new SystemIconsHandler()); - - // General - g.Add(() => new EtoEnvironmentHandler()); - g.Add(() => new ThreadHandler()); - } - - public override IDisposable ThreadStart() - { - return new NSAutoreleasePool(); - } - } -} diff --git a/Source/Eto.Platform.Mac/IO/SystemIconsHandler.cs b/Source/Eto.Platform.Mac/IO/SystemIconsHandler.cs deleted file mode 100644 index 96bcd68886..0000000000 --- a/Source/Eto.Platform.Mac/IO/SystemIconsHandler.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Eto.IO; -using Eto.Drawing; -using MonoMac.AppKit; -using System.IO; -using Eto.Platform.Mac.Drawing; -using System; - -namespace Eto.Platform.Mac.IO -{ - public class SystemIconsHandler : WidgetHandler, ISystemIcons - { - - #region ISystemIcons implementation - - public Icon GetFileIcon(string fileName, IconSize size) - { - var ws = new NSWorkspace(); - var image = ws.IconForFileType(Path.GetExtension(fileName)); - return new Icon(Widget.Generator, new IconHandler(image)); - } - - public Icon GetStaticIcon(StaticIconType type, IconSize size) - { - var ws = new NSWorkspace(); - string code; - switch (type) - { - case StaticIconType.OpenDirectory: - code = "ofld"; - break; - case StaticIconType.CloseDirectory: - code = "ofld"; - break; - default: - throw new NotSupportedException(); - } - var image = ws.IconForFileType(code); - return new Icon(Widget.Generator, new IconHandler(image)); - } - - #endregion - - } -} - diff --git a/Source/Eto.Platform.Mac/InvokeHelper.cs b/Source/Eto.Platform.Mac/InvokeHelper.cs deleted file mode 100644 index 19046b5425..0000000000 --- a/Source/Eto.Platform.Mac/InvokeHelper.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -namespace Eto.Platform.Mac -{ - class InvokeHelper - { - public Delegate Delegate { get; set; } - public object[] Args { get; set; } - public object Return { get; private set; } - - public void Action() - { - Return = Delegate.DynamicInvoke(Args); - } - } -} - diff --git a/Source/Eto.Platform.Mac/KeyMap.cs b/Source/Eto.Platform.Mac/KeyMap.cs deleted file mode 100644 index 8309814175..0000000000 --- a/Source/Eto.Platform.Mac/KeyMap.cs +++ /dev/null @@ -1,224 +0,0 @@ -using System.Collections.Generic; -using Eto.Forms; -using MonoMac.AppKit; - -namespace Eto.Platform.Mac -{ - public static class KeyMap - { - static readonly Dictionary keymap = new Dictionary (); - static readonly Dictionary inverse = new Dictionary (); - - public static Keys MapKey (ushort key) - { - Keys value; - return keymap.TryGetValue(key, out value) ? value : Keys.None; - } - - enum KeyCharacters { - NSParagraphSeparatorCharacter = 0x2029, - NSLineSeparatorCharacter = 0x2028, - NSTabCharacter = 0x0009, - NSFormFeedCharacter = 0x000c, - NSNewlineCharacter = 0x000a, - NSCarriageReturnCharacter = 0x000d, - NSEnterCharacter = 0x0003, - NSBackspaceCharacter = 0x0008, - NSBackTabCharacter = 0x0019, - NSDeleteCharacter = 0x007f - }; - - public static Keys Convert (string keyEquivalent, NSEventModifierMask modifier) - { - return Keys.None; - } - - public static string KeyEquivalent (Keys key) - { - string value; - return inverse.TryGetValue(key & Keys.KeyMask, out value) ? value : string.Empty; - } - - public static NSEventModifierMask KeyEquivalentModifierMask (Keys key) - { - key &= Keys.ModifierMask; - var mask = (NSEventModifierMask)0; - if (key.HasFlag(Keys.Shift)) - mask |= NSEventModifierMask.ShiftKeyMask; - if (key.HasFlag(Keys.Alt)) - mask |= NSEventModifierMask.AlternateKeyMask; - if (key.HasFlag(Keys.Control)) - mask |= NSEventModifierMask.ControlKeyMask; - if (key.HasFlag(Keys.Application)) - mask |= NSEventModifierMask.CommandKeyMask; - return mask; - } - - public static Keys GetModifiers (NSEvent theEvent) - { - Keys key = Keys.None; - if ((theEvent.ModifierFlags & NSEventModifierMask.ControlKeyMask) != 0) - key |= Keys.Control; - if ((theEvent.ModifierFlags & NSEventModifierMask.CommandKeyMask) != 0) - key |= Keys.Application; - if ((theEvent.ModifierFlags & NSEventModifierMask.ShiftKeyMask) != 0) - key |= Keys.Shift; - if ((theEvent.ModifierFlags & NSEventModifierMask.AlternateKeyMask) != 0) - key |= Keys.Alt; - return key; - } - - static KeyMap () - { - keymap.Add(0, Keys.A); - keymap.Add(11, Keys.B); - keymap.Add(8, Keys.C); - keymap.Add(2, Keys.D); - keymap.Add(14, Keys.E); - keymap.Add(3, Keys.F); - keymap.Add(5, Keys.G); - keymap.Add(4, Keys.H); - keymap.Add(34, Keys.I); - keymap.Add(38, Keys.J); - keymap.Add(40, Keys.K); - keymap.Add(37, Keys.L); - keymap.Add(46, Keys.M); - keymap.Add(45, Keys.N); - keymap.Add(31, Keys.O); - keymap.Add(35, Keys.P); - keymap.Add(12, Keys.Q); - keymap.Add(15, Keys.R); - keymap.Add(1, Keys.S); - keymap.Add(17, Keys.T); - keymap.Add(32, Keys.U); - keymap.Add(9, Keys.V); - keymap.Add(13, Keys.W); - keymap.Add(7, Keys.X); - keymap.Add(16, Keys.Y); - keymap.Add(6, Keys.Z); - keymap.Add(18, Keys.D1); - keymap.Add(19, Keys.D2); - keymap.Add(20, Keys.D3); - keymap.Add(21, Keys.D4); - keymap.Add(23, Keys.D5); - keymap.Add(22, Keys.D6); - keymap.Add(26, Keys.D7); - keymap.Add(28, Keys.D8); - keymap.Add(25, Keys.D9); - keymap.Add(29, Keys.D0); - keymap.Add(122, Keys.F1); - keymap.Add(120, Keys.F2); - keymap.Add(99, Keys.F3); - keymap.Add(118, Keys.F4); - keymap.Add(96, Keys.F5); - keymap.Add(97, Keys.F6); - keymap.Add(98, Keys.F7); - keymap.Add(100, Keys.F8); - keymap.Add(101, Keys.F9); - keymap.Add(109, Keys.F10); - keymap.Add(103, Keys.F11); - keymap.Add(111, Keys.F12); - keymap.Add(50, Keys.Grave); - keymap.Add(27, Keys.Minus); - keymap.Add(24, Keys.Equal); - keymap.Add(42, Keys.Backslash); - keymap.Add(49, Keys.Space); - //keymap.Add(30, Keys.]); - //keymap.Add(33, Keys.[); - keymap.Add(39, Keys.Quote); - keymap.Add(41, Keys.Semicolon); - keymap.Add(44, Keys.ForwardSlash); - keymap.Add(47, Keys.Period); - keymap.Add(43, Keys.Comma); - keymap.Add(36, Keys.Enter); - keymap.Add(48, Keys.Tab); - //keymap.Add(76, Keys.Return); - keymap.Add(53, Keys.Escape); - - keymap.Add(76, Keys.Insert); - keymap.Add(51, Keys.Backspace); - keymap.Add(117, Keys.Delete); - - keymap.Add(125, Keys.Down); - keymap.Add(126, Keys.Up); - keymap.Add(123, Keys.Left); - keymap.Add(124, Keys.Right); - - keymap.Add(116, Keys.PageUp); - keymap.Add(121, Keys.PageDown); - keymap.Add(119, Keys.End); - keymap.Add(115, Keys.Home); - keymap.Add(110, Keys.ContextMenu); - - - inverse.Add (Keys.A, "a"); - inverse.Add (Keys.B, "b"); - inverse.Add (Keys.C, "c"); - inverse.Add (Keys.D, "d"); - inverse.Add (Keys.E, "e"); - inverse.Add (Keys.F, "f"); - inverse.Add (Keys.G, "g"); - inverse.Add (Keys.H, "h"); - inverse.Add (Keys.I, "i"); - inverse.Add (Keys.J, "j"); - inverse.Add (Keys.K, "k"); - inverse.Add (Keys.L, "l"); - inverse.Add (Keys.M, "m"); - inverse.Add (Keys.N, "n"); - inverse.Add (Keys.O, "o"); - inverse.Add (Keys.P, "p"); - inverse.Add (Keys.Q, "q"); - inverse.Add (Keys.R, "r"); - inverse.Add (Keys.S, "s"); - inverse.Add (Keys.T, "t"); - inverse.Add (Keys.U, "u"); - inverse.Add (Keys.V, "v"); - inverse.Add (Keys.W, "w"); - inverse.Add (Keys.X, "x"); - inverse.Add (Keys.Y, "y"); - inverse.Add (Keys.Z, "z"); - inverse.Add (Keys.Period, "."); - inverse.Add (Keys.Comma, ","); - inverse.Add (Keys.Space, " "); - inverse.Add (Keys.Backslash, "\\"); - inverse.Add (Keys.ForwardSlash, "/"); - inverse.Add (Keys.Equal, "="); - inverse.Add (Keys.Grave, "`"); - inverse.Add (Keys.Minus, "-"); - inverse.Add (Keys.Semicolon, ";"); - inverse.Add (Keys.Up, ((char)NSKey.UpArrow).ToString()); - inverse.Add (Keys.Down, ((char)NSKey.DownArrow).ToString()); - inverse.Add (Keys.Right, ((char)NSKey.RightArrow).ToString()); - inverse.Add (Keys.Left, ((char)NSKey.LeftArrow).ToString()); - inverse.Add (Keys.Home, ((char)NSKey.Home).ToString()); - inverse.Add (Keys.End, ((char)NSKey.End).ToString()); - inverse.Add (Keys.Insert, ((char)NSKey.Insert).ToString()); - inverse.Add (Keys.Delete, ((char)KeyCharacters.NSDeleteCharacter).ToString()); - inverse.Add (Keys.Backspace, ((char)KeyCharacters.NSBackspaceCharacter).ToString()); - inverse.Add (Keys.Tab, ((char)KeyCharacters.NSTabCharacter).ToString()); - inverse.Add (Keys.D0, "0"); - inverse.Add (Keys.D1, "1"); - inverse.Add (Keys.D2, "2"); - inverse.Add (Keys.D3, "3"); - inverse.Add (Keys.D4, "4"); - inverse.Add (Keys.D5, "5"); - inverse.Add (Keys.D6, "6"); - inverse.Add (Keys.D7, "7"); - inverse.Add (Keys.D8, "8"); - inverse.Add (Keys.D9, "9"); - inverse.Add (Keys.F1, ((char)NSKey.F1).ToString()); - inverse.Add (Keys.F2, ((char)NSKey.F2).ToString()); - inverse.Add (Keys.F3, ((char)NSKey.F3).ToString()); - inverse.Add (Keys.F4, ((char)NSKey.F4).ToString()); - inverse.Add (Keys.F5, ((char)NSKey.F5).ToString()); - inverse.Add (Keys.F6, ((char)NSKey.F6).ToString()); - inverse.Add (Keys.F7, ((char)NSKey.F7).ToString()); - inverse.Add (Keys.F8, ((char)NSKey.F8).ToString()); - inverse.Add (Keys.F9, ((char)NSKey.F9).ToString()); - inverse.Add (Keys.F10, ((char)NSKey.F10).ToString()); - inverse.Add (Keys.F11, ((char)NSKey.F11).ToString()); - inverse.Add (Keys.F12, ((char)NSKey.F12).ToString()); - } - } -} - diff --git a/Source/Eto.Platform.Mac/MacExtensions.cs b/Source/Eto.Platform.Mac/MacExtensions.cs deleted file mode 100644 index cab8ed1827..0000000000 --- a/Source/Eto.Platform.Mac/MacExtensions.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Drawing; -using MonoMac.Foundation; -using MonoMac.AppKit; -using MonoMac.ObjCRuntime; - -namespace Eto.Platform.Mac -{ - /// - /// These are extensions for missing methods in monomac/xamarin.mac, or incorrectly bound. - /// - /// - /// Once monomac/xam.mac supports these methods or are implemented properly, then remove from here. - /// - public static class MacExtensions - { - static readonly IntPtr selBoundingRectWithSize = Selector.GetHandle("boundingRectWithSize:options:"); - - [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend_stret")] - static extern void RectangleF_objc_msgSend_stret_SizeF_int(out RectangleF retval, IntPtr receiver, IntPtr selector, SizeF arg1, int arg2); - - // not bound - public static RectangleF BoundingRect(this NSAttributedString str, SizeF size, NSStringDrawingOptions options) - { - RectangleF rect; - RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options); - return rect; - } - - static readonly IntPtr selNextEventMatchingMask = Selector.GetHandle("nextEventMatchingMask:untilDate:inMode:dequeue:"); - - // untilDate isn't allowed null - public static NSEvent NextEventEx(this NSApplication app, NSEventMask mask, NSDate untilDate, NSString mode, bool dequeue) - { - return (NSEvent)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend_UInt32_IntPtr_IntPtr_bool(app.Handle, selNextEventMatchingMask, (uint)mask, untilDate != null ? untilDate.Handle : IntPtr.Zero, mode.Handle, dequeue)); - } - - [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] - static extern void void_objc_msgSend_NSRange_NSPoint(IntPtr receiver, IntPtr selector, NSRange arg1, PointF arg2); - - static readonly IntPtr selDrawGlyphs = Selector.GetHandle("drawGlyphsForGlyphRange:atPoint:"); - - // not bound - public static void DrawGlyphs(this NSLayoutManager layout, NSRange range, PointF point) - { - void_objc_msgSend_NSRange_NSPoint(layout.Handle, selDrawGlyphs, range, point); - } - } -} - diff --git a/Source/Eto.Platform.Mac/NSImageExtensions.cs b/Source/Eto.Platform.Mac/NSImageExtensions.cs deleted file mode 100644 index 95ee4fcf86..0000000000 --- a/Source/Eto.Platform.Mac/NSImageExtensions.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using MonoMac.AppKit; -using MonoMac.CoreImage; -using sd = System.Drawing; -using MonoMac.Foundation; -using Eto.Drawing; - -namespace Eto.Platform.Mac -{ - public static class NSImageExtensions - { - public static NSImage Resize(this NSImage image, sd.Size newsize, ImageInterpolation interpolation = ImageInterpolation.Default) - { - var newimage = new NSImage(newsize); - var newrep = new NSBitmapImageRep(IntPtr.Zero, newsize.Width, newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * newsize.Width, 32); - newimage.AddRepresentation(newrep); - - var graphics = NSGraphicsContext.FromBitmap(newrep); - NSGraphicsContext.GlobalSaveGraphicsState(); - NSGraphicsContext.CurrentContext = graphics; - graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG(); - image.DrawInRect(new sd.RectangleF(sd.PointF.Empty, newimage.Size), new sd.RectangleF(sd.PointF.Empty, image.Size), NSCompositingOperation.SourceOver, 1f); - NSGraphicsContext.GlobalRestoreGraphicsState(); - return newimage; - } - - public static NSImage Tint(this NSImage image, NSColor tint) - { - var colorGenerator = new CIConstantColorGenerator - { - Color = CIColor.FromCGColor(tint.CGColor) - }; - - var colorFilter = new CIColorControls - { - Image = (CIImage)colorGenerator.ValueForKey(CIFilterOutputKey.Image), - Saturation = 3f, - Brightness = 0.35f, - Contrast = 1f - }; - - var monochromeFilter = new CIColorMonochrome - { - Image = CIImage.FromCGImage(image.CGImage), - Color = CIColor.FromRgb(0.75f, 0.75f, 0.75f), - Intensity = 1f - }; - - var compositingFilter = new CIMultiplyCompositing - { - Image = (CIImage)colorFilter.ValueForKey(CIFilterOutputKey.Image), - BackgroundImage = (CIImage)monochromeFilter.ValueForKey(CIFilterOutputKey.Image) - }; - - var outputImage = (CIImage)compositingFilter.ValueForKey(CIFilterOutputKey.Image); - var extent = outputImage.Extent; - - var newsize = sd.Size.Truncate(extent.Size); - if (newsize.IsEmpty) - return image; - - var tintedImage = new NSImage(newsize); - tintedImage.LockFocus(); - try - { - var graphics = NSGraphicsContext.CurrentContext.GraphicsPort; - var ciContext = CIContext.FromContext(graphics, new CIContextOptions { UseSoftwareRenderer = true }); - ciContext.DrawImage(outputImage, extent, extent); - } - finally - { - tintedImage.UnlockFocus(); - } - - var newrep = tintedImage.Representations()[0]; - newrep.Size = image.Size; - return tintedImage; - } - } -} - diff --git a/Source/Eto.Platform.Mac/Properties/AssemblyInfo.cs b/Source/Eto.Platform.Mac/Properties/AssemblyInfo.cs deleted file mode 100644 index 44d5949393..0000000000 --- a/Source/Eto.Platform.Mac/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Reflection; - -#if XAMMAC -[assembly: AssemblyTitle("Eto.Forms - OS X Platform using Xamarin.Mac")] -[assembly: AssemblyDescription("OS X Platform for the Eto.Forms UI Framework using Xamarin.Mac")] -#else -[assembly: AssemblyTitle("Eto.Forms - OS X Platform using MonoMac")] -[assembly: AssemblyDescription("OS X Platform for the Eto.Forms UI Framework using the open-source MonoMac")] -#endif - diff --git a/Source/Eto.Platform.Mac/Threading/ThreadHandler.cs b/Source/Eto.Platform.Mac/Threading/ThreadHandler.cs deleted file mode 100644 index 07e1f238a2..0000000000 --- a/Source/Eto.Platform.Mac/Threading/ThreadHandler.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using Eto.Threading; - -#if OSX -using MonoMac.Foundation; -using MonoMac.ObjCRuntime; - -namespace Eto.Platform.Mac.Threading -#elif IOS - -using MonoTouch.Foundation; -using MonoTouch.ObjCRuntime; - -namespace Eto.Platform.iOS.Threading -#endif -{ - public class ThreadHandler : WidgetHandler, IThread - { - class Delegate : NSObject - { - WeakReference handler; - public ThreadHandler Handler { get { return (ThreadHandler)handler.Target; } set { handler = new WeakReference(value); } } - - [Export("execute")] - public void Execute() - { - using (var pool = new NSAutoreleasePool()) - { - Handler.Widget.OnExecuted(); - } - } - } - - static readonly Selector selExecute = new Selector("execute"); - - public void Create() - { - Control = new NSThread(new Delegate { Handler = this }, selExecute, null); - } - - public void CreateCurrent() - { - Control = NSThread.Current; - } - - public void CreateMain() - { - Control = NSThread.MainThread; - } - - public void Start() - { - Control.Start(); - } - - public void Abort() - { - Control.Cancel(); - } - - public bool IsAlive { get { return Control.IsExecuting; } } - - public bool IsMain { get { return Control.IsMainThread; } } - } -} - diff --git a/Source/Eto.Platform.Windows/BubbleEventFilter.cs b/Source/Eto.Platform.Windows/BubbleEventFilter.cs deleted file mode 100644 index 12b63e6671..0000000000 --- a/Source/Eto.Platform.Windows/BubbleEventFilter.cs +++ /dev/null @@ -1,228 +0,0 @@ -using Eto.Drawing; -using Eto.Forms; -using System; -using System.Collections.Generic; -using swf = System.Windows.Forms; - -namespace Eto.Platform.Windows -{ - class BubbleEvent - { - public Func HandleEvent { get; set; } - - public Win32.WM Message { get; set; } - } - - class BubbleEventArgs : EventArgs - { - public swf.Message Message { get; private set; } - - public Control Control { get; private set; } - - public swf.Control WinControl { get; private set; } - - public IWindowsControl WindowsControl - { - get { return Control != null ? Control.Handler as IWindowsControl : null; } - } - - public IEnumerable Controls - { - get - { - var control = Control; - while (control != null) - { - yield return control; - control = control.Parent; - } - } - } - - public IEnumerable Parents - { - get - { - if (Control != null) - { - var control = Control.Parent; - while (control != null) - { - yield return control; - control = control.Parent; - } - } - } - } - - public BubbleEventArgs(swf.Message message, swf.Control winControl) - { - this.Message = message; - this.Control = ToEto(winControl); - this.WinControl = winControl; - } - - static Control ToEto(swf.Control child) - { - var handler = child.Tag as IControl; - return handler != null ? handler.Widget as Control : null; - } - } - - class BubbleEventFilter : swf.IMessageFilter - { - readonly Dictionary messages = new Dictionary(); - - public void AddBubbleEvents(Func handleEvent, params Win32.WM[] messages) - { - foreach (var message in messages) - { - AddBubbleEvent(handleEvent, message); - } - } - - public void AddBubbleEvent(Func handleEvent, Win32.WM message) - { - messages.Add((int)message, new BubbleEvent - { - Message = message, - HandleEvent = handleEvent - }); - } - - public bool PreFilterMessage(ref swf.Message message) - { - BubbleEvent bubble; - if (messages.TryGetValue(message.Msg, out bubble)) - { - var child = swf.Control.FromHandle(message.HWnd); - - if (child != null) - { - var args = new BubbleEventArgs(message, child); - if (bubble.HandleEvent(args)) - return true; - } - } - return false; - } - - public void AddBubbleKeyEvent(Action action, Win32.WM message, KeyEventType keyEventType) - { - AddBubbleEvent(be => KeyEvent(be, action, keyEventType), message); - } - - public void AddBubbleKeyCharEvent(Action action, Win32.WM message, KeyEventType keyEventType) - { - AddBubbleEvent(be => KeyCharEvent(be, action, keyEventType), message); - } - - public void AddBubbleMouseEvent(Action action, bool? capture, Win32.WM message, Func modifyButtons = null) - { - AddBubbleEvent(be => MouseEvent(be, action, capture, modifyButtons), message); - } - - public void AddBubbleMouseEvents(Action action, bool? capture, params Win32.WM[] messages) - { - foreach (var message in messages) - { - AddBubbleEvent(be => MouseEvent(be, action, capture), message); - } - } - - static bool MouseEvent(BubbleEventArgs be, Action action, bool? capture, Func modifyButtons = null) - { - var modifiers = swf.Control.ModifierKeys.ToEto(); - var delta = new SizeF(0, Win32.GetWheelDeltaWParam(be.Message.WParam) / Conversions.WheelDelta); - var buttons = Win32.GetMouseButtonWParam(be.Message.WParam).ToEto(); - if (modifyButtons != null) - buttons = modifyButtons(buttons); - var handler = be.WindowsControl; - var mousePosition = swf.Control.MousePosition.ToEto(); - var ret = false; - foreach (var control in be.Controls) - { - var me = new MouseEventArgs(buttons, modifiers, control.PointFromScreen(mousePosition), delta); - action(control, me); - if (me.Handled) - { - ret = true; - break; - } - } - if (capture != null && ret || (handler != null && handler.ShouldCaptureMouse)) - { - //be.WinControl.Capture = capture.Value; - } - return ret; - } - - static bool KeyEvent(BubbleEventArgs be, Action action, KeyEventType keyEventType) - { - Keys keyData = ((swf.Keys)(long)be.Message.WParam | swf.Control.ModifierKeys).ToEto(); - - char? keyChar = null; - var kevt = new KeyEventArgs(keyData, keyEventType, keyChar); - if (be.Control != null) - action(be.Control, kevt); - if (!kevt.Handled && (keyEventType != KeyEventType.KeyDown || !IsInputKey(be.Message.HWnd, keyData))) - { - foreach (var control in be.Parents) - { - action(control, kevt); - if (kevt.Handled) - break; - } - } - return kevt.Handled; - } - - static bool IsInputChar(IntPtr hwnd, char charCode) - { - int num = charCode == '\t' ? 134 : 132; - return ((int)((long)Win32.SendMessage(hwnd, Win32.WM.GETDLGCODE, IntPtr.Zero, IntPtr.Zero)) & num) != 0; - } - - static bool IsInputKey(IntPtr hwnd, Keys keyData) - { - if (keyData.HasFlag(Keys.Alt)) - { - return false; - } - int num = 4; - switch (keyData & Keys.KeyMask) - { - case Keys.Tab: - num = 6; - break; - case Keys.Left: - case Keys.Up: - case Keys.Right: - case Keys.Down: - num = 5; - break; - } - return ((int)((long)Win32.SendMessage(hwnd, Win32.WM.GETDLGCODE, IntPtr.Zero, IntPtr.Zero)) & num) != 0; - } - - static bool KeyCharEvent(BubbleEventArgs be, Action action, KeyEventType keyEventType) - { - Keys keyData = Keys.None; - - char keyChar = (char)((long)be.Message.WParam); - var kevt = new KeyEventArgs(keyData, keyEventType, keyChar); - if (be.Control != null) - action(be.Control, kevt); - if (!kevt.Handled && !IsInputChar(be.Message.HWnd, keyChar)) - { - foreach (var control in be.Parents) - { - action(control, kevt); - if (kevt.Handled) - break; - } - } - return kevt.Handled; - } - } -} diff --git a/Source/Eto.Platform.Windows/Conversions.cs b/Source/Eto.Platform.Windows/Conversions.cs deleted file mode 100644 index ebece8972b..0000000000 --- a/Source/Eto.Platform.Windows/Conversions.cs +++ /dev/null @@ -1,681 +0,0 @@ -using System; -using Eto.Drawing; -using Eto.Forms; -using Eto.Platform.Windows.Drawing; -using sd = System.Drawing; -using sdp = System.Drawing.Printing; -using sd2 = System.Drawing.Drawing2D; -using swf = System.Windows.Forms; -using sdi = System.Drawing.Imaging; -using Eto.Platform.Windows.Forms.Printing; - -namespace Eto.Platform.Windows -{ - public static partial class Conversions - { - public const float WheelDelta = 120f; - - public static Padding ToEto(this swf.Padding padding) - { - return new Padding(padding.Left, padding.Top, padding.Right, padding.Bottom); - } - - public static swf.Padding ToSWF(this Padding padding) - { - return new swf.Padding(padding.Left, padding.Top, padding.Right, padding.Bottom); - } - - public static Color ToEto(this sd.Color color) - { - return new Color(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f); - } - - public static sd.Color ToSD(this Color color) - { - return sd.Color.FromArgb((byte)(color.A * 255), (byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255)); - } - - public static DialogResult ToEto(this swf.DialogResult result) - { - switch (result) - { - case swf.DialogResult.OK: - return DialogResult.Ok; - case swf.DialogResult.Cancel: - return DialogResult.Cancel; - case swf.DialogResult.Yes: - return DialogResult.Yes; - case swf.DialogResult.No: - return DialogResult.No; - case swf.DialogResult.Abort: - return DialogResult.Cancel; - case swf.DialogResult.Ignore: - return DialogResult.Ignore; - case swf.DialogResult.Retry: - return DialogResult.Retry; - case swf.DialogResult.None: - return DialogResult.None; - default: - return DialogResult.None; - } - } - - public static sd.Imaging.ImageFormat ToSD(this ImageFormat format) - { - switch (format) - { - case ImageFormat.Jpeg: - return sd.Imaging.ImageFormat.Jpeg; - case ImageFormat.Bitmap: - return sd.Imaging.ImageFormat.Bmp; - case ImageFormat.Gif: - return sd.Imaging.ImageFormat.Gif; - case ImageFormat.Tiff: - return sd.Imaging.ImageFormat.Tiff; - case ImageFormat.Png: - return sd.Imaging.ImageFormat.Png; - default: - throw new Exception("Invalid format specified"); - } - } - - public static ImageInterpolation ToEto(this sd2.InterpolationMode value) - { - switch (value) - { - case sd2.InterpolationMode.NearestNeighbor: - return ImageInterpolation.None; - case sd2.InterpolationMode.Low: - return ImageInterpolation.Low; - case sd2.InterpolationMode.High: - return ImageInterpolation.Medium; - case sd2.InterpolationMode.HighQualityBilinear: - return ImageInterpolation.High; - case sd2.InterpolationMode.Default: - return ImageInterpolation.Default; - default: - throw new NotSupportedException(); - } - } - - public static sd2.InterpolationMode ToSD(this ImageInterpolation value) - { - switch (value) - { - case ImageInterpolation.Default: - return sd2.InterpolationMode.High; - case ImageInterpolation.None: - return sd2.InterpolationMode.NearestNeighbor; - case ImageInterpolation.Low: - return sd2.InterpolationMode.Low; - case ImageInterpolation.Medium: - return sd2.InterpolationMode.High; - case ImageInterpolation.High: - return sd2.InterpolationMode.HighQualityBilinear; - default: - throw new NotSupportedException(); - } - } - - public static sd.FontStyle ToSD(this FontStyle style) - { - sd.FontStyle ret = sd.FontStyle.Regular; - if (style.HasFlag(FontStyle.Bold)) - ret |= sd.FontStyle.Bold; - if (style.HasFlag(FontStyle.Italic)) - ret |= sd.FontStyle.Italic; - return ret; - } - public static sd.FontStyle ToSD(this FontDecoration decoration) - { - sd.FontStyle ret = sd.FontStyle.Regular; - if (decoration.HasFlag(FontDecoration.Underline)) - ret |= sd.FontStyle.Underline; - if (decoration.HasFlag(FontDecoration.Strikethrough)) - ret |= sd.FontStyle.Strikeout; - return ret; - } - - public static sdp.PrintRange ToSDP(this PrintSelection value) - { - switch (value) - { - case PrintSelection.AllPages: - return sdp.PrintRange.AllPages; - case PrintSelection.SelectedPages: - return sdp.PrintRange.SomePages; - case PrintSelection.Selection: - return sdp.PrintRange.Selection; - default: - throw new NotSupportedException(); - } - } - - public static PrintSelection ToEto(this sdp.PrintRange value) - { - switch (value) - { - case sdp.PrintRange.AllPages: - return PrintSelection.AllPages; - case sdp.PrintRange.SomePages: - return PrintSelection.SelectedPages; - case sdp.PrintRange.Selection: - return PrintSelection.Selection; - default: - throw new NotSupportedException(); - } - } - - public static FontStyle ToEtoStyle(this sd.FontStyle style) - { - var ret = FontStyle.None; - if (style.HasFlag(sd.FontStyle.Bold)) - ret |= FontStyle.Bold; - if (style.HasFlag(sd.FontStyle.Italic)) - ret |= FontStyle.Italic; - return ret; - } - - public static FontDecoration ToEtoDecoration(this sd.FontStyle style) - { - var ret = FontDecoration.None; - if (style.HasFlag(sd.FontStyle.Underline)) - ret |= FontDecoration.Underline; - if (style.HasFlag(sd.FontStyle.Strikeout)) - ret |= FontDecoration.Strikethrough; - return ret; - } - - public static Point ToEto(this sd.Point point) - { - return new Point(point.X, point.Y); - } - - public static PointF ToEto(this sd.PointF point) - { - return new PointF(point.X, point.Y); - } - - public static sd.PointF ToSD(this PointF point) - { - return new sd.PointF(point.X, point.Y); - } - - public static sd.Point ToSDPoint(this PointF point) - { - return new sd.Point((int)point.X, (int)point.Y); - } - - public static Size ToEto(this sd.Size size) - { - return new Size(size.Width, size.Height); - } - - public static sd.Size ToSD(this Size size) - { - return new sd.Size(size.Width, size.Height); - } - - public static Size ToEtoF(this sd.SizeF size) - { - return new Size((int)size.Width, (int)size.Height); - } - - public static SizeF ToEto(this sd.SizeF size) - { - return new SizeF(size.Width, size.Height); - } - - public static sd.SizeF ToSD(this SizeF size) - { - return new sd.SizeF(size.Width, size.Height); - } - - public static Rectangle ToEto(this sd.Rectangle rect) - { - return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height); - } - - public static RectangleF ToEto(this sd.RectangleF rect) - { - return new RectangleF(rect.X, rect.Y, rect.Width, rect.Height); - } - - public static sd.Rectangle ToSD(this Rectangle rect) - { - return new sd.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); - } - - public static sd.RectangleF ToSD(this RectangleF rect) - { - return new sd.RectangleF(rect.X, rect.Y, rect.Width, rect.Height); - } - - public static sd.Rectangle ToSDRectangle(this RectangleF rect) - { - return new sd.Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height); - } - - internal static sd.Point[] ToSD(this Point[] points) - { - var result = - new sd.Point[points.Length]; - - for (var i = 0; - i < points.Length; - ++i) - { - var p = points[i]; - result[i] = - new sd.Point(p.X, p.Y); - } - - return result; - } - - internal static sd.PointF[] ToSD(this PointF[] points) - { - var result = - new sd.PointF[points.Length]; - - for (var i = 0; - i < points.Length; - ++i) - { - var p = points[i]; - result[i] = - new sd.PointF(p.X, p.Y); - } - - return result; - } - - internal static PointF[] ToEto(this sd.PointF[] points) - { - var result = - new PointF[points.Length]; - - for (var i = 0; - i < points.Length; - ++i) - { - var p = points[i]; - result[i] = - new PointF(p.X, p.Y); - } - - return result; - } - - public static sd.Graphics ToSD(this Graphics graphics) - { - var h = (GraphicsHandler)graphics.Handler; - return h.Control; - } - - public static sd.Image ToSD(this Image image, int? size = null) - { - if (image == null) - return null; - var h = (IWindowsImageSource)image.Handler; - return h.GetImageWithSize(size); - } - - public static sd.Font ToSD(this Font font) - { - if (font == null) - return null; - return ((IWindowsFontSource)font.Handler).GetFont(); - } - - public static sd.Font ToSD(this SystemFont systemFont) - { - switch (systemFont) - { - case SystemFont.Default: - return sd.SystemFonts.DefaultFont; - case SystemFont.Bold: - return new sd.Font(sd.SystemFonts.DefaultFont, sd.FontStyle.Bold); - case SystemFont.TitleBar: - return sd.SystemFonts.CaptionFont; - case SystemFont.ToolTip: - return sd.SystemFonts.DefaultFont; - case SystemFont.Label: - return sd.SystemFonts.DialogFont; - case SystemFont.MenuBar: - return sd.SystemFonts.MenuFont; - case SystemFont.Menu: - return sd.SystemFonts.MenuFont; - case SystemFont.Message: - return sd.SystemFonts.MessageBoxFont; - case SystemFont.Palette: - return sd.SystemFonts.DialogFont; - case SystemFont.StatusBar: - return sd.SystemFonts.StatusFont; - default: - throw new NotSupportedException(); - } - } - - public static Font ToEto(this sd.Font font, Eto.Generator generator) - { - return font == null ? null : new Font(generator, new FontHandler(font)); - } - - public static MouseEventArgs ToEto(this swf.MouseEventArgs e, swf.Control control) - { - var point = control.PointToClient(swf.Control.MousePosition).ToEto(); - var buttons = ToEto(e.Button); - var modifiers = swf.Control.ModifierKeys.ToEto(); - - var result = new MouseEventArgs(buttons, modifiers, point); - result.Delta = new SizeF(0, (float)e.Delta / WheelDelta); - - return result; - } - - public static MouseButtons ToEto(this swf.MouseButtons button) - { - MouseButtons buttons = MouseButtons.None; - - if ((button & swf.MouseButtons.Left) != 0) - buttons |= MouseButtons.Primary; - - if ((button & swf.MouseButtons.Right) != 0) - buttons |= MouseButtons.Alternate; - - if ((button & swf.MouseButtons.Middle) != 0) - buttons |= MouseButtons.Middle; - - return buttons; - } - - public static Graphics ToEto(this sd.Graphics g, Eto.Generator generator) - { - return new Graphics(generator, new GraphicsHandler(g)); - } - - public static PaintEventArgs ToEto(this swf.PaintEventArgs e, Eto.Generator generator) - { - return new PaintEventArgs(ToEto(e.Graphics, generator), e.ClipRectangle.ToEto()); - } - - public static sd.Image ToSD(this IImage image) - { - return image == null ? null : image.ControlObject as sd.Image; - } - - public static sd2.PixelOffsetMode ToSD(this PixelOffsetMode mode) - { - switch (mode) - { - case PixelOffsetMode.None: - return sd2.PixelOffsetMode.None; - case PixelOffsetMode.Half: - return sd2.PixelOffsetMode.Half; - default: - throw new NotSupportedException(); - } - } - - public static PixelOffsetMode ToEto(this sd2.PixelOffsetMode mode) - { - switch (mode) - { - case sd2.PixelOffsetMode.None: - return PixelOffsetMode.None; - case sd2.PixelOffsetMode.Half: - return PixelOffsetMode.Half; - default: - throw new NotSupportedException(); - } - } - - public static sd2.Matrix ToSD(this IMatrix m) - { - return (sd2.Matrix)m.ControlObject; - } - - public static IMatrix ToEto(this sd2.Matrix matrix) - { - return new MatrixHandler(matrix); - } - - public static float DegreesToRadians(float angle) - { - return (float)Math.PI * angle / 180.0f; - } - - public static ITreeItem ToEto(this swf.TreeNode treeNode) - { - return - treeNode != null - ? treeNode.Tag as ITreeItem - : null; - } - - public static sd.Pen ToSD(this Pen pen) - { - return (sd.Pen)pen.ControlObject; - } - - public static sd.Brush ToSD(this Brush brush) - { - return ((BrushHandler)brush.Handler).GetBrush(brush); - } - - public static sd2.LineJoin ToSD(this PenLineJoin value) - { - switch (value) - { - case PenLineJoin.Miter: - return sd2.LineJoin.MiterClipped; - case PenLineJoin.Bevel: - return sd2.LineJoin.Bevel; - case PenLineJoin.Round: - return sd2.LineJoin.Round; - default: - throw new NotSupportedException(); - } - } - - public static PenLineJoin ToEto(this sd2.LineJoin value) - { - switch (value) - { - case sd2.LineJoin.Bevel: - return PenLineJoin.Bevel; - case sd2.LineJoin.Miter: - return PenLineJoin.Miter; - case sd2.LineJoin.Round: - return PenLineJoin.Round; - default: - throw new NotSupportedException(); - } - } - - public static sd2.LineCap ToSD(this PenLineCap value) - { - switch (value) - { - case PenLineCap.Butt: - return sd2.LineCap.Flat; - case PenLineCap.Round: - return sd2.LineCap.Round; - case PenLineCap.Square: - return sd2.LineCap.Square; - default: - throw new NotSupportedException(); - } - } - - public static PenLineCap ToEto(this sd2.LineCap value) - { - switch (value) - { - case sd2.LineCap.Flat: - return PenLineCap.Butt; - case sd2.LineCap.Round: - return PenLineCap.Round; - case sd2.LineCap.Square: - return PenLineCap.Square; - default: - throw new NotSupportedException(); - } - } - - public static sd2.GraphicsPath ToSD(this IGraphicsPath path) - { - return (sd2.GraphicsPath)path.ControlObject; - } - - public static sd2.WrapMode ToSD(this GradientWrapMode wrap) - { - switch (wrap) - { - case GradientWrapMode.Reflect: - return sd2.WrapMode.TileFlipXY; - case GradientWrapMode.Repeat: - return sd2.WrapMode.Tile; - default: - throw new NotSupportedException(); - } - } - - public static GradientWrapMode ToEtoGradientWrap(this sd2.WrapMode wrapMode) - { - switch (wrapMode) - { - case sd2.WrapMode.TileFlipXY: - return GradientWrapMode.Reflect; - case sd2.WrapMode.Tile: - return GradientWrapMode.Repeat; - default: - throw new NotSupportedException(); - } - } - - public static int BitsPerPixel(this sdi.PixelFormat format) - { - switch (format) - { - case sdi.PixelFormat.Format1bppIndexed: - return 1; - case sdi.PixelFormat.Format4bppIndexed: - return 4; - case sdi.PixelFormat.Format8bppIndexed: - return 8; - case sdi.PixelFormat.Format24bppRgb: - return 24; - case sdi.PixelFormat.Format32bppArgb: - case sdi.PixelFormat.Format32bppPArgb: - case sdi.PixelFormat.Format32bppRgb: - return 32; - default: - throw new NotSupportedException(); - } - } - - public static swf.TextImageRelation ToSD(this ButtonImagePosition value) - { - switch (value) - { - case ButtonImagePosition.Left: - return swf.TextImageRelation.ImageBeforeText; - case ButtonImagePosition.Right: - return swf.TextImageRelation.TextBeforeImage; - case ButtonImagePosition.Above: - return swf.TextImageRelation.ImageAboveText; - case ButtonImagePosition.Below: - return swf.TextImageRelation.TextAboveImage; - case ButtonImagePosition.Overlay: - return swf.TextImageRelation.Overlay; - default: - throw new NotSupportedException(); - } - } - - public static ButtonImagePosition ToEto(this swf.TextImageRelation value) - { - switch (value) - { - case swf.TextImageRelation.ImageAboveText: - return ButtonImagePosition.Above; - case swf.TextImageRelation.ImageBeforeText: - return ButtonImagePosition.Left; - case swf.TextImageRelation.Overlay: - return ButtonImagePosition.Overlay; - case swf.TextImageRelation.TextAboveImage: - return ButtonImagePosition.Below; - case swf.TextImageRelation.TextBeforeImage: - return ButtonImagePosition.Left; - default: - throw new NotSupportedException(); - } - } - - public static bool IsResizable(this swf.FormBorderStyle style) - { - switch (style) - { - case swf.FormBorderStyle.Fixed3D: - case swf.FormBorderStyle.FixedDialog: - case swf.FormBorderStyle.FixedSingle: - case swf.FormBorderStyle.FixedToolWindow: - case swf.FormBorderStyle.None: - return false; - case swf.FormBorderStyle.Sizable: - case swf.FormBorderStyle.SizableToolWindow: - return true; - default: - throw new NotSupportedException(); - } - } - - public static WindowStyle ToEto(this swf.FormBorderStyle style) - { - switch (style) - { - case swf.FormBorderStyle.Fixed3D: - case swf.FormBorderStyle.Sizable: - case swf.FormBorderStyle.SizableToolWindow: - case swf.FormBorderStyle.FixedDialog: - return WindowStyle.Default; - case swf.FormBorderStyle.None: - return WindowStyle.None; - default: - throw new NotSupportedException(); - } - } - - public static swf.FormBorderStyle ToSWF(this WindowStyle style, bool resizable, swf.FormBorderStyle defaultStyle) - { - switch (style) - { - case WindowStyle.Default: - return resizable ? swf.FormBorderStyle.Sizable : defaultStyle; - case WindowStyle.None: - return swf.FormBorderStyle.None; - default: - throw new NotSupportedException(); - } - } - - public static PrintSettings ToEto(this sdp.PrinterSettings settings, Eto.Generator generator) - { - return settings == null ? null : new PrintSettings(generator, new PrintSettingsHandler(settings)); - } - - public static sdp.PrinterSettings ToSD(this PrintSettings settings) - { - if (settings == null) - return PrintSettingsHandler.DefaultSettings(); - return ((PrintSettingsHandler)settings.Handler).Control; - } - - public static sdp.PrintDocument ToSD(this PrintDocument document) - { - return document == null ? null : ((PrintDocumentHandler)document.Handler).Control; - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/BitmapHandler.cs b/Source/Eto.Platform.Windows/Drawing/BitmapHandler.cs deleted file mode 100644 index 4979223ab8..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/BitmapHandler.cs +++ /dev/null @@ -1,208 +0,0 @@ -using System; -using System.IO; -using Eto.Drawing; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using ImageManipulation; - -namespace Eto.Platform.Windows.Drawing -{ - /// - /// Interface to get an image representation with the specified size - /// - public interface IWindowsImageSource - { - SD.Image GetImageWithSize(int? size); - } - - /// - /// Interface for all windows images - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public interface IWindowsImage : IWindowsImageSource - { - void DrawImage (GraphicsHandler graphics, RectangleF source, RectangleF destination); - - void DrawImage (GraphicsHandler graphics, float x, float y); - - void DrawImage (GraphicsHandler graphics, float x, float y, float width, float height); - } - - /// - /// Bitmap data handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class BitmapDataHandler : BitmapData - { - public BitmapDataHandler(Image image, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) - : base (image, data, scanWidth, bitsPerPixel, controlObject) - { - } - - public override uint TranslateArgbToData(uint argb) - { - return argb; - } - - public override uint TranslateDataToArgb(uint bitmapData) - { - return bitmapData; - } - } - - /// - /// Bitmap handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class BitmapHandler : WidgetHandler, IBitmap, IWindowsImage - { - public BitmapHandler() - { - } - - public BitmapHandler(SD.Bitmap image) - { - Control = image; - } - - public void Create(string fileName) - { - // We create a temp image from the file - // because SD.Bitmap(filename) locks the file - // until the image is disposed. - // this is not the case in mono - if (EtoEnvironment.Platform.IsWindows) - { - using (var temp = new SD.Bitmap(fileName)) - Control = new SD.Bitmap(temp); - } - else - Control = new SD.Bitmap(fileName); - } - - public void Create(Stream stream) - { - Control = new SD.Bitmap(stream); - } - - public void Create(int width, int height, PixelFormat pixelFormat) - { - SD.Imaging.PixelFormat sdPixelFormat; - switch (pixelFormat) - { - case PixelFormat.Format32bppRgb: - sdPixelFormat = SD.Imaging.PixelFormat.Format32bppRgb; - break; - case PixelFormat.Format24bppRgb: - sdPixelFormat = SD.Imaging.PixelFormat.Format24bppRgb; - break; - /*case PixelFormat.Format16bppRgb555: - sdPixelFormat = SD.Imaging.PixelFormat.Format16bppRgb555; - break;*/ - case PixelFormat.Format32bppRgba: - sdPixelFormat = SD.Imaging.PixelFormat.Format32bppPArgb; - break; - default: - throw new ArgumentOutOfRangeException("pixelFormat", pixelFormat, "Not supported"); - } - Control = new SD.Bitmap(width, height, sdPixelFormat); - } - - public void Create(int width, int height, Graphics graphics) - { - Control = new SD.Bitmap(width, height, GraphicsHandler.GetControl(graphics)); - } - - public void Create (Image image, int width, int height, ImageInterpolation interpolation) - { - var source = image.ToSD (); - var pixelFormat = source.PixelFormat; - if (EtoEnvironment.Platform.IsMono && ( - pixelFormat == SD.Imaging.PixelFormat.Indexed - || pixelFormat == SD.Imaging.PixelFormat.Format1bppIndexed - || pixelFormat == SD.Imaging.PixelFormat.Format4bppIndexed - || pixelFormat == SD.Imaging.PixelFormat.Format8bppIndexed - )) - pixelFormat = SD.Imaging.PixelFormat.Format32bppRgb; - Control = new SD.Bitmap (width, height, pixelFormat); - using (var graphics = SD.Graphics.FromImage(Control)) { - graphics.InterpolationMode = interpolation.ToSD (); - var rect = new SD.Rectangle (0, 0, width, height); - graphics.FillRectangle (SD.Brushes.Transparent, rect); - graphics.DrawImage (source, rect); - } - } - - public Size Size - { - get { return new Size(Control.Width, Control.Height); } - } - - public BitmapData Lock() - { - SD.Imaging.BitmapData bd = Control.LockBits(new SD.Rectangle(0, 0, Control.Width, Control.Height), SD.Imaging.ImageLockMode.ReadWrite, Control.PixelFormat); - return new BitmapDataHandler(Widget, bd.Scan0, bd.Stride, bd.PixelFormat.BitsPerPixel(), bd); - } - - public void Unlock(BitmapData bitmapData) - { - Control.UnlockBits((SD.Imaging.BitmapData)bitmapData.ControlObject); - } - - public void Save(Stream stream, ImageFormat format) - { - if (format == ImageFormat.Gif) - { - var quantizer = new OctreeQuantizer (255, 8); - var gif = quantizer.Quantize(Control); - gif.Save(stream, format.ToSD ()); - } - else Control.Save(stream, format.ToSD ()); - } - - public SD.Image GetImageWithSize (int? size) - { - if (size != null) - { - var max = Math.Max(Control.Width, Control.Height); - var newsize = new SD.Size(size.Value * Control.Width / max, size.Value * Control.Height / max); - return new SD.Bitmap(Control, newsize); - } - return Control; - } - - public Bitmap Clone(Rectangle? rectangle = null) - { - SD.Bitmap copy; - if (rectangle == null) - copy = (SD.Bitmap)Control.Clone (); - else - copy = Control.Clone (rectangle.Value.ToSD(), Control.PixelFormat); - - return new Bitmap (Generator, new BitmapHandler (copy)); - } - - public Color GetPixel(int x, int y) - { - return Control.GetPixel(x, y).ToEto(); - } - - public void DrawImage (GraphicsHandler graphics, RectangleF source, RectangleF destination) - { - graphics.Control.DrawImage (Control, destination.ToSD (), source.ToSD (), SD.GraphicsUnit.Pixel); - } - - public void DrawImage (GraphicsHandler graphics, float x, float y) - { - graphics.Control.DrawImage (Control, x, y); - } - - public void DrawImage (GraphicsHandler graphics, float x, float y, float width, float height) - { - graphics.Control.DrawImage (Control, x, y, width, height); - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/BrushHandler.cs b/Source/Eto.Platform.Windows/Drawing/BrushHandler.cs deleted file mode 100644 index e5b5540c3c..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/BrushHandler.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Eto.Drawing; -using sd = System.Drawing; - -namespace Eto.Platform.Windows.Drawing -{ - /// - /// Base handler for , to get the platform-specific brush - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public abstract class BrushHandler - { - public abstract sd.Brush GetBrush (Brush brush); - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/FontFamilyHandler.cs b/Source/Eto.Platform.Windows/Drawing/FontFamilyHandler.cs deleted file mode 100644 index 7e362b1fd7..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/FontFamilyHandler.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Eto.Drawing; -using System.Collections.Generic; -using sd = System.Drawing; - -namespace Eto.Platform.Windows.Drawing -{ - public class FontFamilyHandler : WidgetHandler, IFontFamily - { - public string Name { get; set; } - - public string SDName { get; set; } - - static IEnumerable Styles - { - get - { - yield return sd.FontStyle.Regular; - yield return sd.FontStyle.Bold; - yield return sd.FontStyle.Italic; - yield return sd.FontStyle.Bold | sd.FontStyle.Italic; - } - } - - public IEnumerable Typefaces - { - get - { - foreach (var style in Styles) - { - if (Control.IsStyleAvailable(style)) - yield return new FontTypeface(Widget, new FontTypefaceHandler(style)); - } - } - } - - public FontFamilyHandler() - { - } - - public FontFamilyHandler(sd.FontFamily windowsFamily) - { - this.Control = windowsFamily; - Name = Control.Name; - } - - public void Create(string familyName) - { - Name = familyName; - switch (familyName.ToUpperInvariant()) - { - case FontFamilies.MonospaceFamilyName: - Control = sd.FontFamily.GenericMonospace; - break; - case FontFamilies.SansFamilyName: - Control = sd.FontFamily.GenericSansSerif; - break; - case FontFamilies.SerifFamilyName: - Control = sd.FontFamily.GenericSerif; - break; - case FontFamilies.CursiveFamilyName: - Control = new sd.FontFamily("Comic Sans MS"); - break; - case FontFamilies.FantasyFamilyName: - Control = new sd.FontFamily("Gabriola"); - break; - default: - Control = new sd.FontFamily(familyName); - Name = Control.Name; - break; - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/FontHandler.cs b/Source/Eto.Platform.Windows/Drawing/FontHandler.cs deleted file mode 100644 index 54a1eeee60..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/FontHandler.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using Eto.Drawing; -using sd = System.Drawing; -using swf = System.Windows.Forms; - -namespace Eto.Platform.Windows.Drawing -{ - public interface IWindowsFontSource - { - sd.Font GetFont(); - } - - public class FontHandler : WidgetHandler, IFont, IWindowsFontSource - { - FontTypeface typeface; - FontFamily family; - - public FontHandler() - { - } - - public FontHandler(sd.Font font) - { - Control = font; - } - - public void Create(FontFamily family, float size, FontStyle style, FontDecoration decoration) - { - this.family = family; - var familyHandler = (FontFamilyHandler)family.Handler; - Control = new sd.Font(familyHandler.Control, size, style.ToSD() | decoration.ToSD()); - } - - public void Create(FontTypeface typeface, float size, FontDecoration decoration) - { - this.typeface = typeface; - - var familyHandler = (FontFamilyHandler)typeface.Family.Handler; - Control = new sd.Font(familyHandler.Control, size, typeface.FontStyle.ToSD() | decoration.ToSD()); - } - - public void Create(SystemFont systemFont, float? size, FontDecoration decoration) - { - Control = systemFont.ToSD(); - if (size != null || decoration != FontDecoration.None) - { - var newsize = size ?? Control.SizeInPoints; - Control = new sd.Font(Control.FontFamily, newsize, Control.Style | decoration.ToSD(), sd.GraphicsUnit.Point); - } - } - - public string FamilyName - { - get { return Control.FontFamily.Name; } - } - - public FontStyle FontStyle - { - get { return Control.Style.ToEtoStyle(); } - } - - public FontDecoration FontDecoration - { - get { return Control.Style.ToEtoDecoration(); } - } - - public FontFamily Family - { - get { return family = family ?? new FontFamily(Widget.Generator, new FontFamilyHandler(Control.FontFamily)); } - } - - public FontTypeface Typeface - { - get { return typeface = typeface ?? new FontTypeface(Family, new FontTypefaceHandler(Control.Style)); } - } - - public sd.FontFamily WindowsFamily - { - get { return Control.FontFamily; } - } - - public float XHeight - { - get { return Size * 0.5f; } - } - - public float Baseline - { - get { return Ascent; } - } - - public float Leading - { - get { return LineHeight - (Ascent + Descent); } - } - - float? ascent; - public float Ascent - { - get - { - ascent = ascent ?? Size * Control.FontFamily.GetCellAscent(Control.Style) / Control.FontFamily.GetEmHeight(Control.Style); - return ascent ?? 0f; - } - } - - float? descent; - /// - /// Gets the descent of the font - /// - /// - /// Font metrics from http://msdn.microsoft.com/en-us/library/xwf9s90b(VS.71).aspx - /// - public float Descent - { - get - { - descent = descent ?? Size * Control.FontFamily.GetCellDescent(Control.Style) / Control.FontFamily.GetEmHeight(Control.Style); - return descent ?? 0f; - } - } - - public float LineHeight { get { return Size * Control.FontFamily.GetLineSpacing(Control.Style) / Control.FontFamily.GetEmHeight(Control.Style); } } - - public float Size { get { return Control.SizeInPoints; } } - - public sd.Font GetFont() - { - return Control; - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/FontTypefaceHandler.cs b/Source/Eto.Platform.Windows/Drawing/FontTypefaceHandler.cs deleted file mode 100644 index 539a617f53..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/FontTypefaceHandler.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Eto.Drawing; -using sd = System.Drawing; - -namespace Eto.Platform.Windows.Drawing -{ - public class FontTypefaceHandler : WidgetHandler, IFontTypeface - { - public FontTypefaceHandler (sd.FontStyle style) - { - this.Control = style; - Name = this.FontStyle.ToString ().Replace (',', ' '); - } - - public string Name { get; set; } - - public FontStyle FontStyle - { - get { return Control.ToEtoStyle (); } - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/FontsHandler.cs b/Source/Eto.Platform.Windows/Drawing/FontsHandler.cs deleted file mode 100644 index acf75c33e0..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/FontsHandler.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Eto.Drawing; -using System; -using System.Collections.Generic; -using System.Linq; -using sd = System.Drawing; - -namespace Eto.Platform.Windows.Drawing -{ - public class FontsHandler : WidgetHandler, IFonts - { - HashSet availableFontFamilies; - - public IEnumerable AvailableFontFamilies - { - get { - return sd.FontFamily.Families.Select (r => new FontFamily(Generator, new FontFamilyHandler(r))); - } - } - - public bool FontFamilyAvailable (string fontFamily) - { - if (availableFontFamilies == null) { - availableFontFamilies = new HashSet (StringComparer.InvariantCultureIgnoreCase); - foreach (var family in sd.FontFamily.Families) { - availableFontFamilies.Add (family.Name); - } - } - return availableFontFamilies.Contains (fontFamily); - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/GraphicsHandler.cs b/Source/Eto.Platform.Windows/Drawing/GraphicsHandler.cs deleted file mode 100644 index 0a8d21e771..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/GraphicsHandler.cs +++ /dev/null @@ -1,347 +0,0 @@ -using System; -using Eto.Drawing; -using sd = System.Drawing; -using sdd = System.Drawing.Drawing2D; -using swf = System.Windows.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.Windows.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class GraphicsHandler : WidgetHandler, IGraphics - { - Stack savedTransforms; - - public bool IsRetained { get { return false; } } - - static sd.StringFormat defaultStringFormat; - - static GraphicsHandler () - { - // Set the StringFormat - defaultStringFormat = new sd.StringFormat (sd.StringFormat.GenericTypographic); - defaultStringFormat.FormatFlags |= - sd.StringFormatFlags.MeasureTrailingSpaces - | sd.StringFormatFlags.NoWrap - | sd.StringFormatFlags.NoClip; - } - - ImageInterpolation imageInterpolation; - - public GraphicsHandler () - { - } - - bool shouldDisposeGraphics = true; - - public GraphicsHandler(sd.Graphics graphics, bool shouldDisposeGraphics = true) - { - this.Control = graphics; - this.shouldDisposeGraphics = shouldDisposeGraphics; - } - - protected override void Dispose(bool disposing) - { - if (!shouldDisposeGraphics) - Control = null; - - base.Dispose(disposing); - } - - public bool AntiAlias - { - get - { - return (this.Control.SmoothingMode == System.Drawing.Drawing2D.SmoothingMode.AntiAlias); - } - set - { - if (value) - this.Control.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; - else - this.Control.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; - } - } - - public ImageInterpolation ImageInterpolation - { - get { return imageInterpolation; } - set - { - imageInterpolation = value; - Control.InterpolationMode = value.ToSD (); - } - } - - public PixelOffsetMode PixelOffsetMode - { - get { return Control.PixelOffsetMode.ToEto (); } - set { Control.PixelOffsetMode = value.ToSD (); } - } - - public float PointsPerPixel - { - get { return 72f / Control.DpiX; } - } - - public void CreateFromImage (Bitmap image) - { - Control = sd.Graphics.FromImage ((sd.Image)image.ControlObject); - } - - protected override void Initialize () - { - base.Initialize (); - - Control.PixelOffsetMode = sdd.PixelOffsetMode.None; - Control.SmoothingMode = sdd.SmoothingMode.AntiAlias; - Control.InterpolationMode = sdd.InterpolationMode.HighQualityBilinear; - } - - public void Commit () - { - } - - public void DrawLine (Pen pen, float startx, float starty, float endx, float endy) - { - this.Control.DrawLine (pen.ToSD (), startx, starty, endx, endy); - } - - public void DrawRectangle (Pen pen, float x, float y, float width, float height) - { - Control.DrawRectangle (pen.ToSD (), x, y, width, height); - } - - public void FillRectangle (Brush brush, float x, float y, float width, float height) - { - Control.FillRectangle (brush.ToSD (), x - 0.5f, y - 0.5f, width, height); - } - - public void DrawEllipse (Pen pen, float x, float y, float width, float height) - { - Control.DrawEllipse (pen.ToSD (), x, y, width, height); - } - - public void FillEllipse (Brush brush, float x, float y, float width, float height) - { - Control.FillEllipse (brush.ToSD (), x - 0.5f, y - 0.5f, width, height); - } - - public float GetConvertedAngle (float initialAngle, float majorRadius, float minorRadius, bool circularToElliptical) - { - var angle = initialAngle; - while (angle < 0) - angle += 360.0f; - var modAngle = angle % 360.0f; - angle %= 90.0f; - if (angle == 0) - return initialAngle; - var quadrant2 = (modAngle > 90 && modAngle <= 180); - var quadrant3 = (modAngle > 180 && modAngle <= 270); - var quadrant4 = (modAngle > 270 && modAngle <= 360); - if (quadrant2 || quadrant4) - angle = 90.0f - angle; - angle = DegreeToRadian (angle); - double functionReturnValue = 0; - - double dTan = 0; - dTan = Math.Tan (angle); - - if (Math.Abs (dTan) < 1E-10 | Math.Abs (dTan) > 10000000000.0) { - functionReturnValue = angle; - - } else if (circularToElliptical) { - functionReturnValue = Math.Atan (dTan * majorRadius / minorRadius); - } else { - functionReturnValue = Math.Atan (dTan * minorRadius / majorRadius); - } - - if (functionReturnValue < 0) { - functionReturnValue = functionReturnValue + 2 * Math.PI; - } - var ret = RadianToDegree ((float)functionReturnValue); - - // convert back to right quadrant - if (quadrant2) - ret = 180.0f - ret; - else if (quadrant4) - ret = 360.0f - ret; - else if (quadrant3) - ret += 180.0f; - - // get in the same range - while (initialAngle < 0) { - initialAngle += 360.0f; - ret -= 360.0f; - } - while (initialAngle > 360) { - initialAngle -= 360.0f; - ret += 360.0f; - } - - return ret; - } - - float DegreeToRadian (float angle) - { - return (float)Math.PI * angle / 180.0f; - } - - float RadianToDegree (float radians) - { - return radians * 180.0f / (float)Math.PI; - } - - public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - if (width != height) { - var endAngle = startAngle + sweepAngle; - startAngle = GetConvertedAngle (startAngle, width / 2, height / 2, false); - endAngle = GetConvertedAngle (endAngle, width / 2, height / 2, false); - sweepAngle = endAngle - startAngle; - } - Control.DrawArc (pen.ToSD (), x, y, width, height, startAngle, sweepAngle); - } - - public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) - { - if (width != height) { - var endAngle = startAngle + sweepAngle; - startAngle = GetConvertedAngle (startAngle, width / 2, height / 2, false); - endAngle = GetConvertedAngle (endAngle, width / 2, height / 2, false); - sweepAngle = endAngle - startAngle; - } - Control.FillPie (brush.ToSD (), x - 0.5f, y - 0.5f, width, height, startAngle, sweepAngle); - } - - public void FillPath (Brush brush, IGraphicsPath path) - { - var old = Control.PixelOffsetMode; - Control.PixelOffsetMode = old == sdd.PixelOffsetMode.Half ? sdd.PixelOffsetMode.None : sdd.PixelOffsetMode.Half; - Control.FillPath (brush.ToSD (), path.ToSD ()); - Control.PixelOffsetMode = old; - } - - public void DrawPath (Pen pen, IGraphicsPath path) - { - Control.DrawPath (pen.ToSD (), path.ToSD ()); - } - - public void DrawImage (Image image, float x, float y) - { - var handler = image.Handler as IWindowsImage; - handler.DrawImage (this, x, y); - } - - public void DrawImage (Image image, float x, float y, float width, float height) - { - var handler = image.Handler as IWindowsImage; - handler.DrawImage (this, x, y, width, height); - } - - public void DrawImage (Image image, RectangleF source, RectangleF destination) - { - var handler = image.Handler as IWindowsImage; - handler.DrawImage (this, source, destination); - } - - public void DrawText(Font font, SolidBrush brush, float x, float y, string text) - { - Control.DrawString(text, (sd.Font)font.ControlObject, brush.ControlObject as sd.Brush, x, y, defaultStringFormat); - } - - public SizeF MeasureString (Font font, string text) - { - /* BAD (but not really!?) - * - return this.Control.MeasureString (text, FontHandler.GetControl (font), sd.PointF.Empty, defaultStringFormat).ToEto (); - /**/ - if (string.IsNullOrEmpty (text)) - return Size.Empty; - sd.CharacterRange[] ranges = { new sd.CharacterRange (0, text.Length) }; - defaultStringFormat.SetMeasurableCharacterRanges (ranges); - - var regions = this.Control.MeasureCharacterRanges (text, FontHandler.GetControl (font), sd.Rectangle.Empty, defaultStringFormat); - var rect = regions [0].GetBounds (this.Control); - - return rect.Size.ToEto (); - /**/ - } - - public void Flush () - { - Control.Flush (); - } - - public void TranslateTransform (float offsetX, float offsetY) - { - this.Control.TranslateTransform (offsetX, offsetY); - } - - public void RotateTransform (float angle) - { - this.Control.RotateTransform (angle); - } - - public void ScaleTransform (float scaleX, float scaleY) - { - this.Control.ScaleTransform (scaleX, scaleY); - } - - public void MultiplyTransform (IMatrix matrix) - { - this.Control.MultiplyTransform ((sd.Drawing2D.Matrix)matrix.ControlObject); - } - - public void SaveTransform () - { - if (savedTransforms == null) - savedTransforms = new Stack (); - - savedTransforms.Push (Control.Transform); - } - - public void RestoreTransform () - { - if (savedTransforms != null && savedTransforms.Count > 0) { - var t = savedTransforms.Pop (); - - Control.Transform = t; - - t.Dispose (); - } - } - - public RectangleF ClipBounds - { - get { return this.Control.ClipBounds.ToEto(); } - } - - public void SetClip (RectangleF rectangle) - { - this.Control.SetClip (rectangle.ToSD ()); - } - - public void SetClip (IGraphicsPath path) - { - this.Control.SetClip (path.ToSD ()); - } - - public void ResetClip () - { - this.Control.ResetClip (); - } - - public void Clear(SolidBrush brush) - { - if (brush != null) - Control.Clear (brush.Color.ToSD ()); - else - Control.Clear (sd.Color.Transparent); - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/GraphicsPathHandler.cs b/Source/Eto.Platform.Windows/Drawing/GraphicsPathHandler.cs deleted file mode 100644 index b33680a836..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/GraphicsPathHandler.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System.Linq; -using Eto.Drawing; -using sd = System.Drawing; -using sd2 = System.Drawing.Drawing2D; -using System.Collections.Generic; - -namespace Eto.Platform.Windows.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class GraphicsPathHandler : IGraphicsPathHandler - { - sd2.GraphicsPath Control { get; set; } - sd.PointF position; - - public GraphicsPathHandler () - { - Control = new sd2.GraphicsPath (); - } - - GraphicsPathHandler (sd2.GraphicsPath control) - { - Control = control; - } - - public void LineTo (float x, float y) - { - var point = new sd.PointF (x, y); - Control.AddLine (position, point); - position = point; - } - - public void MoveTo (float x, float y) - { - position = new sd.PointF (x, y); - } - - public void AddLine (float startX, float startY, float endX, float endY) - { - Control.AddLine (new sd.PointF (startX, startY), new sd.PointF (endX, endY)); - position = new sd.PointF (endX, endY); - } - - public void AddLines (IEnumerable points) - { - var sdpoints = from p in points select p.ToSD (); - var pointArray = sdpoints.ToArray (); - Control.AddLines (pointArray); - position = pointArray.Last (); - } - - public void AddBezier (PointF start, PointF control1, PointF control2, PointF end) - { - Control.AddBezier (start.ToSD (), control1.ToSD (), control2.ToSD (), end.ToSD ()); - } - - public void AddPath (IGraphicsPath path, bool connect = false) - { - if (path != null && !path.IsEmpty) // avoid throwing an exception if the path is empty - consistent across platforms. - Control.AddPath(path.ToSD(), connect); - } - - public void Transform (IMatrix matrix) - { - Control.Transform (matrix.ToSD ()); - } - - public void CloseFigure () - { - Control.CloseFigure (); - } - - public void StartFigure () - { - Control.StartFigure (); - } - - public void AddCurve (IEnumerable points, float tension = 0.5f) - { - var sdpoints = from p in points select p.ToSD (); - var pointArray = sdpoints.ToArray (); - Control.AddCurve (pointArray, tension); - position = pointArray.Last (); - } - - public RectangleF Bounds - { - get { return Control.GetBounds ().ToEto (); } - } - - public object ControlObject - { - get { return Control; } - } - - public void Dispose () - { - Control.Dispose (); - } - - - public void AddArc (float x, float y, float width, float height, float startAngle, float sweepAngle) - { - Control.AddArc (x, y, width, height, startAngle, sweepAngle); - } - - public void AddRectangle (float x, float y, float width, float height) - { - Control.AddRectangle (new sd.RectangleF (x, y, width, height)); - } - - public void AddEllipse (float x, float y, float width, float height) - { - Control.AddEllipse (x, y, width, height); - } - - public bool IsEmpty - { - get { return Control.PointCount == 0; } - } - - public PointF CurrentPoint - { - get { return Control.GetLastPoint ().ToEto (); } - } - - public IGraphicsPath Clone () - { - return new GraphicsPathHandler ((sd.Drawing2D.GraphicsPath)Control.Clone ()); - } - - public FillMode FillMode - { - set { Control.FillMode = value == FillMode.Alternate ? sd2.FillMode.Alternate : sd2.FillMode.Winding; } - get { return Control.FillMode == sd2.FillMode.Alternate ? FillMode.Alternate : FillMode.Winding; } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Drawing/IconHandler.cs b/Source/Eto.Platform.Windows/Drawing/IconHandler.cs deleted file mode 100644 index 5a72d264a2..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/IconHandler.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using System.IO; -using Eto.Drawing; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.Windows.Drawing -{ - public interface IWindowsIconSource - { - SD.Icon GetIcon(); - } - - public class IconHandler : WidgetHandler, IIcon, IWindowsImage, IWindowsIconSource - { - SD.Icon[] icons; - - public IconHandler (SD.Icon control) - { - this.Control = control; - } - - public IconHandler () - { - } - - public Size Size { - get - { - var icon = GetLargestIcon(); - return new Size (icon.Width, icon.Height); - } - } - - public void Create (Stream stream) - { - Control = new SD.Icon (stream); - } - - public void Create (string fileName) - { - Control = new SD.Icon (fileName); - } - - public SD.Icon GetLargestIcon () - { - var splitIcons = SplitIcon (Control); - var curicon = splitIcons [0]; - foreach (var icon in splitIcons) { - if (icon.Width > curicon.Width) - curicon = icon; - } - return curicon; - } - - public SD.Icon GetIconClosestToSize (int width) - { - var splitIcons = SplitIcon (Control); - var curicon = splitIcons [0]; - if (curicon.Width == width) - return curicon; - foreach (var icon in splitIcons) { - if (icon.Width > width && icon.Width - width < curicon.Width - width) - curicon = icon; - } - return GetLargestIcon (); - } - - const int sICONDIR = 6; // sizeof(ICONDIR) - const int sICONDIRENTRY = 16; // sizeof(ICONDIRENTRY) - - public SD.Icon[] SplitIcon (SD.Icon icon) - { - if (icons != null) - return icons; - if (icon == null) { - throw new ArgumentNullException ("icon"); - } - - // Get multiple .ico file image. - byte[] srcBuf; - using (var stream = new MemoryStream()) { - icon.Save (stream); - stream.Flush (); - srcBuf = stream.ToArray (); - } - - var splitIcons = new List (); - int count = BitConverter.ToInt16 (srcBuf, 4); // ICONDIR.idCount - - for (int i = 0; i < count; i++) { - using (var destStream = new MemoryStream()) - using (var writer = new BinaryWriter(destStream)) { - // Copy ICONDIR and ICONDIRENTRY. - int pos = 0; - writer.Write (srcBuf, pos, sICONDIR - 2); - writer.Write ((short)1); // ICONDIR.idCount == 1; - - pos += sICONDIR; - pos += sICONDIRENTRY * i; - - writer.Write (srcBuf, pos, sICONDIRENTRY - 4); // write out icon info (minus old offset) - writer.Write (sICONDIR + sICONDIRENTRY); // write offset of icon data - pos += 8; - - // Copy picture and mask data. - int imgSize = BitConverter.ToInt32 (srcBuf, pos); // ICONDIRENTRY.dwBytesInRes - pos += 4; - int imgOffset = BitConverter.ToInt32 (srcBuf, pos); // ICONDIRENTRY.dwImageOffset - if (imgOffset + imgSize > srcBuf.Length) - throw new Exception ("ugh"); - writer.Write (srcBuf, imgOffset, imgSize); - writer.Flush (); - - // Create new icon. - destStream.Seek (0, SeekOrigin.Begin); - splitIcons.Add (new SD.Icon (destStream)); - } - } - - icons = splitIcons.ToArray (); - return icons; - } - - protected override void Dispose (bool disposing) - { - base.Dispose (disposing); - if (disposing) { - if (icons != null) { - foreach (var icon in icons) { - icon.Dispose (); - } - icons = null; - } - } - } - - public SD.Image GetImageWithSize (int? size) - { - if (size != null) - { - var icon = GetIconClosestToSize(size.Value); - return icon.ToBitmap(); - } - return GetLargestIcon().ToBitmap(); - } - - - public void DrawImage (GraphicsHandler graphics, RectangleF source, RectangleF destination) - { - var image = GetImageWithSize((int)Math.Max(destination.Width, destination.Height)); - graphics.Control.DrawImage (image, destination.ToSD (), source.ToSD (), SD.GraphicsUnit.Pixel); - } - - public void DrawImage (GraphicsHandler graphics, float x, float y) - { - var image = GetLargestIcon ().ToBitmap(); - graphics.Control.DrawImage (image, x, y); - } - - public void DrawImage (GraphicsHandler graphics, float x, float y, float width, float height) - { - var image = GetImageWithSize ((int)Math.Max (width, height)); - graphics.Control.DrawImage (image, x, y, width, height); - } - - public SD.Icon GetIcon() - { - return Control; - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/IndexedBitmapHandler.cs b/Source/Eto.Platform.Windows/Drawing/IndexedBitmapHandler.cs deleted file mode 100644 index d1eccc7da8..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/IndexedBitmapHandler.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using Eto.Drawing; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using System.Linq; - -namespace Eto.Platform.Windows.Drawing -{ - - public class IndexedBitmapDataHandler : BitmapData - { - public IndexedBitmapDataHandler(Image image, IntPtr data, int scanWidth, int bitsPerPixel, object controlObject) - : base (image, data, scanWidth, bitsPerPixel, controlObject) - { - } - - public override uint TranslateArgbToData(uint argb) - { - return argb; - } - - public override uint TranslateDataToArgb(uint bitmapData) - { - return bitmapData; - } - } - - public class IndexedBitmapHandler : WidgetHandler, IIndexedBitmap, IWindowsImage - { - public void Create(int width, int height, int bitsPerPixel) - { - SD.Imaging.PixelFormat sdPixelFormat; - switch (bitsPerPixel) - { - case 8: - sdPixelFormat = SD.Imaging.PixelFormat.Format8bppIndexed; - break; - case 4: - sdPixelFormat = SD.Imaging.PixelFormat.Format4bppIndexed; - break; - case 1: - sdPixelFormat = SD.Imaging.PixelFormat.Format1bppIndexed; - break; - default: - throw new ArgumentOutOfRangeException("bitsPerPixel", bitsPerPixel, "Not supported"); - } - Control = new SD.Bitmap(width, height, sdPixelFormat); - } - - public Size Size - { - get { return new Size(Control.Width, Control.Height); } - } - - public void Resize(int width, int height) - { - Control = new SD.Bitmap(Control, new SD.Size(width, height)); - } - - public BitmapData Lock() - { - SD.Imaging.BitmapData bd = Control.LockBits(new SD.Rectangle(0, 0, Control.Width, Control.Height), SD.Imaging.ImageLockMode.ReadWrite, Control.PixelFormat); - return new BitmapDataHandler(Widget, bd.Scan0, bd.Stride, bd.PixelFormat.BitsPerPixel(), bd); - } - - public void Unlock(BitmapData bitmapData) - { - Control.UnlockBits((SD.Imaging.BitmapData)bitmapData.ControlObject); - } - - public Palette Palette - { - get - { - SD.Imaging.ColorPalette cp = Control.Palette; - return new Palette(cp.Entries.Select(r => r.ToEto ()).ToList ()); - } - set - { - SD.Imaging.ColorPalette cp = Control.Palette; - if (value.Count != cp.Entries.Length) throw new ArgumentException("Input palette must have the same colors as the output"); - for (int i=0; i - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class LinearGradientBrushHandler : BrushHandler, ILinearGradientBrush - { - class BrushObject - { - public sd2.LinearGradientBrush Brush { get; set; } - public sd2.Matrix InitialMatrix { get; set; } - public IMatrix Matrix { get; set; } - } - - public object Create (Color startColor, Color endColor, PointF startPoint, PointF endPoint) - { - var brush = new sd2.LinearGradientBrush (startPoint.ToSD (), endPoint.ToSD (), startColor.ToSD (), endColor.ToSD ()); - return new BrushObject { - Brush = brush, - InitialMatrix = brush.Transform - }; - } - - public object Create (RectangleF rectangle, Color startColor, Color endColor, float angle) - { - var brush = new sd2.LinearGradientBrush (rectangle.ToSD (), startColor.ToSD (), endColor.ToSD (), angle, true); - return new BrushObject { - Brush = brush, - InitialMatrix = brush.Transform - }; - } - - public IMatrix GetTransform (LinearGradientBrush widget) - { - return ((BrushObject)widget.ControlObject).Matrix; - } - - public void SetTransform (LinearGradientBrush widget, IMatrix transform) - { - var brush = ((BrushObject)widget.ControlObject); - brush.Matrix = transform; - var newmatrix = brush.InitialMatrix.Clone (); - newmatrix.Multiply (transform.ToSD ()); - brush.Brush.Transform = newmatrix; - } - - public GradientWrapMode GetGradientWrap (LinearGradientBrush widget) - { - return ((BrushObject)widget.ControlObject).Brush.WrapMode.ToEtoGradientWrap (); - } - - public void SetGradientWrap (LinearGradientBrush widget, GradientWrapMode gradientWrap) - { - ((BrushObject)widget.ControlObject).Brush.WrapMode = gradientWrap.ToSD (); - } - - public override sd.Brush GetBrush (Brush brush) - { - return ((BrushObject)brush.ControlObject).Brush; - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/MatrixHandler.cs b/Source/Eto.Platform.Windows/Drawing/MatrixHandler.cs deleted file mode 100644 index 538455dfe7..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/MatrixHandler.cs +++ /dev/null @@ -1,180 +0,0 @@ -using System; -using Eto.Drawing; -using sd = System.Drawing; -using sd2 = System.Drawing.Drawing2D; - -namespace Eto.Platform.Windows.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class MatrixHandler : IMatrixHandler, IDisposable - { - sd2.Matrix control; - - public sd2.Matrix Control { get { return control; } } - - object IControlObjectSource.ControlObject { get { return control; } } - - public MatrixHandler () - { - } - - public MatrixHandler (sd2.Matrix matrix) - { - control = matrix; - } - - public float[] Elements { get { return Control.Elements; } } - - public float Xx - { - get { return control.Elements [0]; } - set - { - var e = control.Elements; - control = new sd2.Matrix (value, e [1], e [2], e [3], e [4], e [5]); - } - } - - public float Xy - { - get { return control.Elements [1]; } - set - { - var e = control.Elements; - control = new sd2.Matrix (e [0], value, e [2], e [3], e [4], e [5]); - } - } - - public float Yx - { - get { return control.Elements [2]; } - set - { - var e = control.Elements; - control = new sd2.Matrix (e [0], e [1], value, e [3], e [4], e [5]); - } - } - - public float Yy - { - get { return control.Elements [3]; } - set - { - var e = control.Elements; - control = new sd2.Matrix (e [0], e [1], e [2], value, e [4], e [5]); - } - } - - public float X0 - { - get { return Control.OffsetX; } - set - { - var e = control.Elements; - control = new sd2.Matrix (e [0], e [1], e [2], e [3], value, e [5]); - } - } - - public float Y0 - { - get { return Control.OffsetY; } - set - { - var e = control.Elements; - control = new sd2.Matrix (e [0], e [1], e [2], e [3], e [4], value); - } - } - - public void Rotate (float angle) - { - Control.Rotate (angle, sd2.MatrixOrder.Prepend); - } - - public void RotateAt (float angle, float centerX, float centerY) - { - Control.RotateAt (angle, new sd.PointF (centerX, centerY), sd2.MatrixOrder.Prepend); - } - - public void Translate (float x, float y) - { - Control.Translate (x, y, sd2.MatrixOrder.Prepend); - } - - public void Scale (float scaleX, float scaleY) - { - Control.Scale (scaleX, scaleY, sd2.MatrixOrder.Prepend); - } - - public void ScaleAt (float scaleX, float scaleY, float centerX, float centerY) - { - var m = new sd2.Matrix (scaleX, 0, 0, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); - Control.Multiply (m, sd2.MatrixOrder.Prepend); - } - - public void Skew (float skewX, float skewY) - { - var m = new sd2.Matrix (1, (float)Math.Tan(Conversions.DegreesToRadians(skewX)), (float)Math.Tan(Conversions.DegreesToRadians(skewY)), 1, 0, 0); - Control.Multiply (m, sd2.MatrixOrder.Prepend); - } - - public void Append (IMatrix matrix) - { - Control.Multiply (matrix.ToSD (), sd2.MatrixOrder.Append); - } - - public void Prepend (IMatrix matrix) - { - Control.Multiply (matrix.ToSD (), sd2.MatrixOrder.Prepend); - } - - public void Create () - { - control = new sd2.Matrix (); - } - - public void Create (float xx, float yx, float xy, float yy, float dx, float dy) - { - control = new sd2.Matrix (xx, yx, xy, yy, dx, dy); - } - - public void Invert () - { - Control.Invert (); - } - - public PointF TransformPoint (Point p) - { - var px = new sd.Point[] { p.ToSD() }; - - Control.TransformPoints (px); - - return px[0].ToEto(); - } - - public PointF TransformPoint (PointF p) - { - var px = new sd.PointF[] { p.ToSD () }; - - Control.TransformPoints (px); - - return px [0].ToEto (); - } - - public void Dispose () - { - if (control != null) { - control.Dispose (); - control = null; - } - } - - public IMatrix Clone () - { - return new MatrixHandler (control.Clone ()); - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/PenHandler.cs b/Source/Eto.Platform.Windows/Drawing/PenHandler.cs deleted file mode 100644 index cd4e8888cd..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/PenHandler.cs +++ /dev/null @@ -1,115 +0,0 @@ -using Eto.Drawing; -using System; -using sd = System.Drawing; -using sd2 = System.Drawing.Drawing2D; - -namespace Eto.Platform.Windows.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class PenHandler : IPen - { - public object Create (Color color, float thickness) - { - var pen = new sd.Pen (color.ToSD (), thickness); - pen.StartCap = pen.EndCap = PenLineCap.Square.ToSD (); - pen.DashCap = sd2.DashCap.Flat; - pen.MiterLimit = 10f; - return pen; - } - - public Color GetColor (Pen widget) - { - return widget.ToSD ().Color.ToEto (); - } - - public void SetColor (Pen widget, Color color) - { - widget.ToSD ().Color = color.ToSD (); - } - - public float GetThickness (Pen widget) - { - return widget.ToSD ().Width; - } - - public void SetThickness (Pen widget, float thickness) - { - widget.ToSD ().Width = thickness; - } - - public PenLineJoin GetLineJoin (Pen widget) - { - return widget.ToSD ().LineJoin.ToEto (); - } - - public void SetLineJoin (Pen widget, PenLineJoin lineJoin) - { - widget.ToSD ().LineJoin = lineJoin.ToSD (); - } - - public PenLineCap GetLineCap (Pen widget) - { - return widget.ToSD ().StartCap.ToEto (); - } - - public void SetLineCap (Pen widget, PenLineCap lineCap) - { - var pen = widget.ToSD (); - // get dash style before changing cap - var dashStyle = widget.DashStyle; - pen.StartCap = pen.EndCap = lineCap.ToSD (); - pen.DashCap = lineCap == PenLineCap.Round ? sd2.DashCap.Round : sd2.DashCap.Flat; - SetDashStyle (widget, dashStyle); - } - - public float GetMiterLimit (Pen widget) - { - return widget.ToSD ().MiterLimit; - } - - public void SetMiterLimit (Pen widget, float miterLimit) - { - widget.ToSD ().MiterLimit = miterLimit; - } - - public DashStyle GetDashStyle (Pen widget) - { - var pen = widget.ToSD (); - if (pen.DashStyle == sd2.DashStyle.Solid) - return DashStyles.Solid; - else { - var offset = pen.StartCap == sd2.LineCap.Square ? pen.DashOffset - 0.5f : pen.DashOffset; - return new DashStyle (offset, pen.DashPattern); - } - } - - public void SetDashStyle (Pen widget, DashStyle dashStyle) - { - var pen = widget.ToSD (); - - pen.DashOffset = 0; - if (dashStyle == null || dashStyle.IsSolid) - pen.DashStyle = sd2.DashStyle.Solid; - else if (dashStyle.Equals(DashStyles.Dash)) - pen.DashStyle = sd2.DashStyle.Dash; - else if (dashStyle.Equals(DashStyles.DashDot)) - pen.DashStyle = sd2.DashStyle.DashDot; - else if (dashStyle.Equals(DashStyles.DashDotDot)) - pen.DashStyle = sd2.DashStyle.DashDotDot; - else - { - pen.DashStyle = sd2.DashStyle.Custom; - pen.DashPattern = dashStyle.Dashes; - pen.DashOffset = dashStyle.Offset; - } - if (pen.StartCap == sd2.LineCap.Square) - { - pen.DashOffset += 0.5f; - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/SolidBrushHandler.cs b/Source/Eto.Platform.Windows/Drawing/SolidBrushHandler.cs deleted file mode 100644 index 6636bc474d..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/SolidBrushHandler.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Eto.Drawing; -using sd = System.Drawing; - -namespace Eto.Platform.Windows.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class SolidBrushHandler : BrushHandler, ISolidBrush - { - public object Create (Color color) - { - return new sd.SolidBrush (color.ToSD ()); - } - - public Color GetColor (SolidBrush widget) - { - return ((sd.SolidBrush)widget.ControlObject).Color.ToEto (); - } - - public void SetColor (SolidBrush widget, Color color) - { - ((sd.SolidBrush)widget.ControlObject).Color = color.ToSD (); - } - - public override sd.Brush GetBrush (Brush brush) - { - return (sd.Brush)brush.ControlObject; - } - } -} diff --git a/Source/Eto.Platform.Windows/Drawing/TextureBrushHandler.cs b/Source/Eto.Platform.Windows/Drawing/TextureBrushHandler.cs deleted file mode 100644 index 0663c43039..0000000000 --- a/Source/Eto.Platform.Windows/Drawing/TextureBrushHandler.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Eto.Drawing; -using sd = System.Drawing; -using sd2 = System.Drawing.Drawing2D; -using sdi = System.Drawing.Imaging; - -namespace Eto.Platform.Windows.Drawing -{ - /// - /// Handler for - /// - /// (c) 2012 by Curtis Wensley - /// See LICENSE for full terms - public class TextureBrushHandler : BrushHandler, ITextureBrush - { - public object Create (Image image, float opacity) - { - var sdimage = new sd.Bitmap (image.ToSD ()); - var att = new sdi.ImageAttributes (); - att.SetWrapMode (sd2.WrapMode.Tile); - if (opacity < 1.0f) { - var colorMatrix = new sdi.ColorMatrix (new float[][] { - new float [] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, - new float [] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, - new float [] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, - new float [] { 0.0f, 0.0f, 0.0f, opacity, 0.0f }, - new float [] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } - }); - att.SetColorMatrix (colorMatrix); - } - return new sd.TextureBrush (sdimage, new sd.RectangleF (0, 0, sdimage.Width, sdimage.Height), att); - } - - public IMatrix GetTransform (TextureBrush widget) - { - return ((sd.TextureBrush)widget.ControlObject).Transform.ToEto (); - } - - public void SetTransform (TextureBrush widget, IMatrix transform) - { - ((sd.TextureBrush)widget.ControlObject).Transform = transform.ToSD (); - } - - public void SetOpacity (TextureBrush widget, float opacity) - { - var brush = ((sd.TextureBrush)widget.ControlObject); - widget.ControlObject = Create (widget.Image, opacity); - var newbrush = ((sd.TextureBrush)widget.ControlObject); - newbrush.Transform = brush.Transform; - } - - public override sd.Brush GetBrush (Brush brush) - { - return (sd.Brush)brush.ControlObject; - } - } -} diff --git a/Source/Eto.Platform.Windows/Eto.Platform.Windows.csproj b/Source/Eto.Platform.Windows/Eto.Platform.Windows.csproj deleted file mode 100644 index 9986cca605..0000000000 --- a/Source/Eto.Platform.Windows/Eto.Platform.Windows.csproj +++ /dev/null @@ -1,339 +0,0 @@ - - - - - Debug - AnyCPU - {69D38C57-AD4B-4A16-A7B1-49BCFBE71491} - Library - Eto.Platform.Windows - Eto.Platform.Windows - ..\ - true - - - 512 - True - prompt - 4 - ..\..\.. - ..\..\Libraries - True - TRACE;WINFORMS - - - ..\..\BuildOutput\Debug\ - DEBUG;TRACE;WINFORMS - false - full - - - ..\..\BuildOutput\Release\ - True - pdbonly - - - - - ..\..\Libraries\SHDocVw\Interop.SHDocVw.dll - False - False - - - System - - - System.Drawing - - - System.Data - - - System.Windows.Forms - - - System.Xml - - - - ..\packages\Windows7APICodePack-Core.1.1.0.0\lib\Microsoft.WindowsAPICodePack.dll - False - - - ..\packages\Windows7APICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.Shell.dll - False - - - - - {16289D2F-044C-49EF-83E9-9391AFF8FD2B} - Eto - - - - - Conversions.sd.cs - - - CustomControls\HttpServer.cs - - - - - - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - Code - - - Code - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Component - - - Code - - - Code - - - Code - - - Properties\GlobalAssemblyInfo.cs - - - - - - - - - Code - - - - - - - - - - - - Code - - - - - - - - - - - - - CustomControls\Assemblies\Interop.SHDocVw.dll - - - - - - - - CustomControls\Assemblies\Microsoft.WindowsAPICodePack.dll - - - CustomControls\Assemblies\Microsoft.WindowsAPICodePack.Shell.dll - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Source/Eto.Platform.Windows/EtoEnvironmentHandler.cs b/Source/Eto.Platform.Windows/EtoEnvironmentHandler.cs deleted file mode 100644 index 36bd17b717..0000000000 --- a/Source/Eto.Platform.Windows/EtoEnvironmentHandler.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using Eto; -using System.Reflection; -using System.IO; - -namespace Eto.Platform.Windows -{ - public class EtoEnvironmentHandler : WidgetHandler, IEtoEnvironment - { - - static System.Environment.SpecialFolder Convert (EtoSpecialFolder folder) - { - switch (folder) { - case EtoSpecialFolder.ApplicationSettings: - return System.Environment.SpecialFolder.ApplicationData; - case EtoSpecialFolder.Documents: - return System.Environment.SpecialFolder.MyDocuments; - default: - throw new NotSupportedException (); - } - - } - - public string GetFolderPath (EtoSpecialFolder folder) - { - switch (folder) { - case EtoSpecialFolder.ApplicationResources: - return Path.GetDirectoryName (Assembly.GetEntryAssembly ().Location); - default: - return System.Environment.GetFolderPath(Convert(folder)); - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/ApplicationHandler.cs b/Source/Eto.Platform.Windows/Forms/ApplicationHandler.cs deleted file mode 100644 index 3b853d4e39..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ApplicationHandler.cs +++ /dev/null @@ -1,209 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using System.Diagnostics; -using System.Threading; -using Microsoft.WindowsAPICodePack.Taskbar; -using System.Collections.Generic; - -namespace Eto.Platform.Windows -{ - public class ApplicationHandler : WidgetHandler, IApplication - { - string badgeLabel; - bool attached; - readonly Thread mainThread; - SynchronizationContext context; - public static bool EnableScrollingUnderMouse = true; - public static bool BubbleMouseEvents = true; - public static bool BubbleKeyEvents = true; - - public ApplicationHandler() - { - mainThread = Thread.CurrentThread; - } - - public void RunIteration() - { - swf.Application.DoEvents(); - } - - public void Restart() - { - swf.Application.Restart(); - } - - public string BadgeLabel - { - get { return badgeLabel; } - set - { - badgeLabel = value; - if (TaskbarManager.IsPlatformSupported) - { - if (!string.IsNullOrEmpty(badgeLabel)) - { - var bmp = new sd.Bitmap(16, 16, sd.Imaging.PixelFormat.Format32bppArgb); - using (var graphics = sd.Graphics.FromImage(bmp)) - { - DrawBadgeLabel(bmp, graphics); - } - var icon = sd.Icon.FromHandle(bmp.GetHicon()); - - TaskbarManager.Instance.SetOverlayIcon(icon, badgeLabel); - } - else - TaskbarManager.Instance.SetOverlayIcon(null, null); - } - } - } - - protected virtual void DrawBadgeLabel(sd.Bitmap bmp, sd.Graphics graphics) - { - var font = new sd.Font(sd.FontFamily.GenericSansSerif, 9, sd.FontStyle.Bold, sd.GraphicsUnit.Pixel); - - var size = graphics.MeasureString(badgeLabel, font, bmp.Size, sd.StringFormat.GenericTypographic); - graphics.SmoothingMode = sd.Drawing2D.SmoothingMode.AntiAlias; - graphics.FillEllipse(sd.Brushes.Red, new sd.Rectangle(0, 0, 16, 16)); - graphics.DrawEllipse(new sd.Pen(sd.Brushes.White, 2), new sd.Rectangle(0, 0, 15, 15)); - var pt = new sd.PointF((bmp.Width - size.Width - 0.5F) / 2, (bmp.Height - size.Height - 1) / 2); - graphics.DrawString(badgeLabel, font, sd.Brushes.White, pt, sd.StringFormat.GenericTypographic); - } - - public void Run(string[] args) - { - if (!attached) - { - swf.Application.EnableVisualStyles(); - if (!EtoEnvironment.Platform.IsMono) - swf.Application.DoEvents(); - - SetOptions(); - // creates sync context - using (var ctl = new swf.Control()) - { - } - context = SynchronizationContext.Current; - - Widget.OnInitialized(EventArgs.Empty); - - if (Widget.MainForm != null && Widget.MainForm.Loaded) - swf.Application.Run((swf.Form)Widget.MainForm.ControlObject); - else - swf.Application.Run(); - } - else - { - Widget.OnInitialized(EventArgs.Empty); - } - } - - static void SetOptions() - { - if (EnableScrollingUnderMouse) - swf.Application.AddMessageFilter(new ScrollMessageFilter()); - - if (BubbleMouseEvents) - { - var bubble = new BubbleEventFilter(); - bubble.AddBubbleMouseEvent((c, e) => c.OnMouseWheel(e), null, Win32.WM.MOUSEWHEEL); - bubble.AddBubbleMouseEvent((c, e) => c.OnMouseMove(e), null, Win32.WM.MOUSEMOVE); - bubble.AddBubbleMouseEvents((c, e) => c.OnMouseDown(e), true, Win32.WM.LBUTTONDOWN, Win32.WM.RBUTTONDOWN, Win32.WM.MBUTTONDOWN); - bubble.AddBubbleMouseEvents((c, e) => { - c.OnMouseDoubleClick(e); - if (!e.Handled) - c.OnMouseDown(e); - }, null, Win32.WM.LBUTTONDBLCLK, Win32.WM.RBUTTONDBLCLK, Win32.WM.MBUTTONDBLCLK); - bubble.AddBubbleMouseEvent((c, e) => c.OnMouseUp(e), false, Win32.WM.LBUTTONUP, b => MouseButtons.Primary); - bubble.AddBubbleMouseEvent((c, e) => c.OnMouseUp(e), false, Win32.WM.RBUTTONUP, b => MouseButtons.Alternate); - bubble.AddBubbleMouseEvent((c, e) => c.OnMouseUp(e), false, Win32.WM.MBUTTONUP, b => MouseButtons.Middle); - swf.Application.AddMessageFilter(bubble); - } - if (BubbleKeyEvents) - { - var bubble = new BubbleEventFilter(); - bubble.AddBubbleKeyEvent((c, e) => c.OnKeyDown(e), Win32.WM.KEYDOWN, KeyEventType.KeyDown); - bubble.AddBubbleKeyEvent((c, e) => c.OnKeyDown(e), Win32.WM.SYSKEYDOWN, KeyEventType.KeyDown); - bubble.AddBubbleKeyCharEvent((c, e) => c.OnKeyDown(e), Win32.WM.CHAR, KeyEventType.KeyDown); - bubble.AddBubbleKeyCharEvent((c, e) => c.OnKeyDown(e), Win32.WM.SYSCHAR, KeyEventType.KeyDown); - bubble.AddBubbleKeyEvent((c, e) => c.OnKeyUp(e), Win32.WM.KEYUP, KeyEventType.KeyUp); - bubble.AddBubbleKeyEvent((c, e) => c.OnKeyUp(e), Win32.WM.SYSKEYUP, KeyEventType.KeyUp); - swf.Application.AddMessageFilter(bubble); - } - } - - public void Attach(object context) - { - attached = true; - SetOptions(); - } - - public void OnMainFormChanged() - { - } - - public void Quit() - { - swf.Application.Exit(); - } - - public void Open(string url) - { - var info = new ProcessStartInfo(url); - Process.Start(info); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Application.TerminatingEvent: - // handled by WindowHandler - break; - default: - base.AttachEvent(id); - break; - } - } - - public void Invoke(Action action) - { - if (Thread.CurrentThread == mainThread) - action(); - else if (context != null) - context.Send(state => action(), null); - } - - public void AsyncInvoke(Action action) - { - if (context != null) - context.Post(state => action(), null); - } - - public IEnumerable GetSystemCommands() - { - yield break; - } - - public void CreateStandardMenu(MenuItemCollection menuItems, IEnumerable commands) - { - } - - public Keys CommonModifier - { - get - { - return Keys.Control; - } - } - - public Keys AlternateModifier - { - get - { - return Keys.Alt; - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Cells/CellHandler.cs b/Source/Eto.Platform.Windows/Forms/Cells/CellHandler.cs deleted file mode 100644 index 15da8247f6..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Cells/CellHandler.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public interface ICellConfigHandler - { - void Paint (sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts); - - int GetRowOffset (int rowIndex); - - bool MouseClick (swf.MouseEventArgs e, int rowIndex); - } - - public interface ICellHandler - { - ICellConfigHandler CellConfig { get; set; } - swf.DataGridViewCell Control { get; } - void SetCellValue (object dataItem, object value); - object GetCellValue (object dataItem); - } - - public abstract class CellHandler : WidgetHandler, ICell, ICellHandler - where TControl: swf.DataGridViewCell - where TWidget: Cell - { - swf.DataGridViewCell ICellHandler.Control { - get { return Control; } - } - - public ICellConfigHandler CellConfig { get; set; } - - protected void PositionEditingControl (int row, ref sd.Rectangle cellClip, ref sd.Rectangle cellBounds, int customOffset = 0) - { - var val = GetRowOffset (row) + customOffset; - if (val > 0) { - cellBounds.X += val; - cellBounds.Width -= val; - cellClip.X += val; - cellClip.Width -= val; - } - } - - protected void Paint (sd.Graphics graphics, sd.Rectangle clipBounds, ref sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts) - { - if (CellConfig != null) { - CellConfig.Paint (graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); - - var offset = CellConfig.GetRowOffset (rowIndex); - cellBounds.X += offset; - cellBounds.Width -= offset; - } - } - - protected bool MouseClick (swf.MouseEventArgs e, int rowIndex) - { - return CellConfig != null && CellConfig.MouseClick(e, rowIndex); - } - - protected int GetRowOffset (int row) - { - return CellConfig != null ? CellConfig.GetRowOffset(row) : 0; - } - - public abstract void SetCellValue (object dataItem, object value); - - public abstract object GetCellValue (object dataItem); - - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Cells/CheckBoxCellHandler.cs b/Source/Eto.Platform.Windows/Forms/Cells/CheckBoxCellHandler.cs deleted file mode 100644 index 78da0bb27b..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Cells/CheckBoxCellHandler.cs +++ /dev/null @@ -1,71 +0,0 @@ -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class CheckBoxCellHandler : CellHandler, ICheckBoxCell - { - - class EtoCell : swf.DataGridViewCheckBoxCell - { - public CheckBoxCellHandler Handler { get; set; } - - public override void PositionEditingControl (bool setLocation, bool setSize, sd.Rectangle cellBounds, sd.Rectangle cellClip, swf.DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) - { - Handler.PositionEditingControl (RowIndex, ref cellClip, ref cellBounds); - base.PositionEditingControl (setLocation, setSize, cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow); - } - - protected override sd.Size GetPreferredSize (sd.Graphics graphics, swf.DataGridViewCellStyle cellStyle, int rowIndex, sd.Size constraintSize) - { - var size = base.GetPreferredSize (graphics, cellStyle, rowIndex, constraintSize); - size.Width += Handler.GetRowOffset (rowIndex); - return size; - } - - protected override void Paint (sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) - { - Handler.Paint (graphics, clipBounds, ref cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); - base.Paint (graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); - } - - protected override void OnMouseClick (swf.DataGridViewCellMouseEventArgs e) - { - if (!Handler.MouseClick (e, e.RowIndex)) - base.OnMouseClick (e); - } - - public override object Clone () - { - var val = (EtoCell)base.Clone(); - val.Handler = Handler; - return val; - } - } - - public CheckBoxCellHandler () - { - Control = new EtoCell { Handler = this }; - } - - public override void SetCellValue (object dataItem, object value) - { - if (Widget.Binding != null) { - Widget.Binding.SetValue (dataItem, value); - } - } - - public override object GetCellValue (object dataItem) - { - if (Widget.Binding != null) - { - if (Control.ThreeState) - return Widget.Binding.GetValue(dataItem); - return Widget.Binding.GetValue(dataItem) ?? false; - } - return Control.ThreeState ? null : (bool?)false; - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Cells/ComboBoxCellHandler.cs b/Source/Eto.Platform.Windows/Forms/Cells/ComboBoxCellHandler.cs deleted file mode 100644 index fb80361066..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Cells/ComboBoxCellHandler.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System.Linq; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class ComboBoxCellHandler : CellHandler, IComboBoxCell - { - CollectionHandler collection; - - class EtoCell : swf.DataGridViewComboBoxCell - { - public ComboBoxCellHandler Handler { get; set; } - - public override void PositionEditingControl (bool setLocation, bool setSize, sd.Rectangle cellBounds, sd.Rectangle cellClip, swf.DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) - { - Handler.PositionEditingControl (RowIndex, ref cellClip, ref cellBounds); - base.PositionEditingControl (setLocation, setSize, cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow); - } - - protected override sd.Size GetPreferredSize (sd.Graphics graphics, swf.DataGridViewCellStyle cellStyle, int rowIndex, sd.Size constraintSize) - { - var size = base.GetPreferredSize (graphics, cellStyle, rowIndex, constraintSize); - size.Width += Handler.GetRowOffset (rowIndex); - return size; - } - - protected override void Paint (sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) - { - Handler.Paint (graphics, clipBounds, ref cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); - base.Paint (graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); - } - - protected override void OnMouseClick (swf.DataGridViewCellMouseEventArgs e) - { - if (!Handler.MouseClick (e, e.RowIndex)) - base.OnMouseClick (e); - } - - public override object Clone () - { - var val = (EtoCell)base.Clone(); - val.Handler = Handler; - return val; - } - } - - - public ComboBoxCellHandler () - { - Control = new EtoCell { - Handler = this, - ValueMember = "Key", - DisplayMember = "Text", - FlatStyle = swf.FlatStyle.Flat - }; - } - - class CollectionHandler : DataStoreChangedHandler - { - public ComboBoxCellHandler Handler { get; set; } - - public override int IndexOf (IListItem item) - { - return Handler.Control.Items.IndexOf (item); - } - - public override void AddRange (IEnumerable items) - { - Handler.Control.Items.AddRange (items.ToArray ()); - } - - public override void AddItem (IListItem item) - { - Handler.Control.Items.Add (item); - } - - public override void InsertItem (int index, IListItem item) - { - Handler.Control.Items.Insert (index, item); - } - - public override void RemoveItem (int index) - { - Handler.Control.Items.RemoveAt (index); - } - - public override void RemoveAllItems () - { - Handler.Control.Items.Clear (); - } - } - - public IListStore DataStore { - get { return collection != null ? collection.Collection : null; } - set { - if (collection != null) - collection.Unregister (); - collection = new CollectionHandler { Handler = this }; - collection.Register (value); - } - } - - public override object GetCellValue (object dataItem) - { - return Widget.Binding == null ? null : Widget.Binding.GetValue(dataItem); - } - - public override void SetCellValue (object dataItem, object value) - { - if (Widget.Binding != null) { - Widget.Binding.SetValue (dataItem, value); - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Cells/ImageTextCellHandler.cs b/Source/Eto.Platform.Windows/Forms/Cells/ImageTextCellHandler.cs deleted file mode 100644 index a286a641bf..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Cells/ImageTextCellHandler.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class ImageTextCellHandler : CellHandler, IImageTextCell - { - public static int IconSize = 16; - public static int IconPadding = 2; - - class EtoCell : swf.DataGridViewTextBoxCell - { - public ImageTextCellHandler Handler { get; set; } - - public override void PositionEditingControl (bool setLocation, bool setSize, sd.Rectangle cellBounds, sd.Rectangle cellClip, swf.DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) - { - Handler.PositionEditingControl (RowIndex, ref cellClip, ref cellBounds, IconSize + IconPadding * 2); - base.PositionEditingControl (setLocation, setSize, cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow); - } - - protected override object GetFormattedValue (object value, int rowIndex, ref swf.DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, swf.DataGridViewDataErrorContexts context) - { - var val = value as object[]; - return base.GetFormattedValue ((val != null) ? val[1] : null, rowIndex, ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context); - } - - protected override sd.Size GetPreferredSize (sd.Graphics graphics, swf.DataGridViewCellStyle cellStyle, int rowIndex, sd.Size constraintSize) - { - var size = base.GetPreferredSize (graphics, cellStyle, rowIndex, constraintSize); - var val = GetValue (rowIndex) as object[]; - var img = val[0] as sd.Image; - if (img != null) size.Width += IconSize + IconPadding * 2; - size.Width += Handler.GetRowOffset (rowIndex); - return size; - } - - protected override void Paint (System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) - { - Handler.Paint (graphics, clipBounds, ref cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); - - var val = value as object[]; - var img = val[0] as sd.Image; - if (img != null) { - var container = graphics.BeginContainer (); - graphics.SetClip (cellBounds); - - graphics.DrawImage (img, new sd.Rectangle (cellBounds.X + IconPadding, cellBounds.Y + (cellBounds.Height - Math.Min(img.Height, cellBounds.Height)) / 2, IconSize, IconSize)); - graphics.EndContainer (container); - cellBounds.X += IconSize + IconPadding * 2; - cellBounds.Width -= IconSize + IconPadding * 2; - } - base.Paint (graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); - } - - protected override void OnMouseClick (swf.DataGridViewCellMouseEventArgs e) - { - if (!Handler.MouseClick (e, e.RowIndex)) - base.OnMouseClick (e); - } - - public override object Clone () - { - var val = (EtoCell)base.Clone (); - val.Handler = Handler; - return val; - } - } - - public ImageTextCellHandler () - { - Control = new EtoCell { Handler = this }; - } - - public override void SetCellValue (object dataItem, object value) - { - if (Widget.TextBinding != null) { - Widget.TextBinding.SetValue (dataItem, value); - } - } - - public override object GetCellValue (object dataItem) - { - var obj = new object[2]; - if (Widget.ImageBinding != null) { - var image = Widget.ImageBinding.GetValue (dataItem) as Image; - if (image != null) { - var imageHandler = image.Handler as IWindowsImageSource; - if (imageHandler != null) { - obj[0] = imageHandler.GetImageWithSize (Math.Max (32, Control.PreferredSize.Height)); - } - } - } - if (Widget.TextBinding != null) { - obj[1] = Convert.ToString (Widget.TextBinding.GetValue (dataItem)); - } - return obj; - } - - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Cells/ImageViewCellHandler.cs b/Source/Eto.Platform.Windows/Forms/Cells/ImageViewCellHandler.cs deleted file mode 100644 index 1ae3d29862..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Cells/ImageViewCellHandler.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class ImageViewCellHandler : CellHandler, IImageViewCell - { - static readonly sd.Bitmap transparent; - - class EtoCell : swf.DataGridViewImageCell - { - public ImageViewCellHandler Handler { get; set; } - - public override void PositionEditingControl (bool setLocation, bool setSize, sd.Rectangle cellBounds, sd.Rectangle cellClip, swf.DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) - { - Handler.PositionEditingControl (RowIndex, ref cellClip, ref cellBounds); - base.PositionEditingControl (setLocation, setSize, cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow); - } - - protected override sd.Size GetPreferredSize (sd.Graphics graphics, swf.DataGridViewCellStyle cellStyle, int rowIndex, sd.Size constraintSize) - { - var size = base.GetPreferredSize (graphics, cellStyle, rowIndex, constraintSize); - size.Width += Handler.GetRowOffset (rowIndex); - return size; - } - - protected override void Paint (sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) - { - Handler.Paint (graphics, clipBounds, ref cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); - base.Paint (graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); - } - - protected override void OnMouseClick (swf.DataGridViewCellMouseEventArgs e) - { - if (!Handler.MouseClick (e, e.RowIndex)) - base.OnMouseClick (e); - } - - public override object Clone () - { - var val = (EtoCell)base.Clone(); - val.Handler = Handler; - return val; - } - } - - - public ImageViewCellHandler () - { - Control = new EtoCell { Handler = this }; - Control.ImageLayout = swf.DataGridViewImageCellLayout.Zoom; - } - - static ImageViewCellHandler () - { - transparent = new sd.Bitmap (1, 1); - using (var g = sd.Graphics.FromImage (transparent)) { - g.FillRectangle (sd.Brushes.Transparent, 0, 0, 1, 1); - } - } - - public override object GetCellValue (object dataItem) - { - if (Widget.Binding != null) { - var image = Widget.Binding.GetValue (dataItem) as Image; - if (image != null) { - var imageHandler = image.Handler as IWindowsImageSource; - if (imageHandler != null) { - return imageHandler.GetImageWithSize (Math.Max (32, Control.PreferredSize.Height)); - } - } - } - return transparent; - } - - public override void SetCellValue (object dataItem, object value) - { - if (Widget.Binding != null) { - Widget.Binding.SetValue (dataItem, value); - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Cells/TextBoxCellHandler.cs b/Source/Eto.Platform.Windows/Forms/Cells/TextBoxCellHandler.cs deleted file mode 100644 index b3e7a1a111..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Cells/TextBoxCellHandler.cs +++ /dev/null @@ -1,66 +0,0 @@ -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class TextBoxCellHandler : CellHandler, ITextBoxCell - { - class EtoCell : swf.DataGridViewTextBoxCell - { - public TextBoxCellHandler Handler { get; set; } - - public override void PositionEditingControl (bool setLocation, bool setSize, sd.Rectangle cellBounds, sd.Rectangle cellClip, swf.DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) - { - Handler.PositionEditingControl (RowIndex, ref cellClip, ref cellBounds); - base.PositionEditingControl (setLocation, setSize, cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow); - } - - protected override sd.Size GetPreferredSize (sd.Graphics graphics, swf.DataGridViewCellStyle cellStyle, int rowIndex, sd.Size constraintSize) - { - var size = base.GetPreferredSize (graphics, cellStyle, rowIndex, constraintSize); - size.Width += Handler.GetRowOffset (rowIndex); - return size; - } - - protected override void Paint (System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) - { - Handler.Paint (graphics, clipBounds, ref cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); - base.Paint (graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); - } - - protected override void OnMouseClick (swf.DataGridViewCellMouseEventArgs e) - { - if (!Handler.MouseClick (e, e.RowIndex)) - base.OnMouseClick (e); - } - - public override object Clone () - { - var val = (EtoCell)base.Clone(); - val.Handler = Handler; - return val; - } - } - - - public TextBoxCellHandler () - { - Control = new EtoCell { Handler = this }; - } - - public override void SetCellValue (object dataItem, object value) - { - if (Widget.Binding != null) { - Widget.Binding.SetValue (dataItem, value); - } - } - - public override object GetCellValue (object dataItem) - { - return Widget.Binding == null ? null : Widget.Binding.GetValue(dataItem); - } - - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/ClipboardHandler.cs b/Source/Eto.Platform.Windows/Forms/ClipboardHandler.cs deleted file mode 100644 index e8435d2cff..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ClipboardHandler.cs +++ /dev/null @@ -1,183 +0,0 @@ -using System; -using Eto.Forms; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using sdi = System.Drawing.Imaging; -using Eto.Platform.Windows.Drawing; -using Eto.Drawing; -using System.Runtime.InteropServices; - -namespace Eto.Platform.Windows.Forms -{ - public class ClipboardHandler : WidgetHandler, IClipboard - { - public ClipboardHandler () - { - Control = new swf.DataObject(); - } - - void Update() - { - swf.Clipboard.SetDataObject (Control); - } - - public void SetData (byte[] value, string type) - { - Control.SetData (type, value); - Update(); - } - - public void SetString (string value, string type) - { - Control.SetData (type, value); - Update(); - } - - public string Html - { - set { - Control.SetText (value, System.Windows.Forms.TextDataFormat.Html); - Update(); - } - get { - return swf.Clipboard.GetText (swf.TextDataFormat.Html); - } - } - - public string Text - { - set { - Control.SetText(value); - Update(); - } - get { - return swf.Clipboard.GetText (); - } - } - - public Image Image - { - set - { - var sdimage = value.ControlObject as sd.Image; - if (sdimage != null) { - Control.SetImage (sdimage); - Update (); - } - } - get - { - Image result = null; - - try { - var sdimage = GetImageFromClipboard () as sd.Bitmap; - - if (sdimage != null) { - var handler = new BitmapHandler (sdimage); - - result = new Bitmap (Widget.Generator, handler); - } - } catch { - } - - return result; - } - } - - /// - /// see http://stackoverflow.com/questions/11273669/how-to-paste-a-transparent-image-from-the-clipboard-in-a-c-sharp-winforms-app - /// - static sd.Image GetImageFromClipboard () - { - if (swf.Clipboard.GetDataObject () == null) - return null; - - if (swf.Clipboard.GetDataObject ().GetDataPresent (swf.DataFormats.Dib)) { - var dib = ((System.IO.MemoryStream)swf.Clipboard.GetData (swf.DataFormats.Dib)).ToArray (); - - var width = BitConverter.ToInt32 (dib, 4); - var height = BitConverter.ToInt32 (dib, 8); - var bpp = BitConverter.ToInt16 (dib, 14); - - if (bpp == 32) { - var gch = GCHandle.Alloc (dib, GCHandleType.Pinned); - - sd.Bitmap bmp = null; - - try { - var ptr = new IntPtr ((long)gch.AddrOfPinnedObject () + 40); - - bmp = new sd.Bitmap (width, height, width * 4, sdi.PixelFormat.Format32bppArgb, ptr); - - var result = new sd.Bitmap (bmp); - - // Images are rotated and flipped for some reason. - // This rotates them back. - result.RotateFlip (sd.RotateFlipType.Rotate180FlipX); - - return result; - } finally { - gch.Free (); - - if (bmp != null) - bmp.Dispose (); - } - } - } - if (swf.Clipboard.ContainsFileDropList()) - { - var list = swf.Clipboard.GetFileDropList(); - if (list != null && list.Count > 0) - { - var path = list[0]; - sd.Image bmp = null; - try - { - bmp = sd.Image.FromFile(path); - var result = new sd.Bitmap(bmp); - return result; - } - catch - { - } - finally - { - if (bmp != null) - bmp.Dispose(); - } - } - } - - return swf.Clipboard.ContainsImage () ? swf.Clipboard.GetImage () : null; - } - - public byte[] GetData (string type) - { - if (swf.Clipboard.ContainsData(type)) - return swf.Clipboard.GetData(type) as byte[]; - return null; - } - - public string GetString (string type) - { - if (swf.Clipboard.ContainsData(type)) - return swf.Clipboard.GetData(type) as string; - return null; - } - - public string[] Types { - get - { - var data = swf.Clipboard.GetDataObject(); - return data != null ? data.GetFormats() : null; - } - } - - public void Clear () - { - swf.Clipboard.Clear (); - Control = new swf.DataObject(); - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/ColorDialogHandler.cs b/Source/Eto.Platform.Windows/Forms/ColorDialogHandler.cs deleted file mode 100644 index 348275aa3a..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ColorDialogHandler.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using SWF = System.Windows.Forms; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows.Forms -{ - public class ColorDialogHandler : WidgetHandler, IColorDialog - { - static int[] customColors; - public ColorDialogHandler () - { - this.Control = new SWF.ColorDialog (); - this.Control.AnyColor = true; - this.Control.AllowFullOpen = true; - this.Control.FullOpen = true; - } - - public Color Color { - get { return Control.Color.ToEto (); } - set { Control.Color = value.ToSD (); } - } - - public DialogResult ShowDialog (Window parent) - { - SWF.DialogResult result; - if (customColors != null) Control.CustomColors = customColors; - - if (parent != null) - result = Control.ShowDialog(parent.GetContainerControl()); - else - result = Control.ShowDialog (); - - if (result == System.Windows.Forms.DialogResult.OK) { - Widget.OnColorChanged (EventArgs.Empty); - } - - customColors = Control.CustomColors; - - return result.ToEto (); - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/ButtonHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/ButtonHandler.cs deleted file mode 100644 index d0c6b33251..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/ButtonHandler.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - /// - /// Button handler. - /// - /// (c) 2012-2013 by Curtis Wensley - /// See LICENSE for full terms - public class ButtonHandler : WindowsControl, IButton - { - Image image; - readonly Size defaultSize; - - public class EtoButton : swf.Button - { - public override sd.Size GetPreferredSize (sd.Size proposedSize) - { - var size = base.GetPreferredSize (sd.Size.Empty); - // fix bug where text will wrap if it has both an image and text - if (AutoSize && Image != null) { - size.Width += 3; - } - return size; - } - } - - public override Size? DefaultSize - { - get { return defaultSize; } - } - - public ButtonHandler () - { - Control = new EtoButton - { - AutoSizeMode = swf.AutoSizeMode.GrowAndShrink, - TextImageRelation = swf.TextImageRelation.ImageBeforeText, - AutoSize = true - }; - Control.Click += delegate { - Widget.OnClick (EventArgs.Empty); - }; - defaultSize = Button.DefaultSize; - } - - public override string Text - { - get { return base.Text; } - set - { - base.Text = value; - SetAlign (); - } - } - - public Image Image - { - get { return image; } - set - { - image = value; - Control.Image = image.ToSD (); - } - } - - void SetAlign () - { - if (string.IsNullOrEmpty (base.Text)) { - if (Control.TextImageRelation == swf.TextImageRelation.ImageBeforeText) - Control.ImageAlign = sd.ContentAlignment.MiddleLeft; - else if (Control.TextImageRelation == swf.TextImageRelation.TextBeforeImage) - Control.ImageAlign = sd.ContentAlignment.MiddleRight; - else - Control.ImageAlign = sd.ContentAlignment.MiddleCenter; - } - else - Control.ImageAlign = sd.ContentAlignment.MiddleCenter; - } - - public ButtonImagePosition ImagePosition - { - get { return Control.TextImageRelation.ToEto (); } - set { - Control.TextImageRelation = value.ToSD (); - SetAlign (); - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/CheckBoxHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/CheckBoxHandler.cs deleted file mode 100644 index 73bb13edac..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/CheckBoxHandler.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using SWF = System.Windows.Forms; -using SD = System.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class CheckBoxHandler : WindowsControl, ICheckBox - { - - public CheckBoxHandler() - { - Control = new SWF.CheckBox(); - Control.AutoSize = true; - Control.CheckStateChanged += (sender, e) => Widget.OnCheckedChanged(EventArgs.Empty); - } - - public bool? Checked - { - get - { - switch (Control.CheckState) - { - case SWF.CheckState.Checked: - return true; - case SWF.CheckState.Unchecked: - return false; - default: - return null; - } - } - set - { - if (value == null) - Control.CheckState = SWF.CheckState.Indeterminate; - else if (value.Value) - Control.CheckState = SWF.CheckState.Checked; - else - Control.CheckState = SWF.CheckState.Unchecked; - } - } - - public bool ThreeState - { - get { return Control.ThreeState; } - set { Control.ThreeState = value; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/ComboBoxHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/ComboBoxHandler.cs deleted file mode 100644 index a687da5f0c..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/ComboBoxHandler.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using System.Collections.Generic; -using System.Linq; -using Eto.Drawing; - -namespace Eto.Platform.Windows -{ - public class ComboBoxHandler : WindowsControl, IComboBox - { - CollectionHandler collection; - - public class EtoComboBox : swf.ComboBox - { - public override sd.Size GetPreferredSize(sd.Size proposedSize) - { - var size = new sd.Size(16, 20); - var font = Font; - - using (var graphics = CreateGraphics()) - { - foreach (object item in Items) - { - var text = GetItemText(item); - var itemSize = graphics.MeasureString(text, font).ToEtoSize(); - // for drop down glyph and border - size.Width = Math.Max(size.Width, itemSize.Width); - size.Height = Math.Max(size.Height, itemSize.Height); - } - } - size.Width += 18; - size.Height += 4; - return size; - } - } - - public ComboBoxHandler() - { - Control = new EtoComboBox - { - DropDownStyle = swf.ComboBoxStyle.DropDownList, - ValueMember = "Key", - DisplayMember = "Text", - AutoSize = true, - Size = new sd.Size(20, 0) - }; - Control.SelectedIndexChanged += delegate - { - Widget.OnSelectedIndexChanged(EventArgs.Empty); - }; - } - - public override Size GetPreferredSize(Size availableSize) - { - if (Control.AutoSize) - return Control.GetPreferredSize(sd.Size.Empty).ToEto(); - return base.GetPreferredSize(availableSize); - } - - public int SelectedIndex - { - get { return Control.SelectedIndex; } - set { Control.SelectedIndex = value; } - } - - class CollectionHandler : DataStoreChangedHandler - { - public ComboBoxHandler Handler { get; set; } - - public override int IndexOf(IListItem item) - { - return Handler.Control.Items.IndexOf(item); - } - - public override void AddRange(IEnumerable items) - { - Handler.Control.Items.AddRange(items.ToArray()); - Handler.UpdateSizes(); - } - - public override void AddItem(IListItem item) - { - Handler.Control.Items.Add(item); - Handler.UpdateSizes(); - } - - public override void InsertItem(int index, IListItem item) - { - Handler.Control.Items.Insert(index, item); - Handler.UpdateSizes(); - } - - public override void RemoveItem(int index) - { - Handler.Control.Items.RemoveAt(index); - Handler.UpdateSizes(); - } - - public override void RemoveAllItems() - { - Handler.Control.Items.Clear(); - Handler.UpdateSizes(); - } - } - - protected void UpdateSizes() - { - SetMinimumSize(); - } - - public IListStore DataStore - { - get { return collection != null ? collection.Collection : null; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler { Handler = this }; - collection.Register(value); - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/DateTimePickerHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/DateTimePickerHandler.cs deleted file mode 100644 index 1d2172cb02..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/DateTimePickerHandler.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using Eto.Forms; -using System.Globalization; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class DateTimePickerHandler : WindowsControl, IDateTimePicker - { - public DateTimePickerHandler() - { - Control = new System.Windows.Forms.DateTimePicker(); - Control.ShowCheckBox = true; - Mode = DateTimePicker.DefaultMode; - Value = null; - Control.ValueChanged += delegate - { - Widget.OnValueChanged(EventArgs.Empty); - }; - } - - public DateTimePickerMode Mode - { - get - { - switch (Control.Format) - { - case System.Windows.Forms.DateTimePickerFormat.Long: - return DateTimePickerMode.DateTime; - case System.Windows.Forms.DateTimePickerFormat.Short: - return DateTimePickerMode.Date; - case System.Windows.Forms.DateTimePickerFormat.Time: - return DateTimePickerMode.Time; - default: - throw new NotImplementedException(); - } - } - set - { - switch (value) - { - case DateTimePickerMode.DateTime: - Control.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - var format = CultureInfo.CurrentUICulture.DateTimeFormat; - Control.CustomFormat = format.ShortDatePattern + " " + format.LongTimePattern; - break; - case DateTimePickerMode.Date: - Control.Format = System.Windows.Forms.DateTimePickerFormat.Short; - break; - case DateTimePickerMode.Time: - Control.Format = System.Windows.Forms.DateTimePickerFormat.Time; - break; - default: - throw new NotImplementedException(); - } - } - } - - public DateTime MinDate - { - get - { - return Control.MinDate; - } - set - { - Control.MinDate = value; - } - } - - public DateTime MaxDate - { - get - { - return Control.MaxDate; - } - set - { - Control.MaxDate = value; - } - } - - public DateTime? Value - { - get - { - return !Control.Checked ? null : (DateTime?)Control.Value; - } - set - { - if (value != null) - { - var date = value.Value; - if (date < MinDate) date = MinDate; - if (date > MaxDate) date = MaxDate; - Control.Value = date; - Control.Checked = true; - } - else - Control.Checked = false; - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/DrawableHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/DrawableHandler.cs deleted file mode 100644 index 165c3863a0..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/DrawableHandler.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Drawing; -using Eto.Forms; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows -{ - public class DrawableHandler : WindowsPanel, IDrawable - { - public virtual bool SupportsCreateGraphics { get { return true; } } - - public class EtoDrawable : swf.Control - { - bool canFocus; - - public DrawableHandler Handler { get; set; } - - public EtoDrawable () - { - this.SetStyle (swf.ControlStyles.AllPaintingInWmPaint, true); - this.SetStyle (swf.ControlStyles.StandardClick, true); - this.SetStyle (swf.ControlStyles.StandardDoubleClick, true); - this.SetStyle (swf.ControlStyles.ContainerControl, true); - this.SetStyle (swf.ControlStyles.UserPaint, true); - this.SetStyle (swf.ControlStyles.DoubleBuffer, true); - this.SetStyle (swf.ControlStyles.ResizeRedraw, true); - this.SetStyle (swf.ControlStyles.SupportsTransparentBackColor, true); - } - - public new void SetStyle(swf.ControlStyles flag, bool value) - { - base.SetStyle(flag, value); - } - - public bool CanFocusMe - { - get { return canFocus; } - set { canFocus = value; SetStyle(swf.ControlStyles.Selectable, value); } - } - - protected override void OnGotFocus (EventArgs e) - { - base.OnGotFocus (e); - Invalidate (); - } - - protected override void OnLostFocus (EventArgs e) - { - base.OnLostFocus (e); - Invalidate (); - } - - protected override bool ProcessDialogKey (swf.Keys keyData) - { - var e = new swf.KeyEventArgs (keyData); - OnKeyDown(e); - if (!e.Handled) { - // Prevent firing the keydown event twice for the same key - Handler.LastKeyDown = e.KeyData.ToEto (); - } - return e.Handled; - } - - protected override bool IsInputKey (swf.Keys keyData) - { - switch (keyData) { - case swf.Keys.Up: - case swf.Keys.Down: - case swf.Keys.Left: - case swf.Keys.Right: - case swf.Keys.Back: - return true; - default: - return base.IsInputKey (keyData); - } - } - - protected override void OnPaint (swf.PaintEventArgs e) - { - base.OnPaint (e); - - Handler.OnPaint(e); - } - - protected override void OnClick (EventArgs e) - { - base.OnClick (e); - if (CanFocusMe) Focus (); - } - } - - public DrawableHandler() - { - } - - /// - /// This is to allow instantiating a DrawableHandler - /// from an existing control. - /// - public DrawableHandler(EtoDrawable control) - { - Control = control; - Control.Handler = this; - Control.TabStop = true; - } - - public void Create () - { - Control = new EtoDrawable { Handler = this }; - Control.TabStop = true; - } - - public virtual Graphics CreateGraphics() - { - return new Graphics(Widget.Generator, new GraphicsHandler(Control.CreateGraphics())); - } - - public bool CanFocus { - get { return Control.CanFocusMe; } - set { Control.CanFocusMe = value; } - } - - public virtual void Update(Rectangle rect) - { - using (var g = Control.CreateGraphics ()) { - var graphics = new Graphics (Widget.Generator, new GraphicsHandler (g)); - - Widget.OnPaint (new PaintEventArgs (graphics, rect)); - } - } - - protected virtual void OnPaint(swf.PaintEventArgs e) - { - Widget.OnPaint(e.ToEto(Widget.Generator)); - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/GridColumnHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/GridColumnHandler.cs deleted file mode 100644 index 3284df97af..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/GridColumnHandler.cs +++ /dev/null @@ -1,120 +0,0 @@ -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Controls -{ - - public class GridColumnHandler : WidgetHandler, IGridColumn, ICellConfigHandler - { - Cell dataCell; - bool autosize; - - public IGridHandler GridHandler { get; private set; } - - public GridColumnHandler () - { - Control = new swf.DataGridViewColumn(); - } - - protected override void Initialize () - { - base.Initialize (); - DataCell = new TextBoxCell(Widget.Generator); - Editable = false; - AutoSize = true; - Resizable = true; - } - - public string HeaderText { - get { return Control.HeaderText; } - set { Control.HeaderText = value; } - } - - public bool Resizable { - get { return Control.Resizable == swf.DataGridViewTriState.True; } - set { Control.Resizable = value ? swf.DataGridViewTriState.True : swf.DataGridViewTriState.False; } - } - - public bool Sortable { - get { return Control.SortMode == swf.DataGridViewColumnSortMode.Programmatic; } - set { Control.SortMode = (value) ? swf.DataGridViewColumnSortMode.Programmatic : swf.DataGridViewColumnSortMode.NotSortable; } - } - - public bool AutoSize { - get { return autosize; } - set { - autosize = value; - Control.AutoSizeMode = (value) ? swf.DataGridViewAutoSizeColumnMode.NotSet : swf.DataGridViewAutoSizeColumnMode.None; - } - } - - public int Width { - get { return Control.Width; } - set { Control.Width = value; } - } - - public Cell DataCell { - get { return dataCell; } - set { - dataCell = value; - if (dataCell != null) { - var cellHandler = (ICellHandler)dataCell.Handler; - cellHandler.CellConfig = this; - Control.CellTemplate = cellHandler.Control; - } - else - Control.CellTemplate = null; - } - } - - public bool Editable { - get { return !Control.ReadOnly; } - set { Control.ReadOnly = !value; } - } - - public bool Visible { - get { return Control.Visible; } - set { Control.Visible = value; } - } - - public void SetCellValue (object dataItem, object value) - { - if (dataCell != null) { - var cellHandler = (ICellHandler)dataCell.Handler; - cellHandler.SetCellValue (dataItem, value); - } - } - - public object GetCellValue (object dataItem) - { - if (dataCell != null) { - var cellHandler = ((ICellHandler)dataCell.Handler); - return cellHandler.GetCellValue (dataItem); - } - return null; - } - - public virtual void Setup (IGridHandler gridHandler) - { - GridHandler = gridHandler; - } - - public void Paint (sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts) - { - if (GridHandler != null) - GridHandler.Paint (this, graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); - } - - public int GetRowOffset (int rowIndex) - { - return GridHandler != null ? GridHandler.GetRowOffset(this, rowIndex) : 0; - } - - public bool MouseClick (swf.MouseEventArgs e, int rowIndex) - { - return GridHandler != null && GridHandler.CellMouseClick(this, e, rowIndex); - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/GridHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/GridHandler.cs deleted file mode 100644 index ec17797994..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/GridHandler.cs +++ /dev/null @@ -1,296 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using Eto.Forms; -using System.Linq; -using System.Collections.Generic; -using sd = System.Drawing; -using Eto.Drawing; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public interface IGridHandler - { - void Paint (GridColumnHandler column, sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts); - int GetRowOffset (GridColumnHandler column, int rowIndex); - bool CellMouseClick (GridColumnHandler column, swf.MouseEventArgs e, int rowIndex); - } - - public abstract class GridHandler : WindowsControl, IGrid, IGridHandler - where TWidget: Grid - { - ColumnCollection columns; - - protected abstract object GetItemAtRow (int row); - - class EtoDataGridView : swf.DataGridView - { - public GridHandler Handler { get; set; } - public override sd.Size GetPreferredSize(sd.Size proposedSize) - { - var size = base.GetPreferredSize(proposedSize); - var def = Handler.UserDesiredSize; - if (def.Width >= 0) - size.Width = def.Width; - if (def.Height >= 0) - size.Height = def.Height; - else - size.Height = Math.Min(size.Height, 100); - return size; - } - } - - protected GridHandler() - { - Control = new EtoDataGridView { - Handler = this, - VirtualMode = true, - MultiSelect = false, - SelectionMode = swf.DataGridViewSelectionMode.FullRowSelect, - RowHeadersVisible = false, - AllowUserToAddRows = false, - AllowUserToResizeRows = false, - AutoSize = true, - AutoSizeColumnsMode = swf.DataGridViewAutoSizeColumnsMode.DisplayedCells, - ColumnHeadersHeightSizeMode = swf.DataGridViewColumnHeadersHeightSizeMode.DisableResizing - }; - Control.CellValueNeeded += (sender, e) => { - var item = GetItemAtRow(e.RowIndex); - if (Widget.Columns.Count > e.ColumnIndex) - { - var col = Widget.Columns[e.ColumnIndex].Handler as GridColumnHandler; - if (item != null && col != null) - e.Value = col.GetCellValue(item); - } - }; - - Control.CellValuePushed += (sender, e) => { - var item = GetItemAtRow(e.RowIndex); - if (Widget.Columns.Count > e.ColumnIndex) - { - var col = Widget.Columns[e.ColumnIndex].Handler as GridColumnHandler; - if (item != null && col != null) - col.SetCellValue(item, e.Value); - } - }; - Control.RowPostPaint += HandleRowPostPaint; - - // The DataGridView automatically selects the first row, which - // is problematic and also not consistent across platforms. - // So we always get rid of the first selection. - var isFirstSelection = true; - Control.SelectionChanged += (s, e) => { - if (isFirstSelection) - Control.ClearSelection(); - isFirstSelection = false; - }; - } - - /// - /// Unlike other controls, DataGridView's background color is implemented - /// via the BackgroundColor property, not the BackColor property. - /// - public override Color BackgroundColor - { - get { return Control.BackgroundColor.ToEto(); } - set { Control.BackgroundColor = value.ToSD(); } - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - LeakHelper.UnhookObject(Control); - } - - bool handledAutoSize; - void HandleRowPostPaint (object sender, swf.DataGridViewRowPostPaintEventArgs e) - { - if (handledAutoSize) return; - - handledAutoSize = true; - int colNum = 0; - foreach (var col in Widget.Columns) { - var colHandler = col.Handler as GridColumnHandler; - if (col.AutoSize) { - Control.AutoResizeColumn (colNum, colHandler.Control.InheritedAutoSizeMode); - var width = col.Width; - colHandler.Control.AutoSizeMode = swf.DataGridViewAutoSizeColumnMode.None; - col.Width = width; - } - colNum++; - } - } - - class FormattingArgs : GridCellFormatEventArgs - { - public swf.DataGridViewCellFormattingEventArgs Args { get; private set; } - - public FormattingArgs (swf.DataGridViewCellFormattingEventArgs args, GridColumn column, object item, int row) - : base(column, item, row) - { - this.Args = args; - } - - Font font; - public override Font Font - { - get { - return font ?? (font = new Font (Column.Generator, new FontHandler (Args.CellStyle.Font))); - } - set { - font = value; - Args.CellStyle.Font = font.ToSD(); - } - } - - public override Color BackgroundColor { - get { return Args.CellStyle.BackColor.ToEto (); } - set { Args.CellStyle.BackColor = value.ToSD (); } - } - - public override Color ForegroundColor { - get { return Args.CellStyle.ForeColor.ToEto (); } - set { Args.CellStyle.ForeColor = value.ToSD (); } - } - } - - public override void AttachEvent (string id) - { - switch (id) { - case Grid.ColumnHeaderClickEvent: - Control.ColumnHeaderMouseClick += (sender, e) => Widget.OnColumnHeaderClick(new GridColumnEventArgs(Widget.Columns[e.ColumnIndex])); - break; - case Grid.CellEditingEvent: - Control.CellBeginEdit += (sender, e) => { - var item = GetItemAtRow (e.RowIndex); - var column = Widget.Columns [e.ColumnIndex]; - Widget.OnCellEditing (new GridViewCellArgs (column, e.RowIndex, e.ColumnIndex, item)); - }; - break; - case Grid.CellEditedEvent: - Control.CellEndEdit += (sender, e) => { - var item = GetItemAtRow (e.RowIndex); - var column = Widget.Columns [e.ColumnIndex]; - Widget.OnCellEdited (new GridViewCellArgs (column, e.RowIndex, e.ColumnIndex, item)); - }; - break; - case Grid.SelectionChangedEvent: - Control.SelectionChanged += delegate { - Widget.OnSelectionChanged (EventArgs.Empty); - }; - break; - case Grid.CellFormattingEvent: - Control.CellFormatting += (sender, e) => { - var column = Widget.Columns[e.ColumnIndex]; - var item = GetItemAtRow (e.RowIndex); - Widget.OnCellFormatting (new FormattingArgs(e, column, item, e.RowIndex)); - }; - break; - default: - base.AttachEvent (id); - break; - } - } - - protected override void Initialize () - { - base.Initialize (); - columns = new ColumnCollection { Handler = this }; - columns.Register (Widget.Columns); - } - - class ColumnCollection : EnumerableChangedHandler - { - public GridHandler Handler { get; set; } - - public override void AddItem (GridColumn item) - { - var colhandler = (GridColumnHandler)item.Handler; - colhandler.Setup (Handler); - Handler.Control.Columns.Add (colhandler.Control); - } - - public override void InsertItem (int index, GridColumn item) - { - var colhandler = (GridColumnHandler)item.Handler; - colhandler.Setup (Handler); - Handler.Control.Columns.Insert (index, colhandler.Control); - } - - public override void RemoveItem (int index) - { - Handler.Control.Columns.RemoveAt (index); - } - - public override void RemoveAllItems () - { - Handler.Control.Columns.Clear (); - } - } - - public bool ShowHeader { - get { return Control.ColumnHeadersVisible; } - set { Control.ColumnHeadersVisible = value; } - } - - public bool AllowColumnReordering { - get { return Control.AllowUserToOrderColumns; } - set { Control.AllowUserToOrderColumns = value; } - } - - public bool AllowMultipleSelection { - get { return Control.MultiSelect; } - set { Control.MultiSelect = value; } - } - - public IEnumerable SelectedRows { - get { return Control.SelectedRows.OfType ().Select (r => r.Index); } - } - - public int RowHeight - { - get { return Control.RowTemplate.Height; } - set { - Control.RowTemplate.Height = value; - foreach (swf.DataGridViewRow row in Control.Rows) { - row.Height = value; - } - } - } - - public void SelectAll () - { - Control.SelectAll (); - } - - public void SelectRow (int row) - { - Control.Rows [row].Selected = true; - } - - public void UnselectRow (int row) - { - Control.Rows [row].Selected = false; - } - - public void UnselectAll () - { - Control.ClearSelection (); - } - - public virtual void Paint (GridColumnHandler column, System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts) - { - } - - public virtual int GetRowOffset (GridColumnHandler column, int rowIndex) - { - return 0; - } - - public virtual bool CellMouseClick (GridColumnHandler column, swf.MouseEventArgs e, int rowIndex) - { - return false; - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/GridViewHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/GridViewHandler.cs deleted file mode 100644 index 0404efb5bd..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/GridViewHandler.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class GridViewHandler : GridHandler, IGridView - { - CollectionHandler collection; - - public bool ShowCellBorders - { - get { return Control.CellBorderStyle != swf.DataGridViewCellBorderStyle.None; } - set { Control.CellBorderStyle = value ? swf.DataGridViewCellBorderStyle.Single : swf.DataGridViewCellBorderStyle.None; } - } - - protected override object GetItemAtRow (int row) - { - if (collection != null && collection.Collection != null && collection.Collection.Count > row) - return collection.Collection[row]; - return null; - } - - public override void AttachEvent(string id) - { - switch (id) { - case GridView.CellClickEvent: - Control.CellClick += (sender, e) => { - var item = GetItemAtRow (e.RowIndex); - var column = Widget.Columns [e.ColumnIndex]; - Widget.OnCellClick (new GridViewCellArgs (column, e.RowIndex, e.ColumnIndex, item)); - }; - break; - default: - base.AttachEvent(id); - break; - } - } - - class CollectionHandler : DataStoreChangedHandler - { - public GridViewHandler Handler { get; set; } - - public override void AddRange (IEnumerable items) - { - Handler.SetRowCount(); - } - - public override void AddItem (object item) - { - Handler.IncrementRowCountBy(1); - } - - public override void InsertItem (int index, object item) - { - Handler.IncrementRowCountBy(1); - } - - public override void InsertRange(int index, IEnumerable items) - { - Handler.SetRowCount(); - } - - public override void RemoveItem (int index) - { - Handler.IncrementRowCountBy(-1); - } - - public override void RemoveRange(int index, int count) - { - Handler.SetRowCount(); - } - - public override void RemoveRange(IEnumerable items) - { - Handler.SetRowCount(); - } - - public override void RemoveAllItems () - { - Handler.SetRowCount(); - } - } - - void SetRowCount() - { - Control.RowCount = collection.Collection != null ? collection.Collection.Count : 0; - Control.Refresh(); // Need to refresh rather than invalidate owing to WinForms DataGridView bugs. - } - - void IncrementRowCountBy(int increment) - { - Control.RowCount += increment; - Control.Refresh(); // Need to refresh rather than invalidate owing to WinForms DataGridView bugs. - } - - public IDataStore DataStore { - get { return collection != null ? collection.Collection : null; } - set { - if (collection != null) - collection.Unregister (); - collection = new CollectionHandler { Handler = this }; - collection.Register (value); - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/GroupBoxHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/GroupBoxHandler.cs deleted file mode 100644 index 595e7d8513..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/GroupBoxHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows -{ - public class GroupBoxHandler : WindowsPanel, IGroupBox - { - readonly swf.Panel content; - - public GroupBoxHandler() - { - Control = new swf.GroupBox - { - AutoSize = true, - AutoSizeMode = swf.AutoSizeMode.GrowAndShrink - }; - content = new swf.Panel - { - Font = sd.SystemFonts.DefaultFont, - Dock = swf.DockStyle.Fill, - AutoSize = true, - AutoSizeMode = swf.AutoSizeMode.GrowAndShrink - }; - Control.Controls.Add(content); - } - - - protected override Size ContentPadding - { - get { return Size.Max(Size.Empty, Control.Size.ToEto() - Control.DisplayRectangle.Size.ToEto()); } - } - - public override swf.Control ContainerContentControl - { - get { return content; } - } - - public override string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/ImageViewHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/ImageViewHandler.cs deleted file mode 100644 index 7f44ff4ba7..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/ImageViewHandler.cs +++ /dev/null @@ -1,59 +0,0 @@ -using SWF = System.Windows.Forms; -using SD = System.Drawing; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows.Forms -{ - public class ImageViewHandler : WindowsControl, IImageView - { - Image image; - bool sizeSet; - - public ImageViewHandler () - { - Control = new SWF.PictureBox { - BorderStyle = SWF.BorderStyle.None, - SizeMode = SWF.PictureBoxSizeMode.Zoom - }; - } - - public override Size Size - { - get - { - return base.Size; - } - set - { - base.Size = value; - sizeSet = true; - SetImage (); - } - } - void SetImage () - { - if (image != null) { - var handler = image.Handler as IWindowsImageSource; - Control.Image = handler != null ? handler.GetImageWithSize(null) : null; - } - else - Control.Image = null; - - if (!sizeSet && Control.Image != null) - Control.Size = Control.Image.Size; - } - - public Image Image { - get { - return image; - } - set { - image = value; - SetImage (); - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/LabelHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/LabelHandler.cs deleted file mode 100644 index dc801da6de..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/LabelHandler.cs +++ /dev/null @@ -1,253 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows -{ - public class LabelHandler : WindowsControl, ILabel - { - public class MyLabel : swf.Label - { - readonly sd.StringFormat stringFormat; - WrapMode wrapMode; - HorizontalAlign horizontalAlign; - sd.SizeF? measuredSize; - sd.Size proposedSizeCache; - VerticalAlign verticalAlign; - - public override sd.Font Font - { - get { return base.Font; } - set - { - measuredSize = null; - base.Font = value; - } - } - - public override string Text - { - get { return base.Text; } - set - { - measuredSize = null; - base.Text = value; - } - } - - public WrapMode Wrap - { - get { return wrapMode; } - set - { - wrapMode = value; - SetStringFormat(); - measuredSize = null; - } - } - - public HorizontalAlign HorizontalAlign - { - get { return horizontalAlign; } - set - { - horizontalAlign = value; - SetStringFormat(); - measuredSize = null; - } - } - - public VerticalAlign VerticalAlign - { - get { return verticalAlign; } - set - { - verticalAlign = value; - measuredSize = null; - } - } - - public MyLabel() - { - stringFormat = new sd.StringFormat(); - Wrap = WrapMode.Word; - } - - static readonly sd.Graphics graphics = sd.Graphics.FromHwnd(IntPtr.Zero); - - public override sd.Size GetPreferredSize(sd.Size proposedSize) - { - var bordersAndPadding = Margin.Size; // this.SizeFromClientSize (SD.Size.Empty); - if (measuredSize == null || proposedSizeCache != proposedSize) - { - proposedSize -= bordersAndPadding; - proposedSize.Height = Math.Max(0, proposedSize.Height); - if (proposedSize.Width <= 1) - proposedSize.Width = int.MaxValue; - measuredSize = graphics.MeasureString(Text, Font, proposedSize.Width, stringFormat); - proposedSizeCache = proposedSize; - } - var size = measuredSize.Value; - size += bordersAndPadding; - if (size.Width < MinimumSize.Width) - size.Width = MinimumSize.Width; - if (size.Height < MinimumSize.Height) - size.Height = MinimumSize.Height; - return sd.Size.Ceiling(size); - } - - void SetStringFormat() - { - stringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; - switch (Wrap) - { - case WrapMode.None: - stringFormat.Trimming = System.Drawing.StringTrimming.None; - stringFormat.FormatFlags = System.Drawing.StringFormatFlags.NoWrap; - break; - case WrapMode.Word: - stringFormat.Trimming = System.Drawing.StringTrimming.Word; - stringFormat.FormatFlags = 0; - break; - case WrapMode.Character: - stringFormat.Trimming = System.Drawing.StringTrimming.Character; - stringFormat.FormatFlags = System.Drawing.StringFormatFlags.NoWrap; - break; - } - switch (HorizontalAlign) - { - case HorizontalAlign.Right: - stringFormat.Alignment = System.Drawing.StringAlignment.Far; - break; - case HorizontalAlign.Center: - stringFormat.Alignment = System.Drawing.StringAlignment.Center; - break; - } - - } - - protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) - { - using (var b = new sd.SolidBrush(ForeColor)) - { - if (Wrap == WrapMode.Character) - { - // draw string one line at a time to trim to character.. - int charactersFitted, linesFilled; - string text = Text; - sd.PointF drawPoint = sd.PointF.Empty; - var font = Font; - var height = font.GetHeight(e.Graphics); - while (!string.IsNullOrEmpty(text)) - { - e.Graphics.MeasureString(text, font, Bounds.Size, stringFormat, out charactersFitted, out linesFilled); - - e.Graphics.DrawString(text.Substring(0, charactersFitted), font, b, drawPoint, stringFormat); - - if (charactersFitted >= text.Length) break; - text = text.Substring(charactersFitted); - - drawPoint.Y += height; - } - } - else - { - var rect = new sd.RectangleF(Margin.Left, Margin.Top, Bounds.Width - Margin.Horizontal, Bounds.Height - Margin.Vertical); - var size = e.Graphics.MeasureString(Text, Font, (int)rect.Width, stringFormat); - - if (size.Height < rect.Height) - { - switch (VerticalAlign) - { - case Eto.Forms.VerticalAlign.Bottom: - rect.Y += rect.Height - size.Height; - rect.Height = size.Height; - break; - case Eto.Forms.VerticalAlign.Middle: - rect.Y += (rect.Height - size.Height) / 2; - rect.Height = size.Height; - break; - } - } - - if (size.Width < rect.Width) - { - switch (HorizontalAlign) - { - case HorizontalAlign.Right: - rect.X = rect.Width - size.Width - Margin.Top; - rect.Width = size.Width; - break; - case HorizontalAlign.Center: - rect.X = (rect.Width - size.Width) / 2 - Margin.Top; - rect.Width = size.Width; - break; - } - } - - e.Graphics.DrawString(Text, Font, b, rect, stringFormat); - } - } - } - } - - public LabelHandler() - { - Control = new MyLabel - { - AutoSize = true - }; - } - - public Color TextColor - { - get { return Control.ForeColor.ToEto(); } - set { Control.ForeColor = value.ToSD(); } - } - - public HorizontalAlign HorizontalAlign - { - get { return Control.HorizontalAlign; } - set - { - if (Control.HorizontalAlign != value) - { - Control.HorizontalAlign = value; - Control.Invalidate(); - } - /*if (Control.Dock != SWF.DockStyle.None) { - Control.Dock = DockStyle; - }*/ - } - } - - public WrapMode Wrap - { - get { return Control.Wrap; } - set - { - if (value != Control.Wrap) - { - Control.Wrap = value; - Control.Invalidate(); - } - } - } - - public VerticalAlign VerticalAlign - { - get { return Control.VerticalAlign; } - set - { - if (Control.VerticalAlign != value) - { - Control.VerticalAlign = value; - Control.Invalidate(); - } - } - } - - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/ListBoxHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/ListBoxHandler.cs deleted file mode 100644 index b97c2b32a5..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/ListBoxHandler.cs +++ /dev/null @@ -1,165 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using System.Collections.Generic; -using System.Linq; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows -{ - public class ListBoxHandler : WindowsControl, IListBox - { - CollectionHandler collection; - - class MyListBox : swf.ListBox - { - public MyListBox() - { - DrawMode = swf.DrawMode.OwnerDrawFixed; - SetStyle(swf.ControlStyles.UserPaint | swf.ControlStyles.OptimizedDoubleBuffer | swf.ControlStyles.EnableNotifyMessage | swf.ControlStyles.ResizeRedraw, true); - ResizeRedraw = false; - ItemHeight = 18; - } - - public override sd.Font Font - { - get { return base.Font; } - set - { - base.Font = value; - ItemHeight = value.Height; - } - } - - protected override void OnPaint(swf.PaintEventArgs e) - { - using (var backBrush = new sd.SolidBrush(BackColor)) - { - e.Graphics.FillRectangle(backBrush, e.ClipRectangle); - } - for (int i = 0; i < Items.Count; ++i) - { - var itemRect = GetItemRectangle(i); - if (e.ClipRectangle.IntersectsWith(itemRect)) - { - var state = swf.DrawItemState.Default; - if ((SelectionMode == swf.SelectionMode.One && SelectedIndex == i) - || (SelectionMode == swf.SelectionMode.MultiSimple && SelectedIndices.Contains(i)) - || (SelectionMode == swf.SelectionMode.MultiExtended && SelectedIndices.Contains(i))) - { - state = swf.DrawItemState.Selected; - } - OnDrawItem(new swf.DrawItemEventArgs(e.Graphics, Font, itemRect, i, state, ForeColor, BackColor)); - } - } - } - - protected override void OnDrawItem(swf.DrawItemEventArgs e) - { - e.DrawBackground(); - e.DrawFocusRectangle(); - - if (e.Index == -1) - return; - using (var foreBrush = new sd.SolidBrush(ForeColor)) - { - var bounds = e.Bounds; - var item = (IListItem)Items[e.Index]; - var imageitem = item as IImageListItem; - if (imageitem != null && imageitem.Image != null) - { - var img = imageitem.Image.Handler as IWindowsImageSource; - if (img != null) - e.Graphics.DrawImage(img.GetImageWithSize(bounds.Height), bounds.Left, bounds.Top, bounds.Height, bounds.Height); - bounds.X += bounds.Height + 2; - } - var stringSize = e.Graphics.MeasureString(item.Text, e.Font); - var adjust = Math.Max(0, (bounds.Height - stringSize.Height) / 2); - e.Graphics.DrawString(item.Text, e.Font, foreBrush, bounds.Left, bounds.Top + adjust); - } - } - } - - public ListBoxHandler() - { - Control = new MyListBox(); - Control.SelectedIndexChanged += control_SelectedIndexChanged; - Control.IntegralHeight = false; - Control.DoubleClick += control_DoubleClick; - Control.KeyDown += control_KeyDown; - } - - public int SelectedIndex - { - get { return Control.SelectedIndex; } - set { Control.SelectedIndex = value; } - } - - void control_SelectedIndexChanged(object sender, EventArgs e) - { - Widget.OnSelectedIndexChanged(e); - } - - void control_DoubleClick(object sender, EventArgs e) - { - Widget.OnActivated(EventArgs.Empty); - } - - void control_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) - { - if (e.KeyData == swf.Keys.Return) - { - Widget.OnActivated(EventArgs.Empty); - e.Handled = true; - } - } - - class CollectionHandler : DataStoreChangedHandler - { - public ListBoxHandler Handler { get; set; } - - public override int IndexOf(IListItem item) - { - return Handler.Control.Items.IndexOf(item); - } - - public override void AddRange(IEnumerable items) - { - Handler.Control.Items.AddRange(items.ToArray()); - } - - public override void AddItem(IListItem item) - { - Handler.Control.Items.Add(item); - } - - public override void InsertItem(int index, IListItem item) - { - Handler.Control.Items.Insert(index, item); - } - - public override void RemoveItem(int index) - { - Handler.Control.Items.RemoveAt(index); - } - - public override void RemoveAllItems() - { - Handler.Control.Items.Clear(); - } - } - - public IListStore DataStore - { - get { return collection != null ? collection.Collection : null; } - set - { - if (collection != null) - collection.Unregister(); - collection = new CollectionHandler { Handler = this }; - collection.Register(value); - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/NumericUpDownHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/NumericUpDownHandler.cs deleted file mode 100644 index 8e3c6a4709..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/NumericUpDownHandler.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using SD = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class NumericUpDownHandler : WindowsControl, INumericUpDown - { - public NumericUpDownHandler() - { - Control = new swf.NumericUpDown - { - Maximum = 100, - Minimum = 0, - Width = 80 - }; - Control.ValueChanged += delegate - { - Widget.OnValueChanged(EventArgs.Empty); - }; - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - LeakHelper.UnhookObject(Control); - } - - public bool ReadOnly - { - get { return Control.ReadOnly; } - set { Control.ReadOnly = value; } - } - - public double Value - { - get { return (double)Control.Value; } - set { Control.Value = (decimal)value; } - } - - public double MinValue - { - get { return (double)Control.Minimum; } - set { Control.Minimum = (decimal)value; } - } - - public double MaxValue - { - get { return (double)Control.Maximum; } - set { Control.Maximum = (decimal)value; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/PanelHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/PanelHandler.cs deleted file mode 100644 index 1232aef95c..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/PanelHandler.cs +++ /dev/null @@ -1,39 +0,0 @@ -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class PanelHandler : WindowsPanel, IPanel - { - public class EtoPanel : swf.Panel - { - // Need to override IsInputKey to capture - // the arrow keys. - protected override bool IsInputKey (swf.Keys keyData) - { - switch (keyData & swf.Keys.KeyCode) { - case swf.Keys.Up: - case swf.Keys.Down: - case swf.Keys.Left: - case swf.Keys.Right: - case swf.Keys.Back: - return true; - default: - return base.IsInputKey (keyData); - } - } - } - - public PanelHandler () - { - Control = new EtoPanel - { - Size = sd.Size.Empty, - MinimumSize = sd.Size.Empty, - AutoSize = true, - AutoSizeMode = swf.AutoSizeMode.GrowAndShrink - }; - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/PasswordBoxHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/PasswordBoxHandler.cs deleted file mode 100644 index cb6b23fd74..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/PasswordBoxHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using SD = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class PasswordBoxHandler : WindowsControl, IPasswordBox - { - public PasswordBoxHandler() - { - Control = new swf.TextBox(); - Control.UseSystemPasswordChar = true; - } - - public bool ReadOnly - { - get { return Control.ReadOnly; } - set { Control.ReadOnly = value; } - } - - public int MaxLength - { - get { return Control.MaxLength; } - set { Control.MaxLength = value; } - } - - public char PasswordChar - { - get { return Control.PasswordChar; } - set - { - if (value == '\0') - Control.UseSystemPasswordChar = true; - else - { - Control.UseSystemPasswordChar = false; - Control.PasswordChar = value; - } - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/ProgressBarHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/ProgressBarHandler.cs deleted file mode 100644 index 33a5528a14..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/ProgressBarHandler.cs +++ /dev/null @@ -1,44 +0,0 @@ -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class ProgressBarHandler : WindowsControl, IProgressBar - { - public ProgressBarHandler () - { - this.Control = new SWF.ProgressBar { - Maximum = 100, - Style = SWF.ProgressBarStyle.Blocks - }; - } - - static SWF.ProgressBarStyle IndeterminateStyle - { - get { return (SWF.Application.RenderWithVisualStyles) ? SWF.ProgressBarStyle.Marquee : SWF.ProgressBarStyle.Continuous; } - } - - public bool Indeterminate { - get { return Control.Style == SWF.ProgressBarStyle.Continuous || Control.Style == SWF.ProgressBarStyle.Marquee; } - set { - Control.Style = value ? IndeterminateStyle : SWF.ProgressBarStyle.Blocks; - } - } - - public int MaxValue { - get { return Control.Maximum; } - set { Control.Maximum = value; } - } - - public int MinValue { - get { return Control.Minimum; } - set { Control.Minimum = value; } - } - - public int Value { - get { return Control.Value; } - set { Control.Value = value; } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/RadioButton.cs b/Source/Eto.Platform.Windows/Forms/Controls/RadioButton.cs deleted file mode 100644 index 4473ab4fc0..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/RadioButton.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.Windows -{ - public class RadioButtonHandler : WindowsControl, IRadioButton - { - List group; - - public class EtoRadioButton : swf.RadioButton - { - public EtoRadioButton() - { - this.SetStyle(swf.ControlStyles.StandardClick | swf.ControlStyles.StandardDoubleClick, true); - } - } - - public RadioButtonHandler() - { - Control = new EtoRadioButton(); - Control.AutoSize = true; - Control.Click += delegate { - Widget.OnClick (EventArgs.Empty); - }; - Control.CheckedChanged += delegate { - Widget.OnCheckedChanged (EventArgs.Empty); - }; - } - - public void Create(RadioButton controller) - { - if (controller != null) - { - var controllerInner = (RadioButtonHandler)controller.Handler; - if (controllerInner.group == null) - { - controllerInner.group = new List(); - controllerInner.group.Add(controller); - controllerInner.Control.Click += controllerInner.control_RadioSwitch; - } - controllerInner.group.Add(Widget); - Control.Click += controllerInner.control_RadioSwitch; - } - } - - void control_RadioSwitch(object sender, EventArgs e) - { - if (group != null) - { - foreach (RadioButton item in group) - { - item.Checked = (item.ControlObject == sender); - } - } - } - - public bool Checked - { - get { return Control.Checked; } - set { Control.Checked = value; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/ScrollableHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/ScrollableHandler.cs deleted file mode 100644 index b22654de8a..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/ScrollableHandler.cs +++ /dev/null @@ -1,273 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class ScrollableHandler : WindowsPanel, IScrollable - { - readonly swf.Panel content; - bool expandWidth = true; - bool expandHeight = true; - bool finalLayoutPass; - - public class CustomScrollable : swf.Panel - { - public ScrollableHandler Handler { get; set; } - - protected override bool ProcessDialogKey(swf.Keys keyData) - { - var e = new swf.KeyEventArgs(keyData); - OnKeyDown(e); - if (!e.Handled) - { - // Prevent firing the keydown event twice for the same key - Handler.LastKeyDown = e.KeyData.ToEto(); - } - return e.Handled; - } - - protected override void OnCreateControl() - { - base.OnCreateControl(); - AutoSize = false; - } - - protected override sd.Point ScrollToControl(swf.Control activeControl) - { - return AutoScrollPosition; - } - - System.Drawing.Size lastClientSize; - protected override void OnLayout(swf.LayoutEventArgs levent) - { - var contentControl = Handler.Content.GetWindowsHandler(); - if (contentControl != null) - { - var minSize = new Size(); - - var clientSize = lastClientSize = ClientSize; - if (!Handler.finalLayoutPass) - { - var preferred = contentControl.GetPreferredSize(Eto.Drawing.Size.Empty); - if (Handler.ExpandContentWidth && preferred.Height > ClientSize.Height) - clientSize.Width -= swf.SystemInformation.VerticalScrollBarWidth; - if (Handler.ExpandContentHeight && preferred.Width > ClientSize.Width) - clientSize.Height -= swf.SystemInformation.HorizontalScrollBarHeight; - } - if (Handler.ExpandContentWidth) - minSize.Width = Math.Max(0, clientSize.Width); - if (Handler.ExpandContentHeight) - minSize.Height = Math.Max(0, clientSize.Height); - - // set minimum size for the content if we want to extend to the size of the scrollable width/height - contentControl.ParentMinimumSize = minSize; - } - base.OnLayout(levent); - } - - protected override void OnClientSizeChanged(EventArgs e) - { - base.OnClientSizeChanged(e); - // when scrollbar is shown/hidden, need to perform layout - if (ClientSize != lastClientSize) - PerformLayout(); - } - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - // ensure we don't show scrollbars unnecessarily: - // perform layout excluding both scrollbars so we don't show them unless necessary - Control.ResumeLayout(); - finalLayoutPass = true; - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - Control.SuspendLayout(); - finalLayoutPass = false; - } - - public override swf.Control ContainerContentControl - { - get { return content; } - } - - public override void SetScale(bool xscale, bool yscale) - { - base.SetScale(xscale, yscale); - if (Content != null) - Content.SetScale(!ExpandContentWidth, !ExpandContentHeight); - } - - protected override void SetContentScale(bool xscale, bool yscale) - { - base.SetContentScale(!ExpandContentWidth, !ExpandContentHeight); - } - - public override Size GetPreferredSize(Size availableSize) - { - var baseSize = UserDesiredSize; - var size = base.GetPreferredSize(availableSize); - // if we have set to a specific size, then try to use that - if (baseSize.Width >= 0) - size.Width = baseSize.Width; - if (baseSize.Height >= 0) - size.Height = baseSize.Height; - return size; - } - - public BorderType Border - { - get - { - switch (Control.BorderStyle) - { - case swf.BorderStyle.FixedSingle: - return BorderType.Line; - case swf.BorderStyle.None: - return BorderType.None; - case swf.BorderStyle.Fixed3D: - return BorderType.Bezel; - default: - throw new NotSupportedException(); - } - } - set - { - switch (value) - { - case BorderType.Bezel: - Control.BorderStyle = swf.BorderStyle.Fixed3D; - break; - case BorderType.Line: - Control.BorderStyle = swf.BorderStyle.FixedSingle; - break; - case BorderType.None: - Control.BorderStyle = swf.BorderStyle.None; - break; - default: - throw new NotSupportedException(); - } - } - } - - public ScrollableHandler() - { - Control = new CustomScrollable - { - Handler = this, - Size = sd.Size.Empty, - MinimumSize = sd.Size.Empty, - BorderStyle = swf.BorderStyle.Fixed3D, - AutoScroll = true, - AutoSize = true, - AutoSizeMode = swf.AutoSizeMode.GrowAndShrink - }; - Control.SuspendLayout(); - Control.VerticalScroll.SmallChange = 5; - Control.VerticalScroll.LargeChange = 10; - Control.HorizontalScroll.SmallChange = 5; - Control.HorizontalScroll.LargeChange = 10; - - content = new swf.Panel - { - Size = sd.Size.Empty, - AutoSize = true, - AutoSizeMode = swf.AutoSizeMode.GrowAndShrink - }; - Control.Controls.Add(content); - } - - protected override void SetContent(swf.Control contentControl) - { - content.Controls.Clear(); - content.Controls.Add(contentControl); - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Scrollable.ScrollEvent: - Control.Scroll += delegate { - Widget.OnScroll(new ScrollEventArgs(ScrollPosition)); - }; - break; - default: - base.AttachEvent(id); - break; - } - } - - public void UpdateScrollSizes() - { - Control.PerformLayout(); - } - - public Point ScrollPosition - { - get { return new Point(-Control.AutoScrollPosition.X, -Control.AutoScrollPosition.Y); } - set - { - Control.AutoScrollPosition = value.ToSD(); - } - } - - public Size ScrollSize - { - get { return Control.DisplayRectangle.Size.ToEto(); } - set { Control.AutoScrollMinSize = value.ToSD(); } - } - - public Rectangle VisibleRect - { - get { return new Rectangle(ScrollPosition, Size.Min(ScrollSize, ClientSize)); } - } - - public override Size ClientSize - { - get { return Control.ClientSize.ToEto(); } - set - { - Control.AutoSize = value.Width == -1 || value.Height == -1; - Control.ClientSize = value.ToSD(); - } - } - - public bool ExpandContentWidth - { - get { return expandWidth; } - set - { - if (expandWidth != value) - { - expandWidth = value; - SetScale(); - if (Widget.Loaded) - Control.PerformLayout(); - } - } - } - - public bool ExpandContentHeight - { - get { return expandHeight; } - set - { - if (expandHeight != value) - { - expandHeight = value; - SetScale(); - if (Widget.Loaded) - Control.PerformLayout(); - } - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/SearchBoxHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/SearchBoxHandler.cs deleted file mode 100644 index 7805fcd7ff..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/SearchBoxHandler.cs +++ /dev/null @@ -1,10 +0,0 @@ -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class SearchBoxHandler : TextBoxHandler, ISearchBox - { - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/SliderHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/SliderHandler.cs deleted file mode 100644 index d37ff6725f..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/SliderHandler.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class SliderHandler : WindowsControl, ISlider - { - int? lastValue; - - class EtoTrackBar : swf.TrackBar - { - protected override void OnCreateControl () - { - SetStyle (swf.ControlStyles.SupportsTransparentBackColor, true); - if (Parent != null) - BackColor = Parent.BackColor; - - base.OnCreateControl (); - } - } - - public SliderHandler () - { - this.Control = new EtoTrackBar { - TickStyle = System.Windows.Forms.TickStyle.BottomRight, - Maximum = 100, - AutoSize = true - }; - } - - public override void OnLoad(EventArgs e) - { - base.OnLoad(e); - Control.ValueChanged += HandleScaleValueChanged; - } - - void HandleScaleValueChanged(object sender, EventArgs e) - { - var value = Control.Value; - var tick = Control.TickFrequency; - var offset = value % tick; - if (SnapToTick && offset != 0) - { - if (offset > tick / 2) - Control.Value = value - offset + tick; - else - Control.Value -= offset; - } - else if (lastValue == null || lastValue.Value != value) - { - Widget.OnValueChanged(EventArgs.Empty); - lastValue = value; - } - } - - public int MaxValue { - get { return Control.Maximum; } - set { Control.Maximum = value; } - } - - public int MinValue { - get { return Control.Minimum; } - set { Control.Minimum = value; } - } - - public int Value { - get { return Control.Value; } - set { Control.Value = value; } - } - - public bool SnapToTick { get; set; } - - public int TickFrequency { - get { return Control.TickFrequency; } - set { - Control.TickFrequency = value; - } - } - - public SliderOrientation Orientation { - get { return Control.Orientation == swf.Orientation.Horizontal ? SliderOrientation.Horizontal : SliderOrientation.Vertical; } - set { Control.Orientation = value == SliderOrientation.Horizontal ? swf.Orientation.Horizontal : swf.Orientation.Vertical; } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/SplitterHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/SplitterHandler.cs deleted file mode 100644 index 48a1e577b6..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/SplitterHandler.cs +++ /dev/null @@ -1,281 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows -{ - public class SplitterHandler : WindowsControl, ISplitter - { - Control panel1; - Control panel2; - int? position; - - public bool RecurseToChildren { get { return true; } } - - public override Size? DefaultSize - { - get - { - var size = base.DefaultSize; - if (size == null && Control.AutoSize) - { - var min = Control.MinimumSize; - Control.MinimumSize = sd.Size.Empty; - size = Control.GetPreferredSize(sd.Size.Empty).ToEto(); - Control.MinimumSize = min; - } - return size; - } - } - - public class EtoSplitContainer : swf.SplitContainer - { - public SplitterHandler Handler { get; set; } - - public override sd.Size GetPreferredSize(sd.Size proposedSize) - { - var size = new sd.Size(); - var size1 = Handler.panel1.GetPreferredSize(); - var size2 = Handler.panel2.GetPreferredSize(); - if (Orientation == swf.Orientation.Vertical) - { - size1.Width = Handler.position ?? size1.Width; - size.Width = size1.Width + size2.Width + SplitterWidth; - size.Height = Math.Max(size1.Height, size2.Height); - } - else - { - size1.Height = Handler.position ?? size1.Height; - size.Height = size1.Height + size2.Height + SplitterWidth; - size.Width = Math.Max(size1.Width, size2.Width); - } - return size; - } - } - - public SplitterHandler() - { - Control = new EtoSplitContainer { - Handler = this, - AutoSize = true, - FixedPanel = swf.FixedPanel.Panel1, - Panel1MinSize = 0, - Panel2MinSize = 0, - }; - } - - public override void AttachEvent(string id) - { - switch (id) - { - case Splitter.PositionChangedEvent: - // Hook SplitterMoving, not SplitterMoved, - // because the latter fires even when the - // splitter distance is changed programmatically. - Control.SplitterMoving += (s, e) => Widget.OnPositionChanged(e); - break; - default: - base.AttachEvent(id); - break; - } - } - - public int Position - { - get { return Control.SplitterDistance; } - set - { - position = value; - if (Control.IsHandleCreated) - SetPosition(value); - } - } - - void SetPosition(int position) - { - if (Control.Orientation == swf.Orientation.Vertical) - { - Control.SplitterDistance = Math.Max(0, Math.Min(Control.Width - Control.Panel2MinSize - 1, position)); - } - else - { - Control.SplitterDistance = Math.Max(0, Math.Min(Control.Height - Control.Panel2MinSize - 1, position)); - } - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - Control.HandleCreated += (sender, ee) => - { - if (position != null) - { - SetPosition(position.Value); - position = null; - } - else - { - switch (FixedPanel) - { - case SplitterFixedPanel.Panel1: - var size1 = panel1.GetPreferredSize(); - SetPosition(Control.Orientation == swf.Orientation.Vertical ? size1.Width : size1.Height); - break; - case SplitterFixedPanel.Panel2: - var size2 = panel2.GetPreferredSize(); - int pos; - if (Control.Orientation == swf.Orientation.Vertical) - pos = Control.Width - size2.Width; - else - pos = Control.Height - size2.Height; - SetPosition(pos); - break; - } - } - }; - Control.Panel1Collapsed = panel1 == null || !(panel1.GetWindowsHandler()).InternalVisible; - Control.Panel2Collapsed = panel2 == null || !(panel2.GetWindowsHandler()).InternalVisible; - } - - public SplitterFixedPanel FixedPanel - { - get - { - switch (Control.FixedPanel) - { - case swf.FixedPanel.None: - return SplitterFixedPanel.None; - case swf.FixedPanel.Panel1: - return SplitterFixedPanel.Panel1; - case swf.FixedPanel.Panel2: - return SplitterFixedPanel.Panel2; - default: - throw new NotSupportedException(); - } - } - set - { - switch (value) - { - case SplitterFixedPanel.None: - Control.FixedPanel = swf.FixedPanel.None; - break; - case SplitterFixedPanel.Panel1: - Control.FixedPanel = swf.FixedPanel.Panel1; - break; - case SplitterFixedPanel.Panel2: - Control.FixedPanel = swf.FixedPanel.Panel2; - break; - default: - throw new NotSupportedException(); - } - } - } - - public SplitterOrientation Orientation - { - get - { - switch (Control.Orientation) - { - case swf.Orientation.Horizontal: - return SplitterOrientation.Vertical; - case swf.Orientation.Vertical: - return SplitterOrientation.Horizontal; - default: - throw new NotSupportedException(); - } - } - set - { - switch (value) - { - case SplitterOrientation.Horizontal: - Control.Orientation = swf.Orientation.Vertical; - break; - case SplitterOrientation.Vertical: - Control.Orientation = swf.Orientation.Horizontal; - break; - default: - throw new NotSupportedException(); - } - } - } - - public Control Panel1 - { - get { return panel1; } - set - { - if (panel1 != value) - { - Control.SuspendLayout(); - var old = panel1.GetContainerControl(); - if (old != null) - { - old.VisibleChanged -= c1_VisibleChanged; - } - panel1 = value; - Control.Panel1.Controls.Clear(); - if (panel1 != null) - { - var control = panel1.GetContainerControl(); - control.Dock = swf.DockStyle.Fill; - control.VisibleChanged += c1_VisibleChanged; - Control.Panel1.Controls.Add(control); - } - if (Widget.Loaded) - Control.Panel1Collapsed = panel1 == null || !(panel1.GetWindowsHandler()).InternalVisible; - Control.ResumeLayout(); - } - } - } - - public Control Panel2 - { - get { return panel2; } - set - { - if (panel2 != value) - { - Control.SuspendLayout(); - var old = panel2.GetContainerControl(); - if (old != null) - { - old.VisibleChanged -= c2_VisibleChanged; - } - panel2 = value; - Control.Panel2.Controls.Clear(); - if (panel2 != null) - { - var control = panel2.GetContainerControl(); - control.Dock = swf.DockStyle.Fill; - control.VisibleChanged += c2_VisibleChanged; - Control.Panel2.Controls.Add(control); - } - if (Widget.Loaded) - Control.Panel2Collapsed = panel2 == null || !(panel2.GetWindowsHandler()).InternalVisible; - Control.ResumeLayout(); - } - } - } - - void c1_VisibleChanged(object sender, EventArgs e) - { - if (panel1 != null && (panel1.GetWindowsHandler()).InternalVisible) - Control.Panel1Collapsed = false; - else - Control.Panel1Collapsed = true; - } - - void c2_VisibleChanged(object sender, EventArgs e) - { - if (panel2 != null && (panel2.GetWindowsHandler()).InternalVisible) - Control.Panel2Collapsed = false; - else - Control.Panel2Collapsed = true; - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/TabControlHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/TabControlHandler.cs deleted file mode 100644 index a2566d48f6..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/TabControlHandler.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class TabControlHandler : WindowsContainer, ITabControl - { - bool disableSelectedIndexChanged; - public TabControlHandler () - { - this.Control = new SWF.TabControl (); - this.Control.ImageList = new SWF.ImageList{ ColorDepth = SWF.ColorDepth.Depth32Bit }; - this.Control.SelectedIndexChanged += (sender, e) => { - if (!disableSelectedIndexChanged) - Widget.OnSelectedIndexChanged (e); - }; - } - - public int SelectedIndex { - get { return Control.SelectedIndex; } - set { Control.SelectedIndex = value; } - } - - public void InsertTab (int index, TabPage page) - { - var pageHandler = (TabPageHandler)page.Handler; - if (index == -1 || index == Control.TabPages.Count) - Control.TabPages.Add (pageHandler.Control); - else - Control.TabPages.Insert (index, pageHandler.Control); - if (Widget.Loaded && Control.TabPages.Count == 1) - Widget.OnSelectedIndexChanged (EventArgs.Empty); - } - - public void RemoveTab (int index, TabPage page) - { - disableSelectedIndexChanged = true; - try { - var tab = Control.TabPages[index]; - var isSelected = Control.SelectedIndex == index; - Control.TabPages.Remove (tab); - if (isSelected) - Control.SelectedIndex = Math.Min (index, Control.TabPages.Count - 1); - if (Widget.Loaded) - Widget.OnSelectedIndexChanged (EventArgs.Empty); - } finally { - disableSelectedIndexChanged = false; - } - } - - public void ClearTabs () - { - Control.TabPages.Clear (); - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/TabPageHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/TabPageHandler.cs deleted file mode 100644 index 45901dfbff..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/TabPageHandler.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class TabPageHandler : WindowsPanel, ITabPage - { - Image image; - swf.TabControl tabcontrol; - - public TabPageHandler () - { - this.Control = new swf.TabPage { - UseVisualStyleBackColor = true - }; - } - - public override Color BackgroundColor { - get { return base.BackgroundColor; } - set { - Control.UseVisualStyleBackColor = false; - base.BackgroundColor = value; - } - } - - public Image Image { - get { return image; } - set { - if (tabcontrol != null && !string.IsNullOrEmpty (Control.ImageKey)) { - tabcontrol.ImageList.Images.RemoveByKey (Control.ImageKey); - Control.ImageIndex = -1; - } - image = value; - if (image != null) { - Control.ImageKey = Guid.NewGuid ().ToString (); - SetImage (); - } - else { - Control.ImageKey = null; - } - } - } - - void SetImage () - { - if (tabcontrol != null && image != null && Control.ImageIndex == -1) { - tabcontrol.ImageList.AddImage (image, Control.ImageKey); - // must set image index since it doesn't work with key for tabs.. ugh - Control.ImageIndex = tabcontrol.ImageList.Images.IndexOfKey (Control.ImageKey); - } - } - - public override void SetParent(Container parent) - { - base.SetParent(parent); - tabcontrol = parent != null ? parent.ControlObject as swf.TabControl : null; - SetImage (); - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/TextAreaHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/TextAreaHandler.cs deleted file mode 100644 index dc5bb03462..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/TextAreaHandler.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using System.Runtime.InteropServices; -using Eto.Drawing; - -namespace Eto.Platform.Windows -{ - public class TextAreaHandler : WindowsControl, ITextArea - { - int? lastCaretIndex; - Size defaultSize; - swf.TableLayoutPanel container; - - public override Size? DefaultSize - { - get { return defaultSize; } - } - - public override swf.Control ContainerControl - { - get { return container; } - } - - public TextAreaHandler () - { - defaultSize = TextArea.DefaultSize; - Control = new swf.RichTextBox { - Size = sd.Size.Empty, - Multiline = true, - AcceptsTab = true, - Dock = swf.DockStyle.Fill, - BorderStyle = swf.BorderStyle.None, - ScrollBars = swf.RichTextBoxScrollBars.Both, - }; - container = new swf.TableLayoutPanel { - MinimumSize = sd.Size.Empty, - BorderStyle = swf.BorderStyle.FixedSingle, - Size = defaultSize.ToSD() - }; - container.ColumnStyles.Add (new swf.ColumnStyle (swf.SizeType.AutoSize, 1)); - container.RowStyles.Add (new swf.RowStyle (swf.SizeType.AutoSize, 1)); - container.Controls.Add (Control, 0, 0); - } - - public override void AttachEvent (string handler) - { - switch (handler) - { - case TextArea.SelectionChangedEvent: - Control.SelectionChanged += (sender, e) => { - Widget.OnSelectionChanged (EventArgs.Empty); - }; - break; - case TextArea.CaretIndexChangedEvent: - Control.SelectionChanged += (sender, e) => { - var caretIndex = CaretIndex; - if (caretIndex != lastCaretIndex) - { - Widget.OnCaretIndexChanged (EventArgs.Empty); - lastCaretIndex = caretIndex; - } - }; - break; - default: - base.AttachEvent (handler); - break; - } - } - - public bool ReadOnly { - get { return Control.ReadOnly; } - set { Control.ReadOnly = value; } - } - - public bool Wrap { - get { return Control.WordWrap; } - set { Control.WordWrap = value; } - } - - public void Append (string text, bool scrollToCursor) - { - Control.AppendText (text); - if (scrollToCursor) { - Control.SelectionStart = Control.Text.Length; - Control.ScrollToCaret (); - } - } - - public string SelectedText - { - get { return Control.SelectedText; } - set { - var start = Control.SelectionStart; - Control.SelectedText = value; - if (value != null) - Control.Select (start, value.Length); - } - } - - public Range Selection - { - get { return new Range (Control.SelectionStart, Control.SelectionLength); } - set { Control.Select (value.Start, value.Length); } - } - - public void SelectAll () - { - Control.SelectAll (); - } - - public int CaretIndex - { - get { return Control.SelectionStart; } - set { Control.Select (value, 0); } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/TextBoxHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/TextBoxHandler.cs deleted file mode 100644 index 6258e67646..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/TextBoxHandler.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; -using System.Runtime.InteropServices; - -namespace Eto.Platform.Windows -{ - public class TextBoxHandler : WindowsControl, ITextBox - { - public class WatermarkTextBox : SWF.TextBox - { - const uint ECM_FIRST = 0x1500; - const uint EM_SETCUEBANNER = ECM_FIRST + 1; - - [DllImport ("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] - static extern IntPtr SendMessage (IntPtr hWnd, uint msg, uint wParam, [MarshalAs (UnmanagedType.LPWStr)] string lParam); - - string watermarkText; - public string WatermarkText - { - get { return watermarkText; } - set - { - watermarkText = value; - SetWatermark (watermarkText); - } - } - - void SetWatermark (string watermarkText) - { - SendMessage(Handle, EM_SETCUEBANNER, 0, watermarkText); - } - - } - public TextBoxHandler () - { - Control = new WatermarkTextBox (); - } - - public bool ReadOnly { - get { return Control.ReadOnly; } - set { Control.ReadOnly = value; } - } - - public int MaxLength { - get { return Control.MaxLength; } - set { Control.MaxLength = value; } - } - - public string PlaceholderText { - get { return Control.WatermarkText; } - set { Control.WatermarkText = value; } - } - - public void SelectAll () - { - Control.Focus (); - Control.SelectAll (); - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Controls/TreeGridViewHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/TreeGridViewHandler.cs deleted file mode 100644 index b36c9879b7..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/TreeGridViewHandler.cs +++ /dev/null @@ -1,312 +0,0 @@ -using System; -using System.Linq; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using System.Collections.Generic; -using Eto.Drawing; -using Eto.Platform.CustomControls; -using System.Collections.Specialized; -using System.Runtime.InteropServices; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class TreeGridViewHandler : GridHandler, ITreeGridView, ITreeHandler - { - public static int INDENT_WIDTH = 16; - ITreeGridItem lastSelected; - - swf.VisualStyles.VisualStyleRenderer openRenderer; - swf.VisualStyles.VisualStyleRenderer closedRenderer; - - public bool ClassicStyle { get; set; } - - public bool ClassicGridLines { get; set; } - - TreeController controller; - - protected override object GetItemAtRow (int row) - { - return controller[row]; - } - - public TreeGridViewHandler () - { - controller = new TreeController { Handler = this }; - controller.CollectionChanged += HandleCollectionChanged; - } - - public override void OnLoad (EventArgs e) - { - base.OnLoad (e); - var col = Widget.Columns.Select (r => r.Handler as GridColumnHandler).FirstOrDefault (); - if (col != null && col.AutoSize) { - col.Control.AutoSizeMode = swf.DataGridViewAutoSizeColumnMode.AllCells; - } - } - - protected override void Initialize () - { - base.Initialize (); - - //Control.AutoSizeColumnsMode = swf.DataGridViewAutoSizeColumnsMode.AllCells; - Control.BackgroundColor = sd.SystemColors.Window; - Control.SelectionMode = swf.DataGridViewSelectionMode.FullRowSelect; - Control.CellBorderStyle = swf.DataGridViewCellBorderStyle.None; - } - - public override void AttachEvent (string handler) - { - switch (handler) { - case TreeGridView.ExpandingEvent: - controller.Expanding += (sender, e) => { - Widget.OnExpanding (e); - }; - break; - case TreeGridView.ExpandedEvent: - controller.Expanded += (sender, e) => { - Widget.OnExpanded (e); - }; - break; - case TreeGridView.CollapsingEvent: - controller.Collapsing += (sender, e) => { - Widget.OnCollapsing (e); - }; - break; - case TreeGridView.CollapsedEvent: - controller.Collapsed += (sender, e) => { - Widget.OnCollapsed (e); - }; - break; - case TreeGridView.SelectedItemChangedEvent: - Control.SelectionChanged += (sender, e) => { - var item = this.SelectedItem; - if (!object.ReferenceEquals(lastSelected, item)) - { - Widget.OnSelectedItemChanged (EventArgs.Empty); - lastSelected = item; - } - }; - break; - default: - base.AttachEvent (handler); - break; - } - } - - public ITreeGridStore DataStore - { - get { return controller.Store; } - set - { - controller.InitializeItems (value); - } - } - - public override void Invalidate () - { - base.Invalidate (); - if (this.Widget.Loaded) { - Control.Refresh (); - AutoSizeColumns (); - } - } - - void HandleCollectionChanged (object sender, NotifyCollectionChangedEventArgs e) - { - Control.RowCount = controller.Count; - if (this.Widget.Loaded) { - Control.Refresh (); - AutoSizeColumns (); - } - } - - public ITreeGridItem SelectedItem - { - get - { - var index = Control.SelectedRows.OfType ().Select (r => r.Index).FirstOrDefault (); - return controller[index]; - } - set - { - if (controller != null && value != null) { - controller.ExpandToItem (value); - var index = controller.IndexOf(value); - if (index >= 0) - Control.Rows[index].Selected = true; - } - else Control.ClearSelection (); - } - } - - void EnsureGlyphRenderers () - { - if (openRenderer == null || closedRenderer == null) { - if (ClassicStyle) { - openRenderer = new swf.VisualStyles.VisualStyleRenderer (swf.VisualStyles.VisualStyleElement.TreeView.Glyph.Opened); - closedRenderer = new swf.VisualStyles.VisualStyleRenderer (swf.VisualStyles.VisualStyleElement.TreeView.Glyph.Closed); - } - else { - openRenderer = new swf.VisualStyles.VisualStyleRenderer ("Explorer::TreeView", 2, 2); - closedRenderer = new swf.VisualStyles.VisualStyleRenderer ("Explorer::TreeView", 2, 1); - } - } - } - - public override void Paint (GridColumnHandler column, sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts) - { - if (object.ReferenceEquals (column.Widget, this.Widget.Columns[0])) { - // paint the background - if (paintParts.HasFlag (swf.DataGridViewPaintParts.Background)) { - sd.Brush brush; - if (cellState.HasFlag (swf.DataGridViewElementStates.Selected)) - brush = new sd.SolidBrush (cellStyle.SelectionBackColor); - else - brush = new sd.SolidBrush (cellStyle.BackColor); - graphics.FillRectangle (brush, cellBounds); - paintParts &= ~swf.DataGridViewPaintParts.Background; - } - - var node = controller.GetNodeAtRow (rowIndex); - var treeRect = cellBounds; - treeRect.X += node.Level * INDENT_WIDTH; - treeRect.Width = 16; - - if (ClassicStyle && ClassicGridLines) { - // Draw grid lines - for classic style - using (var linePen = new sd.Pen (sd.SystemBrushes.ControlDark, 1.0f)) { - var lineRect = treeRect; - lineRect.X += 7; - lineRect.Width = 10; - linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; - var isFirstSibling = node.IsFirstNode; - var isLastSibling = node.IsLastNode; - if (node.Level == 0) { - // the Root nodes display their lines differently - if (isFirstSibling && isLastSibling) { - // only node, both first and last. Just draw horizontal line - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); - } - else if (isLastSibling) { - // last sibling doesn't draw the line extended below. Paint horizontal then vertical - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top, lineRect.X, cellBounds.Top + cellBounds.Height / 2); - } - else if (isFirstSibling) { - // first sibling doesn't draw the line extended above. Paint horizontal then vertical - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.X, cellBounds.Bottom); - } - else { - // normal drawing draws extended from top to bottom. Paint horizontal then vertical - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top, lineRect.X, cellBounds.Bottom); - } - } - else { - if (isLastSibling) { - // last sibling doesn't draw the line extended below. Paint horizontal then vertical - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top, lineRect.X, cellBounds.Top + cellBounds.Height / 2); - } - else { - // normal drawing draws extended from top to bottom. Paint horizontal then vertical - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); - graphics.DrawLine (linePen, lineRect.X, cellBounds.Top, lineRect.X, cellBounds.Bottom); - } - - // paint lines of previous levels to the root - int horizontalStop = lineRect.X - INDENT_WIDTH; - var previousNode = node.Parent; - - while (previousNode != null) { - if (!previousNode.IsLastNode) { - // paint vertical line - graphics.DrawLine (linePen, horizontalStop, lineRect.Top, horizontalStop, lineRect.Bottom); - } - previousNode = previousNode.Parent; - horizontalStop = horizontalStop - INDENT_WIDTH; - } - } - - } - } - - if (node.Item.Expandable) { - // draw open/close glyphs - if (swf.Application.RenderWithVisualStyles) { - EnsureGlyphRenderers (); - if (controller.IsExpanded (rowIndex)) - openRenderer.DrawBackground (graphics, new sd.Rectangle (treeRect.X, treeRect.Y + (treeRect.Height / 2) - 8, 16, 16)); - else { - closedRenderer.DrawBackground (graphics, new sd.Rectangle (treeRect.X, treeRect.Y + (treeRect.Height / 2) - 8, 16, 16)); - } - } - else { - // todo: draw +/- manually - var glyphRect = treeRect; - glyphRect.Width = glyphRect.Height = 8; - glyphRect.X += 3; - glyphRect.Y += (treeRect.Height - glyphRect.Height) / 2; - graphics.FillRectangle (sd.SystemBrushes.Window, glyphRect); - graphics.DrawRectangle (sd.SystemPens.ControlDark, glyphRect); - glyphRect.Inflate (-2, -2); - if (!controller.IsExpanded (rowIndex)) { - var midx = glyphRect.X + glyphRect.Width / 2; - graphics.DrawLine (sd.SystemPens.ControlDarkDark, midx, glyphRect.Top, midx, glyphRect.Bottom); - } - - var midy = glyphRect.Y + glyphRect.Height / 2; - graphics.DrawLine (sd.SystemPens.ControlDarkDark, glyphRect.Left, midy, glyphRect.Right, midy); - } - } - } - } - - public override int GetRowOffset (GridColumnHandler column, int rowIndex) - { - if (object.ReferenceEquals (column.Widget, this.Widget.Columns[0])) - return INDENT_WIDTH + controller.LevelAtRow (rowIndex) * INDENT_WIDTH; - else - return 0; - } - - public override bool CellMouseClick (GridColumnHandler column, swf.MouseEventArgs e, int rowIndex) - { - if (rowIndex >= 0 && object.ReferenceEquals (column.Widget, this.Widget.Columns[0])) { - var offset = INDENT_WIDTH + controller.LevelAtRow (rowIndex) * INDENT_WIDTH; - if (e.X < offset && e.X >= offset - INDENT_WIDTH) { - if (controller.IsExpanded (rowIndex)) - controller.CollapseRow (rowIndex); - else - controller.ExpandRow (rowIndex); - - return true; - } - } - return false; - } - - void AutoSizeColumns () - { - foreach (var colHandler in Widget.Columns.Where (r => r.AutoSize).Select (r => r.Handler).OfType ()) { - if (colHandler.AutoSize) { - // expand this column to fit content width - var width = colHandler.Control.GetPreferredWidth (swf.DataGridViewAutoSizeColumnMode.AllCells, false); - if (width > colHandler.Control.Width) - colHandler.Control.Width = width; - } - } - } - - void ITreeHandler.PreResetTree () - { - } - - void ITreeHandler.PostResetTree () - { - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/TreeViewHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/TreeViewHandler.cs deleted file mode 100644 index 9cc762f9d5..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/TreeViewHandler.cs +++ /dev/null @@ -1,383 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using System.Collections.Generic; -using Eto.Drawing; -using System.Linq; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class TreeViewHandler : WindowsControl, ITreeView - { - ITreeStore top; - readonly Dictionary images = new Dictionary(); - static readonly string EmptyName = Guid.NewGuid().ToString(); - bool ignoreExpandCollapseEvents = true; - - public TreeViewHandler() - { - this.Control = new swf.TreeView - { - HideSelection = false - }; - - this.Control.BeforeExpand += delegate(object sender, System.Windows.Forms.TreeViewCancelEventArgs e) - { - var item = e.Node.Tag as ITreeItem; - if (e.Node.Nodes.Count == 1 && e.Node.Nodes[0].Name == EmptyName) - { - PopulateNodes(e.Node.Nodes, item); - } - }; - } - - protected override void Initialize() - { - base.Initialize(); - HandleEvent(TreeView.ExpandedEvent); - HandleEvent(TreeView.CollapsedEvent); - } - - public ITreeStore DataStore - { - get { return top; } - set - { - top = value; - Control.ImageList = null; - images.Clear(); - Control.BeginUpdate(); - PopulateNodes(Control.Nodes, top); - Control.EndUpdate(); - } - } - - public override void AttachEvent(string id) - { - switch (id) - { - case TreeView.ExpandingEvent: - Control.BeforeExpand += (sender, e) => - { - if (ignoreExpandCollapseEvents) - return; - var item = e.Node.Tag as ITreeItem; - if (!item.Expanded) - { - var args = new TreeViewItemCancelEventArgs(item); - Widget.OnExpanding(args); - e.Cancel = args.Cancel; - } - }; - break; - case TreeView.ExpandedEvent: - Control.AfterExpand += (sender, e) => - { - if (ignoreExpandCollapseEvents) - return; - var item = e.Node.Tag as ITreeItem; - if (!item.Expanded) - { - item.Expanded = true; - Widget.OnExpanded(new TreeViewItemEventArgs(item)); - } - }; - break; - case TreeView.CollapsingEvent: - Control.BeforeCollapse += (sender, e) => - { - if (ignoreExpandCollapseEvents) - return; - var item = e.Node.Tag as ITreeItem; - if (item.Expanded) - { - var args = new TreeViewItemCancelEventArgs(item); - Widget.OnCollapsing(args); - e.Cancel = args.Cancel; - } - }; - break; - case TreeView.CollapsedEvent: - Control.AfterCollapse += (sender, e) => - { - if (ignoreExpandCollapseEvents) - return; - var item = e.Node.Tag as ITreeItem; - if (item.Expanded) - { - item.Expanded = false; - Widget.OnCollapsed(new TreeViewItemEventArgs(item)); - } - }; - break; - case TreeView.ActivatedEvent: - Control.KeyDown += (sender, e) => - { - if (SelectedItem != null) - { - if (e.KeyData == swf.Keys.Return) - { - Widget.OnActivated(new TreeViewItemEventArgs(SelectedItem)); - e.Handled = true; - if (LabelEdit) - Control.SelectedNode.BeginEdit(); - } - else if (e.KeyData == swf.Keys.F2 && LabelEdit) - { - Control.SelectedNode.BeginEdit(); - } - } - }; - - Control.NodeMouseDoubleClick += (sender, e) => - { - if (e.Button == swf.MouseButtons.Left && SelectedItem != null) - { - if (LabelEdit) - Control.SelectedNode.BeginEdit(); - else - Widget.OnActivated(new TreeViewItemEventArgs(SelectedItem)); - } - }; - break; - case TreeView.LabelEditedEvent: - Control.AfterLabelEdit += (s, e) => - { - var args = new TreeViewItemEditEventArgs(e.Node.Tag as ITreeItem, e.Label); - Widget.OnLabelEdited(args); - if (!args.Cancel) - args.Item.Text = e.Label; - e.CancelEdit = args.Cancel; - }; - break; - case TreeView.LabelEditingEvent: - Control.BeforeLabelEdit += (s, e) => - { - var args = new TreeViewItemCancelEventArgs(e.Node.Tag as ITreeItem); - Widget.OnLabelEditing(args); - e.CancelEdit = args.Cancel; - }; - break; - case TreeView.NodeMouseClickEvent: - Control.NodeMouseClick += (s, e) => Widget.OnNodeMouseClick(new TreeViewItemEventArgs(e.Node.Tag as ITreeItem)); - break; - case TreeView.SelectionChangedEvent: - Control.AfterSelect += (sender, e) => Widget.OnSelectionChanged(EventArgs.Empty); - break; - default: - base.AttachEvent(id); - break; - } - } - - void PopulateNodes(System.Windows.Forms.TreeNodeCollection nodes, ITreeStore item) - { - if (Widget.Loaded) - ignoreExpandCollapseEvents = true; - PerformPopulateNodes(nodes, item); - if (Widget.Loaded) - ignoreExpandCollapseEvents = false; - } - - public override void OnLoadComplete(EventArgs e) - { - base.OnLoadComplete(e); - ignoreExpandCollapseEvents = false; - } - - void PerformPopulateNodes(System.Windows.Forms.TreeNodeCollection nodes, ITreeStore item) - { - nodes.Clear(); - var count = item.Count; - for (int i = 0; i < count; i++) - { - var child = item[i]; - var node = new swf.TreeNode - { - Text = child.Text, - Name = child.Key, - Tag = child, - }; - SetImage(child, node); - - if (child.Expandable) - { - if (child.Expanded) - { - PerformPopulateNodes(node.Nodes, child); - node.Expand(); - } - else - { - node.Nodes.Add(EmptyName, string.Empty); - } - } - - nodes.Add(node); - } - } - - string GetImageKey(Image image) - { - if (image == null) - return null; - - if (Control.ImageList == null) - Control.ImageList = new System.Windows.Forms.ImageList { ColorDepth = swf.ColorDepth.Depth32Bit }; - string key; - if (!images.TryGetValue(image, out key)) - { - key = Guid.NewGuid().ToString(); - Control.ImageList.AddImage(image, key); - } - return key; - } - - public ITreeItem SelectedItem - { - get - { - var node = Control.SelectedNode; - return node == null ? null : node.Tag as ITreeItem; - } - set - { - if (value != null) - { - // now select the node - var node = GetTreeNode(value); - - if (node != null) - Control.SelectedNode = node; - } - } - } - - public ITreeItem GetNodeAt(PointF targetPoint) - { - var item = Control.GetNodeAt(targetPoint.ToSDPoint()); - return item != null ? item.Tag as ITreeItem : null; - } - - public Color TextColor - { - get { return Control.ForeColor.ToEto(); } - set { Control.ForeColor = value.ToSD(); } - } - - public bool LabelEdit - { - get { return Control.LabelEdit; } - set { Control.LabelEdit = value; } - } - - public bool AllowDrop - { - get { return Control.AllowDrop; } - set { Control.AllowDrop = value; } - } - - public void AddTo(ITreeItem dest, ITreeItem item) - { - var treeNode = GetTreeNode(item); - - var destNode = GetTreeNode(dest); - - if (treeNode != null && destNode != null) - treeNode.Nodes.Add(destNode); - } - - IEnumerable EnumerateNodes(swf.TreeNodeCollection nodes) - { - foreach (swf.TreeNode node in nodes) - { - yield return node; - foreach (var child in EnumerateNodes(node.Nodes)) - yield return child; - } - } - - swf.TreeNode GetTreeNode(ITreeItem item) - { - if (item.Key == null) - { - return EnumerateNodes(Control.Nodes).FirstOrDefault(r => object.ReferenceEquals(r.Tag, item)); - } - else - { - var nodes = Control.Nodes.Find(item.Key, true); - return nodes.FirstOrDefault(r => object.ReferenceEquals(item, r.Tag)); - } - } - - void SetImage(ITreeItem item, swf.TreeNode node) - { - if (item != null) - { - // set the image key on the TreeNode - node = node ?? GetTreeNode(item); - - // If the node has already - // been constructed, set its image - // key as well. - if (node != null) - { - var imageKey = GetImageKey(item.Image); - - // A workaround for a bug in the - // swf treeview. If a null key is specified, - // it uses the first image, unless an - // image index greater than the number of - // images in the image list is specified - // http://stackoverflow.com/questions/261660 - if (imageKey == null) - { - node.ImageIndex = Int32.MaxValue; - node.SelectedImageIndex = Int32.MaxValue; - } - else - { - node.ImageKey = imageKey; - node.SelectedImageKey = imageKey; - } - } - } - } - - public void RefreshData() - { - Control.BeginUpdate(); - Control.ImageList = null; - images.Clear(); - PopulateNodes(Control.Nodes, top); - Control.EndUpdate(); - } - - public void RefreshItem(ITreeItem item) - { - var node = GetTreeNode(item); - if (node != null) - { - Control.BeginUpdate(); - var selected = SelectedItem; - node.Text = item.Text; - SetImage(item, node); - PopulateNodes(node.Nodes, item); - if (node.IsExpanded != item.Expanded) - { - if (item.Expanded) - node.Expand(); - else - node.Collapse(); - } - SelectedItem = selected; - Control.EndUpdate(); - } - else - RefreshData(); - - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/Controls/WebViewHandler.cs b/Source/Eto.Platform.Windows/Forms/Controls/WebViewHandler.cs deleted file mode 100644 index 279560918a..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Controls/WebViewHandler.cs +++ /dev/null @@ -1,180 +0,0 @@ -using System; -using SWF = System.Windows.Forms; -using Eto.Forms; -using Eto.Platform.CustomControls; -using System.Runtime.InteropServices; -using System.Collections.Generic; - -namespace Eto.Platform.Windows.Forms.Controls -{ - public class WebViewHandler : WindowsControl, IWebView - { - [ComImport, InterfaceType (ComInterfaceType.InterfaceIsIUnknown)] - [Guid ("6d5140c1-7436-11ce-8034-00aa006009fa")] - internal interface IServiceProvider - { - [return: MarshalAs (UnmanagedType.IUnknown)] - object QueryService (ref Guid guidService, ref Guid riid); - } - - HashSet delayedEvents = new HashSet (); - - SHDocVw.WebBrowser_V1 WebBrowserV1 - { - get { return (SHDocVw.WebBrowser_V1)Control.ActiveXInstance; } - } - - public void AttachEvent (SHDocVw.WebBrowser_V1 control, string handler) - { - switch (handler) - { - case WebView.OpenNewWindowEvent: - control.NewWindow += WebBrowserV1_NewWindow; - break; - } - } - - public WebViewHandler () - { - this.Control = new SWF.WebBrowser { - IsWebBrowserContextMenuEnabled = false, - WebBrowserShortcutsEnabled = false, - AllowWebBrowserDrop = false, - ScriptErrorsSuppressed = true - }; - this.Control.HandleCreated += (sender, e) => { - HookDocumentEvents (); - }; - } - - void WebBrowserV1_NewWindow (string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed) - { - var e = new WebViewNewWindowEventArgs (new Uri (URL), TargetFrameName); - Widget.OnOpenNewWindow (e); - Processed = e.Cancel; - } - - public override void AttachEvent (string handler) - { - switch (handler) { - case WebView.NavigatedEvent: - this.Control.Navigated += (s, e) => { - Widget.OnNavigated (new WebViewLoadedEventArgs (e.Url)); - }; - break; - case WebView.DocumentLoadedEvent: - this.Control.DocumentCompleted += (sender, e) => { - Widget.OnDocumentLoaded (new WebViewLoadedEventArgs (e.Url)); - }; - break; - case WebView.DocumentLoadingEvent: - this.Control.Navigating += (sender, e) => { - var args = new WebViewLoadingEventArgs (e.Url, false); - Widget.OnDocumentLoading (args); - e.Cancel = args.Cancel; - }; - break; - case WebView.OpenNewWindowEvent: - HookDocumentEvents (handler); - break; - case WebView.DocumentTitleChangedEvent: - this.Control.DocumentTitleChanged += delegate { - Widget.OnDocumentTitleChanged (new WebViewTitleEventArgs (Control.DocumentTitle)); - }; - break; - default: - base.AttachEvent (handler); - break; - } - - } - - void HookDocumentEvents (string newEvent = null) - { - if (newEvent != null) - delayedEvents.Add (newEvent); - if (Control.ActiveXInstance != null) - { - foreach (var handler in delayedEvents) - AttachEvent (WebBrowserV1, handler); - delayedEvents.Clear (); - } - } - - public Uri Url { - get { return this.Control.Url; } - set { this.Control.Url = value; } - } - - public string DocumentTitle { - get { - return this.Control.DocumentTitle; - } - } - - public string ExecuteScript (string script) - { - var fullScript = string.Format ("var fn = function() {{ {0} }}; fn();", script); - return Convert.ToString (Control.Document.InvokeScript ("eval", new object[] { fullScript })); - } - - public void Stop () - { - this.Control.Stop (); - } - - public void Reload () - { - this.Control.Refresh (); - } - - public void GoBack () - { - this.Control.GoBack (); - } - - public bool CanGoBack { - get { - return this.Control.CanGoBack; - } - } - - public void GoForward () - { - this.Control.GoForward (); - } - - public bool CanGoForward { - get { - return this.Control.CanGoForward; - } - } - - HttpServer server; - - public void LoadHtml (string html, Uri baseUri) - { - if (baseUri != null) { - if (server == null) - server = new HttpServer (); - server.SetHtml (html, baseUri != null ? baseUri.LocalPath : null); - Control.Navigate (server.Url); - } - else - this.Control.DocumentText = html; - - } - - public void ShowPrintDialog () - { - this.Control.ShowPrintDialog(); - } - - public bool BrowserContextMenuEnabled - { - get { return Control.IsWebBrowserContextMenuEnabled; } - set { Control.IsWebBrowserContextMenuEnabled = value; } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/CursorHandler.cs b/Source/Eto.Platform.Windows/Forms/CursorHandler.cs deleted file mode 100644 index 79b0131a7d..0000000000 --- a/Source/Eto.Platform.Windows/Forms/CursorHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms -{ - public class CursorHandler : WidgetHandler, ICursor - { - public void Create (CursorType cursor) - { - switch (cursor) { - case CursorType.Arrow: - Control = SWF.Cursors.Arrow; - break; - case CursorType.Crosshair: - Control = SWF.Cursors.Cross; - break; - case CursorType.Default: - Control = SWF.Cursors.Default; - break; - case CursorType.HorizontalSplit: - Control = SWF.Cursors.HSplit; - break; - case CursorType.IBeam: - Control = SWF.Cursors.IBeam; - break; - case CursorType.Move: - Control = SWF.Cursors.SizeAll; - break; - case CursorType.Pointer: - Control = SWF.Cursors.Hand; - break; - case CursorType.VerticalSplit: - Control = SWF.Cursors.VSplit; - break; - default: - throw new NotSupportedException(); - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/DialogHandler.cs b/Source/Eto.Platform.Windows/Forms/DialogHandler.cs deleted file mode 100644 index 9146eefb83..0000000000 --- a/Source/Eto.Platform.Windows/Forms/DialogHandler.cs +++ /dev/null @@ -1,73 +0,0 @@ -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class DialogHandler : WindowHandler, IDialog - { - Button button; - Button abortButton; - - - public DialogHandler() - { - Control = new swf.Form { - StartPosition = swf.FormStartPosition.CenterParent, - AutoSize = true, - Size = sd.Size.Empty, - MinimumSize = sd.Size.Empty, - ShowInTaskbar = false, - ShowIcon = false, - MaximizeBox = false, - MinimizeBox = false - }; - } - - protected override swf.FormBorderStyle DefaultWindowStyle - { - get { return swf.FormBorderStyle.FixedDialog; } - } - - public Button AbortButton { - get { - return abortButton; - } - set { - abortButton = value; - if (abortButton != null) { - var b = abortButton.ControlObject as swf.IButtonControl; - Control.CancelButton = b; - } - else - Control.CancelButton = null; - } - } - - public Button DefaultButton - { - get { - return button; - } - set { - button = value; - if (button != null) { - var b = button.ControlObject as swf.IButtonControl; - Control.AcceptButton = b; - } - else - Control.AcceptButton = null; - } - } - - public DialogDisplayMode DisplayMode { get; set; } - - public DialogResult ShowDialog(Control parent) - { - if (parent != null) Control.ShowDialog((swf.Control)parent.ControlObject); - else Control.ShowDialog (); - - return Widget.DialogResult; - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Extensions.cs b/Source/Eto.Platform.Windows/Forms/Extensions.cs deleted file mode 100644 index d5fd4cbac6..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Extensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -using SD = System.Drawing; -using Eto.Drawing; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows.Forms -{ - public static class Extensions - { - public static void AddImage (this System.Windows.Forms.ImageList list, Image image, string key, int? size = null) - { - var imageHandler = image.Handler as IWindowsImageSource; - if (imageHandler != null) { - list.Images.Add (key, imageHandler.GetImageWithSize (size ?? list.ImageSize.Width)); - return; - } - - var sdimage = image.ControlObject as SD.Image; - if (sdimage != null) { - list.Images.Add (key, sdimage); - return; - } - var icon = image.ControlObject as SD.Icon; - if (icon != null) { - list.Images.Add (key, icon); - return; - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/FontDialogHandler.cs b/Source/Eto.Platform.Windows/Forms/FontDialogHandler.cs deleted file mode 100644 index 2b554d5c09..0000000000 --- a/Source/Eto.Platform.Windows/Forms/FontDialogHandler.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using swf = System.Windows.Forms; -using sd = System.Drawing; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows.Forms -{ - public class FontDialogHandler : WidgetHandler, IFontDialog - { - Font font; - - public override swf.FontDialog CreateControl () - { - return new swf.FontDialog { - ShowColor = true, - ShowEffects = false - }; - } - - public override void AttachEvent (string id) - { - switch (id) { - case FontDialog.FontChangedEvent: - // handled in ShowDialog - break; - default: - base.AttachEvent (id); - break; - } - } - - public Font Font - { - get { - if (font == null) - font = new Font (Widget.Generator, new FontHandler (Control.Font)); - return font; - } - set { - font = value; - Control.Font = font.ToSD (); - } - } - - public DialogResult ShowDialog (Window parent) - { - var result = Control.ShowDialog(); - if (result == swf.DialogResult.OK) - { - font = Control.Font.ToEto(Widget.Generator); - Widget.OnFontChanged(EventArgs.Empty); - return DialogResult.Ok; - } - return DialogResult.Cancel; - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/FormHandler.cs b/Source/Eto.Platform.Windows/Forms/FormHandler.cs deleted file mode 100644 index f33449c36e..0000000000 --- a/Source/Eto.Platform.Windows/Forms/FormHandler.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class FormHandler : WindowHandler, IForm - { - public class MyForm : swf.Form - { - bool hideFromAltTab; - public bool HideFromAltTab - { - get { return hideFromAltTab; } - set - { - if (hideFromAltTab != value) { - hideFromAltTab = value; - if (IsHandleCreated) { - var style = Win32.GetWindowLong (Handle, Win32.GWL.EXSTYLE); - if (hideFromAltTab) - style |= (uint)Win32.WS_EX.TOOLWINDOW; - else - style &= (uint)~Win32.WS_EX.TOOLWINDOW; - - Win32.SetWindowLong (Handle, Win32.GWL.EXSTYLE, style); - } - } - } - } - - public bool ShouldShowWithoutActivation { get; set; } - - protected override bool ShowWithoutActivation - { - get { return ShouldShowWithoutActivation; } - } - - protected override swf.CreateParams CreateParams - { - get - { - var createParams = base.CreateParams; - - if (hideFromAltTab) - createParams.ExStyle |= (int)Win32.WS_EX.TOOLWINDOW; - - return createParams; - } - } - } - - public FormHandler() - { - Control = new MyForm { - StartPosition = swf.FormStartPosition.CenterParent, - AutoSize = true, - Size = sd.Size.Empty, - MinimumSize = sd.Size.Empty - }; - } - - public void Show() - { - Control.Show(); - } - - public override bool ShowInTaskbar - { - get { return base.ShowInTaskbar; } - set - { - base.ShowInTaskbar = value; - Control.HideFromAltTab = !value; - } - } - - public Color TransparencyKey - { - get { return Control.TransparencyKey.ToEto(); } - set { Control.TransparencyKey = value.ToSD(); } - } - - - public bool KeyPreview - { - get { return Control.KeyPreview; } - set { Control.KeyPreview = value; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Menu/ButtonMenuItemHandler.cs b/Source/Eto.Platform.Windows/Forms/Menu/ButtonMenuItemHandler.cs deleted file mode 100644 index 99c4c13b67..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Menu/ButtonMenuItemHandler.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Linq; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class ButtonMenuItemHandler : MenuHandler, IButtonMenuItem - { - Image image; - int imageSize = 16; - bool openedHandled; - - public ButtonMenuItemHandler() - { - Control = new SWF.ToolStripMenuItem(); - Control.Click += (sender, e) => Widget.OnClick(EventArgs.Empty); - } - - void HandleDropDownOpened (object sender, EventArgs e) - { - foreach (var item in Widget.Items) { - item.OnValidate (EventArgs.Empty); - } - } - - public int ImageSize - { - get { return imageSize; } - set - { - imageSize = value; - Control.Image = image.ToSD (imageSize); - } - } - - public bool Enabled - { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - - public string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - - public string ToolTip { - get { - return Control.ToolTipText; - } - set { - Control.ToolTipText = value; - } - } - - public Keys Shortcut - { - get { return Control.ShortcutKeys.ToEto (); } - set - { - var key = value.ToSWF (); - if (SWF.ToolStripManager.IsValidShortcut(key)) Control.ShortcutKeys = key; - } - } - - public Image Image - { - get { return image; } - set - { - image = value; - Control.Image = image.ToSD (imageSize); - } - } - - public void AddMenu(int index, MenuItem item) - { - Control.DropDownItems.Insert(index, (SWF.ToolStripItem)item.ControlObject); - if (!openedHandled) { - Control.DropDownOpening += HandleDropDownOpened; - openedHandled = true; - } - } - - public void RemoveMenu(MenuItem item) - { - Control.DropDownItems.Remove((SWF.ToolStripItem)item.ControlObject); - } - - public void Clear() - { - Control.DropDownItems.Clear(); - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Menu/CheckMenuItemHandler.cs b/Source/Eto.Platform.Windows/Forms/Menu/CheckMenuItemHandler.cs deleted file mode 100644 index a8d6a44cb8..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Menu/CheckMenuItemHandler.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - /// - /// Summary description for MenuBarHandler. - /// - public class CheckMenuItemHandler : MenuHandler, ICheckMenuItem - { - public CheckMenuItemHandler() - { - Control = new SWF.ToolStripMenuItem(); - Control.Click += control_Click; - } - - void control_Click(object sender, EventArgs e) - { - Widget.OnClick(e); - } - - public bool Enabled - { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - public string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - - public string ToolTip - { - get - { - return Control.ToolTipText; - } - set - { - Control.ToolTipText = value; - } - } - - public Keys Shortcut - { - get { return Control.ShortcutKeys.ToEto(); } - set - { - var key = value.ToSWF(); - if (SWF.ToolStripManager.IsValidShortcut(key)) Control.ShortcutKeys = key; - } - } - - public bool Checked - { - get { return Control.Checked; } - set { Control.Checked = value; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Menu/ContextMenuHandler.cs b/Source/Eto.Platform.Windows/Forms/Menu/ContextMenuHandler.cs deleted file mode 100644 index 99d03ae576..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Menu/ContextMenuHandler.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Linq; -using swf = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class ContextMenuHandler : WidgetHandler, IContextMenu - { - - public ContextMenuHandler() - { - this.Control = new System.Windows.Forms.ContextMenuStrip(); - this.Control.Opened += HandleOpened; - } - - void HandleOpened(object sender, EventArgs e) - { - foreach (var item in Widget.Items) - { - item.OnValidate(EventArgs.Empty); - } - } - - public void AddMenu(int index, MenuItem item) - { - Control.Items.Insert(index, (swf.ToolStripItem)item.ControlObject); - } - - public void RemoveMenu(MenuItem item) - { - Control.Items.Remove((swf.ToolStripItem)item.ControlObject); - } - - public void Clear() - { - Control.Items.Clear(); - } - - public void Show(Control relativeTo) - { - var position = swf.Control.MousePosition; - if (relativeTo != null) - { - var control = relativeTo.GetContainerControl(); - position = control.PointToClient(position); - Control.Show(control, position.X, position.Y); - } - else - Control.Show(position); - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Menu/MenuBarHandler.cs b/Source/Eto.Platform.Windows/Forms/Menu/MenuBarHandler.cs deleted file mode 100644 index 9cae40cf3f..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Menu/MenuBarHandler.cs +++ /dev/null @@ -1,36 +0,0 @@ -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - /// - /// Summary description for MenuBarHandler. - /// - public class MenuBarHandler : WidgetHandler, IMenuBar, IMenu - { - public MenuBarHandler() - { - Control = new SWF.MenuStrip(); - } - - #region IMenu Members - - public void AddMenu(int index, MenuItem item) - { - Control.Items.Insert(index, (SWF.ToolStripItem)item.ControlObject); - } - - public void RemoveMenu(MenuItem item) - { - Control.Items.Remove((SWF.ToolStripItem)item.ControlObject); - } - - public void Clear() - { - Control.Items.Clear(); - } - - #endregion - - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Menu/MenuHandler.cs b/Source/Eto.Platform.Windows/Forms/Menu/MenuHandler.cs deleted file mode 100644 index 25223809ec..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Menu/MenuHandler.cs +++ /dev/null @@ -1,27 +0,0 @@ -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public abstract class MenuHandler : WidgetHandler, IMenu - where TControl: SWF.ToolStripItem - where TWidget: InstanceWidget - { - - public override void AttachEvent (string id) - { - switch (id) { - case MenuItem.ValidateEvent: - // handled by parents - break; - default: - base.AttachEvent (id); - break; - } - } - - public void CreateFromCommand(Command command) - { - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Menu/RadioMenuItemHandler.cs b/Source/Eto.Platform.Windows/Forms/Menu/RadioMenuItemHandler.cs deleted file mode 100644 index d18000e766..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Menu/RadioMenuItemHandler.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - /// - /// Summary description for MenuBarHandler. - /// - public class RadioMenuItemHandler : MenuHandler, IRadioMenuItem - { - ArrayList group; - - public RadioMenuItemHandler() - { - Control = new SWF.ToolStripMenuItem(); - Control.Click += control_Click; - } - - void control_Click(object sender, EventArgs e) - { - Widget.OnClick(e); - } - - public void Create(RadioMenuItem controller) - { - if (controller != null) - { - var controllerInner = (RadioMenuItemHandler)controller.Handler; - if (controllerInner.group == null) - { - controllerInner.group = new ArrayList(); - controllerInner.group.Add(controller); - controllerInner.Control.Click += controllerInner.control_RadioSwitch; - } - controllerInner.group.Add(Widget); - Control.Click += controllerInner.control_RadioSwitch; - } - } - #region IMenuItem Members - - public bool Enabled - { - get { return Control.Enabled; } - set { Control.Enabled = value; } - } - - public string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - - public string ToolTip - { - get { return Control.ToolTipText; } - set { Control.ToolTipText = value; } - } - - public Keys Shortcut - { - get { return Control.ShortcutKeys.ToEto (); } - set - { - var key = value.ToSWF (); - if (SWF.ToolStripManager.IsValidShortcut(key)) Control.ShortcutKeys = key; - } - } - - public bool Checked - { - get { return Control.Checked; } - set { Control.Checked = value; } - } - - #endregion - - void control_RadioSwitch(object sender, EventArgs e) - { - if (group != null) - { - foreach (RadioMenuItem item in group) - { - item.Checked = (item.ControlObject == sender); - } - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Menu/SeparatorMenuItem.cs b/Source/Eto.Platform.Windows/Forms/Menu/SeparatorMenuItem.cs deleted file mode 100644 index 10f7e2764c..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Menu/SeparatorMenuItem.cs +++ /dev/null @@ -1,43 +0,0 @@ -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; -using System; - -namespace Eto.Platform.Windows -{ - /// - /// Summary description for MenuBarHandler. - /// - public class SeparatorMenuItemHandler : MenuHandler, ISeparatorMenuItem - { - - public SeparatorMenuItemHandler() - { - Control = new SWF.ToolStripSeparator(); - } - - public string Text - { - get { return null; } - set { throw new NotSupportedException(); } - } - - public string ToolTip - { - get { return null; } - set { throw new NotSupportedException(); } - } - - public Keys Shortcut - { - get { return Keys.None; } - set { throw new NotSupportedException(); } - } - - public bool Enabled - { - get { return false; } - set { throw new NotSupportedException(); } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/MessageBoxHandler.cs b/Source/Eto.Platform.Windows/Forms/MessageBoxHandler.cs deleted file mode 100644 index 5ec38d8a90..0000000000 --- a/Source/Eto.Platform.Windows/Forms/MessageBoxHandler.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class MessageBoxHandler : WidgetHandler, IMessageBox - { - public string Text { get; set; } - - public string Caption { get; set; } - - public MessageBoxType Type { get; set; } - - public MessageBoxButtons Buttons { get; set; } - - public MessageBoxDefaultButton DefaultButton { get; set; } - - public DialogResult ShowDialog(Control parent) - { - var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null); - swf.Control c = (parent == null) ? null : (swf.Control)parent.ControlObject; - swf.DialogResult result = swf.MessageBox.Show(c, Text, caption, Convert(Buttons), Convert(Type), Convert(DefaultButton, Buttons)); - return result.ToEto(); - } - - public static swf.MessageBoxDefaultButton Convert(MessageBoxDefaultButton defaultButton, MessageBoxButtons buttons) - { - switch (defaultButton) - { - case MessageBoxDefaultButton.OK: - return swf.MessageBoxDefaultButton.Button1; - case MessageBoxDefaultButton.No: - case MessageBoxDefaultButton.Cancel: - return swf.MessageBoxDefaultButton.Button2; - case MessageBoxDefaultButton.Default: - switch (buttons) - { - case MessageBoxButtons.OK: - return swf.MessageBoxDefaultButton.Button1; - case MessageBoxButtons.YesNo: - case MessageBoxButtons.OKCancel: - return swf.MessageBoxDefaultButton.Button2; - case MessageBoxButtons.YesNoCancel: - return swf.MessageBoxDefaultButton.Button3; - default: - throw new NotSupportedException(); - } - default: - throw new NotSupportedException(); - } - } - - public static swf.MessageBoxButtons Convert(MessageBoxButtons buttons) - { - switch (buttons) - { - case MessageBoxButtons.OK: return swf.MessageBoxButtons.OK; - case MessageBoxButtons.OKCancel: return swf.MessageBoxButtons.OKCancel; - case MessageBoxButtons.YesNo: return swf.MessageBoxButtons.YesNo; - case MessageBoxButtons.YesNoCancel: return swf.MessageBoxButtons.YesNoCancel; - default: - throw new NotSupportedException(); - } - } - - public static swf.MessageBoxIcon Convert(MessageBoxType type) - { - switch (type) - { - case MessageBoxType.Error: return swf.MessageBoxIcon.Error; - case MessageBoxType.Warning: return swf.MessageBoxIcon.Warning; - case MessageBoxType.Information: return swf.MessageBoxIcon.Information; - case MessageBoxType.Question: return swf.MessageBoxIcon.Question; - default: - throw new NotSupportedException(); - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/MouseHandler.cs b/Source/Eto.Platform.Windows/Forms/MouseHandler.cs deleted file mode 100644 index 20a515d05b..0000000000 --- a/Source/Eto.Platform.Windows/Forms/MouseHandler.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Eto.Drawing; -using Eto.Forms; -using swf = System.Windows.Forms; - -namespace Eto.Platform.Windows.Forms -{ - public class MouseHandler : IMouse - { - public Widget Widget { get; set; } - - public void Initialize () - { - } - - public Eto.Generator Generator { get; set; } - - public PointF Position - { - get { return swf.Control.MousePosition.ToEto (); } - } - - public MouseButtons Buttons - { - get { return swf.Control.MouseButtons.ToEto (); } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/OpenFileDialog.cs b/Source/Eto.Platform.Windows/Forms/OpenFileDialog.cs deleted file mode 100644 index 643a7292b5..0000000000 --- a/Source/Eto.Platform.Windows/Forms/OpenFileDialog.cs +++ /dev/null @@ -1,26 +0,0 @@ -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.Windows -{ - public class OpenFileDialogHandler : WindowsFileDialog, IOpenFileDialog - { - public OpenFileDialogHandler() - { - Control = new SWF.OpenFileDialog(); - } - - public bool MultiSelect - { - get { return Control.Multiselect; } - set { Control.Multiselect = value; } - } - - public IEnumerable Filenames - { - get { return Control.FileNames; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/PixelLayoutHandler.cs b/Source/Eto.Platform.Windows/Forms/PixelLayoutHandler.cs deleted file mode 100644 index 6564f55ef2..0000000000 --- a/Source/Eto.Platform.Windows/Forms/PixelLayoutHandler.cs +++ /dev/null @@ -1,59 +0,0 @@ -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows -{ - public class PixelLayoutHandler : WindowsContainer, IPixelLayout - { - public PixelLayoutHandler() - { - Control = new swf.Panel - { - Size = sd.Size.Empty, - MinimumSize = sd.Size.Empty, - AutoSize = true, - AutoSizeMode = swf.AutoSizeMode.GrowAndShrink - }; - } - - public override void SetScale(bool xscale, bool yscale) - { - // do not call base class - pixel layout never scales the content - } - - public override Size GetPreferredSize(Size availableSize) - { - return Size.Max(base.GetPreferredSize(availableSize), Control.PreferredSize.ToEto()); - } - - public void Add(Control child, int x, int y) - { - var ctl = child.GetContainerControl(); - var pt = new sd.Point(x, y); - ctl.Dock = swf.DockStyle.None; - ctl.Location = pt; - Control.Controls.Add(ctl); - ctl.BringToFront(); - } - - public void Move(Control child, int x, int y) - { - var ctl = child.GetContainerControl(); - ctl.Location = new sd.Point(x, y); - } - - public void Remove(Control child) - { - var ctl = child.GetContainerControl(); - if (ctl.Parent == Control) - ctl.Parent = null; - } - - public void Update() - { - Control.PerformLayout(); - } - } -} \ No newline at end of file diff --git a/Source/Eto.Platform.Windows/Forms/Printing/PrintDialogHandler.cs b/Source/Eto.Platform.Windows/Forms/Printing/PrintDialogHandler.cs deleted file mode 100644 index cfe5f3d9a1..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Printing/PrintDialogHandler.cs +++ /dev/null @@ -1,63 +0,0 @@ -using swf = System.Windows.Forms; -using sdp = System.Drawing.Printing; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Printing -{ - public class PrintDialogHandler : WidgetHandler, IPrintDialog - { - PrintSettings printSettings; - - public PrintDialogHandler () - { - Control = new swf.PrintDialog { - UseEXDialog = true, - AllowSomePages = true, - PrinterSettings = PrintSettingsHandler.DefaultSettings () - }; - } - - public PrintDocument Document { get; set; } - - public DialogResult ShowDialog (Window parent) - { - swf.DialogResult result; - - Control.PrinterSettings = printSettings.ToSD (); - - if (parent != null) - result = Control.ShowDialog (((IWindowHandler)parent.Handler).Win32Window); - else - result = Control.ShowDialog (); - - return result.ToEto (); - } - - public PrintSettings PrintSettings - { - get - { - if (printSettings == null) - printSettings = Control.PrinterSettings.ToEto (Widget.Generator); - return printSettings; - } - set - { - printSettings = value; - Control.PrinterSettings = value.ToSD (); - } - } - - public bool AllowPageRange - { - get { return Control.AllowSomePages; } - set { Control.AllowSomePages = value; } - } - - public bool AllowSelection - { - get { return Control.AllowSelection; } - set { Control.AllowSelection = value; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Printing/PrintDocumentHandler.cs b/Source/Eto.Platform.Windows/Forms/Printing/PrintDocumentHandler.cs deleted file mode 100644 index ce82dd3d7c..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Printing/PrintDocumentHandler.cs +++ /dev/null @@ -1,78 +0,0 @@ -using swf = System.Windows.Forms; -using sdp = System.Drawing.Printing; -using Eto.Forms; -using Eto.Drawing; -using Eto.Platform.Windows.Drawing; - -namespace Eto.Platform.Windows.Forms.Printing -{ - public class PrintDocumentHandler : WidgetHandler, IPrintDocument - { - int currentPage; - PrintSettings printSettings; - - public PrintDocumentHandler () - { - Control = new sdp.PrintDocument { - PrinterSettings = new sdp.PrinterSettings { MinimumPage = 1, MaximumPage = 1, FromPage = 1, ToPage = 1 } - }; - } - - public void Print () - { - Control.Print (); - } - - public override void AttachEvent (string id) - { - switch (id) { - case PrintDocument.PrintingEvent: - Control.BeginPrint += (sender, e) => { - currentPage = 0; - Widget.OnPrinting (e); - }; - break; - case PrintDocument.PrintedEvent: - Control.EndPrint += (sender, e) => Widget.OnPrinted(e); - break; - case PrintDocument.PrintPageEvent: - Control.PrintPage += (sender, e) => { - var graphics = new Graphics (Widget.Generator, new GraphicsHandler (e.Graphics)); - - var args = new PrintPageEventArgs (graphics, e.PageBounds.Size.ToEto (), currentPage); - Widget.OnPrintPage (args); - currentPage++; - e.HasMorePages = currentPage < PageCount; - }; - break; - default: - base.AttachEvent (id); - break; - } - } - - public string Name - { - get { return Control.DocumentName; } - set { Control.DocumentName = value; } - } - - public int PageCount - { - get; set; - } - - public PrintSettings PrintSettings - { - get { - if (printSettings == null) - printSettings = Control.PrinterSettings.ToEto (Widget.Generator); - return printSettings; - } - set { - printSettings = value; - Control.PrinterSettings = value.ToSD (); - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/Printing/PrintSettingsHandler.cs b/Source/Eto.Platform.Windows/Forms/Printing/PrintSettingsHandler.cs deleted file mode 100644 index c2d6b3f3c2..0000000000 --- a/Source/Eto.Platform.Windows/Forms/Printing/PrintSettingsHandler.cs +++ /dev/null @@ -1,76 +0,0 @@ -using sdp = System.Drawing.Printing; -using swf = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms.Printing -{ - public class PrintSettingsHandler : WidgetHandler, IPrintSettings - { - public PrintSettingsHandler(sdp.PrinterSettings settings) - { - Control = settings; - } - - public static sdp.PrinterSettings DefaultSettings() - { - return new sdp.PrinterSettings { MinimumPage = 1, MaximumPage = 1, FromPage = 1, ToPage = 1, Copies = 1, Collate = true }; - } - - public PrintSettingsHandler() - { - Control = DefaultSettings(); - } - - public int Copies - { - get { return Control.Copies; } - set { Control.Copies = (short)value; } - } - - public Range MaximumPageRange - { - get { return new Range(Control.MinimumPage, Control.MaximumPage - Control.MinimumPage + 1); } - set - { - Control.MinimumPage = value.Start; - Control.MaximumPage = value.End; - } - } - - public Range SelectedPageRange - { - get { return new Range(Control.FromPage, Control.ToPage - Control.FromPage + 1); } - set - { - Control.FromPage = value.Start; - Control.ToPage = value.End; - } - } - - public PageOrientation Orientation - { - get { return Control.DefaultPageSettings.Landscape ? PageOrientation.Landscape : PageOrientation.Portrait; } - set { Control.DefaultPageSettings.Landscape = value == PageOrientation.Landscape; } - } - - public PrintSelection PrintSelection - { - get { return Control.PrintRange.ToEto(); } - set { Control.PrintRange = value.ToSDP(); } - } - - public bool Collate - { - get { return Control.Collate; } - set { Control.Collate = value; } - } - - // not supported by winforms - public bool Reverse - { - get; - set; - } - - } -} diff --git a/Source/Eto.Platform.Windows/Forms/SaveFileDialog.cs b/Source/Eto.Platform.Windows/Forms/SaveFileDialog.cs deleted file mode 100644 index 18bb4666bf..0000000000 --- a/Source/Eto.Platform.Windows/Forms/SaveFileDialog.cs +++ /dev/null @@ -1,16 +0,0 @@ -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class SaveFileDialogHandler : WindowsFileDialog, ISaveFileDialog - { - - public SaveFileDialogHandler() - { - Control = new SWF.SaveFileDialog(); - } - - } -} diff --git a/Source/Eto.Platform.Windows/Forms/ScreenHandler.cs b/Source/Eto.Platform.Windows/Forms/ScreenHandler.cs deleted file mode 100644 index 568eca3983..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ScreenHandler.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using Eto.Forms; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows.Forms -{ - public class ScreenHandler : WidgetHandler, IScreen - { - float scale; - - public ScreenHandler (swf.Screen screen) - { - this.Control = screen; - var form = new swf.Form (); - var graphics = form.CreateGraphics (); - scale = graphics.DpiY / 72f; - } - - public float RealScale - { - get { return scale; } - } - - public float Scale - { - get { return scale; } - } - - public RectangleF Bounds - { - get { return Control.Bounds.ToEto (); } - } - - public RectangleF WorkingArea - { - get { return Control.WorkingArea.ToEto (); } - } - - public int BitsPerPixel - { - get { return Control.BitsPerPixel; } - } - - public bool IsPrimary - { - get { return Control.Primary; } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/ScreensHandler.cs b/Source/Eto.Platform.Windows/Forms/ScreensHandler.cs deleted file mode 100644 index 34e0f7ca43..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ScreensHandler.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Eto.Forms; -using System.Collections.Generic; -using sd = System.Drawing; -using swf = System.Windows.Forms; - -namespace Eto.Platform.Windows.Forms -{ - public class ScreensHandler : IScreens - { - public void Initialize () - { - } - - public Widget Widget { get; set; } - - public Eto.Generator Generator { get; set; } - - public IEnumerable Screens - { - get - { - foreach (var screen in swf.Screen.AllScreens) - { - yield return new Screen(Generator, new ScreenHandler(screen)); - } - } - } - - public Screen PrimaryScreen - { - get - { - var screen = swf.Screen.PrimaryScreen; - return new Screen (Generator, new ScreenHandler (screen)); - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/SelectFolderDialogHandler.cs b/Source/Eto.Platform.Windows/Forms/SelectFolderDialogHandler.cs deleted file mode 100644 index 18619d2340..0000000000 --- a/Source/Eto.Platform.Windows/Forms/SelectFolderDialogHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using SWF = System.Windows.Forms; -using SD = System.Drawing; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms -{ - public class SelectFolderDialogHandler : WidgetHandler, ISelectFolderDialog - { - public SelectFolderDialogHandler () - { - Control = new SWF.FolderBrowserDialog(); - } - - - public DialogResult ShowDialog (Window parent) - { - SWF.DialogResult dr; - if (parent != null) dr = Control.ShowDialog((SWF.IWin32Window)parent.ControlObject); - else dr = Control.ShowDialog(); - return dr.ToEto (); - } - - public string Title { - get { - return Control.Description; - } - set { - Control.Description = value; - } - } - - public string Directory { - get { - return Control.SelectedPath; - } - set { - Control.SelectedPath = value; - } - } -} -} - diff --git a/Source/Eto.Platform.Windows/Forms/TableLayoutHandler.cs b/Source/Eto.Platform.Windows/Forms/TableLayoutHandler.cs deleted file mode 100644 index f6c3ec5cae..0000000000 --- a/Source/Eto.Platform.Windows/Forms/TableLayoutHandler.cs +++ /dev/null @@ -1,271 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using Eto.Drawing; -using System.Linq; - -namespace Eto.Platform.Windows -{ - public class TableLayoutHandler : WindowsContainer, ITableLayout - { - Size spacing; - Control[,] views; - bool[] columnScale; - int lastColumnScale; - bool[] rowScale; - int lastRowScale; - - protected override bool SetMinimumSize(Size size) - { - // ensure that our width doesn't get smaller than the non-scaled child controls - // to make it so the child controls are left-justified when the container - // is smaller than all the children - var widths = Control.GetColumnWidths(); - var heights = Control.GetRowHeights(); - var curSize = Size.Empty; - for (int i = 0; i < widths.Length; i++) - { - if (!columnScale[i] && i != lastColumnScale) - curSize.Width += widths[i]; - } - for (int i = 0; i < heights.Length; i++) - { - if (!rowScale[i] && i != lastRowScale) - curSize.Height += heights[i]; - } - size = Size.Max(size, curSize); - return base.SetMinimumSize(size); - } - - public TableLayoutHandler() - { - Control = new swf.TableLayoutPanel - { - Margin = swf.Padding.Empty, - Dock = swf.DockStyle.Fill, - Size = sd.Size.Empty, - MinimumSize = sd.Size.Empty, - AutoSize = true, - AutoSizeMode = swf.AutoSizeMode.GrowAndShrink - }; - this.Spacing = TableLayout.DefaultSpacing; - this.Padding = TableLayout.DefaultPadding; - Control.SuspendLayout(); - } - - public override void OnLoad(EventArgs e) - { - base.OnLoad(e); - Control.ResumeLayout(); - } - - public override void OnUnLoad(EventArgs e) - { - base.OnUnLoad(e); - Control.SuspendLayout(); - } - - public void Update() - { - Control.PerformLayout(); - } - - public Size Spacing - { - get - { - return spacing; - } - set - { - spacing = value; - var newpadding = new swf.Padding(0, 0, spacing.Width, spacing.Height); - foreach (swf.Control control in Control.Controls) - { - control.Margin = newpadding; - } - } - } - - swf.Padding GetPadding(int x, int y) - { - return new swf.Padding( - x == 0 ? 0 : spacing.Width / 2, - y == 0 ? 0 : spacing.Height / 2, - x == views.GetLength(0) - 1 ? 0 : (spacing.Width + 1) / 2, - y == views.GetLength(1) - 1 ? 0 : (spacing.Height + 1) / 2); - } - - public Padding Padding - { - get { return Control.Padding.ToEto(); } - set { Control.Padding = value.ToSWF(); } - } - - void SetScale(Control control, int x, int y) - { - var xscale = XScale && (x == lastColumnScale || columnScale[x]); - var yscale = YScale && (y == lastRowScale || rowScale[y]); - control.SetScale(xscale, yscale); - } - - public override void SetScale(bool xscale, bool yscale) - { - base.SetScale(xscale, yscale); - for (int y = 0; y < rowScale.Length; y++) - { - var ys = yscale && (y == lastRowScale || rowScale[y]); - for (int x = 0; x < columnScale.Length; x++) - { - var xs = xscale && (x == lastColumnScale || columnScale[x]); - var control = views[x,y]; - if (control != null) - control.SetScale(xs, ys); - } - } - } - - public void Add(Control child, int x, int y) - { - if (Widget.Loaded) - SuspendLayout(); - - var old = views[x, y]; - if (old != null) - { - old.GetContainerControl().Parent = null; - } - views[x, y] = child; - if (child != null) - { - var childControl = child.GetContainerControl(); - childControl.Parent = null; - childControl.Dock = child.GetWindowsHandler().DockStyle; - childControl.Margin = GetPadding(x, y); - SetScale(child, x, y); - - Control.Controls.Add(childControl, x, y); - } - if (Widget.Loaded) - ResumeLayout(); - } - - public void Move(Control child, int x, int y) - { - if (Widget.Loaded) - SuspendLayout(); - swf.Control childControl = child.GetContainerControl(); - Control.SetCellPosition(childControl, new swf.TableLayoutPanelCellPosition(x, y)); - SetScale(child, x, y); - if (Widget.Loaded) - ResumeLayout(); - } - - public void Remove(Control child) - { - swf.Control childControl = child.GetContainerControl(); - if (childControl.Parent == Control) - { - childControl.Parent = null; - for (int y = 0; y < views.GetLength(0); y++) - for (int x = 0; x < views.GetLength(1); x++) - { - if (object.ReferenceEquals(views[y, x], child)) views[y, x] = null; - } - } - } - - public void CreateControl(int cols, int rows) - { - views = new Control[cols, rows]; - columnScale = new bool[cols]; - lastColumnScale = cols - 1; - rowScale = new bool[rows]; - lastRowScale = rows - 1; - Control.RowCount = rows; - Control.ColumnCount = cols; - Control.ColumnStyles.Clear(); - Control.RowStyles.Clear(); - for (int i = 0; i < cols; i++) - Control.ColumnStyles.Add(GetColumnStyle(i)); - for (int i = 0; i < rows; i++) - Control.RowStyles.Add(GetRowStyle(i)); - } - - swf.ColumnStyle GetColumnStyle(int column) - { - var scale = columnScale[column] || column == lastColumnScale; - if (scale) - return new swf.ColumnStyle(swf.SizeType.Percent, 1f); - return new swf.ColumnStyle(swf.SizeType.AutoSize); - } - - swf.RowStyle GetRowStyle(int row) - { - var scale = rowScale[row] || row == lastRowScale; - if (scale) - return new swf.RowStyle(swf.SizeType.Percent, 1f); - return new swf.RowStyle(swf.SizeType.AutoSize); - } - - void ResetColumnScale(int column) - { - var xscale = columnScale[column] || column == lastColumnScale; - for (int i = 0; i < rowScale.Length; i++) - { - var control = views[column, i]; - control.SetScale(xscale, rowScale[i]); - } - } - - void ResetRowScale(int row) - { - var yscale = rowScale[row] || row == lastRowScale; - for (int i = 0; i < columnScale.Length; i++) - { - var control = views[i, row]; - control.SetScale(columnScale[i], yscale); - } - } - - public void SetColumnScale(int column, bool scale) - { - columnScale[column] = scale; - var prev = lastColumnScale; - lastColumnScale = columnScale.Any(r => r) ? -1 : columnScale.Length - 1; - Control.ColumnStyles[column] = GetColumnStyle(column); - ResetColumnScale(column); - if (prev != lastColumnScale && column != columnScale.Length - 1) - { - Control.ColumnStyles[columnScale.Length - 1] = GetColumnStyle(columnScale.Length - 1); - ResetColumnScale(columnScale.Length - 1); - } - } - - public bool GetColumnScale(int column) - { - return columnScale[column]; - } - - public void SetRowScale(int row, bool scale) - { - rowScale[row] = scale; - var prev = lastRowScale; - lastRowScale = rowScale.Any(r => r) ? -1 : rowScale.Length - 1; - Control.RowStyles[row] = GetRowStyle(row); - ResetRowScale(row); - if (prev != lastRowScale && row != rowScale.Length - 1) - { - Control.RowStyles[rowScale.Length - 1] = GetRowStyle(rowScale.Length - 1); - ResetRowScale(rowScale.Length - 1); - } - ResetRowScale(row); - } - - public bool GetRowScale(int row) - { - return rowScale[row]; - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/ToolBar/ButtonToolItemHandler.cs b/Source/Eto.Platform.Windows/Forms/ToolBar/ButtonToolItemHandler.cs deleted file mode 100644 index 37b52e29e6..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ToolBar/ButtonToolItemHandler.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class ButtonToolItemHandler : ToolItemHandler, IButtonToolItem - { - readonly SWF.ToolStripButton control; - - public ButtonToolItemHandler() - { - control = new SWF.ToolStripButton(); - control.Tag = this; - control.Click += control_Click; - Control = control; - } - - void control_Click(object sender, EventArgs e) - { - Widget.OnClick(EventArgs.Empty); - } - - public override bool Enabled - { - get { return control.Enabled; } - set { control.Enabled = value; } - } - - public override void CreateControl(ToolBarHandler handler, int index) - { - handler.Control.Items.Insert(index, control); - } - - public override void InvokeButton() - { - Widget.OnClick(EventArgs.Empty); - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/ToolBar/CheckToolItemHandler.cs b/Source/Eto.Platform.Windows/Forms/ToolBar/CheckToolItemHandler.cs deleted file mode 100644 index 6316654425..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ToolBar/CheckToolItemHandler.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; - -namespace Eto.Platform.Windows -{ - public class CheckToolItemHandler : ToolItemHandler, ICheckToolItem - { - readonly SWF.ToolStripButton control; - - public CheckToolItemHandler() - { - control = new SWF.ToolStripButton(); - control.Tag = this; - control.Click += control_Click; - Control = control; - } - - void control_Click(object sender, EventArgs e) - { - Widget.OnClick(EventArgs.Empty); - } - - public bool Checked - { - get { return control.Checked; } - set { control.Checked = value; } - } - - public override void CreateControl(ToolBarHandler handler, int index) - { - handler.Control.Items.Insert(index, control); - } - - - public override void InvokeButton() - { - Widget.OnClick(EventArgs.Empty); - } - - public override bool Enabled - { - get { return control.Enabled; } - set { control.Enabled = value; } - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/ToolBar/ToolBarHandler.cs b/Source/Eto.Platform.Windows/Forms/ToolBar/ToolBarHandler.cs deleted file mode 100644 index a5eaa41322..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ToolBar/ToolBarHandler.cs +++ /dev/null @@ -1,109 +0,0 @@ -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Forms; -using System; - -namespace Eto.Platform.Windows -{ - public class ToolBarHandler : WidgetHandler, IToolBar - { - ToolBarDock dock = ToolBarDock.Top; - - public ToolBarHandler() - { - Control = new ToolStripEx(); - Control.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.StackWithOverflow; - Control.AutoSize = true; - } - - public ToolBarDock Dock - { - get { return dock; } - set { dock = value; } - } - - public void AddButton(ToolItem item, int index) - { - ((IToolBarItemHandler)item.Handler).CreateControl(this, index); - } - - public void RemoveButton(ToolItem item) - { - Control.Items.Remove((SWF.ToolStripItem)item.ControlObject); - } - - public ToolBarTextAlign TextAlign - { - get - { - /*switch (control.TextAlign) - { - case SWF.ToolBarTextAlign.Right: - return ToolBarTextAlign.Right; - default: - case SWF.ToolBarTextAlign.Underneath: - return ToolBarTextAlign.Underneath; - } - */ - return ToolBarTextAlign.Underneath; - } - set - { - switch (value) - { - case ToolBarTextAlign.Right: - //control.TextAlign = SWF.ToolBarTextAlign.Right; - break; - case ToolBarTextAlign.Underneath: - //control.TextAlign = SWF.ToolBarTextAlign.Underneath; - break; - default: - throw new NotSupportedException(); - } - } - } - - public void Clear() - { - Control.Items.Clear(); - } - } - - /// - /// This class adds on to the functionality provided in System.Windows.Forms.ToolStrip. - /// - /// - public class ToolStripEx - : SWF.ToolStrip - { - /// - /// Gets or sets whether the ToolStripEx honors item clicks when its containing form does - /// not have input focus. - /// - /// - /// Default value is false, which is the same behavior provided by the base ToolStrip class. - /// - public bool ClickThrough { get; set; } - - protected override void WndProc(ref SWF.Message m) - { - base.WndProc(ref m); - if (this.ClickThrough && - m.Msg == NativeConstants.WM_MOUSEACTIVATE && - m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT) - m.Result = (IntPtr)NativeConstants.MA_ACTIVATE; - } - } - - internal sealed class NativeConstants - { - private NativeConstants() - { - } - internal const uint WM_MOUSEACTIVATE = 0x21; - internal const uint MA_ACTIVATE = 1; - internal const uint MA_ACTIVATEANDEAT = 2; - internal const uint MA_NOACTIVATE = 3; - internal const uint MA_NOACTIVATEANDEAT = 4; - } -} diff --git a/Source/Eto.Platform.Windows/Forms/ToolBar/ToolItemHandler.cs b/Source/Eto.Platform.Windows/Forms/ToolBar/ToolItemHandler.cs deleted file mode 100644 index b42ffada6a..0000000000 --- a/Source/Eto.Platform.Windows/Forms/ToolBar/ToolItemHandler.cs +++ /dev/null @@ -1,64 +0,0 @@ -using SWF = System.Windows.Forms; -using SD = System.Drawing; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows -{ - public interface IToolBarItemHandler - { - void CreateControl(ToolBarHandler handler, int index); - } - - public abstract class ToolItemHandler : WidgetHandler, IToolItem, IToolBarItemHandler - where TControl : SWF.ToolStripItem - where TWidget : ToolItem - { - Image image; - int imageSize = 16; - - public abstract void CreateControl(ToolBarHandler handler, int index); - - public virtual void InvokeButton() - { - } - - public int ImageSize - { - get { return imageSize; } - set - { - imageSize = value; - Control.Image = image.ToSD(imageSize); - } - } - - public string Text - { - get { return Control.Text; } - set { Control.Text = value; } - } - - public string ToolTip - { - get { return Control.ToolTipText; } - set { Control.ToolTipText = value; } - } - - public Image Image - { - get { return image; } - set - { - image = value; - Control.Image = image.ToSD(imageSize); - } - } - - public abstract bool Enabled { get; set; } - - public void CreateFromCommand(Command command) - { - } - } -} diff --git a/Source/Eto.Platform.Windows/Forms/UITimerHandler.cs b/Source/Eto.Platform.Windows/Forms/UITimerHandler.cs deleted file mode 100644 index 857e50c5c5..0000000000 --- a/Source/Eto.Platform.Windows/Forms/UITimerHandler.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using Eto.Forms; - -namespace Eto.Platform.Windows.Forms -{ - public class UITimerHandler : WidgetHandler, IUITimer - { - //bool enabled; - - public UITimerHandler () - { - Control = new System.Windows.Forms.Timer (); - Control.Tick += (sender, e) => Widget.OnElapsed(EventArgs.Empty); - } - - public void Start () - { - //enabled = true; - Control.Start (); - } - - public void Stop () - { - //enabled = false; - Control.Stop (); - } - - public double Interval { - get { - return ((double)Control.Interval) / 1000.0; - } - set { - Control.Interval = (int)(value * 1000.0); - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Forms/WindowsContainer.cs b/Source/Eto.Platform.Windows/Forms/WindowsContainer.cs deleted file mode 100644 index 5b42aab06c..0000000000 --- a/Source/Eto.Platform.Windows/Forms/WindowsContainer.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using sd = System.Drawing; -using swf = System.Windows.Forms; -using Eto.Forms; -using Eto.Drawing; - -namespace Eto.Platform.Windows -{ - - public abstract class WindowsContainer : WindowsControl, IContainer - where TControl : swf.Control - where TWidget : Container - { - Size minimumSize; - - protected WindowsContainer() - { - EnableRedrawDuringSuspend = false; - } - - public bool RecurseToChildren { get { return true; } } - - public override Size? DefaultSize - { - get - { - var min = ContainerControl.MinimumSize; - ContainerControl.MinimumSize = sd.Size.Empty; - var size = ContainerControl.GetPreferredSize(Size.MaxValue.ToSD()).ToEto(); - ContainerControl.MinimumSize = min; - return size; - } - } - - public bool EnableRedrawDuringSuspend { get; set; } - - public override Size GetPreferredSize(Size availableSize) - { - var size = base.GetPreferredSize(availableSize); - return Size.Max(minimumSize, size); - } - - public Size MinimumSize - { - get { return minimumSize; } - set - { - minimumSize = value; - SetMinimumSize(); - } - } - - bool restoreRedraw; - - public override void SuspendLayout() - { - base.SuspendLayout(); - if (!EnableRedrawDuringSuspend && Control.IsHandleCreated && EtoEnvironment.Platform.IsWindows) - { - restoreRedraw = (int)Win32.SendMessage(Control.Handle, Win32.WM.SETREDRAW, IntPtr.Zero, IntPtr.Zero) == 0; - } - } - - public override void ResumeLayout() - { - base.ResumeLayout(); - if (restoreRedraw) - { - Win32.SendMessage(Control.Handle, Win32.WM.SETREDRAW, new IntPtr(1), IntPtr.Zero); - Control.Refresh(); - restoreRedraw = false; - } - } - } -} diff --git a/Source/Eto.Platform.Windows/Generator.cs b/Source/Eto.Platform.Windows/Generator.cs deleted file mode 100644 index 897a0c5ecf..0000000000 --- a/Source/Eto.Platform.Windows/Generator.cs +++ /dev/null @@ -1,124 +0,0 @@ -using Eto.Forms; -using Eto.Drawing; -using Eto.IO; -using SD = System.Drawing; -using SWF = System.Windows.Forms; -using Eto.Platform.Windows.Drawing; -using Eto.Platform.Windows.Forms; -using Eto.Platform.Windows.Forms.Printing; -using Eto.Platform.Windows.Forms.Controls; -using Eto.Platform.Windows.IO; -using Eto.Forms.ThemedControls; - -namespace Eto.Platform.Windows -{ - public class Generator : Eto.Generator - { - public override string ID { get { return Generators.Windows; } } - - static readonly EmbeddedAssemblyLoader embeddedAssemblies = EmbeddedAssemblyLoader.Register("Eto.Platform.Windows.CustomControls.Assemblies"); - - public Generator() - { - AddTo(this); - } - - public static void AddTo(Eto.Generator g) - { - // Drawing - g.Add(() => new BitmapHandler()); - g.Add(() => new FontFamilyHandler()); - g.Add(() => new FontHandler()); - g.Add(() => new FontsHandler()); - g.Add(() => new GraphicsHandler()); - g.Add(() => new GraphicsPathHandler()); - g.Add(() => new IconHandler()); - g.Add(() => new IndexedBitmapHandler()); - g.Add(() => new MatrixHandler()); - g.Add(() => new PenHandler()); - g.Add(() => new SolidBrushHandler()); - g.Add(() => new TextureBrushHandler()); - g.Add(() => new LinearGradientBrushHandler()); - - // Forms.Cells - g.Add(() => new CheckBoxCellHandler()); - g.Add(() => new ComboBoxCellHandler()); - g.Add(() => new ImageTextCellHandler()); - g.Add(() => new ImageViewCellHandler()); - g.Add(() => new TextBoxCellHandler()); - - // Forms.Controls - g.Add(() => new ButtonHandler()); - g.Add(() => new CheckBoxHandler()); - g.Add(() => new ComboBoxHandler()); - g.Add(() => new DateTimePickerHandler()); - g.Add(() => new DrawableHandler()); - g.Add(() => new GridColumnHandler()); - g.Add(() => new GridViewHandler()); - g.Add(() => new GroupBoxHandler()); - g.Add(() => new ImageViewHandler()); - g.Add(() => new LabelHandler()); - g.Add(() => new ListBoxHandler()); - g.Add(() => new NumericUpDownHandler()); - g.Add(() => new PanelHandler()); - g.Add(() => new PasswordBoxHandler()); - g.Add(() => new ProgressBarHandler()); - g.Add(() => new RadioButtonHandler()); - g.Add(() => new ScrollableHandler()); - g.Add(() => new SearchBoxHandler()); - g.Add(() => new SliderHandler()); - g.Add(() => new ThemedSpinnerHandler()); - g.Add(() => new SplitterHandler()); - g.Add(() => new TabControlHandler()); - g.Add(() => new TabPageHandler()); - g.Add(() => new TextAreaHandler()); - g.Add(() => new TextBoxHandler()); - g.Add(() => new TreeGridViewHandler()); - g.Add(() => new TreeViewHandler()); - g.Add(() => new WebViewHandler()); - g.Add(() => new ScreensHandler()); - - // Forms.Menu - g.Add(() => new CheckMenuItemHandler()); - g.Add(() => new ContextMenuHandler()); - g.Add(() => new ButtonMenuItemHandler()); - g.Add(() => new MenuBarHandler()); - g.Add(() => new RadioMenuItemHandler()); - g.Add(() => new SeparatorMenuItemHandler()); - - // Forms.Printing - g.Add(() => new PrintDialogHandler()); - g.Add(() => new PrintDocumentHandler()); - g.Add(() => new PrintSettingsHandler()); - - // Forms.ToolBar - g.Add(() => new CheckToolItemHandler()); - g.Add(() => new SeparatorToolBarItemHandler()); - g.Add(() => new ButtonToolItemHandler()); - g.Add(() => new ToolBarHandler()); - - // Forms - g.Add(() => new ApplicationHandler()); - g.Add(() => new ClipboardHandler()); - g.Add(() => new ColorDialogHandler()); - g.Add(() => new CursorHandler()); - g.Add(() => new DialogHandler()); - g.Add(() => new FontDialogHandler()); - g.Add(() => new FormHandler()); - g.Add(() => new MessageBoxHandler()); - g.Add(() => new OpenFileDialogHandler()); - g.Add(() => new PixelLayoutHandler()); - g.Add(() => new SaveFileDialogHandler()); - g.Add(() => new SelectFolderDialogHandler()); - g.Add(() => new TableLayoutHandler()); - g.Add(() => new UITimerHandler()); - g.Add(() => new MouseHandler()); - - // IO - g.Add(() => new SystemIconsHandler()); - - // General - g.Add(() => new EtoEnvironmentHandler()); - } - } -} diff --git a/Source/Eto.Platform.Windows/IO/SystemIcons.cs b/Source/Eto.Platform.Windows/IO/SystemIcons.cs deleted file mode 100644 index 2fadad3dbc..0000000000 --- a/Source/Eto.Platform.Windows/IO/SystemIcons.cs +++ /dev/null @@ -1,68 +0,0 @@ -using SD = System.Drawing; -using Eto.Drawing; -using Eto.IO; -using Eto.Platform.Windows.Drawing; -using System; - -namespace Eto.Platform.Windows.IO -{ - public class SystemIconsHandler : WidgetHandler, ISystemIcons - { - - #region ISystemIcons Members - - public Icon GetFileIcon(string fileName, IconSize size) - { - ShellIcon.IconSize iconSize; - switch (size) - { - case IconSize.Large: - iconSize = ShellIcon.IconSize.Large; - break; - case IconSize.Small: - iconSize = ShellIcon.IconSize.Small; - break; - default: - throw new NotSupportedException(); - } - - SD.Icon icon = ShellIcon.GetFileIcon(fileName, iconSize, false); - return new Icon(Widget.Generator, new IconHandler(icon)); - } - - public Icon GetStaticIcon(StaticIconType type, IconSize size) - { - ShellIcon.IconSize iconSize; - switch (size) - { - case IconSize.Large: - iconSize = ShellIcon.IconSize.Large; - break; - case IconSize.Small: - iconSize = ShellIcon.IconSize.Small; - break; - default: - throw new NotSupportedException(); - } - - ShellIcon.FolderType folderType; - switch (type) - { - case StaticIconType.OpenDirectory: - folderType = ShellIcon.FolderType.Open; - break; - case StaticIconType.CloseDirectory: - folderType = ShellIcon.FolderType.Closed; - break; - default: - throw new NotSupportedException(); - } - - SD.Icon icon = ShellIcon.GetFolderIcon(iconSize, folderType); - return new Icon(Widget.Generator, new IconHandler(icon)); - } - - #endregion - - } -} diff --git a/Source/Eto.Platform.Windows/KeyMap.cs b/Source/Eto.Platform.Windows/KeyMap.cs deleted file mode 100644 index 5229fbf733..0000000000 --- a/Source/Eto.Platform.Windows/KeyMap.cs +++ /dev/null @@ -1,149 +0,0 @@ -using swf = System.Windows.Forms; -using Eto.Forms; -using System.Collections.Generic; - -namespace Eto.Platform.Windows -{ - public static class KeyMap - { - static readonly Dictionary keymap = new Dictionary(); - static readonly Dictionary inverse = new Dictionary(); - - public static Keys ToEto (this swf.Keys keyData) - { - // convert the modifiers - Keys modifiers = Keys.None; - - // Shift - if ((keyData & swf.Keys.Shift) == swf.Keys.Shift) - modifiers |= Keys.Shift; - - // Control - if ((keyData & swf.Keys.Control) == swf.Keys.Control) - modifiers |= Keys.Control; - - // Alt - if ((keyData & swf.Keys.Alt) == swf.Keys.Alt) - modifiers |= Keys.Alt; - - var keyCode = Find(keyData & swf.Keys.KeyCode); - - return keyCode | modifiers; - } - - static Keys Find(swf.Keys key) - { - Keys mapped; - return keymap.TryGetValue(key, out mapped) ? mapped : Keys.None; - } - - public static swf.Keys Find(Keys key) - { - swf.Keys mapped; - return inverse.TryGetValue(key, out mapped) ? mapped : swf.Keys.None; - } - - public static swf.Keys ToSWF (this Keys key) - { - var code = key & Keys.KeyMask; - swf.Keys modifiers = swf.Keys.None; - - // convert the modifiers - // Shift - if (key.HasFlag(Keys.Shift)) - modifiers |= swf.Keys.Shift; - - // Control - if (key.HasFlag(Keys.Control)) - modifiers |= swf.Keys.Control; - - // Alt - if (key.HasFlag(Keys.Alt)) - modifiers |= swf.Keys.Alt; - - return Find (code) | modifiers; - } - - static KeyMap() - { - keymap.Add(swf.Keys.A, Keys.A); - keymap.Add(swf.Keys.B, Keys.B); - keymap.Add(swf.Keys.C, Keys.C); - keymap.Add(swf.Keys.D, Keys.D); - keymap.Add(swf.Keys.E, Keys.E); - keymap.Add(swf.Keys.F, Keys.F); - keymap.Add(swf.Keys.G, Keys.G); - keymap.Add(swf.Keys.H, Keys.H); - keymap.Add(swf.Keys.I, Keys.I); - keymap.Add(swf.Keys.J, Keys.J); - keymap.Add(swf.Keys.K, Keys.K); - keymap.Add(swf.Keys.L, Keys.L); - keymap.Add(swf.Keys.M, Keys.M); - keymap.Add(swf.Keys.N, Keys.N); - keymap.Add(swf.Keys.O, Keys.O); - keymap.Add(swf.Keys.P, Keys.P); - keymap.Add(swf.Keys.Q, Keys.Q); - keymap.Add(swf.Keys.R, Keys.R); - keymap.Add(swf.Keys.S, Keys.S); - keymap.Add(swf.Keys.T, Keys.T); - keymap.Add(swf.Keys.U, Keys.U); - keymap.Add(swf.Keys.V, Keys.V); - keymap.Add(swf.Keys.W, Keys.W); - keymap.Add(swf.Keys.X, Keys.X); - keymap.Add(swf.Keys.Y, Keys.Y); - keymap.Add(swf.Keys.Z, Keys.Z); - keymap.Add(swf.Keys.F1, Keys.F1); - keymap.Add(swf.Keys.F2, Keys.F2); - keymap.Add(swf.Keys.F3, Keys.F3); - keymap.Add(swf.Keys.F4, Keys.F4); - keymap.Add(swf.Keys.F5, Keys.F5); - keymap.Add(swf.Keys.F6, Keys.F6); - keymap.Add(swf.Keys.F7, Keys.F7); - keymap.Add(swf.Keys.F8, Keys.F8); - keymap.Add(swf.Keys.F9, Keys.F9); - keymap.Add(swf.Keys.F10, Keys.F10); - keymap.Add(swf.Keys.F11, Keys.F11); - keymap.Add(swf.Keys.F12, Keys.F12); - keymap.Add(swf.Keys.D0, Keys.D0); - keymap.Add(swf.Keys.D1, Keys.D1); - keymap.Add(swf.Keys.D2, Keys.D2); - keymap.Add(swf.Keys.D3, Keys.D3); - keymap.Add(swf.Keys.D4, Keys.D4); - keymap.Add(swf.Keys.D5, Keys.D5); - keymap.Add(swf.Keys.D6, Keys.D6); - keymap.Add(swf.Keys.D7, Keys.D7); - keymap.Add(swf.Keys.D8, Keys.D8); - keymap.Add(swf.Keys.D9, Keys.D9); - keymap.Add(swf.Keys.Space, Keys.Space); - keymap.Add(swf.Keys.Up, Keys.Up); - keymap.Add(swf.Keys.Down, Keys.Down); - keymap.Add(swf.Keys.Left, Keys.Left); - keymap.Add(swf.Keys.Right, Keys.Right); - keymap.Add(swf.Keys.PageDown, Keys.PageDown); - keymap.Add(swf.Keys.PageUp, Keys.PageUp); - keymap.Add(swf.Keys.Home, Keys.Home); - keymap.Add(swf.Keys.End, Keys.End); - keymap.Add(swf.Keys.Alt, Keys.Alt); - keymap.Add(swf.Keys.Control, Keys.Control); - keymap.Add(swf.Keys.Shift, Keys.Shift); - keymap.Add(swf.Keys.Menu, Keys.Menu); - keymap.Add(swf.Keys.LWin, Keys.Application); - keymap.Add(swf.Keys.RWin, Keys.Application); - keymap.Add(swf.Keys.Escape, Keys.Escape); - keymap.Add(swf.Keys.Delete, Keys.Delete); - keymap.Add(swf.Keys.Back, Keys.Backspace); - keymap.Add(swf.Keys.Divide, Keys.Divide); - keymap.Add(swf.Keys.Enter, Keys.Enter); - keymap.Add(swf.Keys.Insert, Keys.Insert); - keymap.Add(swf.Keys.OemPeriod, Keys.Period); - keymap.Add(swf.Keys.Tab, Keys.Tab); - keymap.Add(swf.Keys.Apps, Keys.ContextMenu); - - foreach (var entry in keymap) - { - inverse[entry.Value] = entry.Key; - } - } - } -} - diff --git a/Source/Eto.Platform.Windows/Properties/AssemblyInfo.cs b/Source/Eto.Platform.Windows/Properties/AssemblyInfo.cs deleted file mode 100644 index 98c73eaa68..0000000000 --- a/Source/Eto.Platform.Windows/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,4 +0,0 @@ -using System.Reflection; - -[assembly: AssemblyTitle("Eto.Forms - Windows Forms Platform")] -[assembly: AssemblyDescription("Windows Forms Platform for the Eto.Forms UI Framework")] diff --git a/Source/Eto.Platform.Windows/Win32.cs b/Source/Eto.Platform.Windows/Win32.cs deleted file mode 100644 index d5f854f186..0000000000 --- a/Source/Eto.Platform.Windows/Win32.cs +++ /dev/null @@ -1,199 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Windows.Forms; - -namespace Eto.Platform -{ - static class Win32 - { - // Analysis disable InconsistentNaming - - [Flags] - public enum SWP : uint - { - ASYNCWINDOWPOS = 0x4000, - DEFERERASE = 0x2000, - DRAWFRAME = 0x0020, - FRAMECHANGED = 0x0020, - HIDEWINDOW = 0x0080, - NOACTIVATE = 0x0010, - NOCOPYBITS = 0x0100, - NOMOVE = 0x0002, - NOOWNERZORDER = 0x0200, - NOREDRAW = 0x0008, - NOREPOSITION = 0x0200, - NOSENDCHANGING = 0x0400, - NOSIZE = 0x0001, - NOZORDER = 0x0004, - SHOWWINDOW = 0x0040, - } - - public static readonly IntPtr HWND_TOPMOST = new IntPtr (-1); - public static readonly IntPtr HWND_NOTOPMOST = new IntPtr (-2); - public static readonly IntPtr HWND_TOP = new IntPtr (0); - public static readonly IntPtr HWND_BOTTOM = new IntPtr (1); - - public enum GWL - { - EXSTYLE = -20, - HINSTANCE = -6, - ID = -12, - STYLE = -16, - USERDATA = -21, - WNDPROC = -4} - - ; - - [Flags] - public enum WS : uint - { - BORDER = 0x00800000, - CAPTION = 0x00C00000, - CHILD = 0x40000000, - CHILDWINDOW = 0x40000000, - CLIPCHILDREN = 0x02000000, - CLIPSIBLINGS = 0x04000000, - DISABLED = 0x08000000, - DLGFRAME = 0x00400000, - GROUP = 0x00020000, - HSCROLL = 0x00100000, - ICONIC = 0x20000000, - MAXIMIZE = 0x01000000, - MAXIMIZEBOX = 0x00010000, - MINIMIZE = 0x20000000, - MINIMIZEBOX = 0x00020000, - OVERLAPPED = 0x00000000, - OVERLAPPEDWINDOW = OVERLAPPED | CAPTION | SYSMENU | THICKFRAME | MINIMIZEBOX | MAXIMIZEBOX, - POPUP = 0x80000000, - POPUPWINDOW = POPUP | BORDER | SYSMENU, - SIZEBOX = 0x00040000, - SYSMENU = 0x00080000, - TABSTOP = 0x00010000, - THICKFRAME = 0x00040000, - TILED = 0x00000000, - TILEDWINDOW = OVERLAPPED | CAPTION | SYSMENU | THICKFRAME | MINIMIZEBOX | MAXIMIZEBOX, - VISIBLE = 0x10000000, - VSCROLL = 0x00200000 - } - - [Flags] - public enum WS_EX : uint - { - TOOLWINDOW = 0x80 - } - - public enum WM - { - SETREDRAW = 0xB, - - GETDLGCODE = 0x0087, - - KEYDOWN = 0x0100, - KEYUP = 0x0101, - CHAR = 0x0102, - SYSKEYDOWN = 0x0104, - SYSKEYUP = 0x0105, - SYSCHAR = 0x0106, - IME_CHAR = 0x0286, - - MOUSEMOVE = 0x0200, - LBUTTONDOWN = 0x0201, - LBUTTONUP = 0x0202, - LBUTTONDBLCLK = 0x0203, - RBUTTONDOWN = 0x0204, - RBUTTONUP = 0x0205, - RBUTTONDBLCLK = 0x0206, - MBUTTONDOWN = 0x0207, - MBUTTONUP = 0x0208, - MBUTTONDBLCLK = 0x0209, - MOUSEWHEEL = 0x20A, - } - - public static ushort LOWORD (IntPtr word) { return (ushort)(((long)word) & 0xffff); } - - public static ushort LOWORD (int word) { return (ushort)(word & 0xFFFF); } - - public static ushort HIWORD (IntPtr dwValue) { return (ushort)((((long)dwValue) >> 0x10) & 0xffff); } - - public static ushort HIWORD (uint dwValue) { return (ushort)(dwValue >> 0x10); } - - public static int SignedHIWORD (IntPtr n) { return SignedHIWORD ((int)((long)n)); } - - public static int SignedLOWORD (IntPtr n) { return SignedLOWORD ((int)((long)n)); } - - public static int SignedHIWORD (int n) { return (n >> 16 & 65535); } - - public static int SignedLOWORD (int n) { return (n & 65535); } - - public static int GetWheelDeltaWParam (IntPtr wParam) { return SignedHIWORD (wParam); } - - [Flags] - public enum MK - { - NONE = 0x0000, - LBUTTON = 0x0001, - RBUTTON = 0x0002, - SHIFT = 0x0004, - CONTROL = 0x0008, - MBUTTON = 0x0010, - XBUTTON1 = 0x0020, - XBUTTON2 = 0x0040 - } - - public static MouseButtons GetMouseButtonWParam (IntPtr wParam) - { - var mask = (MK)LOWORD (wParam); - var buttons = MouseButtons.None; - - if (mask.HasFlag (MK.LBUTTON)) - buttons |= MouseButtons.Left; - if (mask.HasFlag (MK.RBUTTON)) - buttons |= MouseButtons.Right; - if (mask.HasFlag (MK.MBUTTON)) - buttons |= MouseButtons.Middle; - if (mask.HasFlag (MK.XBUTTON1)) - buttons |= MouseButtons.XButton1; - if (mask.HasFlag (MK.XBUTTON2)) - buttons |= MouseButtons.XButton2; - return buttons; - } - - [DllImport ("user32.dll")] - static extern int ShowWindow (IntPtr hWnd, uint msg); - - [DllImport ("user32.dll")] - [return: MarshalAs (UnmanagedType.Bool)] - public static extern bool SetWindowPos (IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SWP uFlags); - - [DllImport ("user32.dll", SetLastError = true)] - public static extern uint GetWindowLong (IntPtr hWnd, GWL nIndex); - - [DllImport ("user32.dll")] - public static extern int SetWindowLong (IntPtr hWnd, GWL nIndex, uint dwNewLong); - - [DllImport("user32.dll")] - public static extern IntPtr SendMessage(IntPtr hWnd, WM wMsg, IntPtr wParam, IntPtr lParam); - - [DllImport("user32.dll", CharSet = CharSet.Auto)] - public static extern bool PeekMessage(ref Message wMsg, IntPtr hwnd, int msgMin, int msgMax, int remove); - - - public static Message? GetNextMessage(Control ctl, params WM[] wMsg) - { - Message? msg = null; - Message pmsg = default(Message); - var ret = false; - do - { - ret = false; - foreach (var wm in wMsg) - { - ret |= PeekMessage(ref pmsg, ctl.Handle, (int)wm, (int)wm, 0); - if (ret) - msg = pmsg; - } - } while (ret); - return msg; - } - } -} diff --git a/Source/Eto.Platform.Wpf/Conversions.cs b/Source/Eto.Platform.Wpf/Conversions.cs deleted file mode 100644 index 0e2a9691ec..0000000000 --- a/Source/Eto.Platform.Wpf/Conversions.cs +++ /dev/null @@ -1,529 +0,0 @@ -using System; -using System.Linq; -using System.Text; -using Eto.Drawing; -using Eto.Forms; -using swi = System.Windows.Input; -using swm = System.Windows.Media; -using sw = System.Windows; -using sp = System.Printing; -using swc = System.Windows.Controls; -using swmi = System.Windows.Media.Imaging; -using System.Text.RegularExpressions; -using Eto.Platform.Wpf.Drawing; - -namespace Eto.Platform.Wpf -{ - public static class Conversions - { - public const float WheelDelta = 120f; - - public static readonly sw.Size PositiveInfinitySize = new sw.Size(double.PositiveInfinity, double.PositiveInfinity); - public static readonly sw.Size ZeroSize = new sw.Size(0, 0); - - public static swm.Color ToWpf(this Color value) - { - - return swm.Color.FromArgb((byte)(value.A * byte.MaxValue), (byte)(value.R * byte.MaxValue), (byte)(value.G * byte.MaxValue), (byte)(value.B * byte.MaxValue)); - } - - public static swm.Brush ToWpfBrush(this Color value, swm.Brush brush = null) - { - var solidBrush = brush as swm.SolidColorBrush; - if (solidBrush == null || solidBrush.IsSealed) - { - solidBrush = new swm.SolidColorBrush(); - } - solidBrush.Color = value.ToWpf(); - return solidBrush; - } - - public static Color ToEto(this swm.Color value) - { - return new Color { A = value.A / 255f, R = value.R / 255f, G = value.G / 255f, B = value.B / 255f }; - } - - public static Color ToEtoColor(this swm.Brush brush) - { - var solidBrush = brush as swm.SolidColorBrush; - if (solidBrush != null) - return solidBrush.Color.ToEto(); - return Colors.Transparent; - } - - public static Padding ToEto(this sw.Thickness value) - { - return new Padding((int)value.Left, (int)value.Top, (int)value.Right, (int)value.Bottom); - } - - public static sw.Thickness ToWpf(this Padding value) - { - return new sw.Thickness(value.Left, value.Top, value.Right, value.Bottom); - } - - public static Rectangle ToEto(this sw.Rect value) - { - return new Rectangle((int)value.X, (int)value.Y, (int)value.Width, (int)value.Height); - } - - public static RectangleF ToEtoF(this sw.Rect value) - { - return new RectangleF((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height); - } - - public static sw.Rect ToWpf(this Rectangle value) - { - return new sw.Rect(value.X, value.Y, value.Width, value.Height); - } - - public static sw.Int32Rect ToWpfInt32(this Rectangle value) - { - return new sw.Int32Rect(value.X, value.Y, value.Width, value.Height); - } - - public static sw.Rect ToWpf(this RectangleF value) - { - return new sw.Rect(value.X, value.Y, value.Width, value.Height); - } - - public static SizeF ToEto(this sw.Size value) - { - return new SizeF((float)value.Width, (float)value.Height); - } - - public static Size ToEtoSize(this sw.Size value) - { - return new Size((int)(double.IsNaN(value.Width) ? -1 : value.Width), (int)(double.IsNaN(value.Height) ? -1 : value.Height)); - } - - public static sw.Size ToWpf(this Size value) - { - return new sw.Size(value.Width == -1 ? double.NaN : value.Width, value.Height == -1 ? double.NaN : value.Height); - } - - public static sw.Size ToWpf(this SizeF value) - { - return new sw.Size(value.Width, value.Height); - } - - public static PointF ToEto(this sw.Point value) - { - return new PointF((float)value.X, (float)value.Y); - } - - public static Point ToEtoPoint(this sw.Point value) - { - return new Point((int)value.X, (int)value.Y); - } - - public static sw.Point ToWpf(this Point value) - { - return new sw.Point(value.X, value.Y); - } - - public static sw.Point ToWpf(this PointF value) - { - return new sw.Point(value.X, value.Y); - } - - public static string ToWpfMneumonic(this string value) - { - if (value == null) - return string.Empty; - value = value.Replace("_", "__"); - var match = Regex.Match(value, @"(?<=([^&](?:[&]{2})*)|^)[&](?![&])"); - if (match.Success) - { - var sb = new StringBuilder(value); - sb[match.Index] = '_'; - sb.Replace("&&", "&"); - return sb.ToString(); - } - return value.Replace("&&", "&"); - } - - public static string ToEtoMneumonic(this string value) - { - if (value == null) - return null; - var match = Regex.Match(value, @"(?<=([^_](?:[_]{2})*)|^)[_](?![_])"); - if (match.Success) - { - var sb = new StringBuilder(value); - sb[match.Index] = '&'; - sb.Replace("__", "_"); - return sb.ToString(); - } - value = value.Replace("__", "_"); - return value; - } - - public static KeyEventArgs ToEto(this swi.KeyEventArgs e, KeyEventType keyType) - { - var key = KeyMap.Convert(e.Key, swi.Keyboard.Modifiers); - return new KeyEventArgs(key, keyType) { Handled = e.Handled }; - } - - public static MouseEventArgs ToEto(this swi.MouseButtonEventArgs e, sw.IInputElement control, swi.MouseButtonState buttonState = swi.MouseButtonState.Pressed) - { - var buttons = MouseButtons.None; - if (e.ChangedButton == swi.MouseButton.Left && e.LeftButton == buttonState) - buttons |= MouseButtons.Primary; - if (e.ChangedButton == swi.MouseButton.Right && e.RightButton == buttonState) - buttons |= MouseButtons.Alternate; - if (e.ChangedButton == swi.MouseButton.Middle && e.MiddleButton == buttonState) - buttons |= MouseButtons.Middle; - var modifiers = Keys.None; - var location = e.GetPosition(control).ToEto(); - - return new MouseEventArgs(buttons, modifiers, location); - } - - public static MouseEventArgs ToEto(this swi.MouseEventArgs e, sw.IInputElement control, swi.MouseButtonState buttonState = swi.MouseButtonState.Pressed) - { - var buttons = MouseButtons.None; - if (e.LeftButton == buttonState) - buttons |= MouseButtons.Primary; - if (e.RightButton == buttonState) - buttons |= MouseButtons.Alternate; - if (e.MiddleButton == buttonState) - buttons |= MouseButtons.Middle; - var modifiers = Keys.None; - var location = e.GetPosition(control).ToEto(); - - return new MouseEventArgs(buttons, modifiers, location); - } - - public static MouseEventArgs ToEto(this swi.MouseWheelEventArgs e, sw.IInputElement control, swi.MouseButtonState buttonState = swi.MouseButtonState.Pressed) - { - var buttons = MouseButtons.None; - if (e.LeftButton == buttonState) - buttons |= MouseButtons.Primary; - if (e.RightButton == buttonState) - buttons |= MouseButtons.Alternate; - if (e.MiddleButton == buttonState) - buttons |= MouseButtons.Middle; - var modifiers = Keys.None; - var location = e.GetPosition(control).ToEto(); - var delta = new SizeF(0, (float)e.Delta / WheelDelta); - - return new MouseEventArgs(buttons, modifiers, location, delta); - } - - public static swm.BitmapScalingMode ToWpf(this ImageInterpolation value) - { - switch (value) - { - case ImageInterpolation.Default: - return swm.BitmapScalingMode.Unspecified; - case ImageInterpolation.None: - return swm.BitmapScalingMode.NearestNeighbor; - case ImageInterpolation.Low: - return swm.BitmapScalingMode.LowQuality; - case ImageInterpolation.Medium: - return swm.BitmapScalingMode.HighQuality; - case ImageInterpolation.High: - return swm.BitmapScalingMode.HighQuality; - default: - throw new NotSupportedException(); - } - } - - public static ImageInterpolation ToEto(this swm.BitmapScalingMode value) - { - switch (value) - { - case swm.BitmapScalingMode.HighQuality: - return ImageInterpolation.High; - case swm.BitmapScalingMode.LowQuality: - return ImageInterpolation.Low; - case swm.BitmapScalingMode.NearestNeighbor: - return ImageInterpolation.None; - case swm.BitmapScalingMode.Unspecified: - return ImageInterpolation.Default; - default: - throw new NotSupportedException(); - } - } - - public static sp.PageOrientation ToSP(this PageOrientation value) - { - switch (value) - { - case PageOrientation.Portrait: - return sp.PageOrientation.Portrait; - case PageOrientation.Landscape: - return sp.PageOrientation.Landscape; - default: - throw new NotSupportedException(); - } - } - - public static PageOrientation ToEto(this sp.PageOrientation? value) - { - if (value == null) - return PageOrientation.Portrait; - switch (value.Value) - { - case sp.PageOrientation.Landscape: - return PageOrientation.Landscape; - case sp.PageOrientation.Portrait: - return PageOrientation.Portrait; - default: - throw new NotSupportedException(); - } - } - - public static swc.PageRange ToPageRange(this Range range) - { - return new swc.PageRange(range.Start, range.End); - } - - public static Range ToEto(this swc.PageRange range) - { - return new Range(range.PageFrom, range.PageTo - range.PageFrom + 1); - } - - public static swc.PageRangeSelection ToSWC(this PrintSelection value) - { - switch (value) - { - case PrintSelection.AllPages: - return swc.PageRangeSelection.AllPages; - case PrintSelection.SelectedPages: - return swc.PageRangeSelection.UserPages; - default: - throw new NotSupportedException(); - } - } - - public static PrintSelection ToEto(this swc.PageRangeSelection value) - { - switch (value) - { - case swc.PageRangeSelection.AllPages: - return PrintSelection.AllPages; - case swc.PageRangeSelection.UserPages: - return PrintSelection.SelectedPages; - default: - throw new NotSupportedException(); - } - } - - public static Size GetSize(this sw.FrameworkElement element) - { - if (element.IsVisible && (!double.IsNaN(element.ActualWidth) && !double.IsNaN(element.ActualHeight))) - return new Size((int)element.ActualWidth, (int)element.ActualHeight); - return new Size((int)(double.IsNaN(element.Width) ? -1 : element.Width), (int)(double.IsNaN(element.Height) ? -1 : element.Height)); - } - - public static void SetSize(this sw.FrameworkElement element, Size size) - { - element.Width = size.Width == -1 ? double.NaN : size.Width; - element.Height = size.Height == -1 ? double.NaN : size.Height; - } - - public static void SetSize(this sw.FrameworkElement element, sw.Size size) - { - element.Width = size.Width; - element.Height = size.Height; - } - - public static FontStyle Convert(sw.FontStyle fontStyle, sw.FontWeight fontWeight) - { - var style = FontStyle.None; - if (fontStyle == sw.FontStyles.Italic) - style |= FontStyle.Italic; - if (fontStyle == sw.FontStyles.Oblique) - style |= FontStyle.Italic; - if (fontWeight == sw.FontWeights.Bold) - style |= FontStyle.Bold; - return style; - } - - public static FontDecoration Convert(sw.TextDecorationCollection decorations) - { - var decoration = FontDecoration.None; - if (decorations != null) - { - if (sw.TextDecorations.Underline.All(decorations.Contains)) - decoration |= FontDecoration.Underline; - if (sw.TextDecorations.Strikethrough.All(decorations.Contains)) - decoration |= FontDecoration.Strikethrough; - } - return decoration; - } - - public static swmi.BitmapSource ToWpf(this Image image, int? size = null) - { - if (image == null) - return null; - var imageHandler = image.Handler as IWpfImage; - if (imageHandler != null) - return imageHandler.GetImageClosestToSize(size); - return image.ControlObject as swmi.BitmapSource; - } - - public static swc.Image ToWpfImage(this Image image, int? size = null) - { - var source = image.ToWpf(size); - if (source == null) - return null; - var swcImage = new swc.Image { Source = source }; - if (size != null) - { - swcImage.MaxWidth = size.Value; - swcImage.MaxHeight = size.Value; - } - return swcImage; - } - - public static swm.Pen ToWpf(this Pen pen, bool clone = false) - { - var p = (swm.Pen)pen.ControlObject; - if (clone) - p = p.Clone(); - return p; - } - - public static swm.PenLineJoin ToWpf(this PenLineJoin value) - { - switch (value) - { - case PenLineJoin.Miter: - return swm.PenLineJoin.Miter; - case PenLineJoin.Bevel: - return swm.PenLineJoin.Bevel; - case PenLineJoin.Round: - return swm.PenLineJoin.Round; - default: - throw new NotSupportedException(); - } - } - - public static PenLineJoin ToEto(this swm.PenLineJoin value) - { - switch (value) - { - case swm.PenLineJoin.Bevel: - return PenLineJoin.Bevel; - case swm.PenLineJoin.Miter: - return PenLineJoin.Miter; - case swm.PenLineJoin.Round: - return PenLineJoin.Round; - default: - throw new NotSupportedException(); - } - } - - public static swm.PenLineCap ToWpf(this PenLineCap value) - { - switch (value) - { - case PenLineCap.Butt: - return swm.PenLineCap.Flat; - case PenLineCap.Round: - return swm.PenLineCap.Round; - case PenLineCap.Square: - return swm.PenLineCap.Square; - default: - throw new NotSupportedException(); - } - } - - public static PenLineCap ToEto(this swm.PenLineCap value) - { - switch (value) - { - case swm.PenLineCap.Flat: - return PenLineCap.Butt; - case swm.PenLineCap.Round: - return PenLineCap.Round; - case swm.PenLineCap.Square: - return PenLineCap.Square; - default: - throw new NotSupportedException(); - } - } - - public static swm.Brush ToWpf(this Brush brush, bool clone = false) - { - var b = (swm.Brush)brush.ControlObject; - if (clone) - b = b.Clone(); - return b; - } - - public static swm.Matrix ToWpf(this IMatrix matrix) - { - return (swm.Matrix)matrix.ControlObject; - } - - public static swm.Transform ToWpfTransform(this IMatrix matrix) - { - return new swm.MatrixTransform(matrix.ToWpf()); - } - - public static IMatrix ToEtoMatrix(this swm.Transform transform) - { - return new MatrixHandler(transform.Value); - } - - public static swm.PathGeometry ToWpf(this IGraphicsPath path) - { - return (swm.PathGeometry)path.ControlObject; - } - - public static swm.GradientSpreadMethod ToWpf(this GradientWrapMode wrap) - { - switch (wrap) - { - case GradientWrapMode.Reflect: - return swm.GradientSpreadMethod.Reflect; - case GradientWrapMode.Repeat: - return swm.GradientSpreadMethod.Repeat; - default: - throw new NotSupportedException(); - } - } - - public static GradientWrapMode ToEto(this swm.GradientSpreadMethod spread) - { - switch (spread) - { - case swm.GradientSpreadMethod.Reflect: - return GradientWrapMode.Reflect; - case swm.GradientSpreadMethod.Repeat: - return GradientWrapMode.Repeat; - default: - throw new NotSupportedException(); - } - } - - public static WindowStyle ToEto(this sw.WindowStyle style) - { - switch (style) - { - case sw.WindowStyle.None: - return WindowStyle.None; - case sw.WindowStyle.ThreeDBorderWindow: - return WindowStyle.Default; - default: - throw new NotSupportedException(); - } - } - - public static sw.WindowStyle ToWpf(this WindowStyle style) - { - switch (style) - { - case WindowStyle.None: - return sw.WindowStyle.None; - case WindowStyle.Default: - return sw.WindowStyle.ThreeDBorderWindow; - default: - throw new NotSupportedException(); - } - } - } -} diff --git a/Source/Eto.Platform.Wpf/CustomControls/EditableTextBlock.cs b/Source/Eto.Platform.Wpf/CustomControls/EditableTextBlock.cs deleted file mode 100644 index d402f3d4f8..0000000000 --- a/Source/Eto.Platform.Wpf/CustomControls/EditableTextBlock.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Input; - -namespace Eto.Platform.Wpf.CustomControls -{ - public class EditableTextBlock : UserControl - { - string oldText; - - public EditableTextBlock() - { - var textBox = new FrameworkElementFactory(typeof(TextBox)); - textBox.SetValue(Control.PaddingProperty, new Thickness(1)); // 1px for border - textBox.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(TextBox_Loaded)); - textBox.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown)); - textBox.AddHandler(UIElement.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus)); - textBox.SetBinding(TextBox.TextProperty, new System.Windows.Data.Binding("Text") { Source = this, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); - var editTemplate = new DataTemplate { VisualTree = textBox }; - - var textBlock = new FrameworkElementFactory(typeof(TextBlock)); - textBlock.SetValue(FrameworkElement.MarginProperty, new Thickness(2)); - textBlock.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(TextBlock_MouseDown)); - textBlock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding("Text") { Source = this }); - var viewTemplate = new DataTemplate { VisualTree = textBlock }; - - var style = new System.Windows.Style(typeof(EditableTextBlock)); - var trigger = new Trigger { Property = IsInEditModeProperty, Value = true }; - trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = editTemplate }); - style.Triggers.Add(trigger); - - trigger = new Trigger { Property = IsInEditModeProperty, Value = false }; - trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = viewTemplate }); - style.Triggers.Add(trigger); - Style = style; - } - - public string Text - { - get { return (string)GetValue(TextProperty); } - set { SetValue(TextProperty, value); } - } - - public static readonly DependencyProperty TextProperty = - DependencyProperty.Register( - "Text", - typeof(string), - typeof(EditableTextBlock), - new PropertyMetadata("")); - - public bool IsEditable - { - get { return (bool)GetValue(IsEditableProperty); } - set { SetValue(IsEditableProperty, value); } - } - - public static readonly DependencyProperty IsEditableProperty = - DependencyProperty.Register( - "IsEditable", - typeof(bool), - typeof(EditableTextBlock), - new PropertyMetadata(true)); - - public bool IsInEditMode - { - get - { - return IsEditable && (bool)GetValue(IsInEditModeProperty); - } - set - { - if (IsEditable) - { - if (value) oldText = Text; - SetValue(IsInEditModeProperty, value); - } - } - } - public static readonly DependencyProperty IsInEditModeProperty = - DependencyProperty.Register( - "IsInEditMode", - typeof(bool), - typeof(EditableTextBlock), - new PropertyMetadata(false)); - - static void TextBox_Loaded(object sender, RoutedEventArgs e) - { - var textBox = (TextBox)sender; - textBox.Focus(); - textBox.SelectAll(); - } - - void TextBox_LostFocus(object sender, RoutedEventArgs e) - { - IsInEditMode = false; - } - - void SetParentFocus() - { - var item = this.GetParent(); - if (item != null) - item.Focus(); - } - - void TextBox_KeyDown(object sender, KeyEventArgs e) - { - if (e.Key == Key.Enter) - { - IsInEditMode = false; - SetParentFocus(); - e.Handled = true; - } - else if (e.Key == Key.Escape) - { - IsInEditMode = false; - SetParentFocus(); - Text = oldText; - e.Handled = true; - } - } - - void TextBlock_MouseDown(object sender, MouseButtonEventArgs e) - { - if (e.ButtonState == MouseButtonState.Pressed && e.ClickCount >= 2 && e.ChangedButton == MouseButton.Left) - { - IsInEditMode = true; - e.Handled = true; - } - } - } -} diff --git a/Source/Eto.Platform.Wpf/CustomControls/FontDialog/fontchooser.xaml b/Source/Eto.Platform.Wpf/CustomControls/FontDialog/fontchooser.xaml deleted file mode 100644 index d8ac72fcad..0000000000 --- a/Source/Eto.Platform.Wpf/CustomControls/FontDialog/fontchooser.xaml +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -