2005-05-10 Peter Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataFormats.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Peter Bartok    (pbartok@novell.com)
24 //
25 //
26
27 // NOT COMPLETE
28
29 using System;
30 using System.Collections;
31 using System.Text;
32
33 namespace System.Windows.Forms {
34         public class DataFormats {
35                 #region DataFormats.Format Subclass
36                 public class Format {
37                         #region Local Variables
38                         private string  name;
39                         private int     id;
40                         private Format  next;
41                         #endregion Local Variables
42
43                         #region Public Constructors
44                         public Format(string name, int ID) {
45                                 this.name = name;
46                                 this.id = ID;
47                         }
48
49                         internal Format(string name, int ID, Format after) : this(name, ID) {
50                                 after.next = this;
51                         }
52                         #endregion      // Public Constructors
53
54                         #region Public Instance Properties
55                         public int Id {
56                                 get {
57                                         return this.id;
58                                 }
59                         }
60
61                         public string Name {
62                                 get {
63                                         return this.name;
64                                 }
65                         }
66                         #endregion      // Public Instance Properties
67
68                         #region Private Methods
69                         internal static Format Find(Format f, int id) {
70                                 while ((f != null) && (f.Id != id)) {
71                                         f = f.next;
72                                 }
73                                 return f;
74                         }
75
76                         internal static Format Find(Format f, string name) {
77                                 while ((f != null) && (!f.Name.Equals(name))) {
78                                         f = f.next;
79                                 }
80                                 return f;
81                         }
82                         #endregion      // Private Methods
83
84                 }
85                 #endregion      // DataFormats.Format Subclass
86
87                 #region Local Variables
88                 private static bool     initialized = false;
89                 private static Format   formats;
90                 #endregion      // Local Variables
91
92                 #region Constructors
93                 private DataFormats() {
94                 }
95                 #endregion      // Constructors
96
97                 #region Public Static Fields
98                 public static readonly string Bitmap                    = "Bitmap";
99                 public static readonly string CommaSeparatedValue       = "Csv";
100                 public static readonly string Dib                       = "DeviceIndependentBitmap";
101                 public static readonly string Dif                       = "DataInterchangeFormat";
102                 public static readonly string EnhancedMetafile          = "EnhancedMetafile";
103                 public static readonly string FileDrop                  = "FileDrop";
104                 public static readonly string Html                      = "HTML Format";
105                 public static readonly string Locale                    = "Locale";
106                 public static readonly string MetafilePict              = "MetaFilePict";
107                 public static readonly string OemText                   = "OEMText";
108                 public static readonly string Palette                   = "Palette";
109                 public static readonly string PenData                   = "PenData";
110                 public static readonly string Riff                      = "RiffAudio";
111                 public static readonly string Rtf                       = "Rich Text Format";
112                 public static readonly string Serializable              = "WindowsForms10PersistentObject";
113                 public static readonly string StringFormat              = "System.String";
114                 public static readonly string SymbolicLink              = "SymbolicLink";
115                 public static readonly string Text                      = "Text";
116                 public static readonly string Tiff                      = "Tiff";
117                 public static readonly string UnicodeText               = "UnicodeText";
118                 public static readonly string WaveAudio                 = "WaveAudio";
119                 #endregion      // Public Static Fields
120
121                 #region Public Static Methods
122                 public static Format GetFormat(int ID) {
123                         if (!initialized) {
124                                 Initialize();
125                         }
126
127                         return Format.Find(formats, ID);
128                 }
129
130                 public static Format GetFormat(string format) {
131                         if (!initialized) {
132                                 Initialize();
133                         }
134
135                         return Format.Find(formats, format);
136                 }
137                 #endregion      // Public Static Methods
138
139                 #region Private Methods
140                 private static void Initialize() {
141                         lock (typeof(DataFormats.Format)) {
142                                 if (!initialized) {
143                                         Format  f;
144                                         IntPtr  cliphandle;
145
146                                         cliphandle = XplatUI.ClipboardOpen();
147                                         formats = new DataFormats.Format(Text, 1);
148                                         f = new Format(Bitmap, 2, formats);
149                                         f = new Format(MetafilePict, 3, f);
150                                         f = new Format(SymbolicLink, 4, f);
151                                         f = new Format(Dif, 5, f);
152                                         f = new Format(Tiff, 6, f);
153                                         f = new Format(OemText, 7, f);
154                                         f = new Format(Dib, 8, f);
155                                         f = new Format(Palette, 9, f);
156                                         f = new Format(PenData, 10, f);
157                                         f = new Format(Riff, 11, f);
158                                         f = new Format(WaveAudio, 12, f);
159                                         f = new Format(UnicodeText, 13, f);
160                                         f = new Format(EnhancedMetafile, 14, f);
161                                         f = new Format(FileDrop, 15, f);
162                                         f = new Format(Locale, 16, f);
163
164                                         f = new Format(CommaSeparatedValue, XplatUI.ClipboardGetID(cliphandle, CommaSeparatedValue), f);
165                                         f = new Format(Html, XplatUI.ClipboardGetID(cliphandle, Html), f);
166                                         f = new Format(Rtf, XplatUI.ClipboardGetID(cliphandle, Rtf), f);
167                                         f = new Format(Serializable, XplatUI.ClipboardGetID(cliphandle, Serializable), f);
168                                         f = new Format(StringFormat, XplatUI.ClipboardGetID(cliphandle, StringFormat), f);
169
170                                         XplatUI.ClipboardClose(cliphandle);
171                                         
172                                 }
173                                 initialized = true;
174                         }
175                 }
176                 #endregion      // Private Methods
177         }
178 }