blob: ad18e31c7898a8abe9cdcaff4f9b5310527fa92e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
using System;
using AppKit;
using CoreGraphics;
using Foundation;
namespace Xamarin.PropertyEditing.Mac
{
internal class TabButton
: NSButton
{
public TabButton (IHostResourceProvider hostResource, string imageName)
{
if (hostResource == null)
throw new ArgumentNullException (nameof (hostResource));
if (imageName == null)
throw new ArgumentNullException (nameof (imageName));
Bordered = false;
Action = new ObjCRuntime.Selector (ClickedName);
var clicked = new NSClickGestureRecognizer (OnClicked);
AddGestureRecognizer (clicked);
this.hostResource = hostResource;
this.imageName = imageName;
AppearanceChanged ();
}
public event EventHandler Clicked;
public bool Selected
{
get { return this.selected; }
set
{
this.selected = value;
NeedsDisplay = true;
}
}
public override CGSize IntrinsicContentSize
{
get
{
var size = base.IntrinsicContentSize;
return new CGSize (size.Width + 2 + 10, size.Height + 2 + 10);
}
}
public sealed override void ViewDidChangeEffectiveAppearance ()
{
base.ViewDidChangeEffectiveAppearance ();
AppearanceChanged ();
}
public override void DrawRect (CGRect dirtyRect)
{
base.DrawRect (dirtyRect);
if (!Selected)
return;
NSBezierPath path = new NSBezierPath ();
path.AppendPathWithRect (new CGRect (Bounds.X, Bounds.Height - 2, Bounds.Width, 2));
(Selected ? NSColor.Text : NSColor.DisabledControlText).Set ();
path.Fill ();
}
private void AppearanceChanged ()
{
Image = this.hostResource.GetNamedImage (this.imageName);
}
private readonly string imageName;
private readonly IHostResourceProvider hostResource;
private bool selected;
private const string ClickedName = "OnClicked";
[Export (ClickedName)]
private void OnClicked()
{
Clicked?.Invoke (this, EventArgs.Empty);
}
}
}
|