* TabControl.cs: Show the tooltip depending on the value
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / X11Clipboard.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) 2009 Novell, Inc.
21 //
22 // Authors:
23 //      Carlos Alberto Cortez (calberto.cortez@gmail.com)
24 //
25
26 using System;
27 using System.Drawing;
28 using System.Collections;
29 using System.Collections.Specialized;
30
31 namespace System.Windows.Forms {
32
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
37
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;
43
44                 public ClipboardData ()
45                 {
46                         source_data = new ListDictionary ();
47                 }
48
49                 public void ClearSources ()
50                 {
51                         source_data.Clear ();
52                         plain_text_source = null;
53                         image_source = null;
54                 }
55
56                 public void AddSource (int type, object source)
57                 {
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;
64
65                         source_data [type] = source;
66                 }
67
68                 public object GetSource (int type)
69                 {
70                         return source_data [type];
71                 }
72
73                 public string GetPlainText ()
74                 {
75                         return plain_text_source;
76                 }
77
78                 public string GetRtfText ()
79                 {
80                         DataFormats.Format format = DataFormats.GetFormat (DataFormats.Rtf);
81                         if (format == null)
82                                 return null; // FIXME - is RTF not supported on any system?
83
84                         return (string)GetSource (format.Id);
85                 }
86
87                 public Image GetImage ()
88                 {
89                         return image_source;
90                 }
91
92                 public bool IsSourceText {
93                         get {
94                                 return plain_text_source != null;
95                         }
96                 }
97
98                 public bool IsSourceImage {
99                         get {
100                                 return image_source != null;
101                         }
102                 }
103         }
104 }
105