5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
using MonoMac.Foundation;
32
using MonoMac.ObjCRuntime;
36
public class ButtonBackend: ViewBackend<NSButton,IButtonEventSink>, IButtonBackend
38
public ButtonBackend ()
42
#region IButtonBackend implementation
43
public override void Initialize ()
45
ViewObject = new MacButton (EventSink);
49
public void EnableEvent (Xwt.Backends.ButtonEvent ev)
51
((MacButton)Widget).EnableEvent (ev);
54
public void DisableEvent (Xwt.Backends.ButtonEvent ev)
56
((MacButton)Widget).DisableEvent (ev);
59
public void SetContent (string label, object imageBackend, ContentPosition imagePosition)
61
Widget.Title = label ?? "";
62
if (string.IsNullOrEmpty (label))
63
imagePosition = ContentPosition.Center;
64
if (imageBackend != null) {
65
Widget.Image = (NSImage)imageBackend;
66
switch (imagePosition) {
67
case ContentPosition.Bottom: Widget.ImagePosition = NSCellImagePosition.ImageBelow; break;
68
case ContentPosition.Left: Widget.ImagePosition = NSCellImagePosition.ImageLeft; break;
69
case ContentPosition.Right: Widget.ImagePosition = NSCellImagePosition.ImageRight; break;
70
case ContentPosition.Top: Widget.ImagePosition = NSCellImagePosition.ImageAbove; break;
71
case ContentPosition.Center: Widget.ImagePosition = NSCellImagePosition.ImageOverlaps; break;
77
public void SetButtonStyle (ButtonStyle style)
80
case ButtonStyle.Normal:
81
Widget.BezelStyle = NSBezelStyle.RoundRect;
82
Widget.SetButtonType (NSButtonType.MomentaryPushIn);
83
Messaging.void_objc_msgSend_bool (Widget.Handle, selSetShowsBorderOnlyWhileMouseInside.Handle, false);
85
case ButtonStyle.Flat:
86
Widget.BezelStyle = NSBezelStyle.RoundRect;
87
Messaging.void_objc_msgSend_bool (Widget.Handle, selSetShowsBorderOnlyWhileMouseInside.Handle, true);
92
static Selector selSetShowsBorderOnlyWhileMouseInside = new Selector ("setShowsBorderOnlyWhileMouseInside:");
94
public void SetButtonType (ButtonType type)
97
case ButtonType.Disclosure: Widget.BezelStyle = NSBezelStyle.Disclosure; break;
98
default: Widget.BezelStyle = NSBezelStyle.RoundRect; break;
105
class MacButton: NSButton, IViewObject
107
public MacButton (IntPtr p): base (p)
111
public MacButton (IButtonEventSink eventSink)
113
BezelStyle = NSBezelStyle.Rounded;
114
Activated += delegate {
115
Toolkit.Invoke (delegate {
116
eventSink.OnClicked ();
121
public MacButton (ICheckBoxEventSink eventSink)
123
Activated += delegate {
124
Toolkit.Invoke (delegate {
125
eventSink.OnClicked ();
130
public Widget Frontend { get; set; }
136
public void EnableEvent (Xwt.Backends.ButtonEvent ev)
140
public void DisableEvent (Xwt.Backends.ButtonEvent ev)