Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo.moya@xamarin.com>2018-11-28 22:22:06 +0300
committerRodrigo Moya <rodrigo.moya@xamarin.com>2018-11-28 22:22:06 +0300
commit92d1b6b8d642604f57c4b8daed567c72f68fa882 (patch)
tree41dfefb02972c9c0cddff919e3e9ea37079e14cc /main/src/core/MonoDevelop.Ide/MonoDevelop.Components
parent56931e9744c1470110833c5399a794d21d7e4e78 (diff)
[Ide] Put common Cocoa helpers/classes in a common place
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSLabel.cs48
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSLine.cs47
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSStackViewExtensions.cs58
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NativeViewHelper.cs107
4 files changed, 260 insertions, 0 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSLabel.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSLabel.cs
new file mode 100644
index 0000000000..e05ef0fc91
--- /dev/null
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSLabel.cs
@@ -0,0 +1,48 @@
+//
+// NSLabel.cs
+//
+// Author:
+// Rodrigo Moya <rodrigo.moya@xamarin.com>
+//
+// Copyright (c) 2018
+//
+// 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.
+
+using System;
+
+#if MAC
+using AppKit;
+
+namespace MonoDevelop.Components.Mac
+{
+ public class NSLabel : NSTextField
+ {
+ public NSLabel ()
+ {
+ Editable = false;
+ Bordered = false;
+ Bezeled = false;
+ DrawsBackground = false;
+ Selectable = false;
+ TranslatesAutoresizingMaskIntoConstraints = false;
+ }
+ }
+}
+
+#endif
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSLine.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSLine.cs
new file mode 100644
index 0000000000..38ef28bb25
--- /dev/null
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSLine.cs
@@ -0,0 +1,47 @@
+//
+// NSLine.cs
+//
+// Author:
+// Rodrigo Moya <rodrigo.moya@xamarin.com>
+//
+// Copyright (c) 2018
+//
+// 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.
+using System;
+
+#if MAC
+using AppKit;
+
+namespace MonoDevelop.Components.Mac
+{
+ public class NSLine : NSBox
+ {
+ public NSLine (NSUserInterfaceLayoutOrientation orientation, int lineWidth = 1)
+ {
+ BoxType = NSBoxType.NSBoxSeparator;
+ if (orientation == NSUserInterfaceLayoutOrientation.Horizontal) {
+ HeightAnchor.ConstraintEqualToConstant (lineWidth).Active = true;
+ } else if (orientation == NSUserInterfaceLayoutOrientation.Vertical) {
+ WidthAnchor.ConstraintEqualToConstant (lineWidth).Active = true;
+ }
+ }
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSStackViewExtensions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSStackViewExtensions.cs
new file mode 100644
index 0000000000..7572040bc5
--- /dev/null
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NSStackViewExtensions.cs
@@ -0,0 +1,58 @@
+//
+// NSStackViewExtensions.cs
+//
+// Author:
+// Rodrigo Moya <rodrigo.moya@xamarin.com>
+//
+// Copyright (c) 2018
+//
+// 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.
+using System;
+
+#if MAC
+using AppKit;
+
+namespace MonoDevelop.Components.Mac
+{
+ public static class NSStackViewExtensions
+ {
+ const int RenderingPriority = 1000;
+ const int LowPriority = 249;
+
+ public static NSStackView CreateHorizontalStackView (int spacing = 10) => new NSStackView () {
+ Orientation = NSUserInterfaceLayoutOrientation.Horizontal,
+ Alignment = NSLayoutAttribute.CenterY,
+ Spacing = spacing,
+ Distribution = NSStackViewDistribution.Fill,
+ TranslatesAutoresizingMaskIntoConstraints = false
+ };
+
+ public static void AddArrangedSubview (this NSStackView stackView, NSView view, bool expandHorizontally, bool expandVertically)
+ {
+ stackView.AddArrangedSubview (view);
+
+ view.SetContentHuggingPriorityForOrientation (expandHorizontally ? RenderingPriority : LowPriority, NSLayoutConstraintOrientation.Horizontal);
+ view.SetContentHuggingPriorityForOrientation (expandVertically ? LowPriority : RenderingPriority, NSLayoutConstraintOrientation.Vertical);
+ view.SetContentCompressionResistancePriority (expandHorizontally ? RenderingPriority : LowPriority, NSLayoutConstraintOrientation.Horizontal);
+ view.SetContentCompressionResistancePriority (expandVertically ? LowPriority : RenderingPriority, NSLayoutConstraintOrientation.Vertical);
+ }
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NativeViewHelper.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NativeViewHelper.cs
new file mode 100644
index 0000000000..18d3eff17a
--- /dev/null
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Mac/NativeViewHelper.cs
@@ -0,0 +1,107 @@
+/*
+ * NativeViewHelper.cs - helper with static methods to create view related things
+ *
+ * Author:
+ * Jose Medrano <josmed@microsoft.com>
+ *
+ * Copyright (C) 2018 Microsoft, Corp
+ *
+ * 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.
+ */
+#if MAC
+using System;
+using AppKit;
+using Foundation;
+
+namespace MonoDevelop.Components.Mac
+{
+ static class NativeViewHelper
+ {
+ public static NSAttributedString GetAttributedStringFromFormattedText (string formattedText)
+ {
+ formattedText = formattedText.Replace ("&amp;", "&");
+ var formated = Xwt.FormattedText.FromMarkup (formattedText);
+ return Xwt.Mac.Util.ToAttributedString (formated);
+ }
+
+ public static NSAttributedString GetAttributedString (string text, NSColor foregroundColor, NSFont font)
+ {
+ //There is no need create NSStringAttributes element
+ var attributed = new NSAttributedString (text, new NSStringAttributes {
+ ForegroundColor = foregroundColor, Font = font
+ });
+ return attributed;
+ }
+
+ static readonly NSAttributedString NewLine = new NSAttributedString ("\n");
+
+ public static NSAttributedString GetMultiLineAttributedString (string title, string description, nfloat fontSize, NSColor titleColor, NSColor descriptionColor, NSParagraphStyle pstyle = null)
+ {
+ var result = new NSMutableAttributedString ();
+ if (!String.IsNullOrEmpty (title)) {
+ result.Append (new NSAttributedString (title, new NSStringAttributes {
+ Font = NSFont.BoldSystemFontOfSize (fontSize),
+ ForegroundColor = titleColor
+ }));
+ }
+
+ if (!String.IsNullOrEmpty (description)) {
+ result.Append (NewLine);
+ result.Append (new NSAttributedString (description, new NSStringAttributes {
+ Font = NSFont.SystemFontOfSize (fontSize - 2),
+ ForegroundColor = descriptionColor,
+ ParagraphStyle = pstyle ?? NSParagraphStyle.DefaultParagraphStyle
+ }));
+ }
+
+ return result;
+ }
+
+ public static NSAttributedString GetMultiLineAttributedStringWithImage (NSImage image, string title, string description, nfloat fontSize, NSColor titleColor, NSColor descriptionColor)
+ {
+ var attrString = new NSMutableAttributedString ("");
+
+ if (image != null) {
+ var cell = new NSTextAttachmentCell (image);
+ image.AlignmentRect = new CoreGraphics.CGRect (0, 5, image.Size.Width, image.Size.Height);
+ cell.Alignment = NSTextAlignment.Natural;
+ attrString.Append (NSAttributedString.FromAttachment (new NSTextAttachment { AttachmentCell = cell }));
+ attrString.Append (new NSAttributedString (" "));
+ }
+
+ var pstyle = new NSMutableParagraphStyle ();
+ pstyle.HeadIndent = pstyle.FirstLineHeadIndent = 24;
+ attrString.Append (GetMultiLineAttributedString (title, description, fontSize, titleColor, descriptionColor, pstyle));
+
+ return attrString;
+ }
+
+ public static NSFont GetSystemFont (bool bold, float size = 0.0f)
+ {
+ if (size <= 0) {
+ size = (float)NSFont.SystemFontSize;
+ }
+ if (bold)
+ return NSFont.BoldSystemFontOfSize (size);
+ return NSFont.SystemFontOfSize (size);
+ }
+ }
+}
+#endif \ No newline at end of file