* TextBoxBase.cs: Take HideSelection into account when
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataFormats.cs
blob4a91ed0295ab955c2c7b9f6eeba52b6538869e58
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.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
22 // Authors:
23 // Peter Bartok (pbartok@novell.com)
27 // COMPLETE
29 using System;
30 using System.Collections;
31 using System.Text;
33 namespace System.Windows.Forms {
34 public class DataFormats {
35 public class Format {
36 static readonly object lockobj = new object ();
38 private static Format formats;
39 private string name;
40 private int id;
41 private Format next;
43 public Format (string name, int ID)
45 this.name = name;
46 this.id = ID;
48 lock (lockobj) {
49 if (formats == null)
50 formats = this;
51 else {
52 Format f = formats;
53 while (f.next != null)
54 f = f.next;
55 f.next = this;
60 #region Public Instance Properties
61 public int Id {
62 get {
63 return this.id;
67 public string Name {
68 get {
69 return this.name;
73 internal Format Next {
74 get {
75 return this.next;
78 #endregion // Public Instance Properties
80 #region Private Methods
81 internal static Format Add(string name) {
82 Format f;
84 f = Find(name);
85 if (f == null) {
86 IntPtr cliphandle;
88 cliphandle = XplatUI.ClipboardOpen(false);
89 f = new Format(name, XplatUI.ClipboardGetID(cliphandle, name));
90 XplatUI.ClipboardClose(cliphandle);
92 return f;
95 internal static Format Add(int id) {
96 Format f;
98 f = Find(id);
99 if (f == null) {
100 f = new Format("Format"+id.ToString(), id);
102 return f;
105 internal static Format Find(int id) {
106 Format f;
108 f = formats;
109 while ((f != null) && (f.Id != id)) {
110 f = f.next;
112 return f;
115 internal static Format Find(string name) {
116 Format f;
118 f = formats;
119 while ((f != null) && (!f.Name.Equals(name))) {
120 f = f.next;
122 return f;
125 internal static Format List {
126 get {
127 return formats;
130 #endregion // Private Methods
134 private DataFormats () {}
136 #region Public Static Fields
137 public static readonly string Bitmap = "Bitmap";
138 public static readonly string CommaSeparatedValue = "Csv";
139 public static readonly string Dib = "DeviceIndependentBitmap";
140 public static readonly string Dif = "DataInterchangeFormat";
141 public static readonly string EnhancedMetafile = "EnhancedMetafile";
142 public static readonly string FileDrop = "FileDrop";
143 public static readonly string Html = "HTML Format";
144 public static readonly string Locale = "Locale";
145 public static readonly string MetafilePict = "MetaFilePict";
146 public static readonly string OemText = "OEMText";
147 public static readonly string Palette = "Palette";
148 public static readonly string PenData = "PenData";
149 public static readonly string Riff = "RiffAudio";
150 public static readonly string Rtf = "Rich Text Format";
151 public static readonly string Serializable = "WindowsForms10PersistentObject";
152 public static readonly string StringFormat = "System.String";
153 public static readonly string SymbolicLink = "SymbolicLink";
154 public static readonly string Text = "Text";
155 public static readonly string Tiff = "Tiff";
156 public static readonly string UnicodeText = "UnicodeText";
157 public static readonly string WaveAudio = "WaveAudio";
158 #endregion // Public Static Fields
160 private static object lock_object = new object ();
161 private static bool initialized;
163 public static Format GetFormat (int ID)
165 lock (lock_object) {
166 if (!initialized)
167 Init ();
168 return Format.Find (ID);
172 public static Format GetFormat (string format)
174 lock (lock_object) {
175 if (!initialized)
176 Init ();
177 return Format.Add (format);
181 // Assumes we are locked on the lock_object when it is called
182 private static void Init ()
184 if (initialized)
185 return;
186 IntPtr cliphandle = XplatUI.ClipboardOpen(false);
188 new Format (Text, XplatUI.ClipboardGetID (cliphandle, Text));
189 new Format (Bitmap, XplatUI.ClipboardGetID (cliphandle, Bitmap));
190 new Format (MetafilePict, XplatUI.ClipboardGetID (cliphandle, MetafilePict));
191 new Format (SymbolicLink, XplatUI.ClipboardGetID (cliphandle, SymbolicLink));
192 new Format (Dif, XplatUI.ClipboardGetID (cliphandle, Dif)) ;
193 new Format (Tiff, XplatUI.ClipboardGetID (cliphandle, Tiff));
194 new Format (OemText, XplatUI.ClipboardGetID (cliphandle, OemText));
195 new Format (Dib, XplatUI.ClipboardGetID (cliphandle, Dib));
196 new Format (Palette, XplatUI.ClipboardGetID (cliphandle, Palette));
197 new Format (PenData, XplatUI.ClipboardGetID (cliphandle, PenData));
198 new Format (Riff, XplatUI.ClipboardGetID (cliphandle, Riff));
199 new Format (WaveAudio, XplatUI.ClipboardGetID (cliphandle, WaveAudio));
200 new Format (UnicodeText, XplatUI.ClipboardGetID (cliphandle, UnicodeText));
201 new Format (EnhancedMetafile, XplatUI.ClipboardGetID (cliphandle, EnhancedMetafile));
202 new Format (FileDrop, XplatUI.ClipboardGetID (cliphandle, FileDrop));
203 new Format (Locale, XplatUI.ClipboardGetID (cliphandle, Locale));
204 new Format (CommaSeparatedValue, XplatUI.ClipboardGetID (cliphandle, CommaSeparatedValue));
205 new Format (Html, XplatUI.ClipboardGetID (cliphandle, Html));
206 new Format (Rtf, XplatUI.ClipboardGetID (cliphandle, Rtf));
207 new Format (Serializable, XplatUI.ClipboardGetID (cliphandle, Serializable));
208 new Format (StringFormat, XplatUI.ClipboardGetID (cliphandle, StringFormat));
210 XplatUI.ClipboardClose (cliphandle);
212 initialized = true;