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

« back to all changes in this revision

Viewing changes to external/xwt/Xwt/Xwt/MenuItem.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
// MenuItem.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 System.ComponentModel;
 
30
using Xwt.Drawing;
 
31
using Xwt.Engine;
 
32
 
 
33
namespace Xwt
 
34
{
 
35
        public class MenuItem: XwtComponent, ICellContainer
 
36
        {
 
37
                CellViewCollection cells;
 
38
                Menu subMenu;
 
39
                EventHandler clicked;
 
40
                Image image;
 
41
                
 
42
                protected class MenuItemBackendHost: BackendHost<MenuItem,IMenuItemBackend>, IMenuItemEventSink
 
43
                {
 
44
                        protected override void OnBackendCreated ()
 
45
                        {
 
46
                                base.OnBackendCreated ();
 
47
                                Backend.Initialize (this);
 
48
                        }
 
49
                        
 
50
                        public void OnClicked ()
 
51
                        {
 
52
                                Parent.DoClick ();
 
53
                        }
 
54
                }
 
55
                
 
56
                protected override Xwt.Backends.BackendHost CreateBackendHost ()
 
57
                {
 
58
                        return new MenuItemBackendHost ();
 
59
                }
 
60
                
 
61
                static MenuItem ()
 
62
                {
 
63
                        MapEvent (MenuItemEvent.Clicked, typeof(MenuItem), "OnClicked");
 
64
                }
 
65
                
 
66
                public MenuItem ()
 
67
                {
 
68
                }
 
69
                
 
70
                public MenuItem (Command command): this ()
 
71
                {
 
72
                        Label = command.Label;
 
73
                        if (!string.IsNullOrEmpty (command.Icon))
 
74
                                Image = Image.FromIcon (command.Icon, IconSize.Small);
 
75
                }
 
76
                
 
77
                public MenuItem (string label): this ()
 
78
                {
 
79
                        Label = label;
 
80
                }
 
81
                
 
82
                IMenuItemBackend Backend {
 
83
                        get { return (IMenuItemBackend) base.BackendHost.Backend; }
 
84
                }
 
85
                
 
86
                [DefaultValue ("")]
 
87
                public string Label {
 
88
                        get { return Backend.Label; }
 
89
                        set { Backend.Label = value; }
 
90
                }
 
91
                
 
92
                [DefaultValue (true)]
 
93
                public bool Sensitive {
 
94
                        get { return Backend.Sensitive; }
 
95
                        set { Backend.Sensitive = value; }
 
96
                }
 
97
                
 
98
                [DefaultValue (true)]
 
99
                public bool Visible {
 
100
                        get { return Backend.Visible; }
 
101
                        set { Backend.Visible = value; }
 
102
                }
 
103
                
 
104
                public Image Image {
 
105
                        get { return image; }
 
106
                        set { image = value; Backend.SetImage (XwtObject.GetBackend (value)); }
 
107
                }
 
108
                
 
109
                public void Show ()
 
110
                {
 
111
                        Visible = true;
 
112
                }
 
113
                
 
114
                public void Hide ()
 
115
                {
 
116
                        Visible = false;
 
117
                }
 
118
                
 
119
                public CellViewCollection Cells {
 
120
                        get {
 
121
                                if (cells == null)
 
122
                                        cells = new CellViewCollection (this);
 
123
                                return cells;
 
124
                        }
 
125
                }
 
126
                
 
127
                public Menu SubMenu {
 
128
                        get { return subMenu; }
 
129
                        set {
 
130
                                subMenu = value;
 
131
                                Backend.SetSubmenu ((IMenuBackend) WidgetRegistry.GetBackend (subMenu));
 
132
                        }
 
133
                }
 
134
                
 
135
                public void NotifyCellChanged ()
 
136
                {
 
137
                        throw new NotImplementedException ();
 
138
                }
 
139
                
 
140
                internal virtual void DoClick ()
 
141
                {
 
142
                        OnClicked (EventArgs.Empty);
 
143
                }
 
144
                
 
145
                protected virtual void OnClicked (EventArgs e)
 
146
                {
 
147
                        if (clicked != null)
 
148
                                clicked (this, e);
 
149
                }
 
150
                
 
151
                public event EventHandler Clicked {
 
152
                        add {
 
153
                                base.BackendHost.OnBeforeEventAdd (MenuItemEvent.Clicked, clicked);
 
154
                                clicked += value;
 
155
                        }
 
156
                        remove {
 
157
                                clicked -= value;
 
158
                                base.BackendHost.OnAfterEventRemove (MenuItemEvent.Clicked, clicked);
 
159
                        }
 
160
                }
 
161
        }
 
162
        
 
163
        public enum MenuItemType
 
164
        {
 
165
                Normal,
 
166
                CheckBox,
 
167
                RadioButton
 
168
        }
 
169
}
 
170