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

« back to all changes in this revision

Viewing changes to external/xwt/Xwt/Xwt/TransferDataType.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
// TransferDataType.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez <lluis@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.Collections.Generic;
 
29
using System.Linq;
 
30
using System.IO;
 
31
using System.Runtime.Serialization.Formatters.Binary;
 
32
using Xwt.Drawing;
 
33
using Xwt.Backends;
 
34
using Xwt.Engine;
 
35
 
 
36
namespace Xwt
 
37
{
 
38
        /// <summary>
 
39
        /// Data type to be used in drag & drop and copy & paste operations
 
40
        /// </summary>
 
41
        public class TransferDataType
 
42
        {
 
43
                string id;
 
44
                
 
45
                /// <summary>
 
46
                /// The URI data type. This is used for file and url copy and drag operations
 
47
                /// </summary>
 
48
                public static readonly TransferDataType Uri = FromId ("uri");
 
49
                
 
50
                /// <summary>
 
51
                /// The text data type
 
52
                /// </summary>
 
53
                public static readonly TransferDataType Text = FromId ("text");
 
54
                
 
55
                /// <summary>
 
56
                /// The RTF data type
 
57
                /// </summary>
 
58
                public static readonly TransferDataType Rtf = FromId ("rtf");
 
59
                
 
60
                /// <summary>
 
61
                /// The image data type
 
62
                /// </summary>
 
63
                public static readonly TransferDataType Image = FromId ("image");
 
64
                
 
65
                private TransferDataType (string id)
 
66
                {
 
67
                        this.id = id;
 
68
                }
 
69
                
 
70
                /// <summary>
 
71
                /// Gets the identifier of the data type
 
72
                /// </summary>
 
73
                /// <value>
 
74
                /// The identifier.
 
75
                /// </value>
 
76
                public string Id {
 
77
                        get { return id; }
 
78
                }
 
79
                
 
80
                /// <summary>
 
81
                /// Creates a data type using a custom identifier
 
82
                /// </summary>
 
83
                /// <returns>
 
84
                /// The data type
 
85
                /// </returns>
 
86
                /// <param name='name'>
 
87
                /// The identifier.
 
88
                /// </param>
 
89
                public static TransferDataType FromId (string id)
 
90
                {
 
91
                        return new TransferDataType (id);
 
92
                }
 
93
                
 
94
                /// <summary>
 
95
                /// Creates a transfer data type from a CLR type
 
96
                /// </summary>
 
97
                /// <returns>
 
98
                /// The data type.
 
99
                /// </returns>
 
100
                /// <param name='type'>
 
101
                /// A type
 
102
                /// </param>
 
103
                /// <remarks>
 
104
                /// This is the data type to be used when transferring
 
105
                /// whole objects through drag & drop or copy & paste
 
106
                /// </remarks>
 
107
                public static TransferDataType FromType (Type type)
 
108
                {
 
109
                        if (type == typeof(string))
 
110
                                return TransferDataType.Text;
 
111
                        else if (type == typeof(Xwt.Drawing.Image))
 
112
                                return TransferDataType.Image;
 
113
                        else
 
114
                                return FromId (type.AssemblyQualifiedName);
 
115
                }
 
116
                
 
117
                public override bool Equals (object obj)
 
118
                {
 
119
                        TransferDataType t = obj as TransferDataType;
 
120
                        return t != null && t.id == id;
 
121
                }
 
122
                
 
123
                public override int GetHashCode ()
 
124
                {
 
125
                        return id.GetHashCode ();
 
126
                }
 
127
                
 
128
                public static bool operator == (TransferDataType c1, TransferDataType c2) 
 
129
                {
 
130
                        if (object.ReferenceEquals (c1, c2))
 
131
                                return true;
 
132
                        
 
133
                        if ((object)c1 == null || (object)c2 == null)
 
134
                                return false;
 
135
                        
 
136
                        return c1.id == c2.id;
 
137
                }
 
138
                
 
139
                public static bool operator != (TransferDataType c1, TransferDataType c2) 
 
140
                {
 
141
                        return !(c1 == c2);
 
142
                }
 
143
        }
 
144
}