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

« back to all changes in this revision

Viewing changes to external/xwt/Xwt.WPF/Xwt.WPFBackend/CheckBoxBackend.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
// CheckBoxBackend.cs
 
3
//  
 
4
// Author:
 
5
//       Eric Maupin <ermau@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2012 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 System.Windows;
 
29
using System.Windows.Controls;
 
30
using Xwt.Backends;
 
31
using Xwt.Engine;
 
32
using WindowsCheckBox = System.Windows.Controls.CheckBox;
 
33
 
 
34
namespace Xwt.WPFBackend
 
35
{
 
36
        public class CheckBoxBackend
 
37
                : WidgetBackend, ICheckBoxBackend
 
38
        {
 
39
                public CheckBoxBackend()
 
40
                {
 
41
                        Widget = new WindowsCheckBox ();
 
42
                }
 
43
 
 
44
                public void SetContent (IWidgetBackend widget)
 
45
                {
 
46
                        if (widget == null)
 
47
                                throw new ArgumentNullException ("widget");
 
48
 
 
49
                        CheckBox.Content = widget.NativeWidget;
 
50
                }
 
51
 
 
52
                public void SetContent (string label)
 
53
                {
 
54
                        CheckBox.Content = new TextBlock { Text = label };
 
55
                }
 
56
 
 
57
                public bool Active
 
58
                {
 
59
                        get { return CheckBox.IsChecked.HasValue && CheckBox.IsChecked.Value; }
 
60
                        set { CheckBox.IsChecked = value; }
 
61
                }
 
62
 
 
63
                public bool Mixed
 
64
                {
 
65
                        get { return !CheckBox.IsChecked.HasValue; }
 
66
                        set
 
67
                        {
 
68
                                if (value)
 
69
                                        CheckBox.IsChecked = null;
 
70
                                else
 
71
                                        CheckBox.IsChecked = false;
 
72
                        }
 
73
                }
 
74
 
 
75
                public bool AllowMixed
 
76
                {
 
77
                        get { return CheckBox.IsThreeState; }
 
78
                        set { CheckBox.IsThreeState = value; }
 
79
                }
 
80
 
 
81
                public override void EnableEvent (object eventId)
 
82
                {
 
83
                        base.EnableEvent (eventId);
 
84
                        if (eventId is CheckBoxEvent) {
 
85
                                switch ((CheckBoxEvent)eventId) {
 
86
                                case CheckBoxEvent.Clicked:
 
87
                                        CheckBox.Click += OnClicked;
 
88
                                        break;
 
89
 
 
90
                                case CheckBoxEvent.Toggled:
 
91
                                        CheckBox.Checked += OnChecked;
 
92
                                        break;
 
93
                                }
 
94
                        }
 
95
                }
 
96
 
 
97
                public override void DisableEvent (object eventId)
 
98
                {
 
99
                        base.DisableEvent (eventId);
 
100
                        if (eventId is CheckBoxEvent) {
 
101
                                switch ((CheckBoxEvent)eventId) {
 
102
                                case CheckBoxEvent.Clicked:
 
103
                                        CheckBox.Click -= OnClicked;
 
104
                                        break;
 
105
 
 
106
                                case CheckBoxEvent.Toggled:
 
107
                                        CheckBox.Checked -= OnChecked;
 
108
                                        break;
 
109
                                }
 
110
                        }
 
111
                }
 
112
 
 
113
                private void OnChecked (object sender, RoutedEventArgs routedEventArgs)
 
114
                {
 
115
                        Toolkit.Invoke (CheckBoxEventSink.OnToggled);
 
116
                }
 
117
 
 
118
                private void OnClicked (object sender, RoutedEventArgs e)
 
119
                {
 
120
                        Toolkit.Invoke (CheckBoxEventSink.OnClicked);
 
121
                }
 
122
 
 
123
                protected ICheckBoxEventSink CheckBoxEventSink
 
124
                {
 
125
                        get { return (ICheckBoxEventSink) EventSink; }
 
126
                }
 
127
 
 
128
                protected WindowsCheckBox CheckBox
 
129
                {
 
130
                        get { return (WindowsCheckBox) Widget; }
 
131
                }
 
132
        }
 
133
}