1 #![allow(dead_code)]
2 //! Standard clipboard formats.
3 //!
4 //! Header: Winuser.h
5 //!
6 //! Description is taken from [Standard Clipboard Formats](https://msdn.microsoft.com/en-us/library/windows/desktop/ff729168%28v=vs.85%29.aspx)
7 
8 use crate::{SysResult, Getter, Setter};
9 
10 use winapi::um::winuser;
11 
12 ///A handle to a bitmap (HBITMAP).
13 pub const CF_BITMAP: u32 = winuser::CF_BITMAP;
14 ///A memory object containing a <b>BITMAPINFO</b> structure followed by the bitmap bits.
15 pub const CF_DIB: u32 = winuser::CF_DIB;
16 ///A memory object containing a <b>BITMAPV5HEADER</b> structure followed by the bitmap color space
17 ///information and the bitmap bits.
18 pub const CF_DIBV5: u32 = winuser::CF_DIBV5;
19 ///Software Arts' Data Interchange Format.
20 pub const CF_DIF: u32 = winuser::CF_DIF;
21 ///Bitmap display format associated with a private format. The hMem parameter must be a handle to
22 ///data that can be displayed in bitmap format in lieu of the privately formatted data.
23 pub const CF_DSPBITMAP: u32 = winuser::CF_DSPBITMAP;
24 ///Enhanced metafile display format associated with a private format. The *hMem* parameter must be a
25 ///handle to data that can be displayed in enhanced metafile format in lieu of the privately
26 ///formatted data.
27 pub const CF_DSPENHMETAFILE: u32 = winuser::CF_DSPENHMETAFILE;
28 ///Metafile-picture display format associated with a private format. The hMem parameter must be a
29 ///handle to data that can be displayed in metafile-picture format in lieu of the privately
30 ///formatted data.
31 pub const CF_DSPMETAFILEPICT: u32 = winuser::CF_DSPMETAFILEPICT;
32 ///Text display format associated with a private format. The *hMem* parameter must be a handle to
33 ///data that can be displayed in text format in lieu of the privately formatted data.
34 pub const CF_DSPTEXT: u32 = winuser::CF_DSPTEXT;
35 ///A handle to an enhanced metafile (<b>HENHMETAFILE</b>).
36 pub const CF_ENHMETAFILE: u32 = winuser::CF_ENHMETAFILE;
37 ///Start of a range of integer values for application-defined GDI object clipboard formats.
38 pub const CF_GDIOBJFIRST: u32 = winuser::CF_GDIOBJFIRST;
39 ///End of a range of integer values for application-defined GDI object clipboard formats.
40 pub const CF_GDIOBJLAST: u32 = winuser::CF_GDIOBJLAST;
41 ///A handle to type <b>HDROP</b> that identifies a list of files.
42 pub const CF_HDROP: u32 = winuser::CF_HDROP;
43 ///The data is a handle to the locale identifier associated with text in the clipboard.
44 ///
45 ///For details see [Standart Clipboard Formats](https://msdn.microsoft.com/en-us/library/windows/desktop/ff729168%28v=vs.85%29.aspx)
46 pub const CF_LOCALE: u32 = winuser::CF_LOCALE;
47 ///Handle to a metafile picture format as defined by the <b>METAFILEPICT</b> structure.
48 pub const CF_METAFILEPICT: u32 = winuser::CF_METAFILEPICT;
49 ///Text format containing characters in the OEM character set.
50 pub const CF_OEMTEXT: u32 = winuser::CF_OEMTEXT;
51 ///Owner-display format.
52 ///
53 ///For details see [Standart Clipboard Formats](https://msdn.microsoft.com/en-us/library/windows/desktop/ff729168%28v=vs.85%29.aspx)
54 pub const CF_OWNERDISPLAY: u32 = winuser::CF_OWNERDISPLAY;
55 ///Handle to a color palette.
56 ///
57 ///For details see [Standart Clipboard Formats](https://msdn.microsoft.com/en-us/library/windows/desktop/ff729168%28v=vs.85%29.aspx)
58 pub const CF_PALETTE: u32 = winuser::CF_PALETTE;
59 ///Data for the pen extensions to the Microsoft Windows for Pen Computing.
60 pub const CF_PENDATA: u32 = winuser::CF_PENDATA;
61 ///Start of a range of integer values for private clipboard formats.
62 pub const CF_PRIVATEFIRST: u32 = winuser::CF_PRIVATEFIRST;
63 ///End of a range of integer values for private clipboard formats.
64 pub const CF_PRIVATELAST: u32 = winuser::CF_PRIVATELAST;
65 ///Represents audio data more complex than can be represented in a ```CF_WAVE``` standard wave format.
66 pub const CF_RIFF: u32 = winuser::CF_RIFF;
67 ///Microsoft Symbolic Link (SYLK) format.
68 pub const CF_SYLK: u32 = winuser::CF_SYLK;
69 ///ANSI text format.
70 pub const CF_TEXT: u32 = winuser::CF_TEXT;
71 ///Tagged-image file format.
72 pub const CF_TIFF: u32 = winuser::CF_TIFF;
73 ///UTF16 text format.
74 pub const CF_UNICODETEXT: u32 = winuser::CF_UNICODETEXT;
75 ///Represents audio data in one of the standard wave formats.
76 pub const CF_WAVE: u32 = winuser::CF_WAVE;
77 
78 ///Format to write/read from clipboard as raw bytes
79 ///
80 ///Has to be initialized with format `id`
81 pub struct RawData(pub u32);
82 
83 impl<T: AsRef<[u8]>> Setter<T> for RawData {
84     #[inline(always)]
85     fn write_clipboard(&self, data: &T) -> SysResult<()> {
86         crate::raw::set(self.0, data.as_ref())
87     }
88 }
89 
90 impl Getter<alloc::vec::Vec<u8>> for RawData {
91     #[inline(always)]
92     fn read_clipboard(&self, out: &mut alloc::vec::Vec<u8>) -> SysResult<usize> {
93         crate::raw::get_vec(self.0, out)
94     }
95 }
96 
97 ///Format to read/write unicode string.
98 ///
99 ///Refer to `Getter` and `Setter`
100 pub struct Unicode;
101 
102 impl Getter<alloc::vec::Vec<u8>> for Unicode {
103     #[inline(always)]
104     fn read_clipboard(&self, out: &mut alloc::vec::Vec<u8>) -> SysResult<usize> {
105         crate::raw::get_string(out)
106     }
107 }
108 
109 impl Getter<alloc::string::String> for Unicode {
110     #[inline(always)]
111     fn read_clipboard(&self, out: &mut alloc::string::String) -> SysResult<usize> {
112         self.read_clipboard(unsafe { out.as_mut_vec() })
113     }
114 }
115 
116 impl<T: AsRef<str>> Setter<T> for Unicode {
117     #[inline(always)]
118     fn write_clipboard(&self, data: &T) -> SysResult<()> {
119         crate::raw::set_string(data.as_ref())
120     }
121 }
122 
123 ///Format for file lists (generated by drag & drop).
124 ///
125 ///Corresponds to `CF_HDROP`
126 ///
127 ///`read_clipboard` returns number of file names
128 pub struct FileList;
129 
130 impl Getter<alloc::vec::Vec<alloc::string::String>> for FileList {
131     #[inline(always)]
132     fn read_clipboard(&self, out: &mut alloc::vec::Vec<alloc::string::String>) -> SysResult<usize> {
133         crate::raw::get_file_list(out)
134     }
135 }
136 
137 ///Format for bitmap images i.e. `CF_BITMAP`.
138 ///
139 ///Both `Getter` and `Setter` expects image as header and rgb payload
140 pub struct Bitmap;
141 
142 impl Getter<alloc::vec::Vec<u8>> for Bitmap {
143     #[inline(always)]
144     fn read_clipboard(&self, out: &mut alloc::vec::Vec<u8>) -> SysResult<usize> {
145         crate::raw::get_bitmap(out)
146     }
147 }
148 
149 impl<T: AsRef<[u8]>> Setter<T> for Bitmap {
150     #[inline(always)]
151     fn write_clipboard(&self, data: &T) -> SysResult<()> {
152         crate::raw::set_bitmap(data.as_ref())
153     }
154 }
155