1#![allow(dead_code)]
2use crate::{SysResult, Getter, Setter};
9use crate::types::c_uint;
10
11use core::num::NonZeroU32;
12
13pub trait Format {
15 fn is_format_avail(&self) -> bool;
17}
18
19macro_rules! impl_format {
20 ($($format:ident),+) => {
21 $(
22 impl From<$format> for u32 {
23 #[inline(always)]
24 fn from(value: $format) -> Self {
25 (&value).into()
26 }
27 }
28
29 impl Format for $format {
30 #[inline(always)]
31 fn is_format_avail(&self) -> bool {
32 crate::raw::is_format_avail(self.into())
33 }
34 }
35 )+
36
37 };
38}
39
40pub const CF_BITMAP: c_uint = 2;
42pub const CF_DIB: c_uint = 8;
44pub const CF_DIBV5: c_uint = 17;
47pub const CF_DIF: c_uint = 5;
49pub const CF_DSPBITMAP: c_uint = 0x0082;
52pub const CF_DSPENHMETAFILE: c_uint = 0x008E;
56pub const CF_DSPMETAFILEPICT: c_uint = 0x0083;
60pub const CF_DSPTEXT: c_uint = 0x0081;
63pub const CF_ENHMETAFILE: c_uint = 14;
65pub const CF_GDIOBJFIRST: c_uint = 0x0300;
67pub const CF_GDIOBJLAST: c_uint = 0x03FF;
69pub const CF_HDROP: c_uint = 15;
71pub const CF_LOCALE: c_uint = 16;
75pub const CF_METAFILEPICT: c_uint = 3;
77pub const CF_OEMTEXT: c_uint = 7;
79pub const CF_OWNERDISPLAY: c_uint = 0x0080;
83pub const CF_PALETTE: c_uint = 9;
87pub const CF_PENDATA: c_uint = 10;
89pub const CF_PRIVATEFIRST: c_uint = 0x0200;
91pub const CF_PRIVATELAST: c_uint = 0x02FF;
93pub const CF_RIFF: c_uint = 11;
95pub const CF_SYLK: c_uint = 4;
97pub const CF_TEXT: c_uint = 1;
99pub const CF_TIFF: c_uint = 6;
101pub const CF_UNICODETEXT: c_uint = 13;
103pub const CF_WAVE: c_uint = 12;
105
106#[derive(Copy, Clone)]
107pub struct RawData(pub c_uint);
111
112impl<T: AsRef<[u8]>> Setter<T> for RawData {
113 #[inline(always)]
114 fn write_clipboard(&self, data: &T) -> SysResult<()> {
115 crate::raw::set(self.0, data.as_ref())
116 }
117}
118
119impl Getter<alloc::vec::Vec<u8>> for RawData {
120 #[inline(always)]
121 fn read_clipboard(&self, out: &mut alloc::vec::Vec<u8>) -> SysResult<usize> {
122 crate::raw::get_vec(self.0, out)
123 }
124}
125
126impl From<&RawData> for u32 {
127 #[inline(always)]
128 fn from(value: &RawData) -> Self {
129 value.0 as _
130 }
131}
132
133#[derive(Copy, Clone)]
134pub struct Unicode;
138
139impl Getter<alloc::vec::Vec<u8>> for Unicode {
140 #[inline(always)]
141 fn read_clipboard(&self, out: &mut alloc::vec::Vec<u8>) -> SysResult<usize> {
142 crate::raw::get_string(out)
143 }
144}
145
146impl Getter<alloc::string::String> for Unicode {
147 #[inline(always)]
148 fn read_clipboard(&self, out: &mut alloc::string::String) -> SysResult<usize> {
149 self.read_clipboard(unsafe { out.as_mut_vec() })
150 }
151}
152
153impl<T: AsRef<str>> Setter<T> for Unicode {
154 #[inline(always)]
155 fn write_clipboard(&self, data: &T) -> SysResult<()> {
156 crate::raw::set_string(data.as_ref())
157 }
158}
159
160impl From<&Unicode> for u32 {
161 #[inline(always)]
162 fn from(_: &Unicode) -> Self {
163 CF_UNICODETEXT
164 }
165}
166
167#[derive(Copy, Clone)]
168pub struct FileList;
174
175impl Getter<alloc::vec::Vec<alloc::string::String>> for FileList {
176 #[inline(always)]
177 fn read_clipboard(&self, out: &mut alloc::vec::Vec<alloc::string::String>) -> SysResult<usize> {
178 crate::raw::get_file_list(out)
179 }
180}
181
182#[cfg(feature = "std")]
183impl Getter<alloc::vec::Vec<std::path::PathBuf>> for FileList {
184 #[inline(always)]
185 fn read_clipboard(&self, out: &mut alloc::vec::Vec<std::path::PathBuf>) -> SysResult<usize> {
186 crate::raw::get_file_list_path(out)
187 }
188}
189
190impl<T: AsRef<str>> Setter<[T]> for FileList {
191 #[inline(always)]
192 fn write_clipboard(&self, data: &[T]) -> SysResult<()> {
193 crate::raw::set_file_list(data)
194 }
195}
196
197impl From<&FileList> for u32 {
198 #[inline(always)]
199 fn from(_: &FileList) -> Self {
200 CF_HDROP
201 }
202}
203
204#[derive(Copy, Clone)]
205pub struct Bitmap;
209
210impl Getter<alloc::vec::Vec<u8>> for Bitmap {
211 #[inline(always)]
212 fn read_clipboard(&self, out: &mut alloc::vec::Vec<u8>) -> SysResult<usize> {
213 crate::raw::get_bitmap(out)
214 }
215}
216
217impl<T: AsRef<[u8]>> Setter<T> for Bitmap {
218 #[inline(always)]
219 fn write_clipboard(&self, data: &T) -> SysResult<()> {
220 crate::raw::set_bitmap(data.as_ref())
221 }
222}
223
224impl From<&Bitmap> for u32 {
225 #[inline(always)]
226 fn from(_: &Bitmap) -> Self {
227 CF_BITMAP
228 }
229}
230
231#[derive(Copy, Clone)]
232pub struct Html(NonZeroU32);
236
237impl Html {
238 #[inline(always)]
239 pub fn new() -> Option<Self> {
241 const NAME: [u16; 12] = [72, 84, 77, 76, 32, 70, 111, 114, 109, 97, 116, 0];
243 unsafe {
244 crate::raw::register_raw_format(&NAME).map(Self)
245 }
246 }
247
248 #[inline(always)]
249 pub fn code(&self) -> u32 {
251 self.0.get()
252 }
253}
254
255impl Getter<alloc::vec::Vec<u8>> for Html {
256 #[inline(always)]
257 fn read_clipboard(&self, out: &mut alloc::vec::Vec<u8>) -> SysResult<usize> {
258 crate::raw::get_html(self.0.get(), out)
259 }
260}
261
262impl Getter<alloc::string::String> for Html {
263 #[inline(always)]
264 fn read_clipboard(&self, out: &mut alloc::string::String) -> SysResult<usize> {
265 crate::raw::get_html(self.0.get(), unsafe { out.as_mut_vec() })
266 }
267}
268
269impl<T: AsRef<str>> Setter<T> for Html {
270 #[inline(always)]
271 fn write_clipboard(&self, data: &T) -> SysResult<()> {
272 crate::raw::set_html(self.code(), data.as_ref())
273 }
274}
275
276impl From<&Html> for u32 {
277 #[inline(always)]
278 fn from(value: &Html) -> Self {
279 value.code()
280 }
281}
282
283impl_format!(Html, Bitmap, RawData, Unicode, FileList);