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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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) 2009 Novell, Inc.
23 // Carlos Alberto Cortez (calberto.cortez@gmail.com)
28 using System.Collections;
29 using System.Collections.Specialized;
31 namespace System.Windows.Forms {
33 internal class ClipboardData {
34 ListDictionary source_data; // Source in its different formats, if any
35 string plain_text_source; // Cached source as plain-text string
36 Image image_source; // Cached source as image
38 internal object Item; // Object on the clipboard
39 internal ArrayList Formats; // list of formats available in the clipboard
40 internal bool Retrieving; // true if we are requesting an item
41 internal bool Enumerating; // true if we are enumerating through all known types
42 internal XplatUI.ObjectToClipboard Converter;
44 public ClipboardData ()
46 source_data = new ListDictionary ();
49 public void ClearSources ()
52 plain_text_source = null;
56 public void AddSource (int type, object source)
58 // Try to detect plain text, based on the old behaviour of XplatUIX11, which usually assigns
59 // -1 as the type when a string is stored in the Clipboard
60 if (source is string && (type == DataFormats.GetFormat (DataFormats.Text).Id || type == -1))
61 plain_text_source = source as string;
62 else if (source is Image)
63 image_source = source as Image;
65 source_data [type] = source;
68 public object GetSource (int type)
70 return source_data [type];
73 public string GetPlainText ()
75 return plain_text_source;
78 public string GetRtfText ()
80 DataFormats.Format format = DataFormats.GetFormat (DataFormats.Rtf);
82 return null; // FIXME - is RTF not supported on any system?
84 return (string)GetSource (format.Id);
87 public Image GetImage ()
92 public bool IsSourceText {
94 return plain_text_source != null;
98 public bool IsSourceImage {
100 return image_source != null;