~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Xwt/Xwt/Button.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// Button.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez <lluis@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2011 Xamarin Inc
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using Xwt.Backends;
 
29
using Xwt.Drawing;
 
30
 
 
31
namespace Xwt
 
32
{
 
33
        public class Button: Widget
 
34
        {
 
35
                EventHandler clicked;
 
36
                ButtonStyle style = ButtonStyle.Normal;
 
37
                ButtonType type = ButtonType.Normal;
 
38
                Image image;
 
39
                string label;
 
40
                ContentPosition imagePosition = ContentPosition.Left;
 
41
                
 
42
                protected new class WidgetBackendHost: Widget.WidgetBackendHost, IButtonEventSink
 
43
                {
 
44
                        protected override void OnBackendCreated ()
 
45
                        {
 
46
                                base.OnBackendCreated ();
 
47
                                ((IButtonBackend)Backend).SetButtonStyle (((Button)Parent).style);
 
48
                        }
 
49
                        
 
50
                        public void OnClicked ()
 
51
                        {
 
52
                                ((Button)Parent).OnClicked (EventArgs.Empty);
 
53
                        }
 
54
                }
 
55
                
 
56
                static Button ()
 
57
                {
 
58
                        MapEvent (ButtonEvent.Clicked, typeof(Button), "OnClicked");
 
59
                }
 
60
                
 
61
                public Button ()
 
62
                {
 
63
                }
 
64
                
 
65
                public Button (string label): this ()
 
66
                {
 
67
                        Label = label;
 
68
                }
 
69
                
 
70
                public Button (Image img, string label): this ()
 
71
                {
 
72
                        Label = label;
 
73
                        Image = img;
 
74
                }
 
75
                
 
76
                public Button (Image img): this ()
 
77
                {
 
78
                        Image = img;
 
79
                }
 
80
                
 
81
                protected override BackendHost CreateBackendHost ()
 
82
                {
 
83
                        return new WidgetBackendHost ();
 
84
                }
 
85
                
 
86
                IButtonBackend Backend {
 
87
                        get { return (IButtonBackend) BackendHost.Backend; }
 
88
                }
 
89
                
 
90
                public string Label {
 
91
                        get { return label; }
 
92
                        set {
 
93
                                label = value;
 
94
                                Backend.SetContent (label, XwtObject.GetBackend (image), imagePosition);
 
95
                                OnPreferredSizeChanged ();
 
96
                        }
 
97
                }
 
98
                
 
99
                public Image Image {
 
100
                        get { return image; }
 
101
                        set {
 
102
                                image = value;
 
103
                                Backend.SetContent (label, XwtObject.GetBackend (value), imagePosition); 
 
104
                                OnPreferredSizeChanged ();
 
105
                        }
 
106
                }
 
107
                
 
108
                public ContentPosition ImagePosition {
 
109
                        get { return imagePosition; }
 
110
                        set {
 
111
                                imagePosition = value;
 
112
                                Backend.SetContent (label, XwtObject.GetBackend (image), imagePosition); 
 
113
                                OnPreferredSizeChanged ();
 
114
                        }
 
115
                }
 
116
                
 
117
                public ButtonStyle Style {
 
118
                        get { return style; }
 
119
                        set {
 
120
                                style = value;
 
121
                                Backend.SetButtonStyle (style);
 
122
                                OnPreferredSizeChanged ();
 
123
                        }
 
124
                }
 
125
                
 
126
                public ButtonType Type {
 
127
                        get { return type; }
 
128
                        set {
 
129
                                type = value;
 
130
                                Backend.SetButtonType (type);
 
131
                                OnPreferredSizeChanged ();
 
132
                        }
 
133
                }
 
134
                
 
135
                protected virtual void OnClicked (EventArgs e)
 
136
                {
 
137
                        if (clicked != null)
 
138
                                clicked (this, e);
 
139
                }
 
140
                
 
141
                public event EventHandler Clicked {
 
142
                        add {
 
143
                                BackendHost.OnBeforeEventAdd (ButtonEvent.Clicked, clicked);
 
144
                                clicked += value;
 
145
                        }
 
146
                        remove {
 
147
                                clicked -= value;
 
148
                                BackendHost.OnAfterEventRemove (ButtonEvent.Clicked, clicked);
 
149
                        }
 
150
                }
 
151
        }
 
152
}
 
153